Skip to content

Commit

Permalink
getAllBlockTransactionsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
lucca30 committed Jan 12, 2025
1 parent a345d6c commit 5646ee6
Showing 1 changed file with 37 additions and 21 deletions.
58 changes: 37 additions & 21 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, "", " ")
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 5646ee6

Please sign in to comment.