|
|
@ -11,6 +11,7 @@ import ( |
|
|
|
dbm "github.com/tendermint/tm-db" |
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/libs/log" |
|
|
|
"github.com/tendermint/tendermint/lite2/provider" |
|
|
|
mockp "github.com/tendermint/tendermint/lite2/provider/mock" |
|
|
|
dbs "github.com/tendermint/tendermint/lite2/store/db" |
|
|
|
"github.com/tendermint/tendermint/types" |
|
|
@ -127,6 +128,11 @@ func TestClient_SequentialVerification(t *testing.T) { |
|
|
|
tc.otherHeaders, |
|
|
|
tc.vals, |
|
|
|
), |
|
|
|
[]provider.Provider{mockp.New( |
|
|
|
chainID, |
|
|
|
tc.otherHeaders, |
|
|
|
tc.vals, |
|
|
|
)}, |
|
|
|
dbs.New(dbm.NewMemDB(), chainID), |
|
|
|
SequentialVerification(), |
|
|
|
) |
|
|
@ -228,6 +234,11 @@ func TestClient_SkippingVerification(t *testing.T) { |
|
|
|
tc.otherHeaders, |
|
|
|
tc.vals, |
|
|
|
), |
|
|
|
[]provider.Provider{mockp.New( |
|
|
|
chainID, |
|
|
|
tc.otherHeaders, |
|
|
|
tc.vals, |
|
|
|
)}, |
|
|
|
dbs.New(dbm.NewMemDB(), chainID), |
|
|
|
SkippingVerification(DefaultTrustLevel), |
|
|
|
) |
|
|
@ -264,6 +275,26 @@ func TestClientRemovesNoLongerTrustedHeaders(t *testing.T) { |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)) |
|
|
|
) |
|
|
|
|
|
|
|
primary := mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header, |
|
|
|
// interim header (3/3 signed)
|
|
|
|
2: keys.GenSignedHeader(chainID, 2, bTime.Add(2*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
// last header (3/3 signed)
|
|
|
|
3: keys.GenSignedHeader(chainID, 3, bTime.Add(4*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
4: vals, |
|
|
|
}, |
|
|
|
) |
|
|
|
|
|
|
|
c, err := NewClient( |
|
|
|
chainID, |
|
|
|
TrustOptions{ |
|
|
@ -271,25 +302,8 @@ func TestClientRemovesNoLongerTrustedHeaders(t *testing.T) { |
|
|
|
Height: 1, |
|
|
|
Hash: header.Hash(), |
|
|
|
}, |
|
|
|
mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header, |
|
|
|
// interim header (3/3 signed)
|
|
|
|
2: keys.GenSignedHeader(chainID, 2, bTime.Add(2*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
// last header (3/3 signed)
|
|
|
|
3: keys.GenSignedHeader(chainID, 3, bTime.Add(4*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
4: vals, |
|
|
|
}, |
|
|
|
), |
|
|
|
primary, |
|
|
|
[]provider.Provider{primary}, |
|
|
|
dbs.New(dbm.NewMemDB(), chainID), |
|
|
|
Logger(log.TestingLogger()), |
|
|
|
) |
|
|
@ -333,6 +347,18 @@ func TestClient_Cleanup(t *testing.T) { |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)) |
|
|
|
) |
|
|
|
|
|
|
|
primary := mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
}, |
|
|
|
) |
|
|
|
|
|
|
|
c, err := NewClient( |
|
|
|
chainID, |
|
|
|
TrustOptions{ |
|
|
@ -340,17 +366,8 @@ func TestClient_Cleanup(t *testing.T) { |
|
|
|
Height: 1, |
|
|
|
Hash: header.Hash(), |
|
|
|
}, |
|
|
|
mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
}, |
|
|
|
), |
|
|
|
primary, |
|
|
|
[]provider.Provider{primary}, |
|
|
|
dbs.New(dbm.NewMemDB(), chainID), |
|
|
|
Logger(log.TestingLogger()), |
|
|
|
) |
|
|
@ -388,6 +405,18 @@ func TestClientRestoreTrustedHeaderAfterStartup1(t *testing.T) { |
|
|
|
err := trustedStore.SaveSignedHeaderAndNextValidatorSet(header, vals) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
primary := mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
}, |
|
|
|
) |
|
|
|
|
|
|
|
c, err := NewClient( |
|
|
|
chainID, |
|
|
|
TrustOptions{ |
|
|
@ -395,17 +424,8 @@ func TestClientRestoreTrustedHeaderAfterStartup1(t *testing.T) { |
|
|
|
Height: 1, |
|
|
|
Hash: header.Hash(), |
|
|
|
}, |
|
|
|
mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
}, |
|
|
|
), |
|
|
|
primary, |
|
|
|
[]provider.Provider{primary}, |
|
|
|
trustedStore, |
|
|
|
Logger(log.TestingLogger()), |
|
|
|
) |
|
|
@ -430,6 +450,18 @@ func TestClientRestoreTrustedHeaderAfterStartup1(t *testing.T) { |
|
|
|
header1 := keys.GenSignedHeader(chainID, 1, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)) |
|
|
|
|
|
|
|
primary := mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header1, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
}, |
|
|
|
) |
|
|
|
|
|
|
|
c, err := NewClient( |
|
|
|
chainID, |
|
|
|
TrustOptions{ |
|
|
@ -437,17 +469,8 @@ func TestClientRestoreTrustedHeaderAfterStartup1(t *testing.T) { |
|
|
|
Height: 1, |
|
|
|
Hash: header1.Hash(), |
|
|
|
}, |
|
|
|
mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header1, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
}, |
|
|
|
), |
|
|
|
primary, |
|
|
|
[]provider.Provider{primary}, |
|
|
|
trustedStore, |
|
|
|
Logger(log.TestingLogger()), |
|
|
|
) |
|
|
@ -487,6 +510,18 @@ func TestClientRestoreTrustedHeaderAfterStartup2(t *testing.T) { |
|
|
|
header2 := keys.GenSignedHeader(chainID, 2, bTime.Add(2*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)) |
|
|
|
|
|
|
|
primary := mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
1: header, |
|
|
|
2: header2, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
}, |
|
|
|
) |
|
|
|
c, err := NewClient( |
|
|
|
chainID, |
|
|
|
TrustOptions{ |
|
|
@ -494,18 +529,8 @@ func TestClientRestoreTrustedHeaderAfterStartup2(t *testing.T) { |
|
|
|
Height: 2, |
|
|
|
Hash: header2.Hash(), |
|
|
|
}, |
|
|
|
mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
1: header, |
|
|
|
2: header2, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
}, |
|
|
|
), |
|
|
|
primary, |
|
|
|
[]provider.Provider{primary}, |
|
|
|
trustedStore, |
|
|
|
Logger(log.TestingLogger()), |
|
|
|
) |
|
|
@ -535,6 +560,19 @@ func TestClientRestoreTrustedHeaderAfterStartup2(t *testing.T) { |
|
|
|
header2 := keys.GenSignedHeader(chainID, 2, bTime.Add(2*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)) |
|
|
|
|
|
|
|
primary := mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
1: header1, |
|
|
|
2: header2, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
}, |
|
|
|
) |
|
|
|
|
|
|
|
c, err := NewClient( |
|
|
|
chainID, |
|
|
|
TrustOptions{ |
|
|
@ -542,18 +580,8 @@ func TestClientRestoreTrustedHeaderAfterStartup2(t *testing.T) { |
|
|
|
Height: 2, |
|
|
|
Hash: header2.Hash(), |
|
|
|
}, |
|
|
|
mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
1: header1, |
|
|
|
2: header2, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
}, |
|
|
|
), |
|
|
|
primary, |
|
|
|
[]provider.Provider{primary}, |
|
|
|
trustedStore, |
|
|
|
Logger(log.TestingLogger()), |
|
|
|
) |
|
|
@ -595,6 +623,19 @@ func TestClientRestoreTrustedHeaderAfterStartup3(t *testing.T) { |
|
|
|
err = trustedStore.SaveSignedHeaderAndNextValidatorSet(header2, vals) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
primary := mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
1: header, |
|
|
|
2: header2, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
}, |
|
|
|
) |
|
|
|
|
|
|
|
c, err := NewClient( |
|
|
|
chainID, |
|
|
|
TrustOptions{ |
|
|
@ -602,18 +643,8 @@ func TestClientRestoreTrustedHeaderAfterStartup3(t *testing.T) { |
|
|
|
Height: 1, |
|
|
|
Hash: header.Hash(), |
|
|
|
}, |
|
|
|
mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
1: header, |
|
|
|
2: header2, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
}, |
|
|
|
), |
|
|
|
primary, |
|
|
|
[]provider.Provider{primary}, |
|
|
|
trustedStore, |
|
|
|
Logger(log.TestingLogger()), |
|
|
|
) |
|
|
@ -650,6 +681,17 @@ func TestClientRestoreTrustedHeaderAfterStartup3(t *testing.T) { |
|
|
|
err = trustedStore.SaveSignedHeaderAndNextValidatorSet(header2, vals) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
primary := mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
1: header1, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
}, |
|
|
|
) |
|
|
|
|
|
|
|
c, err := NewClient( |
|
|
|
chainID, |
|
|
|
TrustOptions{ |
|
|
@ -657,16 +699,8 @@ func TestClientRestoreTrustedHeaderAfterStartup3(t *testing.T) { |
|
|
|
Height: 1, |
|
|
|
Hash: header1.Hash(), |
|
|
|
}, |
|
|
|
mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
1: header1, |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
}, |
|
|
|
), |
|
|
|
primary, |
|
|
|
[]provider.Provider{primary}, |
|
|
|
trustedStore, |
|
|
|
Logger(log.TestingLogger()), |
|
|
|
) |
|
|
@ -702,6 +736,26 @@ func TestClient_Update(t *testing.T) { |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)) |
|
|
|
) |
|
|
|
|
|
|
|
primary := mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header, |
|
|
|
// interim header (3/3 signed)
|
|
|
|
2: keys.GenSignedHeader(chainID, 2, bTime.Add(30*time.Minute), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
// last header (3/3 signed)
|
|
|
|
3: keys.GenSignedHeader(chainID, 3, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
4: vals, |
|
|
|
}, |
|
|
|
) |
|
|
|
|
|
|
|
c, err := NewClient( |
|
|
|
chainID, |
|
|
|
TrustOptions{ |
|
|
@ -709,25 +763,8 @@ func TestClient_Update(t *testing.T) { |
|
|
|
Height: 1, |
|
|
|
Hash: header.Hash(), |
|
|
|
}, |
|
|
|
mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header, |
|
|
|
// interim header (3/3 signed)
|
|
|
|
2: keys.GenSignedHeader(chainID, 2, bTime.Add(30*time.Minute), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
// last header (3/3 signed)
|
|
|
|
3: keys.GenSignedHeader(chainID, 3, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
4: vals, |
|
|
|
}, |
|
|
|
), |
|
|
|
primary, |
|
|
|
[]provider.Provider{primary}, |
|
|
|
dbs.New(dbm.NewMemDB(), chainID), |
|
|
|
Logger(log.TestingLogger()), |
|
|
|
) |
|
|
@ -760,6 +797,26 @@ func TestClient_Concurrency(t *testing.T) { |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)) |
|
|
|
) |
|
|
|
|
|
|
|
primary := mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header, |
|
|
|
// interim header (3/3 signed)
|
|
|
|
2: keys.GenSignedHeader(chainID, 2, bTime.Add(30*time.Minute), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
// last header (3/3 signed)
|
|
|
|
3: keys.GenSignedHeader(chainID, 3, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
4: vals, |
|
|
|
}, |
|
|
|
) |
|
|
|
|
|
|
|
c, err := NewClient( |
|
|
|
chainID, |
|
|
|
TrustOptions{ |
|
|
@ -767,25 +824,8 @@ func TestClient_Concurrency(t *testing.T) { |
|
|
|
Height: 1, |
|
|
|
Hash: header.Hash(), |
|
|
|
}, |
|
|
|
mockp.New( |
|
|
|
chainID, |
|
|
|
map[int64]*types.SignedHeader{ |
|
|
|
// trusted header
|
|
|
|
1: header, |
|
|
|
// interim header (3/3 signed)
|
|
|
|
2: keys.GenSignedHeader(chainID, 2, bTime.Add(30*time.Minute), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
// last header (3/3 signed)
|
|
|
|
3: keys.GenSignedHeader(chainID, 3, bTime.Add(1*time.Hour), nil, vals, vals, |
|
|
|
[]byte("app_hash"), []byte("cons_hash"), []byte("results_hash"), 0, len(keys)), |
|
|
|
}, |
|
|
|
map[int64]*types.ValidatorSet{ |
|
|
|
1: vals, |
|
|
|
2: vals, |
|
|
|
3: vals, |
|
|
|
4: vals, |
|
|
|
}, |
|
|
|
), |
|
|
|
primary, |
|
|
|
[]provider.Provider{primary}, |
|
|
|
dbs.New(dbm.NewMemDB(), chainID), |
|
|
|
UpdatePeriod(0), |
|
|
|
Logger(log.TestingLogger()), |
|
|
|