Skip to content

Commit

Permalink
Add tests to bring us closer to 100%
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Whitehead <[email protected]>
  • Loading branch information
matthew1001 committed Apr 28, 2023
1 parent 5c2749a commit 2c846fd
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
16 changes: 16 additions & 0 deletions internal/ethereum/deploy_contract_prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ func TestDeployContractPrepareBadABIDefinition(t *testing.T) {

}

func TestDeployContractPrepareBadErrorABI(t *testing.T) {

ctx, c, _, done := newTestConnector(t)
defer done()

var req ffcapi.ContractDeployPrepareRequest
err := json.Unmarshal([]byte(samplePrepareDeployTX), &req)
req.Errors = []*fftypes.JSONAny{fftypes.JSONAnyPtr(`[`)}
assert.NoError(t, err)
_, reason, err := c.DeployContractPrepare(ctx, &req)

assert.Regexp(t, "FF23013", err)
assert.Equal(t, ffcapi.ErrorReasonInvalidInputs, reason)

}

func TestDeployContractPrepareEstimateNoConstructor(t *testing.T) {

ctx, c, mRPC, done := newTestConnector(t)
Expand Down
30 changes: 30 additions & 0 deletions internal/ethereum/event_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion internal/ethereum/send_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2c846fd

Please sign in to comment.