(t *testing.T)
| 404 | } |
| 405 | |
| 406 | func 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 | |
| 446 | func newTestAddress(t *testing.T, variation ...int) crypto.AddressI { |
| 447 | kg := newTestKeyGroup(t, variation...) |
nothing calls this directly
no test coverage detected