Skip to content

Commit

Permalink
Add block receipt test
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliy committed Sep 10, 2024
1 parent c9bb555 commit 5bffb35
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
61 changes: 61 additions & 0 deletions packages/evm/jsonrpc/jsonrpctest/jsonrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,67 @@ func TestRPCTraceBlock(t *testing.T) {
require.Empty(t, innerCall2.RevertReason)
}

func TestRPCBlockReceipt(t *testing.T) {
env := newSoloTestEnv(t)
creator, creatorAddress := env.soloChain.NewEthereumAccountWithL2Funds()
creator2, creatorAddress2 := env.soloChain.NewEthereumAccountWithL2Funds()
contractABI, err := abi.JSON(strings.NewReader(evmtest.ISCTestContractABI))
require.NoError(t, err)
_, _, contractAddress := env.DeployEVMContract(creator, contractABI, evmtest.ISCTestContractBytecode)

tx1 := types.MustSignNewTx(creator, types.NewEIP155Signer(big.NewInt(int64(env.ChainID))),
&types.LegacyTx{
Nonce: env.NonceAt(creatorAddress),
To: &contractAddress,
Value: big.NewInt(123),
Gas: 100000,
GasPrice: big.NewInt(10000000000),
Data: lo.Must(contractABI.Pack("sendTo", common.Address{0x1}, big.NewInt(2))),
})

tx2 := types.MustSignNewTx(creator2, types.NewEIP155Signer(big.NewInt(int64(env.ChainID))),
&types.LegacyTx{
Nonce: env.NonceAt(creatorAddress2),
To: &contractAddress,
Value: big.NewInt(321),
Gas: 100000,
GasPrice: big.NewInt(10000000000),
Data: lo.Must(contractABI.Pack("sendTo", common.Address{0x2}, big.NewInt(3))),
})

req1 := lo.Must(isc.NewEVMOffLedgerTxRequest(env.soloChain.ChainID, tx1))
req2 := lo.Must(isc.NewEVMOffLedgerTxRequest(env.soloChain.ChainID, tx2))
env.soloChain.WaitForRequestsMark()
env.soloChain.Env.AddRequestsToMempool(env.soloChain, []isc.Request{req1, req2})
require.True(t, env.soloChain.WaitForRequestsThrough(2, 180*time.Second))

bi := env.soloChain.GetLatestBlockInfo()
require.EqualValues(t, 2, bi.NumSuccessfulRequests)

var resceipts []*types.Receipt
err = env.RawClient.CallContext(
context.Background(),
&resceipts,
"eth_getBlockReceipts",
env.BlockNumber())
require.NoError(t, err)

require.Len(t, resceipts, 2)

r1 := resceipts[slices.IndexFunc(resceipts, func(v *types.Receipt) bool {
return v.TxHash == tx1.Hash()
})]

r2 := resceipts[slices.IndexFunc(resceipts, func(v *types.Receipt) bool {
return v.TxHash == tx2.Hash()
})]

require.Equal(t, uint64(1), r1.Status)
require.Equal(t, big.NewInt(4), r1.BlockNumber)
require.Equal(t, uint64(1), r2.Status)
require.Equal(t, big.NewInt(4), r1.BlockNumber)
}

func BenchmarkRPCEstimateGas(b *testing.B) {
env := newSoloTestEnv(b)
_, addr := env.soloChain.NewEthereumAccountWithL2Funds()
Expand Down
4 changes: 2 additions & 2 deletions packages/evm/jsonrpc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,9 @@ func (e *EthService) Logs(ctx context.Context, q *RPCFilterQuery) (*rpc.Subscrip
return rpcSub, nil
}

func (e *EthService) GetBlockReceipts(blockNumber rpc.BlockNumber) ([]*types.Receipt, error) {
func (e *EthService) GetBlockReceipts(blockNumber int64) ([]*types.Receipt, error) {
return withMetrics(e.metrics, "eth_getBlockReceipts", func() ([]*types.Receipt, error) {
receipts, err := e.evmChain.GetBlockReceipts(blockNumber)
receipts, err := e.evmChain.GetBlockReceipts(rpc.BlockNumber(blockNumber))
if err != nil {
return nil, e.resolveError(err)
}
Expand Down

0 comments on commit 5bffb35

Please sign in to comment.