43 lines
1.9 KiB
Nim
Raw Normal View History

2024-12-10 15:45:32 +01:00
import ../basics
2024-12-04 15:10:22 +01:00
import codexvalidator/transaction
2024-12-04 15:43:34 +01:00
import codexvalidator/transaction/serialization
2024-12-04 15:10:22 +01:00
2024-12-04 15:43:34 +01:00
suite "Transaction serialization":
2024-12-04 15:10:22 +01:00
test "serializes a transaction with protobuf":
let transaction = Transaction.example
let serialized = transaction.toBytes()
{.warning[Deprecated]: off.} # ignore warning in protobuf_serialization
let protobuf = ProtoBuf.decode(serialized, TransactionMessage)
{.warning[Deprecated]: on.}
check protobuf.version == transaction.version.uint32
check protobuf.kind == transaction.kind.uint32
check protobuf.requestId == array[32, byte](transaction.requestId)
check protobuf.slotIndex == transaction.slotIndex
check protobuf.period == transaction.period.uint64
check protobuf.merkleRoot == array[32, byte](transaction.merkleRoot)
check protobuf.challenge == array[32, byte](transaction.challenge)
2024-12-04 15:10:22 +01:00
test "serializes a storage proof with protobuf":
let proof = Groth16Proof.example
let transaction = Transaction.storageProof(
StorageRequestId.example,
uint32.example,
Period.example,
array[32, byte].example,
array[32, byte].example,
2024-12-04 15:10:22 +01:00
proof
)
let serialized = transaction.toBytes()
{.warning[Deprecated]: off.} # ignore warning in protobuf_serialization
let protobuf = ProtoBuf.decode(serialized, TransactionMessage)
{.warning[Deprecated]: on.}
check protobuf.proof.a.x == transaction.proof.a.x.toBytesBE()
check protobuf.proof.a.y == transaction.proof.a.y.toBytesBE()
check protobuf.proof.b.x.real == transaction.proof.b.x.real.toBytesBE()
check protobuf.proof.b.x.imag == transaction.proof.b.x.imag.toBytesBE()
check protobuf.proof.b.y.real == transaction.proof.b.y.real.toBytesBE()
check protobuf.proof.b.y.imag == transaction.proof.b.y.imag.toBytesBE()
check protobuf.proof.c.x == transaction.proof.c.x.toBytesBE()
check protobuf.proof.c.y == transaction.proof.c.y.toBytesBE()