nim-mysticeti/tests/mysticeti/testBlocks.nim

38 lines
1.2 KiB
Nim
Raw Normal View History

2024-10-07 14:29:52 +02:00
import ./basics
import mysticeti
import mysticeti/blocks
suite "Blocks":
type Block = mysticeti.Block[MockDependencies]
2024-12-09 11:14:39 +01:00
type BlockId = mysticeti.BlockId[MockDependencies.Hash]
2024-11-27 11:48:50 +01:00
type Identity = MockDependencies.Identity
2024-11-21 14:30:40 +01:00
type Transaction = MockDependencies.Transaction
2024-11-21 15:12:03 +01:00
type Hash = MockDependencies.Hash
type Serialization = MockDependencies.Serialization
2024-10-07 14:29:52 +02:00
test "blocks have an author, a round, parents and transactions":
let author = CommitteeMember.example
let round = uint64.example
let parents = seq[BlockId].example
let transactions = seq[Transaction].example
let blck = Block.new(author, round, parents, transactions)
check blck.author == author
check blck.round == round
check blck.parents == parents.immutable
check blck.transactions == transactions.immutable
2024-10-07 14:29:52 +02:00
test "blocks have an id consisting of author, round and hash":
let blck = Block.example
let id = blck.id
check id.author == blck.author
check id.round == blck.round
check id.hash == Hash.hash(Serialization.toBytes(blck))
2024-10-07 14:29:52 +02:00
test "blocks can be signed":
let signer = Identity.init
let blck = Block.example
2024-11-27 11:48:50 +01:00
let signed = blck.sign(signer)
2024-10-07 14:29:52 +02:00
check signed.blck == blck
check signed.signer == signer.identifier