diff options
author | Felföldi Zsolt <zsfelfoldi@gmail.com> | 2019-05-13 19:41:10 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-05-13 19:41:10 +0800 |
commit | 40cdcf8c47ff094775aca08fd5d94051f9cf1dbb (patch) | |
tree | 3a9fc715ec501ab0fec8c81004e17477bd136f9f /les/odr_test.go | |
parent | f4fb1a18015d88aa7b424709aac346da59edf410 (diff) | |
download | go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar.gz go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar.bz2 go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar.lz go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar.xz go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.tar.zst go-tangerine-40cdcf8c47ff094775aca08fd5d94051f9cf1dbb.zip |
les, light: implement ODR transaction lookup by hash (#19069)
* les, light: implement ODR transaction lookup by hash
* les: delete useless file
* internal/ethapi: always use backend to find transaction
* les, eth, internal/ethapi: renamed GetCanonicalTransaction to GetTransaction
* light: add canonical header verification to GetTransaction
Diffstat (limited to 'les/odr_test.go')
-rw-r--r-- | les/odr_test.go | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/les/odr_test.go b/les/odr_test.go index 2cc28e384..a1d547956 100644 --- a/les/odr_test.go +++ b/les/odr_test.go @@ -38,7 +38,7 @@ import ( type odrTestFn func(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte -func TestOdrGetBlockLes2(t *testing.T) { testOdr(t, 2, 1, odrGetBlock) } +func TestOdrGetBlockLes2(t *testing.T) { testOdr(t, 2, 1, true, odrGetBlock) } func odrGetBlock(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { var block *types.Block @@ -54,7 +54,7 @@ func odrGetBlock(ctx context.Context, db ethdb.Database, config *params.ChainCon return rlp } -func TestOdrGetReceiptsLes2(t *testing.T) { testOdr(t, 2, 1, odrGetReceipts) } +func TestOdrGetReceiptsLes2(t *testing.T) { testOdr(t, 2, 1, true, odrGetReceipts) } func odrGetReceipts(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { var receipts types.Receipts @@ -74,7 +74,7 @@ func odrGetReceipts(ctx context.Context, db ethdb.Database, config *params.Chain return rlp } -func TestOdrAccountsLes2(t *testing.T) { testOdr(t, 2, 1, odrAccounts) } +func TestOdrAccountsLes2(t *testing.T) { testOdr(t, 2, 1, true, odrAccounts) } func odrAccounts(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { dummyAddr := common.HexToAddress("1234567812345678123456781234567812345678") @@ -102,7 +102,7 @@ func odrAccounts(ctx context.Context, db ethdb.Database, config *params.ChainCon return res } -func TestOdrContractCallLes2(t *testing.T) { testOdr(t, 2, 2, odrContractCall) } +func TestOdrContractCallLes2(t *testing.T) { testOdr(t, 2, 2, true, odrContractCall) } type callmsg struct { types.Message @@ -151,8 +151,32 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *params.Chai return res } +func TestOdrTxStatusLes2(t *testing.T) { testOdr(t, 2, 1, false, odrTxStatus) } + +func odrTxStatus(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { + var txs types.Transactions + if bc != nil { + block := bc.GetBlockByHash(bhash) + txs = block.Transactions() + } else { + if block, _ := lc.GetBlockByHash(ctx, bhash); block != nil { + btxs := block.Transactions() + txs = make(types.Transactions, len(btxs)) + for i, tx := range btxs { + var err error + txs[i], _, _, _, err = light.GetTransaction(ctx, lc.Odr(), tx.Hash()) + if err != nil { + return nil + } + } + } + } + rlp, _ := rlp.EncodeToBytes(txs) + return rlp +} + // testOdr tests odr requests whose validation guaranteed by block headers. -func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) { +func testOdr(t *testing.T, protocol int, expFail uint64, checkCached bool, fn odrTestFn) { // Assemble the test environment server, client, tearDown := newClientServerEnv(t, 4, protocol, nil, true) defer tearDown() @@ -193,9 +217,10 @@ func testOdr(t *testing.T, protocol int, expFail uint64, fn odrTestFn) { client.rPeer.hasBlock = func(common.Hash, uint64, bool) bool { return true } client.peers.lock.Unlock() test(5) - - // still expect all retrievals to pass, now data should be cached locally - client.peers.Unregister(client.rPeer.id) - time.Sleep(time.Millisecond * 10) // ensure that all peerSetNotify callbacks are executed - test(5) + if checkCached { + // still expect all retrievals to pass, now data should be cached locally + client.peers.Unregister(client.rPeer.id) + time.Sleep(time.Millisecond * 10) // ensure that all peerSetNotify callbacks are executed + test(5) + } } |