2020-03-02 07:55:38 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
2020-07-18 18:05:04 +00:00
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/util"
|
2020-03-02 07:55:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestArchivedPointIndexRoot_CanSaveRetrieve(t *testing.T) {
|
|
|
|
db := setupDB(t)
|
|
|
|
ctx := context.Background()
|
2023-01-26 14:40:12 +00:00
|
|
|
i1 := primitives.Slot(100)
|
2020-03-02 07:55:38 +00:00
|
|
|
r1 := [32]byte{'A'}
|
|
|
|
|
|
|
|
received := db.ArchivedPointRoot(ctx, i1)
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NotEqual(t, r1, received, "Should not have been saved")
|
2021-09-23 18:53:46 +00:00
|
|
|
st, err := util.NewBeaconState()
|
2021-02-08 20:00:09 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, st.SetSlot(i1))
|
|
|
|
require.NoError(t, db.SaveState(ctx, st, r1))
|
2020-03-02 07:55:38 +00:00
|
|
|
received = db.ArchivedPointRoot(ctx, i1)
|
2020-08-08 18:39:01 +00:00
|
|
|
assert.Equal(t, r1, received, "Should have been saved")
|
2020-03-02 07:55:38 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 19:07:07 +00:00
|
|
|
func TestLastArchivedPoint_CanRetrieve(t *testing.T) {
|
|
|
|
db := setupDB(t)
|
|
|
|
ctx := context.Background()
|
2020-07-18 18:05:04 +00:00
|
|
|
i, err := db.LastArchivedSlot(ctx)
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, err)
|
2023-01-26 14:40:12 +00:00
|
|
|
assert.Equal(t, primitives.Slot(0), i, "Did not get correct index")
|
2020-04-11 20:54:19 +00:00
|
|
|
|
2021-09-23 18:53:46 +00:00
|
|
|
st, err := util.NewBeaconState()
|
2021-02-08 20:00:09 +00:00
|
|
|
require.NoError(t, err)
|
2020-08-08 18:39:01 +00:00
|
|
|
assert.NoError(t, db.SaveState(ctx, st, [32]byte{'A'}))
|
|
|
|
assert.Equal(t, [32]byte{'A'}, db.LastArchivedRoot(ctx), "Did not get wanted root")
|
2020-03-16 19:07:07 +00:00
|
|
|
|
2020-08-08 18:39:01 +00:00
|
|
|
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))
|
2020-03-16 19:07:07 +00:00
|
|
|
|
2020-08-08 18:39:01 +00:00
|
|
|
assert.NoError(t, st.SetSlot(3))
|
|
|
|
assert.NoError(t, db.SaveState(ctx, st, [32]byte{'C'}))
|
2020-04-11 20:54:19 +00:00
|
|
|
|
2020-07-18 18:05:04 +00:00
|
|
|
i, err = db.LastArchivedSlot(ctx)
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, err)
|
2023-01-26 14:40:12 +00:00
|
|
|
assert.Equal(t, primitives.Slot(3), i, "Did not get correct index")
|
2020-03-16 19:07:07 +00:00
|
|
|
}
|