mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 17:22:18 +00:00
a069738c20
* update shared/params * update eth2-types deps * update protobufs * update shared/* * fix testutil/state * update beacon-chain/state * update beacon-chain/db * update tests * fix test * update beacon-chain/core * update beacon-chain/blockchain * update beacon-chain/cache * beacon-chain/forkchoice * update beacon-chain/operations * update beacon-chain/p2p * update beacon-chain/rpc * update sync/initial-sync * update deps * update deps * go fmt * update beacon-chain/sync * update endtoend/ * bazel build //beacon-chain - works w/o issues * update slasher code * udpate tools/ * update validator/ * update fastssz * fix build * fix test building * update tests * update ethereumapis deps * fix tests * update state/stategen * fix build * fix test * add FarFutureSlot * go imports * Radek's suggestions * Ivan's suggestions * type conversions * Nishant's suggestions * add more tests to rpc_send_request * fix test * clean up * fix conflicts Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: nisdas <nishdas93@gmail.com>
186 lines
4.1 KiB
Go
186 lines
4.1 KiB
Go
package beacon
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestInfostream_EpochToTimestamp(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
params.OverrideBeaconConfig(params.MainnetConfig())
|
|
tests := []struct {
|
|
name string
|
|
epoch types.Epoch
|
|
timestamp uint64
|
|
}{
|
|
{
|
|
name: "Genesis",
|
|
epoch: 0,
|
|
timestamp: 0,
|
|
},
|
|
{
|
|
name: "One",
|
|
epoch: 1,
|
|
timestamp: 384,
|
|
},
|
|
{
|
|
name: "Two",
|
|
epoch: 2,
|
|
timestamp: 768,
|
|
},
|
|
{
|
|
name: "OneHundred",
|
|
epoch: 100,
|
|
timestamp: 38400,
|
|
},
|
|
}
|
|
|
|
is := &infostream{}
|
|
for _, test := range tests {
|
|
timestamp := is.epochToTimestamp(test.epoch)
|
|
assert.Equal(t, test.timestamp, timestamp, "Incorrect timestamp")
|
|
}
|
|
}
|
|
|
|
func TestInfostream_HandleSetValidatorKeys(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
params.OverrideBeaconConfig(params.MainnetConfig())
|
|
tests := []struct {
|
|
name string
|
|
reqPubKeys [][]byte
|
|
}{
|
|
{
|
|
name: "None",
|
|
},
|
|
{
|
|
name: "One",
|
|
reqPubKeys: [][]byte{{0x01}},
|
|
},
|
|
{
|
|
name: "Two",
|
|
reqPubKeys: [][]byte{{0x01}, {0x02}},
|
|
},
|
|
}
|
|
|
|
s, err := testutil.NewBeaconState()
|
|
require.NoError(t, err)
|
|
|
|
is := &infostream{
|
|
pubKeysMutex: &sync.RWMutex{},
|
|
pubKeys: make([][]byte, 0),
|
|
headFetcher: &mock.ChainService{
|
|
State: s,
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
assert.NoError(t, is.handleSetValidatorKeys(test.reqPubKeys))
|
|
assert.Equal(t, len(test.reqPubKeys), len(is.pubKeys), "Incorrect number of keys")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestInfostream_HandleAddValidatorKeys(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
params.OverrideBeaconConfig(params.MainnetConfig())
|
|
tests := []struct {
|
|
name string
|
|
initialPubKeys [][]byte
|
|
reqPubKeys [][]byte
|
|
finalLen int
|
|
}{
|
|
{
|
|
name: "None",
|
|
finalLen: 0,
|
|
},
|
|
{
|
|
name: "NoneAddOne",
|
|
reqPubKeys: [][]byte{{0x01}},
|
|
finalLen: 1,
|
|
},
|
|
{
|
|
name: "OneAddOne",
|
|
initialPubKeys: [][]byte{{0x01}},
|
|
reqPubKeys: [][]byte{{0x02}},
|
|
finalLen: 2,
|
|
},
|
|
{
|
|
name: "Duplicate",
|
|
initialPubKeys: [][]byte{{0x01}},
|
|
reqPubKeys: [][]byte{{0x01}},
|
|
finalLen: 1,
|
|
},
|
|
}
|
|
|
|
s, err := testutil.NewBeaconState()
|
|
require.NoError(t, err)
|
|
is := &infostream{
|
|
pubKeysMutex: &sync.RWMutex{},
|
|
pubKeys: make([][]byte, 0),
|
|
headFetcher: &mock.ChainService{
|
|
State: s,
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
assert.NoError(t, is.handleSetValidatorKeys(test.initialPubKeys))
|
|
assert.NoError(t, is.handleAddValidatorKeys(test.reqPubKeys))
|
|
assert.Equal(t, test.finalLen, len(is.pubKeys), "Incorrect number of keys")
|
|
}
|
|
}
|
|
|
|
func TestInfostream_HandleRemoveValidatorKeys(t *testing.T) {
|
|
params.SetupTestConfigCleanup(t)
|
|
params.OverrideBeaconConfig(params.MainnetConfig())
|
|
tests := []struct {
|
|
name string
|
|
initialPubKeys [][]byte
|
|
reqPubKeys [][]byte
|
|
finalLen int
|
|
}{
|
|
{
|
|
name: "None",
|
|
finalLen: 0,
|
|
},
|
|
{
|
|
name: "OneRemoveNone",
|
|
initialPubKeys: [][]byte{{0x01}},
|
|
finalLen: 1,
|
|
},
|
|
{
|
|
name: "NoneRemoveOne",
|
|
initialPubKeys: [][]byte{},
|
|
reqPubKeys: [][]byte{{0x01}},
|
|
finalLen: 0,
|
|
},
|
|
{
|
|
name: "TwoRemoveOne",
|
|
initialPubKeys: [][]byte{{0x01, 0x02}},
|
|
reqPubKeys: [][]byte{{0x01}},
|
|
finalLen: 1,
|
|
},
|
|
}
|
|
|
|
s, err := testutil.NewBeaconState()
|
|
require.NoError(t, err)
|
|
|
|
is := &infostream{
|
|
pubKeysMutex: &sync.RWMutex{},
|
|
pubKeys: make([][]byte, 0),
|
|
headFetcher: &mock.ChainService{
|
|
State: s,
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
assert.NoError(t, is.handleSetValidatorKeys(test.initialPubKeys))
|
|
is.handleRemoveValidatorKeys(test.reqPubKeys)
|
|
assert.Equal(t, test.finalLen, len(is.pubKeys), "Incorrect number of keys")
|
|
}
|
|
}
|