MCPcopy
hub / github.com/canopy-network/canopy / TestCheckBlockHeader

Function TestCheckBlockHeader

lib/block_test.go:12–254  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestCheckBlockHeader(t *testing.T) {
13 // predefine a block in order to make a valid hash
14 validBlock := &BlockHeader{
15 ProposerAddress: newTestAddressBytes(t),
16 StateRoot: crypto.Hash([]byte("hash")),
17 TransactionRoot: crypto.Hash([]byte("hash")),
18 ValidatorRoot: crypto.Hash([]byte("hash")),
19 NextValidatorRoot: crypto.Hash([]byte("hash")),
20 LastBlockHash: crypto.Hash([]byte("hash")),
21 LastQuorumCertificate: &QuorumCertificate{
22 Header: &View{
23 NetworkId: 1,
24 },
25 ResultsHash: crypto.Hash([]byte("hash")),
26 BlockHash: crypto.Hash([]byte("hash")),
27 ProposerKey: newTestAddressBytes(t),
28 Signature: &AggregateSignature{
29 Signature: bytes.Repeat([]byte("F"), 96),
30 Bitmap: []byte("some_bitmap"),
31 },
32 },
33 NetworkId: 1,
34 Time: uint64(time.Now().UnixMicro()),
35 }
36 // set the block hash
37 _, e := validBlock.SetHash()
38 require.NoError(t, e)
39 tests := []struct {
40 name string
41 detail string
42 blockHeader *BlockHeader
43 networkId uint64
44 chainId uint64
45 error string
46 }{
47 {
48 name: "nil block header",
49 detail: "the block header is nil",
50 blockHeader: nil,
51 error: "block.header is nil",
52 },
53 {
54 name: "wrong proposer address size",
55 detail: "the proposer address should be of length 'address size'",
56 blockHeader: &BlockHeader{ProposerAddress: []byte("wrong_size")},
57 error: "block proposer address is invalid",
58 },
59 {
60 name: "wrong block hash size",
61 detail: "the block should be of length 'hash size'",
62 blockHeader: &BlockHeader{
63 ProposerAddress: newTestAddressBytes(t),
64 Hash: []byte("wrong_size"),
65 },
66 error: "wrong length block hash",
67 },
68 {
69 name: "wrong state root size",

Callers

nothing calls this directly

Calls 6

SetHashMethod · 0.95
HashFunction · 0.92
RunMethod · 0.80
EqualMethod · 0.80
newTestAddressBytesFunction · 0.70
CheckMethod · 0.65

Tested by

no test coverage detected