(t *testing.T)
| 254 | } |
| 255 | |
| 256 | func TestSetHash(t *testing.T) { |
| 257 | // predefine a block in order to make a valid hash |
| 258 | validBlock := &BlockHeader{ |
| 259 | ProposerAddress: newTestAddressBytes(t), |
| 260 | StateRoot: crypto.Hash([]byte("hash")), |
| 261 | TransactionRoot: crypto.Hash([]byte("hash")), |
| 262 | ValidatorRoot: crypto.Hash([]byte("hash")), |
| 263 | NextValidatorRoot: crypto.Hash([]byte("hash")), |
| 264 | LastBlockHash: crypto.Hash([]byte("hash")), |
| 265 | LastQuorumCertificate: &QuorumCertificate{ |
| 266 | Header: &View{ |
| 267 | NetworkId: 1, |
| 268 | }, |
| 269 | ResultsHash: crypto.Hash([]byte("hash")), |
| 270 | BlockHash: crypto.Hash([]byte("hash")), |
| 271 | ProposerKey: newTestAddressBytes(t), |
| 272 | Signature: &AggregateSignature{ |
| 273 | Signature: bytes.Repeat([]byte("F"), 96), |
| 274 | Bitmap: []byte("some_bitmap"), |
| 275 | }, |
| 276 | }, |
| 277 | NetworkId: 1, |
| 278 | Time: uint64(time.Now().UnixMicro()), |
| 279 | } |
| 280 | // set the hash |
| 281 | gotHash, err := validBlock.SetHash() |
| 282 | // validate no error |
| 283 | require.NoError(t, err) |
| 284 | // validate hash was set |
| 285 | require.Equal(t, gotHash, validBlock.Hash) |
| 286 | // manually recompute hash |
| 287 | validBlock.Hash = nil |
| 288 | // get block bytes |
| 289 | bz, err := Marshal(validBlock) |
| 290 | // ensure no error |
| 291 | require.NoError(t, err) |
| 292 | // reset the hash |
| 293 | validBlock.Hash = crypto.Hash(bz) |
| 294 | // check got vs expected |
| 295 | require.Equal(t, gotHash, validBlock.Hash) |
| 296 | } |
| 297 | |
| 298 | func TestBlockHeaderJSON(t *testing.T) { |
| 299 | // predefine a valid block header |
nothing calls this directly
no test coverage detected