mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
add more tests
This commit is contained in:
parent
9c861920d5
commit
cb9d29151c
1 changed files with 35 additions and 0 deletions
|
|
@ -43,6 +43,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// downloadTester is a test simulator for mocking out local block chain.
|
||||
|
|
@ -1464,3 +1465,37 @@ func TestFakedSyncProgress66WhitelistMatch(t *testing.T) {
|
|||
t.Fatal("succeeded attacker synchronisation")
|
||||
}
|
||||
}
|
||||
|
||||
// TestFakedSyncProgress66NoRemoteCheckpoint tests if in case of missing/invalid
|
||||
// checkpointed blocks with opposite peer, the sync should fail initially but
|
||||
// with the retry mechanism, it should succeed eventually.
|
||||
func TestFakedSyncProgress66NoRemoteCheckpoint(t *testing.T) {
|
||||
protocol := uint(eth.ETH66)
|
||||
mode := FullSync
|
||||
|
||||
tester := newTester()
|
||||
validate := func(count int) (bool, error) {
|
||||
// only return the `ErrNoRemoteCheckoint` error for the first call
|
||||
if count == 0 {
|
||||
return false, whitelist.ErrNoRemoteCheckoint
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
tester.downloader.ChainValidator = newWhitelistFake(validate)
|
||||
|
||||
defer tester.terminate()
|
||||
|
||||
chainA := testChainForkLightA.blocks
|
||||
tester.newPeer("light", protocol, chainA[1:])
|
||||
|
||||
// Synchronise with the peer and make sure all blocks were retrieved
|
||||
// Should fail in first attempt
|
||||
if err := tester.sync("light", nil, mode); err != nil {
|
||||
assert.Equal(t, whitelist.ErrNoRemoteCheckoint, err, "failed synchronisation")
|
||||
}
|
||||
|
||||
// Try syncing again, should succeed
|
||||
if err := tester.sync("light", nil, mode); err != nil {
|
||||
t.Fatal("succeeded attacker synchronisation")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue