|
|
@ -24,13 +24,15 @@ import ( |
|
|
|
|
|
|
|
var ctx = context.Background() |
|
|
|
|
|
|
|
const testAppVersion = 9 |
|
|
|
|
|
|
|
func TestSyncer_SyncAny(t *testing.T) { |
|
|
|
state := sm.State{ |
|
|
|
ChainID: "chain", |
|
|
|
Version: sm.Version{ |
|
|
|
Consensus: version.Consensus{ |
|
|
|
Block: version.BlockProtocol, |
|
|
|
App: 0, |
|
|
|
App: testAppVersion, |
|
|
|
}, |
|
|
|
Software: version.TMVersion, |
|
|
|
}, |
|
|
@ -178,7 +180,7 @@ func TestSyncer_SyncAny(t *testing.T) { |
|
|
|
Index: 2, Chunk: []byte{1, 1, 2}, |
|
|
|
}).Once().Return(&abci.ResponseApplySnapshotChunk{Result: abci.ResponseApplySnapshotChunk_ACCEPT}, nil) |
|
|
|
connQuery.On("InfoSync", ctx, proxy.RequestInfo).Return(&abci.ResponseInfo{ |
|
|
|
AppVersion: 9, |
|
|
|
AppVersion: testAppVersion, |
|
|
|
LastBlockHeight: 1, |
|
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
|
}, nil) |
|
|
@ -192,10 +194,7 @@ func TestSyncer_SyncAny(t *testing.T) { |
|
|
|
require.Equal(t, map[uint32]int{0: 1, 1: 2, 2: 1}, chunkRequests) |
|
|
|
chunkRequestsMtx.Unlock() |
|
|
|
|
|
|
|
// The syncer should have updated the state app version from the ABCI info response.
|
|
|
|
expectState := state |
|
|
|
expectState.Version.Consensus.App = 9 |
|
|
|
|
|
|
|
require.Equal(t, expectState, newState) |
|
|
|
require.Equal(t, commit, lastCommit) |
|
|
|
|
|
|
@ -669,45 +668,47 @@ func TestSyncer_applyChunks_RejectSenders(t *testing.T) { |
|
|
|
|
|
|
|
func TestSyncer_verifyApp(t *testing.T) { |
|
|
|
boom := errors.New("boom") |
|
|
|
const appVersion = 9 |
|
|
|
appVersionMismatchErr := errors.New("app version mismatch. Expected: 9, got: 2") |
|
|
|
s := &snapshot{Height: 3, Format: 1, Chunks: 5, Hash: []byte{1, 2, 3}, trustedAppHash: []byte("app_hash")} |
|
|
|
|
|
|
|
testcases := map[string]struct { |
|
|
|
response *abci.ResponseInfo |
|
|
|
err error |
|
|
|
expectErr error |
|
|
|
}{ |
|
|
|
"verified": {&abci.ResponseInfo{ |
|
|
|
LastBlockHeight: 3, |
|
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
|
AppVersion: 9, |
|
|
|
}, nil, nil}, |
|
|
|
AppVersion: appVersion, |
|
|
|
}, nil}, |
|
|
|
"invalid app version": {&abci.ResponseInfo{ |
|
|
|
LastBlockHeight: 3, |
|
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
|
AppVersion: 2, |
|
|
|
}, appVersionMismatchErr}, |
|
|
|
"invalid height": {&abci.ResponseInfo{ |
|
|
|
LastBlockHeight: 5, |
|
|
|
LastBlockAppHash: []byte("app_hash"), |
|
|
|
AppVersion: 9, |
|
|
|
}, nil, errVerifyFailed}, |
|
|
|
AppVersion: appVersion, |
|
|
|
}, errVerifyFailed}, |
|
|
|
"invalid hash": {&abci.ResponseInfo{ |
|
|
|
LastBlockHeight: 3, |
|
|
|
LastBlockAppHash: []byte("xxx"), |
|
|
|
AppVersion: 9, |
|
|
|
}, nil, errVerifyFailed}, |
|
|
|
"error": {nil, boom, boom}, |
|
|
|
AppVersion: appVersion, |
|
|
|
}, errVerifyFailed}, |
|
|
|
"error": {nil, boom}, |
|
|
|
} |
|
|
|
for name, tc := range testcases { |
|
|
|
tc := tc |
|
|
|
t.Run(name, func(t *testing.T) { |
|
|
|
rts := setup(t, nil, nil, nil, 2) |
|
|
|
|
|
|
|
rts.connQuery.On("InfoSync", ctx, proxy.RequestInfo).Return(tc.response, tc.err) |
|
|
|
version, err := rts.syncer.verifyApp(s) |
|
|
|
unwrapped := errors.Unwrap(err) |
|
|
|
if unwrapped != nil { |
|
|
|
err = unwrapped |
|
|
|
} |
|
|
|
|
|
|
|
require.Equal(t, tc.expectErr, err) |
|
|
|
if err == nil { |
|
|
|
require.Equal(t, tc.response.AppVersion, version) |
|
|
|
rts.connQuery.On("InfoSync", mock.Anything, proxy.RequestInfo).Return(tc.response, tc.expectErr) |
|
|
|
err := rts.syncer.verifyApp(ctx, s, appVersion) |
|
|
|
if tc.expectErr != nil { |
|
|
|
require.ErrorIs(t, err, tc.expectErr) |
|
|
|
} else { |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|