2024-10-07 14:29:52 +02:00
|
|
|
import ./basics
|
|
|
|
|
import mysticeti
|
|
|
|
|
import mysticeti/blocks
|
|
|
|
|
|
|
|
|
|
suite "Blocks":
|
|
|
|
|
|
2024-11-06 13:45:37 +01:00
|
|
|
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
|
2024-11-20 15:51:34 +01:00
|
|
|
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
|
2024-11-25 15:47:01 +01:00
|
|
|
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
|
2024-11-20 15:51:34 +01:00
|
|
|
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
|