Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eth tests #8

Merged
merged 1 commit into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eth/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestStorageRangeAt(t *testing.T) {
}
tds.IntermediateRoot(statedb, false)
tds.SetBlockNr(1)
statedb.Finalise(false, tds.DbStateWriter())
statedb.Commit(false, tds.DbStateWriter())

// Check a few combinations of limit and start/end.
tests := []struct {
Expand Down
11 changes: 8 additions & 3 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,14 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
return errResp(ErrDecode, "msg %v: %v", msg, err)
}
// Retrieve the requested block body, stopping if enough was found
if data := pm.blockchain.GetBodyRLP(hash); len(data) != 0 {
bodies = append(bodies, data)
bytes += len(data)
if body := pm.blockchain.GetBody(hash); body != nil {
smallBody := &blockBody{Transactions: body.Transactions, Uncles: body.Uncles}
if data, err := rlp.EncodeToBytes(smallBody); err == nil {
bodies = append(bodies, data)
bytes += len(data)
} else {
return err
}
}
}
return p.SendBlockBodiesRLP(bodies)
Expand Down
8 changes: 4 additions & 4 deletions eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ func TestGetBlockHeaders63(t *testing.T) { testGetBlockHeaders(t, 63) }

func testGetBlockHeaders(t *testing.T, protocol int) {
pm, _ := newTestProtocolManagerMust(t, downloader.FullSync, downloader.MaxHashFetch+15, nil, nil)
peer, _ := newTestPeer("peer", protocol, pm, true)
defer peer.close()

// Create a "random" unknown hash for testing
var unknown common.Hash
Expand Down Expand Up @@ -201,6 +199,8 @@ func testGetBlockHeaders(t *testing.T, protocol int) {
}
// Run each of the tests and verify the results against the chain
for i, tt := range tests {
peer, _ := newTestPeer("peer", protocol, pm, true)
defer peer.close()
// Collect the headers to expect in the response
headers := []*types.Header{}
for _, hash := range tt.expect {
Expand Down Expand Up @@ -231,8 +231,6 @@ func TestGetBlockBodies63(t *testing.T) { testGetBlockBodies(t, 63) }

func testGetBlockBodies(t *testing.T, protocol int) {
pm, _ := newTestProtocolManagerMust(t, downloader.FullSync, downloader.MaxBlockFetch+15, nil, nil)
peer, _ := newTestPeer("peer", protocol, pm, true)
defer peer.close()

// Create a batch of tests for various scenarios
limit := downloader.MaxBlockFetch
Expand Down Expand Up @@ -263,6 +261,8 @@ func testGetBlockBodies(t *testing.T, protocol int) {
}
// Run each of the tests and verify the results against the chain
for i, tt := range tests {
peer, _ := newTestPeer("peer", protocol, pm, true)
defer peer.close()
// Collect the hashes to request, and the response to expect
hashes, seen := []common.Hash{}, make(map[int64]bool)
bodies := []*blockBody{}
Expand Down
21 changes: 16 additions & 5 deletions eth/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,28 @@ func newTestProtocolManager(mode downloader.SyncMode, blocks int, generator func
var (
evmux = new(event.TypeMux)
engine = ethash.NewFaker()
db = ethdb.NewMemDatabase()
gspec = &core.Genesis{
Config: params.TestChainConfig,
Alloc: core.GenesisAlloc{testBank: {Balance: big.NewInt(1000000)}},
}
genesis = gspec.MustCommit(db)
blockchain, _ = core.NewBlockChain(db, nil, gspec.Config, engine, vm.Config{}, nil)
)
chain, _ := core.GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, blocks, generator)
var chain []*types.Block
{
db_gen := ethdb.NewMemDatabase() // This database is only used to generate the chain, then discarded
genesis := gspec.MustCommit(db_gen)
chain, _ = core.GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db_gen, blocks, generator)
}
// Fresh database
db := ethdb.NewMemDatabase()
// Regenerate genesis block in the fresh database
gspec.MustCommit(db)
blockchain, err := core.NewBlockChain(db, nil, gspec.Config, engine, vm.Config{}, nil)
if err != nil {
return nil, nil, err
}
blockchain.EnableReceipts(true)
if _, err := blockchain.InsertChain(chain); err != nil {
panic(err)
return nil, nil, err
}

pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, evmux, &testTxPool{added: newtx}, engine, blockchain, db, nil)
Expand Down