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

Function TestCheckBlock

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

Source from the content-addressed store, hash-verified

336}
337
338func TestCheckBlock(t *testing.T) {
339 // predefine a valid block header
340 validBlock := Block{BlockHeader: &BlockHeader{
341 ProposerAddress: newTestAddressBytes(t),
342 StateRoot: crypto.Hash([]byte("hash")),
343 TransactionRoot: crypto.Hash([]byte("hash")),
344 ValidatorRoot: crypto.Hash([]byte("hash")),
345 NextValidatorRoot: crypto.Hash([]byte("hash")),
346 LastBlockHash: crypto.Hash([]byte("hash")),
347 LastQuorumCertificate: &QuorumCertificate{
348 Header: &View{
349 NetworkId: 1,
350 },
351 ResultsHash: crypto.Hash([]byte("hash")),
352 BlockHash: crypto.Hash([]byte("hash")),
353 ProposerKey: newTestAddressBytes(t),
354 Signature: &AggregateSignature{
355 Signature: bytes.Repeat([]byte("F"), 96),
356 Bitmap: []byte("some_bitmap"),
357 },
358 },
359 NetworkId: 1,
360 Time: uint64(1731418066000000),
361 }}
362 // set the block hash
363 _, e := validBlock.Hash()
364 require.NoError(t, e)
365 // define test cases
366 tests := []struct {
367 name string
368 detail string
369 block *Block
370 error string
371 }{
372 {
373 name: "nil block",
374 detail: "nil / empty block",
375 block: nil,
376 error: "block is nil",
377 },
378 {
379 name: "nil block header",
380 detail: "nil / empty block header",
381 block: &Block{
382 BlockHeader: nil,
383 },
384 error: "block.header is nil",
385 },
386 {
387 name: "valid block",
388 detail: "testing the happy path 'valid block'",
389 block: &validBlock,
390 },
391 }
392 for _, test := range tests {
393 t.Run(test.name, func(t *testing.T) {
394 // execute the function call
395 err := test.block.Check(uint64(validBlock.BlockHeader.NetworkId), 0)

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected