|
|
@ -14,6 +14,7 @@ import ( |
|
|
|
|
|
|
|
func TestLast_FirstSignedHeaderHeight(t *testing.T) { |
|
|
|
dbStore := New(dbm.NewMemDB(), "TestLast_FirstSignedHeaderHeight") |
|
|
|
vals, _ := types.RandValidatorSet(10, 100) |
|
|
|
|
|
|
|
// Empty store
|
|
|
|
height, err := dbStore.LastSignedHeaderHeight() |
|
|
@ -26,7 +27,7 @@ func TestLast_FirstSignedHeaderHeight(t *testing.T) { |
|
|
|
|
|
|
|
// 1 key
|
|
|
|
err = dbStore.SaveSignedHeaderAndValidatorSet( |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: 1}}, &types.ValidatorSet{}) |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: 1}}, vals) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
height, err = dbStore.LastSignedHeaderHeight() |
|
|
@ -40,7 +41,7 @@ func TestLast_FirstSignedHeaderHeight(t *testing.T) { |
|
|
|
|
|
|
|
func Test_SaveSignedHeaderAndValidatorSet(t *testing.T) { |
|
|
|
dbStore := New(dbm.NewMemDB(), "Test_SaveSignedHeaderAndValidatorSet") |
|
|
|
|
|
|
|
vals, _ := types.RandValidatorSet(10, 100) |
|
|
|
// Empty store
|
|
|
|
h, err := dbStore.SignedHeader(1) |
|
|
|
require.Error(t, err) |
|
|
@ -51,8 +52,9 @@ func Test_SaveSignedHeaderAndValidatorSet(t *testing.T) { |
|
|
|
assert.Nil(t, valSet) |
|
|
|
|
|
|
|
// 1 key
|
|
|
|
pa := vals.Validators[0].Address |
|
|
|
err = dbStore.SaveSignedHeaderAndValidatorSet( |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: 1}}, &types.ValidatorSet{}) |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: 1, ProposerAddress: pa}}, vals) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
h, err = dbStore.SignedHeader(1) |
|
|
@ -78,6 +80,8 @@ func Test_SaveSignedHeaderAndValidatorSet(t *testing.T) { |
|
|
|
|
|
|
|
func Test_SignedHeaderBefore(t *testing.T) { |
|
|
|
dbStore := New(dbm.NewMemDB(), "Test_SignedHeaderBefore") |
|
|
|
valSet, _ := types.RandValidatorSet(10, 100) |
|
|
|
pa := valSet.Proposer.Address |
|
|
|
|
|
|
|
assert.Panics(t, func() { |
|
|
|
_, _ = dbStore.SignedHeaderBefore(0) |
|
|
@ -85,7 +89,7 @@ func Test_SignedHeaderBefore(t *testing.T) { |
|
|
|
}) |
|
|
|
|
|
|
|
err := dbStore.SaveSignedHeaderAndValidatorSet( |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: 2}}, &types.ValidatorSet{}) |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: 2, ProposerAddress: pa}}, valSet) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
h, err := dbStore.SignedHeaderBefore(3) |
|
|
@ -97,6 +101,7 @@ func Test_SignedHeaderBefore(t *testing.T) { |
|
|
|
|
|
|
|
func Test_Prune(t *testing.T) { |
|
|
|
dbStore := New(dbm.NewMemDB(), "Test_Prune") |
|
|
|
valSet, _ := types.RandValidatorSet(10, 100) |
|
|
|
|
|
|
|
// Empty store
|
|
|
|
assert.EqualValues(t, 0, dbStore.Size()) |
|
|
@ -105,7 +110,7 @@ func Test_Prune(t *testing.T) { |
|
|
|
|
|
|
|
// One header
|
|
|
|
err = dbStore.SaveSignedHeaderAndValidatorSet( |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: 2}}, &types.ValidatorSet{}) |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: 2}}, valSet) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
assert.EqualValues(t, 1, dbStore.Size()) |
|
|
@ -121,7 +126,7 @@ func Test_Prune(t *testing.T) { |
|
|
|
// Multiple headers
|
|
|
|
for i := 1; i <= 10; i++ { |
|
|
|
err = dbStore.SaveSignedHeaderAndValidatorSet( |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: int64(i)}}, &types.ValidatorSet{}) |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: int64(i)}}, valSet) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
|
|
|
@ -136,6 +141,7 @@ func Test_Prune(t *testing.T) { |
|
|
|
|
|
|
|
func Test_Concurrency(t *testing.T) { |
|
|
|
dbStore := New(dbm.NewMemDB(), "Test_Prune") |
|
|
|
vals, _ := types.RandValidatorSet(10, 100) |
|
|
|
|
|
|
|
var wg sync.WaitGroup |
|
|
|
for i := 1; i <= 100; i++ { |
|
|
@ -144,7 +150,7 @@ func Test_Concurrency(t *testing.T) { |
|
|
|
defer wg.Done() |
|
|
|
|
|
|
|
dbStore.SaveSignedHeaderAndValidatorSet( |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: i}}, &types.ValidatorSet{}) |
|
|
|
&types.SignedHeader{Header: &types.Header{Height: i}}, vals) |
|
|
|
|
|
|
|
dbStore.SignedHeader(i) |
|
|
|
dbStore.ValidatorSet(i) |
|
|
|