mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
2d10bcf179
* 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
85 lines
1.7 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|