Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manav2401 committed May 24, 2022
1 parent 9c86192 commit cb9d291
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions eth/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
}
}

0 comments on commit cb9d291

Please sign in to comment.