prysm-pulse/shared/htrutils/htrutils_test.go
Victor Farazdagi a8e501b3cf
ETH2 Types: Epoch (#8373)
* update deps

* update deps

* update protos/*

* update deps

* reset protos

* update protos

* update shared/params/config

* update protos

* update /shared

* update shared/slotutil and shared/testutil

* update beacon-chain/core/helpers

* updates beacon-chain/state

* update beacon-chain/forkchoice

* update beacon-chain/blockchain

* update beacon-chain/cache

* update beacon-chain/core

* update beacon-chain/db

* update beacon-chain/node

* update beacon-chain/p2p

* update beacon-chain/rpc

* update beacon-chain/sync

* go mod tidy

* make sure that beacon-chain build suceeds

* go fmt

* update e2e tests

* update slasher

* remove redundant alias

* update validator

* gazelle

* fix build errors in unit tests

* go fmt

* update deps

* update fuzz/BUILD.bazel

* fix unit tests

* more unit test fixes

* fix blockchain UTs

* more unit test fixes
2021-02-09 10:05:22 +00:00

65 lines
2.2 KiB
Go

package htrutils_test
import (
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/htrutils"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestUint64Root(t *testing.T) {
uintVal := uint64(1234567890)
expected := [32]byte{210, 2, 150, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
result := htrutils.Uint64Root(uintVal)
assert.Equal(t, expected, result)
}
func TestForkRoot(t *testing.T) {
testFork := pb.Fork{
PreviousVersion: []byte{123},
CurrentVersion: []byte{124},
Epoch: 1234567890,
}
expected := [32]byte{19, 46, 77, 103, 92, 175, 247, 33, 100, 64, 17, 111, 199, 145, 69, 38, 217, 112, 6, 16, 149, 201, 225, 144, 192, 228, 197, 172, 157, 78, 114, 140}
result, err := htrutils.ForkRoot(&testFork)
require.NoError(t, err)
assert.Equal(t, expected, result)
}
func TestCheckPointRoot(t *testing.T) {
testHasher := hashutil.CustomSHA256Hasher()
testCheckpoint := ethpb.Checkpoint{
Epoch: 1234567890,
Root: []byte{222},
}
expected := [32]byte{228, 65, 39, 109, 183, 249, 167, 232, 125, 239, 25, 155, 207, 4, 84, 174, 176, 229, 175, 224, 62, 33, 215, 254, 170, 220, 132, 65, 246, 128, 68, 194}
result, err := htrutils.CheckpointRoot(testHasher, &testCheckpoint)
require.NoError(t, err)
assert.Equal(t, expected, result)
}
func TestHistoricalRootsRoot(t *testing.T) {
testHistoricalRoots := [][]byte{{123}, {234}}
expected := [32]byte{70, 204, 150, 196, 89, 138, 190, 205, 65, 207, 120, 166, 179, 247, 147, 20, 29, 133, 117, 116, 151, 234, 129, 32, 22, 15, 79, 178, 98, 73, 132, 152}
result, err := htrutils.HistoricalRootsRoot(testHistoricalRoots)
require.NoError(t, err)
assert.Equal(t, expected, result)
}
func TestSlashingsRoot(t *testing.T) {
testSlashingsRoot := []uint64{123, 234}
expected := [32]byte{123, 0, 0, 0, 0, 0, 0, 0, 234, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
result, err := htrutils.SlashingsRoot(testSlashingsRoot)
require.NoError(t, err)
assert.Equal(t, expected, result)
}