|
|
@ -4,12 +4,10 @@ import ( |
|
|
|
"testing" |
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
"github.com/stretchr/testify/mock" |
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/p2p" |
|
|
|
p2pmocks "github.com/tendermint/tendermint/p2p/mocks" |
|
|
|
"github.com/tendermint/tendermint/statesync/mocks" |
|
|
|
) |
|
|
|
|
|
|
|
func TestSnapshot_Key(t *testing.T) { |
|
|
@ -41,14 +39,11 @@ func TestSnapshot_Key(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestSnapshotPool_Add(t *testing.T) { |
|
|
|
stateProvider := &mocks.StateProvider{} |
|
|
|
stateProvider.On("AppHash", mock.Anything, uint64(1)).Return([]byte("app_hash"), nil) |
|
|
|
|
|
|
|
peer := &p2pmocks.Peer{} |
|
|
|
peer.On("ID").Return(p2p.ID("id")) |
|
|
|
|
|
|
|
// Adding to the pool should work
|
|
|
|
pool := newSnapshotPool(stateProvider) |
|
|
|
pool := newSnapshotPool() |
|
|
|
added, err := pool.Add(peer, &snapshot{ |
|
|
|
Height: 1, |
|
|
|
Format: 1, |
|
|
@ -73,15 +68,10 @@ func TestSnapshotPool_Add(t *testing.T) { |
|
|
|
// The pool should have populated the snapshot with the trusted app hash
|
|
|
|
snapshot := pool.Best() |
|
|
|
require.NotNil(t, snapshot) |
|
|
|
assert.Equal(t, []byte("app_hash"), snapshot.trustedAppHash) |
|
|
|
|
|
|
|
stateProvider.AssertExpectations(t) |
|
|
|
} |
|
|
|
|
|
|
|
func TestSnapshotPool_GetPeer(t *testing.T) { |
|
|
|
stateProvider := &mocks.StateProvider{} |
|
|
|
stateProvider.On("AppHash", mock.Anything, mock.Anything).Return([]byte("app_hash"), nil) |
|
|
|
pool := newSnapshotPool(stateProvider) |
|
|
|
pool := newSnapshotPool() |
|
|
|
|
|
|
|
s := &snapshot{Height: 1, Format: 1, Chunks: 1, Hash: []byte{1}} |
|
|
|
peerA := &p2pmocks.Peer{} |
|
|
@ -115,9 +105,7 @@ func TestSnapshotPool_GetPeer(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestSnapshotPool_GetPeers(t *testing.T) { |
|
|
|
stateProvider := &mocks.StateProvider{} |
|
|
|
stateProvider.On("AppHash", mock.Anything, mock.Anything).Return([]byte("app_hash"), nil) |
|
|
|
pool := newSnapshotPool(stateProvider) |
|
|
|
pool := newSnapshotPool() |
|
|
|
|
|
|
|
s := &snapshot{Height: 1, Format: 1, Chunks: 1, Hash: []byte{1}} |
|
|
|
peerA := &p2pmocks.Peer{} |
|
|
@ -139,9 +127,7 @@ func TestSnapshotPool_GetPeers(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestSnapshotPool_Ranked_Best(t *testing.T) { |
|
|
|
stateProvider := &mocks.StateProvider{} |
|
|
|
stateProvider.On("AppHash", mock.Anything, mock.Anything).Return([]byte("app_hash"), nil) |
|
|
|
pool := newSnapshotPool(stateProvider) |
|
|
|
pool := newSnapshotPool() |
|
|
|
|
|
|
|
// snapshots in expected order (best to worst). Highest height wins, then highest format.
|
|
|
|
// Snapshots with different chunk hashes are considered different, and the most peers is
|
|
|
@ -184,9 +170,7 @@ func TestSnapshotPool_Ranked_Best(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestSnapshotPool_Reject(t *testing.T) { |
|
|
|
stateProvider := &mocks.StateProvider{} |
|
|
|
stateProvider.On("AppHash", mock.Anything, mock.Anything).Return([]byte("app_hash"), nil) |
|
|
|
pool := newSnapshotPool(stateProvider) |
|
|
|
pool := newSnapshotPool() |
|
|
|
peer := &p2pmocks.Peer{} |
|
|
|
peer.On("ID").Return(p2p.ID("id")) |
|
|
|
|
|
|
@ -214,9 +198,7 @@ func TestSnapshotPool_Reject(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestSnapshotPool_RejectFormat(t *testing.T) { |
|
|
|
stateProvider := &mocks.StateProvider{} |
|
|
|
stateProvider.On("AppHash", mock.Anything, mock.Anything).Return([]byte("app_hash"), nil) |
|
|
|
pool := newSnapshotPool(stateProvider) |
|
|
|
pool := newSnapshotPool() |
|
|
|
peer := &p2pmocks.Peer{} |
|
|
|
peer.On("ID").Return(p2p.ID("id")) |
|
|
|
|
|
|
@ -245,9 +227,7 @@ func TestSnapshotPool_RejectFormat(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestSnapshotPool_RejectPeer(t *testing.T) { |
|
|
|
stateProvider := &mocks.StateProvider{} |
|
|
|
stateProvider.On("AppHash", mock.Anything, mock.Anything).Return([]byte("app_hash"), nil) |
|
|
|
pool := newSnapshotPool(stateProvider) |
|
|
|
pool := newSnapshotPool() |
|
|
|
|
|
|
|
peerA := &p2pmocks.Peer{} |
|
|
|
peerA.On("ID").Return(p2p.ID("a")) |
|
|
@ -287,9 +267,7 @@ func TestSnapshotPool_RejectPeer(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestSnapshotPool_RemovePeer(t *testing.T) { |
|
|
|
stateProvider := &mocks.StateProvider{} |
|
|
|
stateProvider.On("AppHash", mock.Anything, mock.Anything).Return([]byte("app_hash"), nil) |
|
|
|
pool := newSnapshotPool(stateProvider) |
|
|
|
pool := newSnapshotPool() |
|
|
|
|
|
|
|
peerA := &p2pmocks.Peer{} |
|
|
|
peerA.On("ID").Return(p2p.ID("a")) |
|
|
|