mirror of
https://github.com/luxfi/bft.git
synced 2026-10-30 17:01:54 +00:00
Modules declare go 1.27.1 and the build images follow. go fix applied the modernizers; omitzero is not applied, since it changes what the JSON says. Co-authored-by: Hanzo Dev <[email protected]>
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package common
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"crypto/sha256"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMetadata(t *testing.T) {
|
|
var prev Digest
|
|
var digest Digest
|
|
|
|
_, err := rand.Read(prev[:])
|
|
require.NoError(t, err)
|
|
|
|
_, err = rand.Read(digest[:])
|
|
require.NoError(t, err)
|
|
|
|
bh := BlockHeader{
|
|
Version: 1,
|
|
Round: 2,
|
|
Seq: 3,
|
|
Epoch: 4,
|
|
Prev: prev,
|
|
Digest: digest,
|
|
}
|
|
|
|
var bh2 BlockHeader
|
|
require.NoError(t, bh2.FromBytes(bh.Bytes()))
|
|
require.True(t, bh.Equals(&bh2))
|
|
}
|
|
|
|
func FuzzMetadata(f *testing.F) {
|
|
f.Fuzz(func(t *testing.T, version uint8, round uint64, seq uint64, epoch uint64, prevPreimage []byte, digestPreimage []byte) {
|
|
|
|
prev := sha256.Sum256(prevPreimage)
|
|
digest := sha256.Sum256(digestPreimage)
|
|
|
|
bh := BlockHeader{
|
|
Version: version,
|
|
Round: round,
|
|
Seq: seq,
|
|
Epoch: epoch,
|
|
Prev: prev,
|
|
Digest: digest,
|
|
}
|
|
|
|
var bh2 BlockHeader
|
|
require.NoError(t, bh2.FromBytes(bh.Bytes()))
|
|
require.True(t, bh.Equals(&bh2))
|
|
})
|
|
}
|