mirror of
https://github.com/logos-storage/logos-storage-nim-validator.git
synced 2026-01-10 09:23:09 +00:00
25 lines
852 B
Nim
25 lines
852 B
Nim
|
|
import std/unittest
|
||
|
|
import codexvalidator/basics
|
||
|
|
import codexvalidator/signatures
|
||
|
|
import codexvalidator/transaction
|
||
|
|
import ../examples
|
||
|
|
|
||
|
|
suite "Transaction signing":
|
||
|
|
|
||
|
|
test "transactions can be signed":
|
||
|
|
let identity = Identity.example
|
||
|
|
let transaction = Transaction.example
|
||
|
|
let signed = identity.sign(transaction)
|
||
|
|
check signed.transaction == transaction
|
||
|
|
check signed.signer == identity.identifier
|
||
|
|
check signed.signature == identity.sign(transaction.toBytes())
|
||
|
|
|
||
|
|
test "transaction signature can be verified":
|
||
|
|
let identity = Identity.example
|
||
|
|
let transaction = Transaction.example
|
||
|
|
let signed = identity.sign(transaction)
|
||
|
|
check signed.verifySignature()
|
||
|
|
let forger = Identity.example.identifier
|
||
|
|
let forged = SignedTransaction.init(transaction, forger, signed.signature)
|
||
|
|
check not forged.verifySignature()
|