Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tests after 66e169aa6418f70b22abced33a3335c81d299927 #106

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions optimism/client_bedrock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ type ClientBedrockTestSuite struct {
mockCurrencyFetcher *mocks.CurrencyFetcher
}

func (t *ClientBedrockTestSuite) MockJSONRPC() *mocks.JSONRPC {
return t.mockJSONRPC
}

func TestClientBedrock(t *testing.T) {
suite.Run(t, new(ClientBedrockTestSuite))
}
Expand Down Expand Up @@ -284,8 +288,8 @@ func (testSuite *ClientBedrockTestSuite) TestBedrockBlockCurrent() {
tx2 := EthCommon.HexToHash("0x6103c9a945fabd69b2cfe25cd0f5c9ebe73b7f68f4fed2c68b2cfdd8429a6a88")

// Execute the transaction trace
mockBedrockTraceTransaction(ctx, testSuite, "testdata/goerli_bedrock_tx_trace_5003318_1.json")
mockBedrockTraceTransaction(ctx, testSuite, "testdata/goerli_bedrock_tx_trace_5003318_2.json")
mockTraceTransaction(ctx, testSuite, "testdata/goerli_bedrock_tx_trace_5003318_1.json")
mockTraceTransaction(ctx, testSuite, "testdata/goerli_bedrock_tx_trace_5003318_2.json")
// mockDebugTraceBedrockBlock(ctx, testSuite, "testdata/goerli_bedrock_block_trace_5003318.json")
mockGetBedrockTransactionReceipt(ctx, testSuite, []EthCommon.Hash{tx1, tx2}, []string{"testdata/goerli_bedrock_tx_receipt_5003318_1.json", "testdata/goerli_bedrock_tx_receipt_5003318_2.json"})

Expand Down Expand Up @@ -319,28 +323,6 @@ func (testSuite *ClientBedrockTestSuite) TestBedrockBlockCurrent() {
runTest(client)
}

func mockBedrockTraceTransaction(ctx context.Context, testSuite *ClientBedrockTestSuite, txFileData string) {
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
mock.MatchedBy(func(rpcs []rpc.BatchElem) bool {
return len(rpcs) == 1 && rpcs[0].Method == "debug_traceTransaction"
}),
).Return(
nil,
).Run(
func(args mock.Arguments) {
r := args.Get(1).([]rpc.BatchElem)
file, err := os.ReadFile(txFileData)
testSuite.NoError(err)

call := new(Call)
testSuite.NoError(call.UnmarshalJSON(file))
*(r[0].Result.(**Call)) = call
},
).Once()
}

//nolint:unused
func mockDebugTraceBedrockBlock(ctx context.Context, testSuite *ClientBedrockTestSuite, txFileData string) {
testSuite.mockJSONRPC.On(
Expand Down
27 changes: 4 additions & 23 deletions optimism/client_blocks_bedrock_tracers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/ethereum-optimism/optimism/l2geth/eth"
"github.com/ethereum-optimism/optimism/l2geth/params"
"github.com/ethereum-optimism/optimism/l2geth/rpc"
EthCommon "github.com/ethereum/go-ethereum/common"
EthHexutil "github.com/ethereum/go-ethereum/common/hexutil"
mocks "github.com/inphi/optimism-rosetta/mocks/optimism"
Expand All @@ -52,6 +51,10 @@ type BedrockTracersTestSuite struct {
mockCurrencyFetcher *mocks.CurrencyFetcher
}

func (testSuite *BedrockTracersTestSuite) MockJSONRPC() *mocks.JSONRPC {
return testSuite.mockJSONRPC
}

func (testSuite *BedrockTracersTestSuite) SetupTest() {
testSuite.mockJSONRPC = &mocks.JSONRPC{}
testSuite.mockGraphQL = &mocks.GraphQL{}
Expand Down Expand Up @@ -645,25 +648,3 @@ func constructTxTwoExpectedCalls(m map[string][]*FlatCall, txTwoHash EthCommon.H
},
}
}

func mockTraceTransaction(ctx context.Context, testSuite *BedrockTracersTestSuite, txFileData string) {
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
mock.MatchedBy(func(rpcs []rpc.BatchElem) bool {
return len(rpcs) == 1 && rpcs[0].Method == "debug_traceTransaction"
}),
).Return(
nil,
).Run(
func(args mock.Arguments) {
r := args.Get(1).([]rpc.BatchElem)
file, err := os.ReadFile(txFileData)
testSuite.NoError(err)

call := new(Call)
testSuite.NoError(call.UnmarshalJSON(file))
*(r[0].Result.(**Call)) = call
},
).Once()
}
159 changes: 9 additions & 150 deletions optimism/client_blocks_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ type ClientBlocksHandlerTestSuite struct {
client *Client
}

func (t *ClientBlocksHandlerTestSuite) MockJSONRPC() *mocks.JSONRPC {
return t.mockJSONRPC
}

// SetupTest configures the test suite.
func (testSuite *ClientBlocksHandlerTestSuite) SetupTest() {
testSuite.mockJSONRPC = &mocks.JSONRPC{}
Expand Down Expand Up @@ -106,36 +110,7 @@ func (testSuite *ClientBlocksHandlerTestSuite) TestBlock_ERC20Mint() {
*r = json.RawMessage(file)
},
).Once()
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
mock.MatchedBy(func(rpcs []rpc.BatchElem) bool {
return len(rpcs) == 1 && rpcs[0].Method == "debug_traceTransaction"
}),
).Return(
nil,
).Run(
func(args mock.Arguments) {
r := args.Get(1).([]rpc.BatchElem)

testSuite.Len(r, 1)
testSuite.Len(r[0].Args, 2)
testSuite.Equal(
common.HexToHash("0xd919fe87c4bc24f767d1b7a165266658d542af9e3f9bc11dd1a2d1f4695df009").Hex(),
r[0].Args[0],
)
testSuite.Equal(tc, r[0].Args[1])

file, err := os.ReadFile(
"testdata/tx_trace_1241186.json",
)
testSuite.NoError(err)

call := new(Call)
testSuite.NoError(call.UnmarshalJSON(file))
*(r[0].Result.(**Call)) = call
},
).Once()
mockTraceTransaction(ctx, testSuite, "testdata/tx_trace_1241186.json", common.HexToHash("0xd919fe87c4bc24f767d1b7a165266658d542af9e3f9bc11dd1a2d1f4695df009").Hex(), tc)
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
Expand Down Expand Up @@ -231,36 +206,7 @@ func (testSuite *ClientBlocksHandlerTestSuite) TestBlock_1502839_OPCriticalBug()
*r = json.RawMessage(file)
},
).Once()
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
mock.MatchedBy(func(rpcs []rpc.BatchElem) bool {
return len(rpcs) == 1 && rpcs[0].Method == "debug_traceTransaction"
}),
).Return(
nil,
).Run(
func(args mock.Arguments) {
r := args.Get(1).([]rpc.BatchElem)

testSuite.Len(r, 1)
testSuite.Len(r[0].Args, 2)
testSuite.Equal(
common.HexToHash("0x3ff079ba4ea0745401e9661d623550d24c9412ea9ad578bfbb0d441dadcce9bc").Hex(),
r[0].Args[0],
)
testSuite.Equal(tc, r[0].Args[1])

file, err := os.ReadFile(
"testdata/tx_trace_1502839.json",
)
testSuite.NoError(err)

call := new(Call)
testSuite.NoError(call.UnmarshalJSON(file))
*(r[0].Result.(**Call)) = call
},
).Once()
mockTraceTransaction(ctx, testSuite, "testdata/tx_trace_1502839.json", common.HexToHash("0x3ff079ba4ea0745401e9661d623550d24c9412ea9ad578bfbb0d441dadcce9bc").Hex(), tc)
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
Expand Down Expand Up @@ -439,36 +385,7 @@ func (testSuite *ClientBlocksHandlerTestSuite) TestBlock_ERC20TransferFailed() {
*r = json.RawMessage(file)
},
).Once()
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
mock.MatchedBy(func(rpcs []rpc.BatchElem) bool {
return len(rpcs) == 1 && rpcs[0].Method == "debug_traceTransaction"
}),
).Return(
nil,
).Run(
func(args mock.Arguments) {
r := args.Get(1).([]rpc.BatchElem)

testSuite.Len(r, 1)
testSuite.Len(r[0].Args, 2)
testSuite.Equal(
common.HexToHash("0x5a1ec671315432cf8b6a67d95b857109fcafae277ae2c673db40b44ca8dd5c1b").Hex(),
r[0].Args[0],
)
testSuite.Equal(tc, r[0].Args[1])

file, err := os.ReadFile(
"testdata/tx_trace_14930491.json",
)
testSuite.NoError(err)

call := new(Call)
testSuite.NoError(call.UnmarshalJSON(file))
*(r[0].Result.(**Call)) = call
},
).Once()
mockTraceTransaction(ctx, testSuite, "testdata/tx_trace_14930491.json", common.HexToHash("0x5a1ec671315432cf8b6a67d95b857109fcafae277ae2c673db40b44ca8dd5c1b").Hex())
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
Expand Down Expand Up @@ -562,36 +479,7 @@ func (testSuite *ClientBlocksHandlerTestSuite) TestBlock_GoerliNoFeeEnforcement(
*r = json.RawMessage(file)
},
).Once()
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
mock.MatchedBy(func(rpcs []rpc.BatchElem) bool {
return len(rpcs) == 1 && rpcs[0].Method == "debug_traceTransaction"
}),
).Return(
nil,
).Run(
func(args mock.Arguments) {
r := args.Get(1).([]rpc.BatchElem)

testSuite.Len(r, 1)
testSuite.Len(r[0].Args, 2)
testSuite.Equal(
common.HexToHash("0x2992c7d87b09484c5940f7d649bd9957c629a43ac477473b655dbb07d8c742a5").Hex(),
r[0].Args[0],
)
testSuite.Equal(tc, r[0].Args[1])

file, err := os.ReadFile(
"testdata/tx_trace_goerli_367675.json",
)
testSuite.NoError(err)

call := new(Call)
testSuite.NoError(call.UnmarshalJSON(file))
*(r[0].Result.(**Call)) = call
},
).Once()
mockTraceTransaction(ctx, testSuite, "testdata/tx_trace_goerli_367675.json", common.HexToHash("0x2992c7d87b09484c5940f7d649bd9957c629a43ac477473b655dbb07d8c742a5").Hex(), tc)
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
Expand Down Expand Up @@ -672,36 +560,7 @@ func (testSuite *ClientBlocksHandlerTestSuite) TestBlock_OVMSelfDestruct() {
*r = json.RawMessage(file)
},
).Once()
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
mock.MatchedBy(func(rpcs []rpc.BatchElem) bool {
return len(rpcs) == 1 && rpcs[0].Method == "debug_traceTransaction"
}),
).Return(
nil,
).Run(
func(args mock.Arguments) {
r := args.Get(1).([]rpc.BatchElem)

testSuite.Len(r, 1)
testSuite.Len(r[0].Args, 2)
testSuite.Equal(
common.HexToHash("0xfa6db346b928db4c98ebf72a14ac52d0c884e2cfa70cf40816542c9d7d1caf13").Hex(),
r[0].Args[0],
)
testSuite.Equal(tc, r[0].Args[1])

file, err := os.ReadFile(
"testdata/tx_trace_1909952.json",
)
testSuite.NoError(err)

call := new(Call)
testSuite.NoError(call.UnmarshalJSON(file))
*(r[0].Result.(**Call)) = call
},
).Once()
mockTraceTransaction(ctx, testSuite, "testdata/tx_trace_1909952.json", common.HexToHash("0xfa6db346b928db4c98ebf72a14ac52d0c884e2cfa70cf40816542c9d7d1caf13").Hex(), tc)
testSuite.mockJSONRPC.On(
"BatchCallContext",
ctx,
Expand Down
Loading