2019-08-21 21:32:44 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2021-07-21 21:34:07 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
2021-09-23 18:53:46 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
2021-05-17 18:32:04 +00:00
|
|
|
"google.golang.org/protobuf/proto"
|
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
|
|
|
}
|