From 85cdd9d281e9da1c3eaa6d1a2250cb1268001f5c Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Mon, 2 May 2022 16:56:41 +0530 Subject: [PATCH 1/7] Initial Setup --- internal/ethapi/api.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 91d88ec815..c9dc0aa3f6 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1332,7 +1332,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} { // RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are // returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain // transaction hashes. -func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig) (map[string]interface{}, error) { +func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig, backend *Backend) (map[string]interface{}, error) { fields := RPCMarshalHeader(block.Header()) fields["size"] = hexutil.Uint64(block.Size()) @@ -1342,7 +1342,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param } if fullTx { formatTx = func(tx *types.Transaction) (interface{}, error) { - return newRPCTransactionFromBlockHash(block, tx.Hash(), config), nil + return newRPCTransactionFromBlockHash(block, tx.Hash(), config, backend), nil } } txs := block.Transactions() @@ -1376,7 +1376,7 @@ func (s *PublicBlockChainAPI) rpcMarshalHeader(ctx context.Context, header *type // rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires // a `PublicBlockchainAPI`. func (s *PublicBlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) { - fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig()) + fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig(), &s.b) if err != nil { return nil, err } @@ -1469,8 +1469,12 @@ func newRPCPendingTransaction(tx *types.Transaction, current *types.Header, conf } // newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation. -func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig) *RPCTransaction { +func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig, backend Backend) *RPCTransaction { txs := b.Transactions() + tx, _, _, _ := rawdb.ReadBorTransaction(backend.ChainDb(), b.Hash()) + if tx != nil { + txs = append(txs, tx) + } if index >= uint64(len(txs)) { return nil } @@ -1488,10 +1492,10 @@ func newRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.By } // newRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation. -func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash, config *params.ChainConfig) *RPCTransaction { +func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash, config *params.ChainConfig, backend *Backend) *RPCTransaction { for idx, tx := range b.Transactions() { if tx.Hash() == hash { - return newRPCTransactionFromBlockIndex(b, uint64(idx), config) + return newRPCTransactionFromBlockIndex(b, uint64(idx), config, *backend) } } return nil @@ -1633,7 +1637,7 @@ func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Co // GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index. func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction { if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil { - return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig()) + return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig(), s.b) } return nil } @@ -1641,7 +1645,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx conte // GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index. func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction { if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil { - return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig()) + return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig(), s.b) } return nil } From 938578c2e20d240ebb541d86c76619810bbc598b Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 3 Aug 2022 01:07:15 +0530 Subject: [PATCH 2/7] fix : minor change --- eth/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/api.go b/eth/api.go index f81dfa922b..aba982a6e1 100644 --- a/eth/api.go +++ b/eth/api.go @@ -343,7 +343,7 @@ func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, } else { blockRlp = fmt.Sprintf("0x%x", rlpBytes) } - if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig()); err != nil { + if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig(), nil); err != nil { blockJSON = map[string]interface{}{"error": err.Error()} } results = append(results, &BadBlockArgs{ From d3231c08844c92cab2324f52991759230c925cfc Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 3 Aug 2022 15:29:24 +0530 Subject: [PATCH 3/7] fix :GetTransactionByBlockNumberAndIndex + testGetTransactionByBlockNumberAndIndex --- eth/api.go | 2 +- eth/tracers/api_bor.go | 2 +- internal/ethapi/api.go | 29 +++++---- tests/bor/bor_api_test.go | 134 ++++++++++++++++++++++++-------------- 4 files changed, 106 insertions(+), 61 deletions(-) diff --git a/eth/api.go b/eth/api.go index aba982a6e1..ba688b4483 100644 --- a/eth/api.go +++ b/eth/api.go @@ -343,7 +343,7 @@ func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, } else { blockRlp = fmt.Sprintf("0x%x", rlpBytes) } - if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig(), nil); err != nil { + if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig(), api.eth.chainDb); err != nil { blockJSON = map[string]interface{}{"error": err.Error()} } results = append(results, &BadBlockArgs{ diff --git a/eth/tracers/api_bor.go b/eth/tracers/api_bor.go index 6ab1a4290a..f42c7a27f7 100644 --- a/eth/tracers/api_bor.go +++ b/eth/tracers/api_bor.go @@ -43,7 +43,7 @@ func (api *API) traceBorBlock(ctx context.Context, block *types.Block, config *T } // block object cannot be converted to JSON since much of the fields are non-public - blockFields, err := ethapi.RPCMarshalBlock(block, true, true, api.backend.ChainConfig()) + blockFields, err := ethapi.RPCMarshalBlock(block, true, true, api.backend.ChainConfig(), api.backend.ChainDb()) if err != nil { return nil, err } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index c9dc0aa3f6..a71ec3bd87 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -44,6 +44,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth/tracers/logger" + "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/params" @@ -1332,7 +1333,7 @@ func RPCMarshalHeader(head *types.Header) map[string]interface{} { // RPCMarshalBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are // returned. When fullTx is true the returned block contains full transaction details, otherwise it will only contain // transaction hashes. -func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig, backend *Backend) (map[string]interface{}, error) { +func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *params.ChainConfig, db ethdb.Database) (map[string]interface{}, error) { fields := RPCMarshalHeader(block.Header()) fields["size"] = hexutil.Uint64(block.Size()) @@ -1342,7 +1343,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param } if fullTx { formatTx = func(tx *types.Transaction) (interface{}, error) { - return newRPCTransactionFromBlockHash(block, tx.Hash(), config, backend), nil + return newRPCTransactionFromBlockHash(block, tx.Hash(), config, db), nil } } txs := block.Transactions() @@ -1376,7 +1377,7 @@ func (s *PublicBlockChainAPI) rpcMarshalHeader(ctx context.Context, header *type // rpcMarshalBlock uses the generalized output filler, then adds the total difficulty field, which requires // a `PublicBlockchainAPI`. func (s *PublicBlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Block, inclTx bool, fullTx bool) (map[string]interface{}, error) { - fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig(), &s.b) + fields, err := RPCMarshalBlock(b, inclTx, fullTx, s.b.ChainConfig(), s.b.ChainDb()) if err != nil { return nil, err } @@ -1469,12 +1470,18 @@ func newRPCPendingTransaction(tx *types.Transaction, current *types.Header, conf } // newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation. -func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig, backend Backend) *RPCTransaction { +func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig, db ethdb.Database) *RPCTransaction { txs := b.Transactions() - tx, _, _, _ := rawdb.ReadBorTransaction(backend.ChainDb(), b.Hash()) - if tx != nil { - txs = append(txs, tx) + + borReceipt := rawdb.ReadBorReceipt(db, b.Hash(), b.NumberU64()) + if borReceipt != nil { + tx, _, _, _ := rawdb.ReadBorTransaction(db, borReceipt.TxHash) + + if tx != nil { + txs = append(txs, tx) + } } + if index >= uint64(len(txs)) { return nil } @@ -1492,10 +1499,10 @@ func newRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.By } // newRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation. -func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash, config *params.ChainConfig, backend *Backend) *RPCTransaction { +func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash, config *params.ChainConfig, db ethdb.Database) *RPCTransaction { for idx, tx := range b.Transactions() { if tx.Hash() == hash { - return newRPCTransactionFromBlockIndex(b, uint64(idx), config, *backend) + return newRPCTransactionFromBlockIndex(b, uint64(idx), config, db) } } return nil @@ -1637,7 +1644,7 @@ func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Co // GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index. func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx context.Context, blockNr rpc.BlockNumber, index hexutil.Uint) *RPCTransaction { if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil { - return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig(), s.b) + return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig(), s.b.ChainDb()) } return nil } @@ -1645,7 +1652,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockNumberAndIndex(ctx conte // GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index. func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context.Context, blockHash common.Hash, index hexutil.Uint) *RPCTransaction { if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil { - return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig(), s.b) + return newRPCTransactionFromBlockIndex(block, uint64(index), s.b.ChainConfig(), s.b.ChainDb()) } return nil } diff --git a/tests/bor/bor_api_test.go b/tests/bor/bor_api_test.go index b0e627bd54..a7bc5d6863 100644 --- a/tests/bor/bor_api_test.go +++ b/tests/bor/bor_api_test.go @@ -1,3 +1,5 @@ +//go:build integration + package bor import ( @@ -13,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/ethconfig" + "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" @@ -20,6 +23,19 @@ import ( "github.com/stretchr/testify/assert" ) +var ( + key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") + addr = crypto.PubkeyToAddress(key1.PublicKey) + stack, _ = node.New(&node.DefaultConfig) + backend, _ = eth.New(stack, ðconfig.Defaults) + db = backend.ChainDb() + hash1 = common.BytesToHash([]byte("topic1")) + hash2 = common.BytesToHash([]byte("topic2")) + hash3 = common.BytesToHash([]byte("topic3")) + hash4 = common.BytesToHash([]byte("topic4")) + hash5 = common.BytesToHash([]byte("topic5")) +) + func duplicateInArray(arr []common.Hash) bool { visited := make(map[common.Hash]bool, 0) for i := 0; i < len(arr); i++ { @@ -45,21 +61,72 @@ func areDifferentHashes(receipts []map[string]interface{}) bool { return true } -func TestGetTransactionReceiptsByBlock(t *testing.T) { - t.Parallel() +func testGetTransactionReceiptsByBlock(t *testing.T, publicBlockchainAPI *ethapi.PublicBlockChainAPI) { + // check 1 : zero transactions + receiptsOut, err := publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(1)) + if err != nil { + t.Error(err) + } + + assert.Equal(t, 0, len(receiptsOut)) + + // check 2 : one transactions ( normal ) + receiptsOut, err = publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(2)) + if err != nil { + t.Error(err) + } + + assert.Equal(t, 1, len(receiptsOut)) + assert.True(t, areDifferentHashes(receiptsOut)) + + // check 3 : two transactions ( both normal ) + receiptsOut, err = publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(3)) + if err != nil { + t.Error(err) + } + + assert.Equal(t, 2, len(receiptsOut)) + assert.True(t, areDifferentHashes(receiptsOut)) + + // check 4 : two transactions ( one normal + one state-sync) + receiptsOut, err = publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(4)) + if err != nil { + t.Error(err) + } + + assert.Equal(t, 2, len(receiptsOut)) + assert.True(t, areDifferentHashes(receiptsOut)) + +} + +func testGetTransactionByBlockNumberAndIndex(t *testing.T, publicTransactionPoolAPI *ethapi.PublicTransactionPoolAPI) { + // check 1 : False ( no transaction ) + tx := publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(1), 0) + assert.Nil(t, tx) - var ( - key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") - addr = crypto.PubkeyToAddress(key1.PublicKey) - stack, _ = node.New(&node.DefaultConfig) - backend, _ = eth.New(stack, ðconfig.Defaults) - db = backend.ChainDb() - hash1 = common.BytesToHash([]byte("topic1")) - hash2 = common.BytesToHash([]byte("topic2")) - hash3 = common.BytesToHash([]byte("topic3")) - hash4 = common.BytesToHash([]byte("topic4")) - hash5 = common.BytesToHash([]byte("topic5")) - ) + // check 2 : Normal Transaction + tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(2), 0) + assert.Equal(t, common.HexToAddress("0x24"), *tx.To) + + // check 3 : Normal Transaction + tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(3), 0) + assert.Equal(t, common.HexToAddress("0x992"), *tx.To) + + // check 4 : Normal Transaction + tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(3), 1) + assert.Equal(t, common.HexToAddress("0x993"), *tx.To) + + // check 5 : Normal Transaction + tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(4), 0) + assert.Equal(t, common.HexToAddress("0x1000"), *tx.To) + + // check 5 : Normal Transaction + tx = publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(4), 1) + assert.Equal(t, common.HexToAddress("0x0"), *tx.To) +} + +func TestAPIs(t *testing.T) { + t.Parallel() defer func() { if err := stack.Close(); err != nil { @@ -114,7 +181,7 @@ func TestGetTransactionReceiptsByBlock(t *testing.T) { }, } gen.AddUncheckedReceipt(receipt) - gen.AddUncheckedTx(types.NewTransaction(1000, common.HexToAddress("0x0"), big.NewInt(1000), 1000, gen.BaseFee(), nil)) + gen.AddUncheckedTx(types.NewTransaction(1000, common.HexToAddress("0x1000"), big.NewInt(1000), 1000, gen.BaseFee(), nil)) // state-sync transaction receipt2 := types.NewReceipt(nil, false, 0) @@ -174,39 +241,10 @@ func TestGetTransactionReceiptsByBlock(t *testing.T) { } publicBlockchainAPI := backend.PublicBlockChainAPI() + testGetTransactionReceiptsByBlock(t, publicBlockchainAPI) - // check 1 : zero transactions - receiptsOut, err := publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(1)) - if err != nil { - t.Error(err) - } - - assert.Equal(t, 0, len(receiptsOut)) - - // check 2 : one transactions ( normal ) - receiptsOut, err = publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(2)) - if err != nil { - t.Error(err) - } - - assert.Equal(t, 1, len(receiptsOut)) - assert.True(t, areDifferentHashes(receiptsOut)) - - // check 3 : two transactions ( both normal ) - receiptsOut, err = publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(3)) - if err != nil { - t.Error(err) - } - - assert.Equal(t, 2, len(receiptsOut)) - assert.True(t, areDifferentHashes(receiptsOut)) - - // check 4 : two transactions ( one normal + one state-sync) - receiptsOut, err = publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(4)) - if err != nil { - t.Error(err) - } + nonceLock := new(ethapi.AddrLocker) + publicTransactionPoolAPI := ethapi.NewPublicTransactionPoolAPI(backend.APIBackend, nonceLock) + testGetTransactionByBlockNumberAndIndex(t, publicTransactionPoolAPI) - assert.Equal(t, 2, len(receiptsOut)) - assert.True(t, areDifferentHashes(receiptsOut)) } From 57e1282caf698e21ffb40fad6664eb50bb997b54 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 3 Aug 2022 15:56:36 +0530 Subject: [PATCH 4/7] fix : lint --- eth/api.go | 1 + 1 file changed, 1 insertion(+) diff --git a/eth/api.go b/eth/api.go index ba688b4483..f571a57507 100644 --- a/eth/api.go +++ b/eth/api.go @@ -343,6 +343,7 @@ func (api *PrivateDebugAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, } else { blockRlp = fmt.Sprintf("0x%x", rlpBytes) } + if blockJSON, err = ethapi.RPCMarshalBlock(block, true, true, api.eth.APIBackend.ChainConfig(), api.eth.chainDb); err != nil { blockJSON = map[string]interface{}{"error": err.Error()} } From d5e51c9f76f85fc66e736a9c3ae4287bd065a8bf Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 3 Aug 2022 16:05:45 +0530 Subject: [PATCH 5/7] add : more comments --- tests/bor/bor_api_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/bor/bor_api_test.go b/tests/bor/bor_api_test.go index a7bc5d6863..960baf3413 100644 --- a/tests/bor/bor_api_test.go +++ b/tests/bor/bor_api_test.go @@ -61,6 +61,7 @@ func areDifferentHashes(receipts []map[string]interface{}) bool { return true } +// Test for GetTransactionReceiptsByBlock func testGetTransactionReceiptsByBlock(t *testing.T, publicBlockchainAPI *ethapi.PublicBlockChainAPI) { // check 1 : zero transactions receiptsOut, err := publicBlockchainAPI.GetTransactionReceiptsByBlock(context.Background(), rpc.BlockNumberOrHashWithNumber(1)) @@ -99,6 +100,7 @@ func testGetTransactionReceiptsByBlock(t *testing.T, publicBlockchainAPI *ethapi } +// Test for GetTransactionByBlockNumberAndIndex func testGetTransactionByBlockNumberAndIndex(t *testing.T, publicTransactionPoolAPI *ethapi.PublicTransactionPoolAPI) { // check 1 : False ( no transaction ) tx := publicTransactionPoolAPI.GetTransactionByBlockNumberAndIndex(context.Background(), rpc.BlockNumber(1), 0) @@ -125,6 +127,8 @@ func testGetTransactionByBlockNumberAndIndex(t *testing.T, publicTransactionPool assert.Equal(t, common.HexToAddress("0x0"), *tx.To) } +// This Testcase tests functions for RPC API calls. +// NOTE : Changes to this function might affect the child testcases. func TestAPIs(t *testing.T) { t.Parallel() @@ -240,9 +244,11 @@ func TestAPIs(t *testing.T) { } } + // Testing GetTransactionReceiptsByBlock publicBlockchainAPI := backend.PublicBlockChainAPI() testGetTransactionReceiptsByBlock(t, publicBlockchainAPI) + // Testing GetTransactionByBlockNumberAndIndex nonceLock := new(ethapi.AddrLocker) publicTransactionPoolAPI := ethapi.NewPublicTransactionPoolAPI(backend.APIBackend, nonceLock) testGetTransactionByBlockNumberAndIndex(t, publicTransactionPoolAPI) From 460bd4dde70d9189ec5c9932566756df38c0cb82 Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 3 Aug 2022 16:42:01 +0530 Subject: [PATCH 6/7] fix : tests --- tests/bor/bor_api_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/bor/bor_api_test.go b/tests/bor/bor_api_test.go index 960baf3413..ea8003d9b4 100644 --- a/tests/bor/bor_api_test.go +++ b/tests/bor/bor_api_test.go @@ -25,7 +25,7 @@ import ( var ( key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") - addr = crypto.PubkeyToAddress(key1.PublicKey) + addrr = crypto.PubkeyToAddress(key1.PublicKey) stack, _ = node.New(&node.DefaultConfig) backend, _ = eth.New(stack, ðconfig.Defaults) db = backend.ChainDb() @@ -138,7 +138,7 @@ func TestAPIs(t *testing.T) { } }() - genesis := core.GenesisBlockForTesting(db, addr, big.NewInt(1000000)) + genesis := core.GenesisBlockForTesting(db, addrr, big.NewInt(1000000)) sprint := params.TestChainConfig.Bor.Sprint chain, receipts := core.GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 6, func(i int, gen *core.BlockGen) { @@ -148,7 +148,7 @@ func TestAPIs(t *testing.T) { receipt := types.NewReceipt(nil, false, 0) receipt.Logs = []*types.Log{ { - Address: addr, + Address: addrr, Topics: []common.Hash{hash1}, }, } @@ -159,7 +159,7 @@ func TestAPIs(t *testing.T) { receipt := types.NewReceipt(nil, false, 0) receipt.Logs = []*types.Log{ { - Address: addr, + Address: addrr, Topics: []common.Hash{hash2}, }, } @@ -169,7 +169,7 @@ func TestAPIs(t *testing.T) { receipt2 := types.NewReceipt(nil, false, 0) receipt2.Logs = []*types.Log{ { - Address: addr, + Address: addrr, Topics: []common.Hash{hash3}, }, } @@ -180,7 +180,7 @@ func TestAPIs(t *testing.T) { receipt := types.NewReceipt(nil, false, 0) receipt.Logs = []*types.Log{ { - Address: addr, + Address: addrr, Topics: []common.Hash{hash4}, }, } @@ -191,7 +191,7 @@ func TestAPIs(t *testing.T) { receipt2 := types.NewReceipt(nil, false, 0) receipt2.Logs = []*types.Log{ { - Address: addr, + Address: addrr, Topics: []common.Hash{hash5}, }, } From 6b651f49569c347d0cf1ae1c2c0c57e5079cc26f Mon Sep 17 00:00:00 2001 From: Shivam Sharma Date: Wed, 3 Aug 2022 23:26:45 +0530 Subject: [PATCH 7/7] rm : t.parallel() --- tests/bor/bor_api_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/bor/bor_api_test.go b/tests/bor/bor_api_test.go index ea8003d9b4..63d2c8f3d5 100644 --- a/tests/bor/bor_api_test.go +++ b/tests/bor/bor_api_test.go @@ -130,7 +130,6 @@ func testGetTransactionByBlockNumberAndIndex(t *testing.T, publicTransactionPool // This Testcase tests functions for RPC API calls. // NOTE : Changes to this function might affect the child testcases. func TestAPIs(t *testing.T) { - t.Parallel() defer func() { if err := stack.Close(); err != nil {