mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
7842fd9da6
* beacon chain * format imports * Update beacon-chain/db/kv/migration_archived_index_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update beacon-chain/db/kv/migration_block_slot_index_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * remove unused imports * Update beacon-chain/core/state/skip_slot_cache_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update beacon-chain/core/state/skip_slot_cache_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update beacon-chain/core/state/skip_slot_cache_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update beacon-chain/core/state/skip_slot_cache_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update beacon-chain/db/kv/migration_archived_index_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> * Update beacon-chain/db/kv/migration_block_slot_index_test.go Co-authored-by: Victor Farazdagi <simple.square@gmail.com> Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
60 lines
1.5 KiB
Go
60 lines
1.5 KiB
Go
package stateutil
|
|
|
|
import (
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestAttestationDataRoot_EqualGeneric(t *testing.T) {
|
|
attData := ðpb.AttestationData{
|
|
Slot: 39,
|
|
CommitteeIndex: 2,
|
|
BeaconBlockRoot: bytesutil.PadTo([]byte("block root"), 32),
|
|
Source: ðpb.Checkpoint{
|
|
Root: bytesutil.PadTo([]byte("source root"), 32),
|
|
Epoch: 0,
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: bytesutil.PadTo([]byte("target root"), 32),
|
|
Epoch: 9,
|
|
},
|
|
}
|
|
genericHtr, err := attData.HashTreeRoot()
|
|
require.NoError(t, err)
|
|
dataHtr, err := AttestationDataRoot(attData)
|
|
require.NoError(t, err)
|
|
|
|
require.DeepEqual(t, genericHtr[:], dataHtr[:])
|
|
}
|
|
|
|
func BenchmarkAttestationDataRoot(b *testing.B) {
|
|
attData := ðpb.AttestationData{
|
|
Slot: 39,
|
|
CommitteeIndex: 2,
|
|
BeaconBlockRoot: bytesutil.PadTo([]byte("block root"), 32),
|
|
Source: ðpb.Checkpoint{
|
|
Root: bytesutil.PadTo([]byte("source root"), 32),
|
|
Epoch: 0,
|
|
},
|
|
Target: ðpb.Checkpoint{
|
|
Root: bytesutil.PadTo([]byte("target root"), 32),
|
|
Epoch: 9,
|
|
},
|
|
}
|
|
b.Run("generic", func(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := attData.HashTreeRoot()
|
|
require.NoError(b, err)
|
|
}
|
|
})
|
|
b.Run("stateutil", func(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := AttestationDataRoot(attData)
|
|
require.NoError(b, err)
|
|
}
|
|
})
|
|
}
|