2019-08-21 21:32:44 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gogo/protobuf/proto"
|
2019-11-27 05:08:18 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
2020-08-08 18:39:01 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2019-08-21 21:32:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStore_VoluntaryExits_CRUD(t *testing.T) {
|
|
|
|
db := setupDB(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
exit := ðpb.VoluntaryExit{
|
|
|
|
Epoch: 5,
|
|
|
|
}
|
2020-08-27 18:13:32 +00:00
|
|
|
exitRoot, err := exit.HashTreeRoot()
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, err)
|
2019-08-21 21:32:44 +00:00
|
|
|
retrieved, err := db.VoluntaryExit(ctx, exitRoot)
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, (*ethpb.VoluntaryExit)(nil), retrieved, "Expected nil voluntary exit")
|
|
|
|
require.NoError(t, db.SaveVoluntaryExit(ctx, exit))
|
|
|
|
assert.Equal(t, true, db.HasVoluntaryExit(ctx, exitRoot), "Expected voluntary exit to exist in the db")
|
2019-08-21 21:32:44 +00:00
|
|
|
retrieved, err = db.VoluntaryExit(ctx, exitRoot)
|
2020-08-08 18:39:01 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, true, proto.Equal(exit, retrieved), "Wanted %v, received %v", exit, retrieved)
|
|
|
|
require.NoError(t, db.deleteVoluntaryExit(ctx, exitRoot))
|
|
|
|
assert.Equal(t, false, db.HasVoluntaryExit(ctx, exitRoot), "Expected voluntary exit to have been deleted from the db")
|
2019-08-21 21:32:44 +00:00
|
|
|
}
|