prysm-pulse/beacon-chain/db/kv/archived_point_test.go
Victor Farazdagi a069738c20
ETH2 Types: Slot (#8408)
* 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>
2021-02-16 07:45:34 +00:00

52 lines
1.5 KiB
Go

package kv
import (
"context"
"testing"
types "github.com/prysmaticlabs/eth2-types"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestArchivedPointIndexRoot_CanSaveRetrieve(t *testing.T) {
db := setupDB(t)
ctx := context.Background()
i1 := types.Slot(100)
r1 := [32]byte{'A'}
received := db.ArchivedPointRoot(ctx, i1)
require.NotEqual(t, r1, received, "Should not have been saved")
st, err := testutil.NewBeaconState()
require.NoError(t, err)
require.NoError(t, st.SetSlot(i1))
require.NoError(t, db.SaveState(ctx, st, r1))
received = db.ArchivedPointRoot(ctx, i1)
assert.Equal(t, r1, received, "Should have been saved")
}
func TestLastArchivedPoint_CanRetrieve(t *testing.T) {
db := setupDB(t)
ctx := context.Background()
i, err := db.LastArchivedSlot(ctx)
require.NoError(t, err)
assert.Equal(t, types.Slot(0), i, "Did not get correct index")
st, err := testutil.NewBeaconState()
require.NoError(t, err)
assert.NoError(t, db.SaveState(ctx, st, [32]byte{'A'}))
assert.Equal(t, [32]byte{'A'}, db.LastArchivedRoot(ctx), "Did not get wanted root")
assert.NoError(t, st.SetSlot(2))
assert.NoError(t, db.SaveState(ctx, st, [32]byte{'B'}))
assert.Equal(t, [32]byte{'B'}, db.LastArchivedRoot(ctx))
assert.NoError(t, st.SetSlot(3))
assert.NoError(t, db.SaveState(ctx, st, [32]byte{'C'}))
i, err = db.LastArchivedSlot(ctx)
require.NoError(t, err)
assert.Equal(t, types.Slot(3), i, "Did not get correct index")
}