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

Function TestBlockHeaderJSON

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

Source from the content-addressed store, hash-verified

296}
297
298func TestBlockHeaderJSON(t *testing.T) {
299 // predefine a valid block header
300 validBlock := &BlockHeader{
301 ProposerAddress: newTestAddressBytes(t),
302 StateRoot: crypto.Hash([]byte("hash")),
303 TransactionRoot: crypto.Hash([]byte("hash")),
304 ValidatorRoot: crypto.Hash([]byte("hash")),
305 NextValidatorRoot: crypto.Hash([]byte("hash")),
306 LastBlockHash: crypto.Hash([]byte("hash")),
307 LastQuorumCertificate: &QuorumCertificate{
308 Header: &View{
309 NetworkId: 1,
310 },
311 ResultsHash: crypto.Hash([]byte("hash")),
312 BlockHash: crypto.Hash([]byte("hash")),
313 ProposerKey: newTestAddressBytes(t),
314 Signature: &AggregateSignature{
315 Signature: bytes.Repeat([]byte("F"), 96),
316 Bitmap: []byte("some_bitmap"),
317 },
318 },
319 NetworkId: 1,
320 Time: uint64(1731418066000000),
321 }
322 // set the hash
323 _, err := validBlock.SetHash()
324 require.NoError(t, err)
325 // convert to json bytes
326 jsonBytes, e := json.Marshal(validBlock)
327 require.NoError(t, e)
328 // define a new bh object
329 blockHeader := new(BlockHeader)
330 // unmarshal bytes into the block header object
331 require.NoError(t, json.Unmarshal(jsonBytes, blockHeader))
332 // hardcode time as we'll lose precision
333 blockHeader.Time = validBlock.Time
334 // ensure the new object is equal to the old
335 require.EqualExportedValues(t, validBlock, blockHeader)
336}
337
338func TestCheckBlock(t *testing.T) {
339 // predefine a valid block header

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected