mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 02:02:18 +00:00
5a66807989
* First take at updating everything to v5 * Patch gRPC gateway to use prysm v5 Fix patch * Update go ssz --------- Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package kv
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams"
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
|
)
|
|
|
|
func TestStore_GenesisValidatorsRoot_ReadAndWrite(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
tests := []struct {
|
|
name string
|
|
init []byte
|
|
want []byte
|
|
write []byte
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "empty then write",
|
|
init: nil,
|
|
want: params.BeaconConfig().ZeroHash[:],
|
|
write: params.BeaconConfig().ZeroHash[:],
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "zero then overwrite with the same value",
|
|
init: params.BeaconConfig().ZeroHash[:],
|
|
want: params.BeaconConfig().ZeroHash[:],
|
|
write: params.BeaconConfig().ZeroHash[:],
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "zero then overwrite with a different value",
|
|
init: params.BeaconConfig().ZeroHash[:],
|
|
want: params.BeaconConfig().ZeroHash[:],
|
|
write: []byte{5},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
// Initialize the database with the initial value.
|
|
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{})
|
|
err := db.SaveGenesisValidatorsRoot(ctx, tt.init)
|
|
require.NoError(t, err)
|
|
|
|
// Read the value from the database (just to ensure our setup is OK).
|
|
got, err := db.GenesisValidatorsRoot(ctx)
|
|
require.NoError(t, err)
|
|
require.DeepEqual(t, tt.init, got)
|
|
|
|
// Write the value to the database.
|
|
err = db.SaveGenesisValidatorsRoot(ctx, tt.write)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("GenesisValidatorsRoot() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
|
|
// Read the value from the database.
|
|
got, err = db.GenesisValidatorsRoot(ctx)
|
|
require.NoError(t, err)
|
|
require.DeepEqual(t, tt.want, got)
|
|
|
|
// Close the database.
|
|
require.NoError(t, db.Close())
|
|
})
|
|
}
|
|
}
|