From 5646ee62581c72b93dd98a3d1a45a205cdedb0e1 Mon Sep 17 00:00:00 2001 From: Lucca Martins Date: Sun, 12 Jan 2025 18:30:00 -0300 Subject: [PATCH] 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) - } -}