Skip to content

Commit

Permalink
jsonrpc: add tests for the jsonRPC calls we make to arbitrum nitro.
Browse files Browse the repository at this point in the history
the test data file now is labelled w/ the block number and chain..
  • Loading branch information
msf committed Jul 29, 2024
1 parent de66997 commit 9786d69
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 0 deletions.
82 changes: 82 additions & 0 deletions client/jsonrpc/arbitrum_nitro_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package jsonrpc_test

import (
"bytes"
"context"
"testing"

"github.com/duneanalytics/blockchain-ingester/models"
"github.com/stretchr/testify/require"
)

func TestArbitrumNitroBasic(t *testing.T) {
getBlockByNumberResponse := readFileForTest(
"testdata/arbitrumnitro-DEGEN-block-0x16870e9-eth_getBlockByNumber.json")
debugtraceBlockByNumberResponse := readFileForTest(
"testdata/arbitrumnitro-DEGEN-block-0x16870e9-debug_traceBlockByNumber.json")
tx0ReceiptResponse := readFileForTest(
"testdata/arbitrumnitro-DEGEN-block-0x16870e9-eth_getTransactionReceipt-0x0.json")
tx1ReceiptResponse := readFileForTest(
"testdata/arbitrumnitro-DEGEN-block-0x16870e9-eth_getTransactionReceipt-0x1.json")

var expectedPayload bytes.Buffer
expectedPayload.Write(getBlockByNumberResponse.Bytes())
expectedPayload.Write(debugtraceBlockByNumberResponse.Bytes())
expectedPayload.Write(tx0ReceiptResponse.Bytes())
expectedPayload.Write(tx1ReceiptResponse.Bytes())
expectedPayloadBytes := expectedPayload.Bytes()

tx0Hash := "0x19ee83020d4dad7e96dbb2c01ce2441e75717ee038a022fc6a3b61300b1b801c"
tx1Hash := "0x4e805891b568698f8419f8e162d70ed9675e42a32e4972cbeb7f78d7fd51de76"
blockNumberHex := "0x16870e9"
blockNumber := int64(23621865)
httpClientMock := MockHTTPRequests(
[]MockedRequest{
{
Req: jsonRPCRequest{
Method: "eth_getBlockByNumber",
Params: []interface{}{blockNumberHex, true},
},
Resp: jsonRPCResponse{
Body: getBlockByNumberResponse,
},
},
{
Req: jsonRPCRequest{
Method: "debug_traceBlockByNumber",
Params: []interface{}{blockNumberHex, map[string]string{"tracer": "callTracer"}},
},
Resp: jsonRPCResponse{
Body: debugtraceBlockByNumberResponse,
},
},
{
Req: jsonRPCRequest{
Method: "eth_getTransactionReceipt",
Params: []interface{}{tx0Hash},
},
Resp: jsonRPCResponse{
Body: tx0ReceiptResponse,
},
},
{
Req: jsonRPCRequest{
Method: "eth_getTransactionReceipt",
Params: []interface{}{tx1Hash},
},
Resp: jsonRPCResponse{
Body: tx1ReceiptResponse,
},
},
})

opstack, err := NewTestRPCClient(httpClientMock, models.ArbitrumNitro)
require.NoError(t, err)

block, err := opstack.BlockByNumber(context.Background(), blockNumber)
require.NoError(t, err)
require.NotNil(t, block)
require.Equal(t, blockNumber, block.BlockNumber)
require.False(t, block.Errored())
require.Equal(t, expectedPayloadBytes, block.Payload)
}
9 changes: 9 additions & 0 deletions client/jsonrpc/opstack_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jsonrpc_test

import (
"bytes"
"context"
"testing"

Expand All @@ -12,6 +13,13 @@ func TestOpStackBasic(t *testing.T) {
getBlockByNumberResponse := readFileForTest("testdata/opstack-eth_getBlockByNumber.json")
getBlockReceiptsResponse := readFileForTest("testdata/opstack-eth_getBlockReceipts.json")
debugtraceBlockByNumberResponse := readFileForTest("testdata/opstack-debug_traceBlockByNumber.json")

var expectedPayload bytes.Buffer
expectedPayload.Write(getBlockByNumberResponse.Bytes())
expectedPayload.Write(getBlockReceiptsResponse.Bytes())
expectedPayload.Write(debugtraceBlockByNumberResponse.Bytes())
expectedPayloadBytes := expectedPayload.Bytes()

blockNumberHex := "0x7a549b"
blockNumber := int64(8017051)
httpClientMock := MockHTTPRequests(
Expand Down Expand Up @@ -53,4 +61,5 @@ func TestOpStackBasic(t *testing.T) {
require.NotNil(t, block)
require.Equal(t, blockNumber, block.BlockNumber)
require.False(t, block.Errored())
require.Equal(t, expectedPayloadBytes, block.Payload)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":[{"result":{"afterEVMTransfers":[],"beforeEVMTransfers":[],"from":"0x00000000000000000000000000000000000a4b05","gas":"0x0","gasUsed":"0x0","input":"0x6bf6a42d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010a1d9000000000000000000000000000000000000000000000000000000000016870e90000000000000000000000000000000000000000000000000000000000000006","to":"0x00000000000000000000000000000000000a4b05","type":"CALL","value":"0x0"},"txHash":"0x19ee83020d4dad7e96dbb2c01ce2441e75717ee038a022fc6a3b61300b1b801c"},{"result":{"afterEVMTransfers":[{"from":null,"purpose":"gasRefund","to":"0xE68ca824c376eA70c439Fd7F3C978772903E7f9d","value":"0x0"},{"from":null,"purpose":"feeCollection","to":"0x6CBb552855CE5Eb70af49B76a8048be8E3799A05","value":"0x1f2d8b299eb000"},{"from":null,"purpose":"feeCollection","to":"0xa4B00000000000000000000000000000000000F6","value":"0x0"}],"beforeEVMTransfers":[{"from":"0xE68ca824c376eA70c439Fd7F3C978772903E7f9d","purpose":"feePayment","to":null,"value":"0x1f2d8b299eb000"}],"calls":[{"from":"0x831f011b38fd707229b2d1fcf3c8a1964200c9fe","gas":"0xe898","gasUsed":"0xe66d","input":"0x6a62784200000000000000000000000031613e09f7e42cf1130ee49dcafad8f72d13411a","to":"0x1f48d1d51d8530c51e052bb423b1ae46e18668c3","type":"CALL","value":"0x0"}],"from":"0xe68ca824c376ea70c439fd7f3c978772903e7f9d","gas":"0x156ce","gasUsed":"0x156ce","input":"0xae152cf30000000000000000000000001f48d1d51d8530c51e052bb423b1ae46e18668c300000000000000000000000031613e09f7e42cf1130ee49dcafad8f72d13411a","to":"0x831f011b38fd707229b2d1fcf3c8a1964200c9fe","type":"CALL","value":"0x0"},"txHash":"0x4e805891b568698f8419f8e162d70ed9675e42a32e4972cbeb7f78d7fd51de76"}],"id":1}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":{"baseFeePerGas":"0x174876e800","difficulty":"0x1","extraData":"0x1f843dfe91368c7b0fe8fc5b8fe4b9015064a5b391552dc3b655d8be7a67e447","gasLimit":"0x4000000000000","gasUsed":"0x156ce","hash":"0xd00591af64d4426dff9597120c1800de53d249f90f89732cb73387879daceb29","l1BlockNumber":"0x10a1d90","logsBloom":"0x00000000000000000000000000000000000000008010080000000000000000000000000000008000000000000000000000000000000000000000000000000000000000002000000000000008000000000000000000000000000000000000002010000000020000000000000000000800000000000000000000000010000000000000000000000000020000000000000000000000000000000000000000000000000000000100000000100000000000000000000004008000000000800000000000000013000000000000000000000000000000000000000000000000002020000000000000000000000000000000000004000000000000000000080000000000","miner":"0xa4b000000000000000000073657175656e636572","mixHash":"0x000000000000529c00000000010a1d9000000000000000140000000000000000","nonce":"0x0000000000021135","number":"0x16870e9","parentHash":"0x40221a13bf33965af67788ef34350eaa1e4217ce292bdda64c5c1a247fe026f2","receiptsRoot":"0xc7a9596b2cde78841ad26d844f022f1e8448884dfa94c031af2f21d5cfa946fb","sendCount":"0x529c","sendRoot":"0x1f843dfe91368c7b0fe8fc5b8fe4b9015064a5b391552dc3b655d8be7a67e447","sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x37c","stateRoot":"0x604316caa3dc894abb531902a7b47e455a4a7dba004a51e4e59bb5be490a3518","timestamp":"0x669e9808","totalDifficulty":"0x16870ea","transactions":[{"blockHash":"0xd00591af64d4426dff9597120c1800de53d249f90f89732cb73387879daceb29","blockNumber":"0x16870e9","chainId":"0x27bc86aa","from":"0x00000000000000000000000000000000000a4b05","gas":"0x0","gasPrice":"0x0","hash":"0x19ee83020d4dad7e96dbb2c01ce2441e75717ee038a022fc6a3b61300b1b801c","input":"0x6bf6a42d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010a1d9000000000000000000000000000000000000000000000000000000000016870e90000000000000000000000000000000000000000000000000000000000000006","nonce":"0x0","r":"0x0","s":"0x0","to":"0x00000000000000000000000000000000000a4b05","transactionIndex":"0x0","type":"0x6a","v":"0x0","value":"0x0"},{"accessList":[],"blockHash":"0xd00591af64d4426dff9597120c1800de53d249f90f89732cb73387879daceb29","blockNumber":"0x16870e9","chainId":"0x27bc86aa","from":"0xe68ca824c376ea70c439fd7f3c978772903e7f9d","gas":"0x156ce","gasPrice":"0x17a1df1700","hash":"0x4e805891b568698f8419f8e162d70ed9675e42a32e4972cbeb7f78d7fd51de76","input":"0xae152cf30000000000000000000000001f48d1d51d8530c51e052bb423b1ae46e18668c300000000000000000000000031613e09f7e42cf1130ee49dcafad8f72d13411a","maxFeePerGas":"0x2eea55ff00","maxPriorityFeePerGas":"0x59682f00","nonce":"0x8fed7","r":"0x4053346a2e1e4eee95bf434c77fe54638bce942fa0da17bbc9dd47a2615cc5c4","s":"0x14c3dbdcb2ae020e3b2dc7fb3dd825e3c61f53619de1a56c43cdf8bf1af9e099","to":"0x831f011b38fd707229b2d1fcf3c8a1964200c9fe","transactionIndex":"0x1","type":"0x2","v":"0x0","value":"0x0","yParity":"0x0"}],"transactionsRoot":"0x54421d2781309c17000f621600f43db048aa3d1205cf1bc08f65bc37e2e48ab0","uncles":[]},"id":1}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":{"blockHash":"0xd00591af64d4426dff9597120c1800de53d249f90f89732cb73387879daceb29","blockNumber":"0x16870e9","contractAddress":null,"cumulativeGasUsed":"0x0","effectiveGasPrice":"0x174876e800","from":"0x00000000000000000000000000000000000a4b05","gasUsed":"0x0","gasUsedForL1":"0x0","l1BlockNumber":"0x10a1d90","logs":[],"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","status":"0x1","to":"0x00000000000000000000000000000000000a4b05","transactionHash":"0x19ee83020d4dad7e96dbb2c01ce2441e75717ee038a022fc6a3b61300b1b801c","transactionIndex":"0x0","type":"0x6a"},"id":1}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"jsonrpc":"2.0","result":{"blockHash":"0xd00591af64d4426dff9597120c1800de53d249f90f89732cb73387879daceb29","blockNumber":"0x16870e9","contractAddress":null,"cumulativeGasUsed":"0x156ce","effectiveGasPrice":"0x174876e800","from":"0xe68ca824c376ea70c439fd7f3c978772903e7f9d","gasUsed":"0x156ce","gasUsedForL1":"0x0","l1BlockNumber":"0x10a1d90","logs":[{"address":"0x1f48d1d51d8530c51e052bb423b1ae46e18668c3","blockHash":"0xd00591af64d4426dff9597120c1800de53d249f90f89732cb73387879daceb29","blockNumber":"0x16870e9","data":"0x","logIndex":"0x0","removed":false,"topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000031613e09f7e42cf1130ee49dcafad8f72d13411a","0x000000000000000000000000000000000000000000000000000000000000001b"],"transactionHash":"0x4e805891b568698f8419f8e162d70ed9675e42a32e4972cbeb7f78d7fd51de76","transactionIndex":"0x1"},{"address":"0x831f011b38fd707229b2d1fcf3c8a1964200c9fe","blockHash":"0xd00591af64d4426dff9597120c1800de53d249f90f89732cb73387879daceb29","blockNumber":"0x16870e9","data":"0x00000000000000000000000031613e09f7e42cf1130ee49dcafad8f72d13411a","logIndex":"0x1","removed":false,"topics":["0x4765472e8d7a205f24a8863709e382af628b1267cefb31a8d59dfeec4c042433","0x0000000000000000000000001f48d1d51d8530c51e052bb423b1ae46e18668c3"],"transactionHash":"0x4e805891b568698f8419f8e162d70ed9675e42a32e4972cbeb7f78d7fd51de76","transactionIndex":"0x1"}],"logsBloom":"0x00000000000000000000000000000000000000008010080000000000000000000000000000008000000000000000000000000000000000000000000000000000000000002000000000000008000000000000000000000000000000000000002010000000020000000000000000000800000000000000000000000010000000000000000000000000020000000000000000000000000000000000000000000000000000000100000000100000000000000000000004008000000000800000000000000013000000000000000000000000000000000000000000000000002020000000000000000000000000000000000004000000000000000000080000000000","status":"0x1","to":"0x831f011b38fd707229b2d1fcf3c8a1964200c9fe","transactionHash":"0x4e805891b568698f8419f8e162d70ed9675e42a32e4972cbeb7f78d7fd51de76","transactionIndex":"0x1","type":"0x2"},"id":1}

0 comments on commit 9786d69

Please sign in to comment.