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

Function TestBlockJSON

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

Source from the content-addressed store, hash-verified

404}
405
406func TestBlockJSON(t *testing.T) {
407 // predefine a valid block header
408 validBlock := &Block{BlockHeader: &BlockHeader{
409 ProposerAddress: newTestAddressBytes(t),
410 StateRoot: crypto.Hash([]byte("hash")),
411 TransactionRoot: crypto.Hash([]byte("hash")),
412 ValidatorRoot: crypto.Hash([]byte("hash")),
413 NextValidatorRoot: crypto.Hash([]byte("hash")),
414 LastBlockHash: crypto.Hash([]byte("hash")),
415 LastQuorumCertificate: &QuorumCertificate{
416 Header: &View{
417 NetworkId: 1,
418 },
419 ResultsHash: crypto.Hash([]byte("hash")),
420 BlockHash: crypto.Hash([]byte("hash")),
421 ProposerKey: newTestAddressBytes(t),
422 Signature: &AggregateSignature{
423 Signature: bytes.Repeat([]byte("F"), 96),
424 Bitmap: []byte("some_bitmap"),
425 },
426 },
427 NetworkId: 1,
428 Time: uint64(1731418066000000),
429 }, Transactions: [][]byte{[]byte("abcdef")}}
430 // set the hash
431 _, err := validBlock.Hash()
432 require.NoError(t, err)
433 // convert to json bytes
434 jsonBytes, e := json.Marshal(validBlock)
435 require.NoError(t, e)
436 // define a new bh object
437 block := new(Block)
438 // unmarshal bytes into the block header object
439 require.NoError(t, json.Unmarshal(jsonBytes, block))
440 // hardcode time as we'll lose precision
441 block.BlockHeader.Time = validBlock.BlockHeader.Time
442 // ensure the new object is equal to the old
443 require.EqualExportedValues(t, validBlock, block)
444}
445
446func newTestAddress(t *testing.T, variation ...int) crypto.AddressI {
447 kg := newTestKeyGroup(t, variation...)

Callers

nothing calls this directly

Calls 5

HashMethod · 0.95
HashFunction · 0.92
newTestAddressBytesFunction · 0.70
MarshalMethod · 0.65
UnmarshalMethod · 0.65

Tested by

no test coverage detected