prysm-pulse/beacon-chain/state/v2/state_trie_test.go
Raul Jordan 2d10bcf179
Move State Protos Into V2 Namespace (#9257)
* move state protos

* regen ssz

* edit v1 code

* fix imports

* building

* beacon chain builds

* validator and shared builds

* fuzz builds

* changes

* spectest builds

* tools build

* remove import cycle

* generate ssz

* pcli

* gaz

* kafka

* gaz
2021-07-23 08:07:40 -05:00

85 lines
1.7 KiB
Go

package v2_test
import (
"testing"
stateAltair "github.com/prysmaticlabs/prysm/beacon-chain/state/v2"
statepb "github.com/prysmaticlabs/prysm/proto/prysm/v2/state"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestInitializeFromProto(t *testing.T) {
type test struct {
name string
state *statepb.BeaconStateAltair
error string
}
initTests := []test{
{
name: "nil state",
state: nil,
error: "received nil state",
},
{
name: "nil validators",
state: &statepb.BeaconStateAltair{
Slot: 4,
Validators: nil,
},
},
{
name: "empty state",
state: &statepb.BeaconStateAltair{},
},
// TODO: Add full state. Blocked by testutil migration.
}
for _, tt := range initTests {
t.Run(tt.name, func(t *testing.T) {
_, err := stateAltair.InitializeFromProto(tt.state)
if tt.error != "" {
require.ErrorContains(t, tt.error, err)
} else {
require.NoError(t, err)
}
})
}
}
func TestInitializeFromProtoUnsafe(t *testing.T) {
type test struct {
name string
state *statepb.BeaconStateAltair
error string
}
initTests := []test{
{
name: "nil state",
state: nil,
error: "received nil state",
},
{
name: "nil validators",
state: &statepb.BeaconStateAltair{
Slot: 4,
Validators: nil,
},
},
{
name: "empty state",
state: &statepb.BeaconStateAltair{},
},
// TODO: Add full state. Blocked by testutil migration.
}
for _, tt := range initTests {
t.Run(tt.name, func(t *testing.T) {
_, err := stateAltair.InitializeFromProtoUnsafe(tt.state)
if tt.error != "" {
assert.ErrorContains(t, tt.error, err)
} else {
assert.NoError(t, err)
}
})
}
}