From ffa99b824494d3b1dc809405030776bedaa3c01b Mon Sep 17 00:00:00 2001 From: Matthew Whitehead Date: Fri, 28 Apr 2023 09:13:02 +0100 Subject: [PATCH] Add tests to bring us closer to 100% Signed-off-by: Matthew Whitehead --- internal/ethereum/event_listener_test.go | 30 ++++++++++++++++++++++ internal/ethereum/send_transaction_test.go | 4 ++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/internal/ethereum/event_listener_test.go b/internal/ethereum/event_listener_test.go index cb42638..ab7ddb1 100644 --- a/internal/ethereum/event_listener_test.go +++ b/internal/ethereum/event_listener_test.go @@ -311,6 +311,36 @@ func TestFilterEnrichEthLogMethodInputsOk(t *testing.T) { } +func TestFilterEnrichEthLogMethodInputsTxInfoWithErr(t *testing.T) { + + l, mRPC, _ := newTestListener(t, true) + + var abiEvent *abi.Entry + err := json.Unmarshal([]byte(abiTransferEvent), &abiEvent) + assert.NoError(t, err) + + mRPC.On("CallRPC", mock.Anything, mock.Anything, "eth_getBlockByHash", mock.MatchedBy(func(bh string) bool { + return bh == "0x6b012339fbb85b70c58ecfd97b31950c4a28bcef5226e12dbe551cb1abaf3b4c" + }), false).Return(nil).Run(func(args mock.Arguments) { + *args[1].(**blockInfoJSONRPC) = &blockInfoJSONRPC{ + Number: ethtypes.NewHexInteger64(1024), + } + }) + mRPC.On("CallRPC", mock.Anything, mock.Anything, "eth_getTransactionByHash", mock.MatchedBy(func(th ethtypes.HexBytes0xPrefix) bool { + return th.String() == "0x1a1f797ee000c529b6a2dd330cedd0d081417a30d16a4eecb3f863ab4657246f" + })).Return(&rpcbackend.RPCError{Message: "pop"}).Run(func(args mock.Arguments) { + *args[1].(**txInfoJSONRPC) = &txInfoJSONRPC{ + From: ethtypes.MustNewAddress("0x3968ef051b422d3d1cdc182a88bba8dd922e6fa4"), + Input: ethtypes.MustNewHexBytes0xPrefix("0xa9059cbb000000000000000000000000d0f2f5103fd050739a9fb567251bc460cc24d09100000000000000000000000000000000000000000000000000000000000003e8"), + } + }).Once() + + _, ok, err := l.filterEnrichEthLog(context.Background(), l.config.filters[0], sampleTransferLog()) + assert.False(t, ok) + assert.Error(t, err) + +} + func TestFilterEnrichEthLogTXInfoFail(t *testing.T) { l, mRPC, _ := newTestListener(t, true) diff --git a/internal/ethereum/send_transaction_test.go b/internal/ethereum/send_transaction_test.go index 792b91c..4ae77ec 100644 --- a/internal/ethereum/send_transaction_test.go +++ b/internal/ethereum/send_transaction_test.go @@ -222,12 +222,14 @@ func TestSendTransactionFail(t *testing.T) { } func TestSendErrorMapping(t *testing.T) { - assert.Equal(t, ffcapi.ErrorReasonNonceTooLow, mapError(sendRPCMethods, fmt.Errorf("nonce too low"))) assert.Equal(t, ffcapi.ErrorReasonInsufficientFunds, mapError(sendRPCMethods, fmt.Errorf("insufficient funds"))) assert.Equal(t, ffcapi.ErrorReasonTransactionUnderpriced, mapError(sendRPCMethods, fmt.Errorf("transaction underpriced"))) assert.Equal(t, ffcapi.ErrorKnownTransaction, mapError(sendRPCMethods, fmt.Errorf("known transaction"))) +} +func TestCallErrorMapping(t *testing.T) { + assert.Equal(t, ffcapi.ErrorReasonTransactionReverted, mapError(callRPCMethods, fmt.Errorf("execution reverted"))) } func TestSendTransactionBadFrom(t *testing.T) {