From 41134d047383edccaa8340795c7a58b6ab5137e2 Mon Sep 17 00:00:00 2001 From: Lucca Martins Date: Sun, 12 Jan 2025 04:07:25 -0300 Subject: [PATCH 1/7] state sync tests on rpc methods --- internal/ethapi/api.go | 10 ++- internal/ethapi/api_test.go | 67 +++++++++++++++++-- ...h_getTransactionReceipt-state-sync-tx.json | 31 +++++---- 3 files changed, 86 insertions(+), 22 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a469a8c0e0..c02b66f256 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -2074,7 +2074,10 @@ func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash commo } if !found { - tx, blockHash, blockNumber, index = rawdb.ReadBorTransaction(api.b.ChainDb(), hash) + tx, blockHash, blockNumber, index, err = api.b.GetBorBlockTransaction(ctx, hash) + if err != nil { + return nil, err + } borTx = true } @@ -2086,7 +2089,10 @@ func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash commo if borTx { // Fetch bor block receipt - receipt = rawdb.ReadBorReceipt(api.b.ChainDb(), blockHash, blockNumber, api.b.ChainConfig()) + receipt, err = api.b.GetBorBlockReceipt(ctx, blockHash) + if err != nil { + return nil, err + } } else { receipts, err := api.b.GetReceipts(ctx, blockHash) if err != nil { diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index a6d620b330..619bd9f072 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -587,7 +587,11 @@ func (b testBackend) SendTx(ctx context.Context, signedTx *types.Transaction) er } func (b testBackend) GetTransaction(ctx context.Context, txHash common.Hash) (bool, *types.Transaction, common.Hash, uint64, uint64, error) { tx, blockHash, blockNumber, index := rawdb.ReadTransaction(b.db, txHash) - return true, tx, blockHash, blockNumber, index, nil + found := true + if tx == nil { + found = false + } + return found, tx, blockHash, blockNumber, index, nil } func (b testBackend) GetPoolTransactions() (types.Transactions, error) { panic("implement me") } func (b testBackend) GetPoolTransaction(txHash common.Hash) *types.Transaction { panic("implement me") } @@ -625,7 +629,8 @@ func (b testBackend) ServiceFilter(ctx context.Context, session *bloombits.Match // GetBorBlockTransaction returns bor block tx func (b testBackend) GetBorBlockTransaction(ctx context.Context, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) { - panic("implement me") + tx, blockHash, blockNumber, index := rawdb.ReadBorTransaction(b.ChainDb(), hash) + return tx, blockHash, blockNumber, index, nil } func (b testBackend) GetBorBlockTransactionWithBlockHash(ctx context.Context, txHash common.Hash, blockHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error) { @@ -1935,7 +1940,7 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha }, } signer = types.LatestSignerForChainID(params.TestChainConfig.ChainID) - txHashes = make([]common.Hash, genBlocks) + txHashes = make([]common.Hash, genBlocks+1) ) // Set the terminal total difficulty in the config @@ -1997,9 +2002,33 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha txHashes[i] = tx.Hash() } }) + + txHashes[genBlocks] = mockStateSyncTxOnCurrentBlock(t, backend) + return backend, txHashes } +func mockStateSyncTxOnCurrentBlock(t *testing.T, backend *testBackend) common.Hash { + // State Sync Tx Setup + var stateSyncLogs []*types.Log + block, err := backend.BlockByHash(context.Background(), backend.CurrentBlock().Hash()) + if err != nil { + t.Errorf("failed to get current block: %v", err) + } + + types.DeriveFieldsForBorLogs(stateSyncLogs, block.Hash(), block.NumberU64(), 0, 0) + + // Write bor receipt + rawdb.WriteBorReceipt(backend.ChainDb(), block.Hash(), block.NumberU64(), &types.ReceiptForStorage{ + Status: types.ReceiptStatusSuccessful, // make receipt status successful + Logs: stateSyncLogs, + }) + + // Write bor tx reverse lookup + rawdb.WriteBorTxLookupEntry(backend.ChainDb(), block.Hash(), block.NumberU64()) + return types.GetDerivedBorTxHash(types.BorReceiptKey(block.NumberU64(), block.Hash())) +} + func TestRPCGetTransactionReceipt(t *testing.T) { t.Parallel() @@ -2052,6 +2081,11 @@ func TestRPCGetTransactionReceipt(t *testing.T) { txHash: txHashes[5], file: "blob-tx", }, + // 8. state sync tx found + { + txHash: txHashes[6], + file: "state-sync-tx", + }, } for i, tt := range testSuite { @@ -2103,7 +2137,7 @@ func TestRPCGetTransactionReceiptsByBlock(t *testing.T) { contract: {Balance: big.NewInt(params.Ether), Code: common.FromHex("0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063a9059cbb14610030575b600080fd5b61004a6004803603810190610045919061016a565b610060565b60405161005791906101c5565b60405180910390f35b60008273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516100bf91906101ef565b60405180910390a36001905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610101826100d6565b9050919050565b610111816100f6565b811461011c57600080fd5b50565b60008135905061012e81610108565b92915050565b6000819050919050565b61014781610134565b811461015257600080fd5b50565b6000813590506101648161013e565b92915050565b60008060408385031215610181576101806100d1565b5b600061018f8582860161011f565b92505060206101a085828601610155565b9150509250929050565b60008115159050919050565b6101bf816101aa565b82525050565b60006020820190506101da60008301846101b6565b92915050565b6101e981610134565b82525050565b600060208201905061020460008301846101e0565b9291505056fea2646970667358221220b469033f4b77b9565ee84e0a2f04d496b18160d26034d54f9487e57788fd36d564736f6c63430008120033")}, }, } - genTxs = 5 + genTxs = 6 genBlocks = 1 signer = types.LatestSignerForChainID(params.TestChainConfig.ChainID) txHashes = make([]common.Hash, 0, genTxs) @@ -2149,6 +2183,11 @@ func TestRPCGetTransactionReceiptsByBlock(t *testing.T) { } }) + txHashes = append(txHashes, mockStateSyncTxOnCurrentBlock(t, backend)) + + // map sprint 0 to block 1 + backend.ChainConfig().Bor.Sprint["0"] = 1 + api := NewBlockChainAPI(backend) blockHashes := make([]common.Hash, genBlocks+1) ctx := context.Background() @@ -2315,6 +2354,26 @@ func TestRPCGetTransactionReceiptsByBlock(t *testing.T) { "type": "0x1" }`, }, + // 5. state sync tx + { + txHash: txHashes[5], + want: `{ + "blockHash": "0x1728b788dfe51e507d25f14f01414b5a17f807953c13833811d2afae1982b53b", + "blockNumber": "0x1", + "contractAddress": null, + "cumulativeGasUsed": "0x0", + "effectiveGasPrice": "0x0", + "from": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x0", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "status": "0x1", + "to": "0x0000000000000000000000000000000000000000", + "transactionHash": "0xba46f68d5c3729ac3fb672fec579fc2cad543bc9edf5b2d47d7c6636ac2fbec9", + "transactionIndex": "0x5", + "type": "0x0" + }`, + }, } receipts, err := api.GetTransactionReceiptsByBlock(context.Background(), blockNrOrHash) diff --git a/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json b/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json index 2fb229ce2f..5096fa818f 100644 --- a/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json +++ b/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json @@ -1,17 +1,16 @@ { - "blockHash": "0x4d780246cde52e535f40603d47af8fa1aea807dd3065e1acd97127bea0922b3e", - "blockNumber": "0x6", - "contractAddress": null, - "cumulativeGasUsed": "0xe01c", - "effectiveGasPrice": "0x1ecb3fb4", - "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", - "gasUsed": "0xe01c", - "logs": [], - "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "status": "0x1", - "to": null, - "transactionHash": "0xb5a1148819cfdfff9bfe70035524fec940eb735d89b76960b97751d01ae2a9f2", - "transactionIndex": "0x0", - "type": "0x1" - } - \ No newline at end of file + "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", + "blockNumber": "0x6", + "contractAddress": null, + "cumulativeGasUsed": "0x0", + "effectiveGasPrice": "0x0", + "from": "0x0000000000000000000000000000000000000000", + "gasUsed": "0x0", + "logs": [], + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "status": "0x1", + "to": "0x0000000000000000000000000000000000000000", + "transactionHash": "0xfff9ab54386f3f5c5817e27cf1c8249968c13578c027389c021172d0568ebe12", + "transactionIndex": "0x1", + "type": "0x0" +} \ No newline at end of file From 828fc00b6f039445a3be8fc490ca521c68e390f4 Mon Sep 17 00:00:00 2001 From: Lucca Martins Date: Sun, 12 Jan 2025 09:44:47 -0300 Subject: [PATCH 2/7] GetTransactionByHash tests and rawdb call replacement --- internal/ethapi/api.go | 12 ++- internal/ethapi/api_test.go | 97 ++++++++++++------- .../eth_getTransactionByHash-blob-tx.json | 26 +++++ ...tTransactionByHash-create-contract-tx.json | 18 ++++ ...Hash-create-contract-with-access-list.json | 27 ++++++ ...ransactionByHash-dynamic-tx-with-logs.json | 22 +++++ ...tTransactionByHash-normal-transfer-tx.json | 17 ++++ ...th_getTransactionByHash-state-sync-tx.json | 17 ++++ ...eth_getTransactionByHash-txhash-empty.json | 1 + ..._getTransactionByHash-txhash-notfound.json | 1 + .../eth_getTransactionByHash-with-logs.json | 18 ++++ 11 files changed, 218 insertions(+), 38 deletions(-) create mode 100644 internal/ethapi/testdata/eth_getTransactionByHash-blob-tx.json create mode 100644 internal/ethapi/testdata/eth_getTransactionByHash-create-contract-tx.json create mode 100644 internal/ethapi/testdata/eth_getTransactionByHash-create-contract-with-access-list.json create mode 100644 internal/ethapi/testdata/eth_getTransactionByHash-dynamic-tx-with-logs.json create mode 100644 internal/ethapi/testdata/eth_getTransactionByHash-normal-transfer-tx.json create mode 100644 internal/ethapi/testdata/eth_getTransactionByHash-state-sync-tx.json create mode 100644 internal/ethapi/testdata/eth_getTransactionByHash-txhash-empty.json create mode 100644 internal/ethapi/testdata/eth_getTransactionByHash-txhash-notfound.json create mode 100644 internal/ethapi/testdata/eth_getTransactionByHash-with-logs.json diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index c02b66f256..a2621afc33 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -704,7 +704,10 @@ func (api *BlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context, blo var txHash common.Hash - borReceipt := rawdb.ReadBorReceipt(api.b.ChainDb(), block.Hash(), block.NumberU64(), api.b.ChainConfig()) + borReceipt, err := api.b.GetBorBlockReceipt(ctx, block.Hash()) + if err != nil { + return nil, err + } if borReceipt != nil { receipts = append(receipts, borReceipt) @@ -1115,7 +1118,10 @@ func (api *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rp result[i] = marshalReceipt(receipt, block.Hash(), block.NumberU64(), signer, txs[i], i, false) } - stateSyncReceipt := rawdb.ReadBorReceipt(api.b.ChainDb(), block.Hash(), block.NumberU64(), api.b.ChainConfig()) + stateSyncReceipt, err := api.b.GetBorBlockReceipt(ctx, block.Hash()) + if err != nil { + return nil, err + } if stateSyncReceipt != nil { tx, _, _, _ := rawdb.ReadBorTransaction(api.b.ChainDb(), stateSyncReceipt.TxHash) result = append(result, marshalReceipt(stateSyncReceipt, block.Hash(), block.NumberU64(), signer, tx, len(result), true)) @@ -1901,7 +1907,7 @@ func (api *TransactionAPI) getAllBlockTransactions(ctx context.Context, block *t stateSyncPresent := false - borReceipt := rawdb.ReadBorReceipt(api.b.ChainDb(), block.Hash(), block.NumberU64(), api.b.ChainConfig()) + borReceipt, _ := api.b.GetBorBlockReceipt(ctx, block.Hash()) if borReceipt != nil { txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash())) if txHash != (common.Hash{}) { diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 619bd9f072..4c72340c83 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -593,8 +593,10 @@ func (b testBackend) GetTransaction(ctx context.Context, txHash common.Hash) (bo } return found, tx, blockHash, blockNumber, index, nil } -func (b testBackend) GetPoolTransactions() (types.Transactions, error) { panic("implement me") } -func (b testBackend) GetPoolTransaction(txHash common.Hash) *types.Transaction { panic("implement me") } +func (b testBackend) GetPoolTransactions() (types.Transactions, error) { panic("implement me") } +func (b testBackend) GetPoolTransaction(txHash common.Hash) *types.Transaction { + return nil +} func (b testBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error) { return 0, nil } @@ -1907,7 +1909,10 @@ func TestRPCGetBlockOrHeader(t *testing.T) { } } -func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Hash) { +func setupBackendWithTxs(t *testing.T, genBlocks int) (*testBackend, []common.Hash, []struct { + txHash common.Hash + file string +}) { config := *params.TestChainConfig config.ShanghaiBlock = big.NewInt(0) @@ -2005,38 +2010,6 @@ func setupReceiptBackend(t *testing.T, genBlocks int) (*testBackend, []common.Ha txHashes[genBlocks] = mockStateSyncTxOnCurrentBlock(t, backend) - return backend, txHashes -} - -func mockStateSyncTxOnCurrentBlock(t *testing.T, backend *testBackend) common.Hash { - // State Sync Tx Setup - var stateSyncLogs []*types.Log - block, err := backend.BlockByHash(context.Background(), backend.CurrentBlock().Hash()) - if err != nil { - t.Errorf("failed to get current block: %v", err) - } - - types.DeriveFieldsForBorLogs(stateSyncLogs, block.Hash(), block.NumberU64(), 0, 0) - - // Write bor receipt - rawdb.WriteBorReceipt(backend.ChainDb(), block.Hash(), block.NumberU64(), &types.ReceiptForStorage{ - Status: types.ReceiptStatusSuccessful, // make receipt status successful - Logs: stateSyncLogs, - }) - - // Write bor tx reverse lookup - rawdb.WriteBorTxLookupEntry(backend.ChainDb(), block.Hash(), block.NumberU64()) - return types.GetDerivedBorTxHash(types.BorReceiptKey(block.NumberU64(), block.Hash())) -} - -func TestRPCGetTransactionReceipt(t *testing.T) { - t.Parallel() - - var ( - backend, txHashes = setupReceiptBackend(t, 6) - api = NewTransactionAPI(backend, new(AddrLocker)) - ) - var testSuite = []struct { txHash common.Hash file string @@ -2088,6 +2061,38 @@ func TestRPCGetTransactionReceipt(t *testing.T) { }, } + return backend, txHashes, testSuite +} + +func mockStateSyncTxOnCurrentBlock(t *testing.T, backend *testBackend) common.Hash { + // State Sync Tx Setup + var stateSyncLogs []*types.Log + block, err := backend.BlockByHash(context.Background(), backend.CurrentBlock().Hash()) + if err != nil { + t.Errorf("failed to get current block: %v", err) + } + + types.DeriveFieldsForBorLogs(stateSyncLogs, block.Hash(), block.NumberU64(), 0, 0) + + // Write bor receipt + rawdb.WriteBorReceipt(backend.ChainDb(), block.Hash(), block.NumberU64(), &types.ReceiptForStorage{ + Status: types.ReceiptStatusSuccessful, // make receipt status successful + Logs: stateSyncLogs, + }) + + // Write bor tx reverse lookup + rawdb.WriteBorTxLookupEntry(backend.ChainDb(), block.Hash(), block.NumberU64()) + return types.GetDerivedBorTxHash(types.BorReceiptKey(block.NumberU64(), block.Hash())) +} + +func TestRPCGetTransactionReceipt(t *testing.T) { + t.Parallel() + + var ( + backend, _, testSuite = setupBackendWithTxs(t, 6) + api = NewTransactionAPI(backend, new(AddrLocker)) + ) + for i, tt := range testSuite { var ( result interface{} @@ -2391,3 +2396,25 @@ func TestRPCGetTransactionReceiptsByBlock(t *testing.T) { require.JSONEqf(t, want, have, "test %d: json not match, want: %s, have: %s", i, want, have) } } + +func TestRPCGetTransactionByHash(t *testing.T) { + t.Parallel() + + var ( + backend, _, testSuite = setupBackendWithTxs(t, 6) + api = NewTransactionAPI(backend, new(AddrLocker)) + ) + + for i, tt := range testSuite { + var ( + result interface{} + err error + ) + result, err = api.GetTransactionByHash(context.Background(), tt.txHash) + if err != nil { + t.Errorf("test %d: want no error, have %v", i, err) + continue + } + testRPCResponseWithFile(t, i, result, "eth_getTransactionByHash", tt.file) + } +} diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-blob-tx.json b/internal/ethapi/testdata/eth_getTransactionByHash-blob-tx.json new file mode 100644 index 0000000000..a933311fdc --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByHash-blob-tx.json @@ -0,0 +1,26 @@ +{ + "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", + "blockNumber": "0x6", + "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", + "gas": "0x5208", + "gasPrice": "0x1b09d63b", + "maxFeePerGas": "0x1b09d82e", + "maxPriorityFeePerGas": "0x1", + "maxFeePerBlobGas": "0x1", + "hash": "0xb51ee3d2a89ba5d5623c73133c8d7a6ba9fb41194c17f4302c21b30994a1180f", + "input": "0x", + "nonce": "0x5", + "to": "0x0d3ab14bbad3d99f4203bd7a11acb94882050e7e", + "transactionIndex": "0x0", + "value": "0x0", + "type": "0x3", + "accessList": [], + "chainId": "0x1", + "blobVersionedHashes": [ + "0x0100000000000000000000000000000000000000000000000000000000000000" + ], + "v": "0x1", + "r": "0x38bb9fd000a5c38eab56c1b8ae96556fd58b417d2c8e175d22aadacbdea85d69", + "s": "0x2d50cc6ec19ce8d0736554e740ed7d451ac5e72488c186f87402d28bf301f0a3", + "yParity": "0x1" +} \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-create-contract-tx.json b/internal/ethapi/testdata/eth_getTransactionByHash-create-contract-tx.json new file mode 100644 index 0000000000..b4107154ae --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByHash-create-contract-tx.json @@ -0,0 +1,18 @@ +{ + "blockHash": "0xc594f1b119b071d288cd11371da2de73d67986a717974a85cac4ce634eba3015", + "blockNumber": "0x2", + "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", + "gas": "0xcf6c", + "gasPrice": "0x2db16291", + "hash": "0x340e58cda5086495010b571fe25067fecc9954dc4ee3cedece00691fa3f5904a", + "input": "0x60806040", + "nonce": "0x1", + "to": null, + "transactionIndex": "0x0", + "value": "0x0", + "type": "0x0", + "chainId": "0x1", + "v": "0x26", + "r": "0xfa210b09f8a13ea096b3a005a5feb0270121ab259555898bf03826e993ec14f4", + "s": "0x7173d180059852006668647a793207d488723b89acdd6c484273f16beb9aaa3" +} \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-create-contract-with-access-list.json b/internal/ethapi/testdata/eth_getTransactionByHash-create-contract-with-access-list.json new file mode 100644 index 0000000000..6a8f8f1804 --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByHash-create-contract-with-access-list.json @@ -0,0 +1,27 @@ +{ + "blockHash": "0x4d780246cde52e535f40603d47af8fa1aea807dd3065e1acd97127bea0922b3e", + "blockNumber": "0x5", + "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", + "gas": "0xe2f4", + "gasPrice": "0x1ecb3fb4", + "hash": "0xb5a1148819cfdfff9bfe70035524fec940eb735d89b76960b97751d01ae2a9f2", + "input": "0x60806040", + "nonce": "0x4", + "to": null, + "transactionIndex": "0x0", + "value": "0x0", + "type": "0x1", + "accessList": [ + { + "address": "0x0000000000000000000000000000000000031ec7", + "storageKeys": [ + "0x0000000000000000000000000000000000000000000000000000000000000000" + ] + } + ], + "chainId": "0x1", + "v": "0x0", + "r": "0xb4f6dc1e9c3c5904b7b3969e84dd3eefe68cf1b1951039ccf1848f471660671c", + "s": "0x77137b10f51515bcf3268f969a8bee4cb6d0d9521f402b058927071a9cc7e3d8", + "yParity": "0x0" +} \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-dynamic-tx-with-logs.json b/internal/ethapi/testdata/eth_getTransactionByHash-dynamic-tx-with-logs.json new file mode 100644 index 0000000000..d40f81aa75 --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByHash-dynamic-tx-with-logs.json @@ -0,0 +1,22 @@ +{ + "blockHash": "0x15158c4fb0661a38967dbf81b1592c54999b44a4580153b3469b29724903fc95", + "blockNumber": "0x4", + "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", + "gas": "0xea60", + "gasPrice": "0x2325c42f", + "maxFeePerGas": "0x2325c42f", + "maxPriorityFeePerGas": "0x1f4", + "hash": "0xdcde2574628c9d7dff22b9afa19f235959a924ceec65a9df903a517ae91f5c84", + "input": "0xa9059cbb0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e", + "nonce": "0x3", + "to": "0x0000000000000000000000000000000000031ec7", + "transactionIndex": "0x0", + "value": "0x1", + "type": "0x2", + "accessList": [], + "chainId": "0x1", + "v": "0x1", + "r": "0x41fa5d541e9081c6f636e6cb6c5dc0c4369c7d65df9b17f8ac47834f1eba4a6a", + "s": "0x6f811df916d0ec44e108740d6d307fd203273c26f9f52a785cb5fc551c5802f9", + "yParity": "0x1" +} \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-normal-transfer-tx.json b/internal/ethapi/testdata/eth_getTransactionByHash-normal-transfer-tx.json new file mode 100644 index 0000000000..54b5d3eeda --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByHash-normal-transfer-tx.json @@ -0,0 +1,17 @@ +{ + "blockHash": "0xfddc403b2acdace77774a35cbad7b68d50ce258fafaac399e21533a3b77ad94a", + "blockNumber": "0x1", + "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", + "gas": "0x5208", + "gasPrice": "0x342770c0", + "hash": "0x644a31c354391520d00e95b9affbbb010fc79ac268144ab8e28207f4cf51097e", + "input": "0x", + "nonce": "0x0", + "to": "0x0d3ab14bbad3d99f4203bd7a11acb94882050e7e", + "transactionIndex": "0x0", + "value": "0x3e8", + "type": "0x0", + "v": "0x1b", + "r": "0xcd190747077598c3b9c5f21ea06f8487d6ab1e23358fbe0e0e0c4e64651b68f3", + "s": "0x467ebcb2186b332969991e2e25244959dcdb3feb7652ff6b81ce96e646d86abd" +} \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-state-sync-tx.json b/internal/ethapi/testdata/eth_getTransactionByHash-state-sync-tx.json new file mode 100644 index 0000000000..3ac56785a2 --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByHash-state-sync-tx.json @@ -0,0 +1,17 @@ +{ + "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", + "blockNumber": "0x6", + "from": "0x0000000000000000000000000000000000000000", + "gas": "0x0", + "gasPrice": "0x0", + "hash": "0xfff9ab54386f3f5c5817e27cf1c8249968c13578c027389c021172d0568ebe12", + "input": "0x", + "nonce": "0x0", + "to": "0x0000000000000000000000000000000000000000", + "transactionIndex": "0x1", + "value": "0x0", + "type": "0x0", + "v": "0x0", + "r": "0x0", + "s": "0x0" +} \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-txhash-empty.json b/internal/ethapi/testdata/eth_getTransactionByHash-txhash-empty.json new file mode 100644 index 0000000000..ec747fa47d --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByHash-txhash-empty.json @@ -0,0 +1 @@ +null \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-txhash-notfound.json b/internal/ethapi/testdata/eth_getTransactionByHash-txhash-notfound.json new file mode 100644 index 0000000000..ec747fa47d --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByHash-txhash-notfound.json @@ -0,0 +1 @@ +null \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-with-logs.json b/internal/ethapi/testdata/eth_getTransactionByHash-with-logs.json new file mode 100644 index 0000000000..a9a8f9a472 --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByHash-with-logs.json @@ -0,0 +1,18 @@ +{ + "blockHash": "0x12db9de067ca71d47e360ab4eb9bf7bc80824f5edd39c7576e253f37a1a22782", + "blockNumber": "0x3", + "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", + "gas": "0xea60", + "gasPrice": "0x281c2585", + "hash": "0xeaf3921cbf03ba45bad4e6ab807b196ce3b2a0b5bacc355b6272fa96b11b4287", + "input": "0xa9059cbb0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000d", + "nonce": "0x2", + "to": "0x0000000000000000000000000000000000031ec7", + "transactionIndex": "0x0", + "value": "0x0", + "type": "0x0", + "chainId": "0x1", + "v": "0x25", + "r": "0xabecc8622990867d3889d6abb094e9247b5af59978c23d95b7020da6efa2c834", + "s": "0x31267ff2ffba8d2ff70d908feb98584872c3b3df47454cc3d04f342eb6c68b77" +} \ No newline at end of file From a345d6c95c189d2e9f2786dd872778a79ac7531c Mon Sep 17 00:00:00 2001 From: Lucca Martins Date: Sun, 12 Jan 2025 17:05:00 -0300 Subject: [PATCH 3/7] GetBlockReceipts test --- internal/ethapi/api_test.go | 84 ++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 4c72340c83..19b31c2ce8 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -690,14 +690,9 @@ func (b testBackend) GetBorBlockLogs(ctx context.Context, hash common.Hash) ([]* } func (b testBackend) GetBorBlockReceipt(ctx context.Context, hash common.Hash) (*types.Receipt, error) { - number := rawdb.ReadHeaderNumber(b.db, hash) - if number == nil { - return nil, nil - } - - receipt := rawdb.ReadRawBorReceipt(b.db, hash, *number) + receipt := b.chain.GetBorReceiptByHash(hash) if receipt == nil { - return nil, nil + return nil, ethereum.NotFound } return receipt, nil @@ -1909,12 +1904,12 @@ func TestRPCGetBlockOrHeader(t *testing.T) { } } -func setupBackendWithTxs(t *testing.T, genBlocks int) (*testBackend, []common.Hash, []struct { +func setupTransactionsToApiTest(t *testing.T) (*TransactionAPI, []common.Hash, []struct { txHash common.Hash file string }) { config := *params.TestChainConfig - + genBlocks := 6 config.ShanghaiBlock = big.NewInt(0) config.CancunBlock = big.NewInt(0) @@ -2060,8 +2055,9 @@ func setupBackendWithTxs(t *testing.T, genBlocks int) (*testBackend, []common.Ha file: "state-sync-tx", }, } + api := NewTransactionAPI(backend, new(AddrLocker)) - return backend, txHashes, testSuite + return api, txHashes, testSuite } func mockStateSyncTxOnCurrentBlock(t *testing.T, backend *testBackend) common.Hash { @@ -2089,8 +2085,7 @@ func TestRPCGetTransactionReceipt(t *testing.T) { t.Parallel() var ( - backend, _, testSuite = setupBackendWithTxs(t, 6) - api = NewTransactionAPI(backend, new(AddrLocker)) + api, _, testSuite = setupTransactionsToApiTest(t) ) for i, tt := range testSuite { @@ -2127,6 +2122,49 @@ func testRPCResponseWithFile(t *testing.T, testid int, result interface{}, rpc s func TestRPCGetTransactionReceiptsByBlock(t *testing.T) { t.Parallel() + api, blockNrOrHash, testSuite := setupBlocksToApiTest(t) + + receipts, err := api.GetTransactionReceiptsByBlock(context.Background(), blockNrOrHash) + if err != nil { + t.Fatal("api error") + } + + for i, tt := range testSuite { + data, err := json.Marshal(receipts[i]) + if err != nil { + t.Errorf("test %d: json marshal error", i) + continue + } + want, have := tt.want, string(data) + require.JSONEqf(t, want, have, "test %d: json not match, want: %s, have: %s", i, want, have) + } +} + +func TestRPCGetBlockReceipts(t *testing.T) { + t.Parallel() + + api, blockNrOrHash, testSuite := setupBlocksToApiTest(t) + + receipts, err := api.GetBlockReceipts(context.Background(), blockNrOrHash) + if err != nil { + t.Fatal("api error") + } + + for i, tt := range testSuite { + data, err := json.Marshal(receipts[i]) + if err != nil { + t.Errorf("test %d: json marshal error", i) + continue + } + want, have := tt.want, string(data) + require.JSONEqf(t, want, have, "test %d: json not match, want: %s, have: %s", i, want, have) + } +} + +func setupBlocksToApiTest(t *testing.T) (*BlockChainAPI, rpc.BlockNumberOrHash, []struct { + txHash common.Hash + want string +}) { // Initialize test accounts var ( acc1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") @@ -2194,9 +2232,9 @@ func TestRPCGetTransactionReceiptsByBlock(t *testing.T) { backend.ChainConfig().Bor.Sprint["0"] = 1 api := NewBlockChainAPI(backend) - blockHashes := make([]common.Hash, genBlocks+1) + blockHashes := make([]common.Hash, 2) ctx := context.Background() - for i := 0; i <= genBlocks; i++ { + for i := 0; i < 2; i++ { header, err := backend.HeaderByNumber(ctx, rpc.BlockNumber(i)) if err != nil { t.Errorf("failed to get block: %d err: %v", i, err) @@ -2381,28 +2419,14 @@ func TestRPCGetTransactionReceiptsByBlock(t *testing.T) { }, } - receipts, err := api.GetTransactionReceiptsByBlock(context.Background(), blockNrOrHash) - if err != nil { - t.Fatal("api error") - } - - for i, tt := range testSuite { - data, err := json.Marshal(receipts[i]) - if err != nil { - t.Errorf("test %d: json marshal error", i) - continue - } - want, have := tt.want, string(data) - require.JSONEqf(t, want, have, "test %d: json not match, want: %s, have: %s", i, want, have) - } + return api, blockNrOrHash, testSuite } func TestRPCGetTransactionByHash(t *testing.T) { t.Parallel() var ( - backend, _, testSuite = setupBackendWithTxs(t, 6) - api = NewTransactionAPI(backend, new(AddrLocker)) + api, _, testSuite = setupTransactionsToApiTest(t) ) for i, tt := range testSuite { From 5646ee62581c72b93dd98a3d1a45a205cdedb0e1 Mon Sep 17 00:00:00 2001 From: Lucca Martins Date: Sun, 12 Jan 2025 18:30:00 -0300 Subject: [PATCH 4/7] getAllBlockTransactionsTest --- internal/ethapi/api_test.go | 58 +++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 19b31c2ce8..59c16b5178 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -2055,6 +2055,9 @@ func setupTransactionsToApiTest(t *testing.T) (*TransactionAPI, []common.Hash, [ file: "state-sync-tx", }, } + // map sprint 0 to block 6 + backend.ChainConfig().Bor.Sprint["0"] = 6 + api := NewTransactionAPI(backend, new(AddrLocker)) return api, txHashes, testSuite @@ -2101,6 +2104,40 @@ func TestRPCGetTransactionReceipt(t *testing.T) { testRPCResponseWithFile(t, i, result, "eth_getTransactionReceipt", tt.file) } } +func TestRPCGetTransactionByHash(t *testing.T) { + t.Parallel() + + var ( + api, _, testSuite = setupTransactionsToApiTest(t) + ) + + for i, tt := range testSuite { + var ( + result interface{} + err error + ) + result, err = api.GetTransactionByHash(context.Background(), tt.txHash) + if err != nil { + t.Errorf("test %d: want no error, have %v", i, err) + continue + } + testRPCResponseWithFile(t, i, result, "eth_getTransactionByHash", tt.file) + } +} + +func TestRPCGetBlockTransactionCountByHash(t *testing.T) { + t.Parallel() + + var ( + api, _, _ = setupTransactionsToApiTest(t) + ) + + cnt := api.GetBlockTransactionCountByHash(context.Background(), api.b.CurrentBlock().Hash()) + + // 2 txs: blob tx + state sync tx + expected := hexutil.Uint(2) + require.Equal(t, expected, *cnt) +} func testRPCResponseWithFile(t *testing.T, testid int, result interface{}, rpc string, file string) { data, err := json.MarshalIndent(result, "", " ") @@ -2421,24 +2458,3 @@ func setupBlocksToApiTest(t *testing.T) (*BlockChainAPI, rpc.BlockNumberOrHash, return api, blockNrOrHash, testSuite } - -func TestRPCGetTransactionByHash(t *testing.T) { - t.Parallel() - - var ( - api, _, testSuite = setupTransactionsToApiTest(t) - ) - - for i, tt := range testSuite { - var ( - result interface{} - err error - ) - result, err = api.GetTransactionByHash(context.Background(), tt.txHash) - if err != nil { - t.Errorf("test %d: want no error, have %v", i, err) - continue - } - testRPCResponseWithFile(t, i, result, "eth_getTransactionByHash", tt.file) - } -} From 3582958cc083df554da6e98149f7e73cc3b29908 Mon Sep 17 00:00:00 2001 From: Lucca Martins Date: Sun, 12 Jan 2025 19:03:19 -0300 Subject: [PATCH 5/7] eth_getTransactionByBlockHashAndIndex tests and fix on parallel tests --- internal/ethapi/api_test.go | 22 +++++++++------- ...ransactionByBlockHashAndIndex-blob-tx.json | 26 +++++++++++++++++++ ...tionByBlockHashAndIndex-state-sync-tx.json | 17 ++++++++++++ 3 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-blob-tx.json create mode 100644 internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-state-sync-tx.json diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 59c16b5178..e232ae5206 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -2085,8 +2085,6 @@ func mockStateSyncTxOnCurrentBlock(t *testing.T, backend *testBackend) common.Ha } func TestRPCGetTransactionReceipt(t *testing.T) { - t.Parallel() - var ( api, _, testSuite = setupTransactionsToApiTest(t) ) @@ -2105,8 +2103,6 @@ func TestRPCGetTransactionReceipt(t *testing.T) { } } func TestRPCGetTransactionByHash(t *testing.T) { - t.Parallel() - var ( api, _, testSuite = setupTransactionsToApiTest(t) ) @@ -2126,8 +2122,6 @@ func TestRPCGetTransactionByHash(t *testing.T) { } func TestRPCGetBlockTransactionCountByHash(t *testing.T) { - t.Parallel() - var ( api, _, _ = setupTransactionsToApiTest(t) ) @@ -2139,6 +2133,18 @@ func TestRPCGetBlockTransactionCountByHash(t *testing.T) { require.Equal(t, expected, *cnt) } +func TestRPCGetTransactionByBlockHashAndIndex(t *testing.T) { + var ( + api, _, _ = setupTransactionsToApiTest(t) + ) + + blobTx := api.GetTransactionByBlockHashAndIndex(context.Background(), api.b.CurrentBlock().Hash(), 0) + stateSyncTx := api.GetTransactionByBlockHashAndIndex(context.Background(), api.b.CurrentBlock().Hash(), 1) + + testRPCResponseWithFile(t, 0, blobTx, "eth_getTransactionByBlockHashAndIndex", "blob-tx") + testRPCResponseWithFile(t, 1, stateSyncTx, "eth_getTransactionByBlockHashAndIndex", "state-sync-tx") +} + func testRPCResponseWithFile(t *testing.T, testid int, result interface{}, rpc string, file string) { data, err := json.MarshalIndent(result, "", " ") if err != nil { @@ -2157,8 +2163,6 @@ func testRPCResponseWithFile(t *testing.T, testid int, result interface{}, rpc s } func TestRPCGetTransactionReceiptsByBlock(t *testing.T) { - t.Parallel() - api, blockNrOrHash, testSuite := setupBlocksToApiTest(t) receipts, err := api.GetTransactionReceiptsByBlock(context.Background(), blockNrOrHash) @@ -2178,8 +2182,6 @@ func TestRPCGetTransactionReceiptsByBlock(t *testing.T) { } func TestRPCGetBlockReceipts(t *testing.T) { - t.Parallel() - api, blockNrOrHash, testSuite := setupBlocksToApiTest(t) receipts, err := api.GetBlockReceipts(context.Background(), blockNrOrHash) diff --git a/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-blob-tx.json b/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-blob-tx.json new file mode 100644 index 0000000000..a933311fdc --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-blob-tx.json @@ -0,0 +1,26 @@ +{ + "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", + "blockNumber": "0x6", + "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", + "gas": "0x5208", + "gasPrice": "0x1b09d63b", + "maxFeePerGas": "0x1b09d82e", + "maxPriorityFeePerGas": "0x1", + "maxFeePerBlobGas": "0x1", + "hash": "0xb51ee3d2a89ba5d5623c73133c8d7a6ba9fb41194c17f4302c21b30994a1180f", + "input": "0x", + "nonce": "0x5", + "to": "0x0d3ab14bbad3d99f4203bd7a11acb94882050e7e", + "transactionIndex": "0x0", + "value": "0x0", + "type": "0x3", + "accessList": [], + "chainId": "0x1", + "blobVersionedHashes": [ + "0x0100000000000000000000000000000000000000000000000000000000000000" + ], + "v": "0x1", + "r": "0x38bb9fd000a5c38eab56c1b8ae96556fd58b417d2c8e175d22aadacbdea85d69", + "s": "0x2d50cc6ec19ce8d0736554e740ed7d451ac5e72488c186f87402d28bf301f0a3", + "yParity": "0x1" +} \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-state-sync-tx.json b/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-state-sync-tx.json new file mode 100644 index 0000000000..3ac56785a2 --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-state-sync-tx.json @@ -0,0 +1,17 @@ +{ + "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", + "blockNumber": "0x6", + "from": "0x0000000000000000000000000000000000000000", + "gas": "0x0", + "gasPrice": "0x0", + "hash": "0xfff9ab54386f3f5c5817e27cf1c8249968c13578c027389c021172d0568ebe12", + "input": "0x", + "nonce": "0x0", + "to": "0x0000000000000000000000000000000000000000", + "transactionIndex": "0x1", + "value": "0x0", + "type": "0x0", + "v": "0x0", + "r": "0x0", + "s": "0x0" +} \ No newline at end of file From 31e7d4a4edcfb41d2051e64ac1b0316a3473c5dd Mon Sep 17 00:00:00 2001 From: Lucca Martins Date: Mon, 13 Jan 2025 07:26:21 -0300 Subject: [PATCH 6/7] proper error handling for not found scenarios --- internal/ethapi/api.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a2621afc33..9cb7131d31 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -29,6 +29,7 @@ import ( "github.com/davecgh/go-spew/spew" "github.com/tyler-smith/go-bip39" + "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/scwallet" @@ -705,7 +706,7 @@ func (api *BlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context, blo var txHash common.Hash borReceipt, err := api.b.GetBorBlockReceipt(ctx, block.Hash()) - if err != nil { + if err != nil && err != ethereum.NotFound { return nil, err } if borReceipt != nil { @@ -1119,7 +1120,7 @@ func (api *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rp } stateSyncReceipt, err := api.b.GetBorBlockReceipt(ctx, block.Hash()) - if err != nil { + if err != nil && err != ethereum.NotFound { return nil, err } if stateSyncReceipt != nil { @@ -2096,7 +2097,7 @@ func (api *TransactionAPI) GetTransactionReceipt(ctx context.Context, hash commo if borTx { // Fetch bor block receipt receipt, err = api.b.GetBorBlockReceipt(ctx, blockHash) - if err != nil { + if err != nil && err != ethereum.NotFound { return nil, err } } else { From b0bba24d7c98380785a6288a18b0fe4f184afb14 Mon Sep 17 00:00:00 2001 From: Lucca Martins Date: Tue, 14 Jan 2025 04:08:07 -0300 Subject: [PATCH 7/7] removed blob tx tests --- internal/ethapi/api_test.go | 35 +++++-------------- ...h_getBlockReceipts-block-with-blob-tx.json | 20 ----------- .../eth_getBlockReceipts-tag-latest.json | 4 +-- ...ransactionByBlockHashAndIndex-blob-tx.json | 26 -------------- ...ndex-create-contract-with-access-list.json | 27 ++++++++++++++ ...tionByBlockHashAndIndex-state-sync-tx.json | 6 ++-- .../eth_getTransactionByHash-blob-tx.json | 26 -------------- ...th_getTransactionByHash-state-sync-tx.json | 6 ++-- .../eth_getTransactionReceipt-blob-tx.json | 18 ---------- ...h_getTransactionReceipt-state-sync-tx.json | 6 ++-- 10 files changed, 46 insertions(+), 128 deletions(-) delete mode 100644 internal/ethapi/testdata/eth_getBlockReceipts-block-with-blob-tx.json delete mode 100644 internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-blob-tx.json create mode 100644 internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-create-contract-with-access-list.json delete mode 100644 internal/ethapi/testdata/eth_getTransactionByHash-blob-tx.json delete mode 100644 internal/ethapi/testdata/eth_getTransactionReceipt-blob-tx.json diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index e232ae5206..7d1d8519f0 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -1909,7 +1909,7 @@ func setupTransactionsToApiTest(t *testing.T) (*TransactionAPI, []common.Hash, [ file string }) { config := *params.TestChainConfig - genBlocks := 6 + genBlocks := 5 config.ShanghaiBlock = big.NewInt(0) config.CancunBlock = big.NewInt(0) @@ -1979,20 +1979,6 @@ func setupTransactionsToApiTest(t *testing.T) (*TransactionAPI, []common.Hash, [ StorageKeys: []common.Hash{{0}}, }} tx, err = types.SignTx(types.NewTx(&types.AccessListTx{Nonce: uint64(i), To: nil, Gas: 58100, GasPrice: b.BaseFee(), Data: common.FromHex("0x60806040"), AccessList: accessList}), signer, acc1Key) - case 5: - // blob tx - fee := big.NewInt(500) - fee.Add(fee, b.BaseFee()) - tx, err = types.SignTx(types.NewTx(&types.BlobTx{ - Nonce: uint64(i), - GasTipCap: uint256.NewInt(1), - GasFeeCap: uint256.MustFromBig(fee), - Gas: params.TxGas, - To: acc2Addr, - BlobFeeCap: uint256.NewInt(1), - BlobHashes: []common.Hash{{1}}, - Value: new(uint256.Int), - }), signer, acc1Key) } if err != nil { t.Errorf("failed to sign tx: %v", err) @@ -2044,19 +2030,14 @@ func setupTransactionsToApiTest(t *testing.T) (*TransactionAPI, []common.Hash, [ txHash: common.HexToHash("deadbeef"), file: "txhash-notfound", }, - // 7. blob tx + // 7. state sync tx found { txHash: txHashes[5], - file: "blob-tx", - }, - // 8. state sync tx found - { - txHash: txHashes[6], file: "state-sync-tx", }, } // map sprint 0 to block 6 - backend.ChainConfig().Bor.Sprint["0"] = 6 + backend.ChainConfig().Bor.Sprint["0"] = uint64(genBlocks) api := NewTransactionAPI(backend, new(AddrLocker)) @@ -2128,7 +2109,7 @@ func TestRPCGetBlockTransactionCountByHash(t *testing.T) { cnt := api.GetBlockTransactionCountByHash(context.Background(), api.b.CurrentBlock().Hash()) - // 2 txs: blob tx + state sync tx + // 2 txs: create-contract-with-access-list + state sync tx expected := hexutil.Uint(2) require.Equal(t, expected, *cnt) } @@ -2138,10 +2119,10 @@ func TestRPCGetTransactionByBlockHashAndIndex(t *testing.T) { api, _, _ = setupTransactionsToApiTest(t) ) - blobTx := api.GetTransactionByBlockHashAndIndex(context.Background(), api.b.CurrentBlock().Hash(), 0) + createContractWithAccessList := api.GetTransactionByBlockHashAndIndex(context.Background(), api.b.CurrentBlock().Hash(), 0) stateSyncTx := api.GetTransactionByBlockHashAndIndex(context.Background(), api.b.CurrentBlock().Hash(), 1) - testRPCResponseWithFile(t, 0, blobTx, "eth_getTransactionByBlockHashAndIndex", "blob-tx") + testRPCResponseWithFile(t, 0, createContractWithAccessList, "eth_getTransactionByBlockHashAndIndex", "create-contract-with-access-list") testRPCResponseWithFile(t, 1, stateSyncTx, "eth_getTransactionByBlockHashAndIndex", "state-sync-tx") } @@ -2271,9 +2252,9 @@ func setupBlocksToApiTest(t *testing.T) (*BlockChainAPI, rpc.BlockNumberOrHash, backend.ChainConfig().Bor.Sprint["0"] = 1 api := NewBlockChainAPI(backend) - blockHashes := make([]common.Hash, 2) + blockHashes := make([]common.Hash, genBlocks+1) ctx := context.Background() - for i := 0; i < 2; i++ { + for i := 0; i <= genBlocks; i++ { header, err := backend.HeaderByNumber(ctx, rpc.BlockNumber(i)) if err != nil { t.Errorf("failed to get block: %d err: %v", i, err) diff --git a/internal/ethapi/testdata/eth_getBlockReceipts-block-with-blob-tx.json b/internal/ethapi/testdata/eth_getBlockReceipts-block-with-blob-tx.json deleted file mode 100644 index 65c485f09b..0000000000 --- a/internal/ethapi/testdata/eth_getBlockReceipts-block-with-blob-tx.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "blobGasPrice": null, - "blobGasUsed": "0x20000", - "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", - "blockNumber": "0x6", - "contractAddress": null, - "cumulativeGasUsed": "0x5208", - "effectiveGasPrice": "0x1b09d63b", - "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", - "gasUsed": "0x5208", - "logs": [{"address": "0x0000000000000000000000000000000000001010", "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", "blockNumber": "0x6", "data": "0x00000000000000000000000000000000000000000000000000000000000052080000000000000000000000000000000000000000000000000de04bce435b746d0000000000000000000000000000000000000000000000000000000000a32f640000000000000000000000000000000000000000000000000de04bce435b22650000000000000000000000000000000000000000000000000000000000a3816c", "logIndex": "0x0", "removed": false, "topics": ["0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63", "0x0000000000000000000000000000000000000000000000000000000000001010", "0x000000000000000000000000703c4b2bd70c169f5717101caee543299fc946c7", "0x0000000000000000000000000000000000000000000000000000000000000000"], "transactionHash": "0xb51ee3d2a89ba5d5623c73133c8d7a6ba9fb41194c17f4302c21b30994a1180f", "transactionIndex": "0x0"}], - "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000800000000000000000000100000020000000000000020000000000000000000800000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004000000000000000000001800000000000000000000000000000100000000020000000000000000000000000000000000000000020000000000000000000100000", - "status": "0x1", - "to": "0x0d3ab14bbad3d99f4203bd7a11acb94882050e7e", - "transactionHash": "0xb51ee3d2a89ba5d5623c73133c8d7a6ba9fb41194c17f4302c21b30994a1180f", - "transactionIndex": "0x0", - "type": "0x3" - } -] diff --git a/internal/ethapi/testdata/eth_getBlockReceipts-tag-latest.json b/internal/ethapi/testdata/eth_getBlockReceipts-tag-latest.json index 65c485f09b..0ae57519ff 100644 --- a/internal/ethapi/testdata/eth_getBlockReceipts-tag-latest.json +++ b/internal/ethapi/testdata/eth_getBlockReceipts-tag-latest.json @@ -2,14 +2,14 @@ { "blobGasPrice": null, "blobGasUsed": "0x20000", - "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", + "blockHash": "0x4d780246cde52e535f40603d47af8fa1aea807dd3065e1acd97127bea0922b3e", "blockNumber": "0x6", "contractAddress": null, "cumulativeGasUsed": "0x5208", "effectiveGasPrice": "0x1b09d63b", "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", "gasUsed": "0x5208", - "logs": [{"address": "0x0000000000000000000000000000000000001010", "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", "blockNumber": "0x6", "data": "0x00000000000000000000000000000000000000000000000000000000000052080000000000000000000000000000000000000000000000000de04bce435b746d0000000000000000000000000000000000000000000000000000000000a32f640000000000000000000000000000000000000000000000000de04bce435b22650000000000000000000000000000000000000000000000000000000000a3816c", "logIndex": "0x0", "removed": false, "topics": ["0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63", "0x0000000000000000000000000000000000000000000000000000000000001010", "0x000000000000000000000000703c4b2bd70c169f5717101caee543299fc946c7", "0x0000000000000000000000000000000000000000000000000000000000000000"], "transactionHash": "0xb51ee3d2a89ba5d5623c73133c8d7a6ba9fb41194c17f4302c21b30994a1180f", "transactionIndex": "0x0"}], + "logs": [{"address": "0x0000000000000000000000000000000000001010", "blockHash": "0x4d780246cde52e535f40603d47af8fa1aea807dd3065e1acd97127bea0922b3e", "blockNumber": "0x6", "data": "0x00000000000000000000000000000000000000000000000000000000000052080000000000000000000000000000000000000000000000000de04bce435b746d0000000000000000000000000000000000000000000000000000000000a32f640000000000000000000000000000000000000000000000000de04bce435b22650000000000000000000000000000000000000000000000000000000000a3816c", "logIndex": "0x0", "removed": false, "topics": ["0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63", "0x0000000000000000000000000000000000000000000000000000000000001010", "0x000000000000000000000000703c4b2bd70c169f5717101caee543299fc946c7", "0x0000000000000000000000000000000000000000000000000000000000000000"], "transactionHash": "0xb51ee3d2a89ba5d5623c73133c8d7a6ba9fb41194c17f4302c21b30994a1180f", "transactionIndex": "0x0"}], "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000800000000000000000000100000020000000000000020000000000000000000800000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004000000000000000000001800000000000000000000000000000100000000020000000000000000000000000000000000000000020000000000000000000100000", "status": "0x1", "to": "0x0d3ab14bbad3d99f4203bd7a11acb94882050e7e", diff --git a/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-blob-tx.json b/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-blob-tx.json deleted file mode 100644 index a933311fdc..0000000000 --- a/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-blob-tx.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", - "blockNumber": "0x6", - "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", - "gas": "0x5208", - "gasPrice": "0x1b09d63b", - "maxFeePerGas": "0x1b09d82e", - "maxPriorityFeePerGas": "0x1", - "maxFeePerBlobGas": "0x1", - "hash": "0xb51ee3d2a89ba5d5623c73133c8d7a6ba9fb41194c17f4302c21b30994a1180f", - "input": "0x", - "nonce": "0x5", - "to": "0x0d3ab14bbad3d99f4203bd7a11acb94882050e7e", - "transactionIndex": "0x0", - "value": "0x0", - "type": "0x3", - "accessList": [], - "chainId": "0x1", - "blobVersionedHashes": [ - "0x0100000000000000000000000000000000000000000000000000000000000000" - ], - "v": "0x1", - "r": "0x38bb9fd000a5c38eab56c1b8ae96556fd58b417d2c8e175d22aadacbdea85d69", - "s": "0x2d50cc6ec19ce8d0736554e740ed7d451ac5e72488c186f87402d28bf301f0a3", - "yParity": "0x1" -} \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-create-contract-with-access-list.json b/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-create-contract-with-access-list.json new file mode 100644 index 0000000000..6a8f8f1804 --- /dev/null +++ b/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-create-contract-with-access-list.json @@ -0,0 +1,27 @@ +{ + "blockHash": "0x4d780246cde52e535f40603d47af8fa1aea807dd3065e1acd97127bea0922b3e", + "blockNumber": "0x5", + "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", + "gas": "0xe2f4", + "gasPrice": "0x1ecb3fb4", + "hash": "0xb5a1148819cfdfff9bfe70035524fec940eb735d89b76960b97751d01ae2a9f2", + "input": "0x60806040", + "nonce": "0x4", + "to": null, + "transactionIndex": "0x0", + "value": "0x0", + "type": "0x1", + "accessList": [ + { + "address": "0x0000000000000000000000000000000000031ec7", + "storageKeys": [ + "0x0000000000000000000000000000000000000000000000000000000000000000" + ] + } + ], + "chainId": "0x1", + "v": "0x0", + "r": "0xb4f6dc1e9c3c5904b7b3969e84dd3eefe68cf1b1951039ccf1848f471660671c", + "s": "0x77137b10f51515bcf3268f969a8bee4cb6d0d9521f402b058927071a9cc7e3d8", + "yParity": "0x0" +} \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-state-sync-tx.json b/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-state-sync-tx.json index 3ac56785a2..e1e290b0ff 100644 --- a/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-state-sync-tx.json +++ b/internal/ethapi/testdata/eth_getTransactionByBlockHashAndIndex-state-sync-tx.json @@ -1,10 +1,10 @@ { - "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", - "blockNumber": "0x6", + "blockHash": "0x4d780246cde52e535f40603d47af8fa1aea807dd3065e1acd97127bea0922b3e", + "blockNumber": "0x5", "from": "0x0000000000000000000000000000000000000000", "gas": "0x0", "gasPrice": "0x0", - "hash": "0xfff9ab54386f3f5c5817e27cf1c8249968c13578c027389c021172d0568ebe12", + "hash": "0x08ce9234678f85834bdf3ebed2d580dbac00a3899f9e7020e36c9a93fd1a610a", "input": "0x", "nonce": "0x0", "to": "0x0000000000000000000000000000000000000000", diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-blob-tx.json b/internal/ethapi/testdata/eth_getTransactionByHash-blob-tx.json deleted file mode 100644 index a933311fdc..0000000000 --- a/internal/ethapi/testdata/eth_getTransactionByHash-blob-tx.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", - "blockNumber": "0x6", - "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", - "gas": "0x5208", - "gasPrice": "0x1b09d63b", - "maxFeePerGas": "0x1b09d82e", - "maxPriorityFeePerGas": "0x1", - "maxFeePerBlobGas": "0x1", - "hash": "0xb51ee3d2a89ba5d5623c73133c8d7a6ba9fb41194c17f4302c21b30994a1180f", - "input": "0x", - "nonce": "0x5", - "to": "0x0d3ab14bbad3d99f4203bd7a11acb94882050e7e", - "transactionIndex": "0x0", - "value": "0x0", - "type": "0x3", - "accessList": [], - "chainId": "0x1", - "blobVersionedHashes": [ - "0x0100000000000000000000000000000000000000000000000000000000000000" - ], - "v": "0x1", - "r": "0x38bb9fd000a5c38eab56c1b8ae96556fd58b417d2c8e175d22aadacbdea85d69", - "s": "0x2d50cc6ec19ce8d0736554e740ed7d451ac5e72488c186f87402d28bf301f0a3", - "yParity": "0x1" -} \ No newline at end of file diff --git a/internal/ethapi/testdata/eth_getTransactionByHash-state-sync-tx.json b/internal/ethapi/testdata/eth_getTransactionByHash-state-sync-tx.json index 3ac56785a2..e1e290b0ff 100644 --- a/internal/ethapi/testdata/eth_getTransactionByHash-state-sync-tx.json +++ b/internal/ethapi/testdata/eth_getTransactionByHash-state-sync-tx.json @@ -1,10 +1,10 @@ { - "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", - "blockNumber": "0x6", + "blockHash": "0x4d780246cde52e535f40603d47af8fa1aea807dd3065e1acd97127bea0922b3e", + "blockNumber": "0x5", "from": "0x0000000000000000000000000000000000000000", "gas": "0x0", "gasPrice": "0x0", - "hash": "0xfff9ab54386f3f5c5817e27cf1c8249968c13578c027389c021172d0568ebe12", + "hash": "0x08ce9234678f85834bdf3ebed2d580dbac00a3899f9e7020e36c9a93fd1a610a", "input": "0x", "nonce": "0x0", "to": "0x0000000000000000000000000000000000000000", diff --git a/internal/ethapi/testdata/eth_getTransactionReceipt-blob-tx.json b/internal/ethapi/testdata/eth_getTransactionReceipt-blob-tx.json deleted file mode 100644 index 610cd2c821..0000000000 --- a/internal/ethapi/testdata/eth_getTransactionReceipt-blob-tx.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "blobGasPrice": null, - "blobGasUsed": "0x20000", - "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", - "blockNumber": "0x6", - "contractAddress": null, - "cumulativeGasUsed": "0x5208", - "effectiveGasPrice": "0x1b09d63b", - "from": "0x703c4b2bd70c169f5717101caee543299fc946c7", - "gasUsed": "0x5208", - "logs": [{"address": "0x0000000000000000000000000000000000001010", "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", "blockNumber": "0x6", "data": "0x00000000000000000000000000000000000000000000000000000000000052080000000000000000000000000000000000000000000000000de04bce435b746d0000000000000000000000000000000000000000000000000000000000a32f640000000000000000000000000000000000000000000000000de04bce435b22650000000000000000000000000000000000000000000000000000000000a3816c", "logIndex": "0x0", "removed": false, "topics": ["0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63", "0x0000000000000000000000000000000000000000000000000000000000001010", "0x000000000000000000000000703c4b2bd70c169f5717101caee543299fc946c7", "0x0000000000000000000000000000000000000000000000000000000000000000"], "transactionHash": "0xb51ee3d2a89ba5d5623c73133c8d7a6ba9fb41194c17f4302c21b30994a1180f", "transactionIndex": "0x0"}], - "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000800000000000000000000100000020000000000000020000000000000000000800000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000004000000000000000000001800000000000000000000000000000100000000020000000000000000000000000000000000000000020000000000000000000100000", - "status": "0x1", - "to": "0x0d3ab14bbad3d99f4203bd7a11acb94882050e7e", - "transactionHash": "0xb51ee3d2a89ba5d5623c73133c8d7a6ba9fb41194c17f4302c21b30994a1180f", - "transactionIndex": "0x0", - "type": "0x3" -} diff --git a/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json b/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json index 5096fa818f..a40d454741 100644 --- a/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json +++ b/internal/ethapi/testdata/eth_getTransactionReceipt-state-sync-tx.json @@ -1,6 +1,6 @@ { - "blockHash": "0x4446b1498499cab37cfec330097fadf285c703444d431756940528d32fe0e97b", - "blockNumber": "0x6", + "blockHash": "0x4d780246cde52e535f40603d47af8fa1aea807dd3065e1acd97127bea0922b3e", + "blockNumber": "0x5", "contractAddress": null, "cumulativeGasUsed": "0x0", "effectiveGasPrice": "0x0", @@ -10,7 +10,7 @@ "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "status": "0x1", "to": "0x0000000000000000000000000000000000000000", - "transactionHash": "0xfff9ab54386f3f5c5817e27cf1c8249968c13578c027389c021172d0568ebe12", + "transactionHash": "0x08ce9234678f85834bdf3ebed2d580dbac00a3899f9e7020e36c9a93fd1a610a", "transactionIndex": "0x1", "type": "0x0" } \ No newline at end of file