diff --git a/core/chains/evm/client/client_test.go b/core/chains/evm/client/client_test.go index 673fe044afe..631b5722dec 100644 --- a/core/chains/evm/client/client_test.go +++ b/core/chains/evm/client/client_test.go @@ -89,7 +89,7 @@ func TestEthClient_TransactionReceipt(t *testing.T) { t.Run("happy path", func(t *testing.T) { result := mustReadResult(t, "../../../testdata/jsonrpc/getTransactionReceipt.json") - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -104,7 +104,7 @@ func TestEthClient_TransactionReceipt(t *testing.T) { resp.Result = string(result) } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -121,7 +121,7 @@ func TestEthClient_TransactionReceipt(t *testing.T) { t.Run("no tx hash, returns ethereum.NotFound", func(t *testing.T) { result := mustReadResult(t, "../../../testdata/jsonrpc/getTransactionReceipt_notFound.json") - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -136,7 +136,7 @@ func TestEthClient_TransactionReceipt(t *testing.T) { resp.Result = string(result) } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -155,7 +155,7 @@ func TestEthClient_PendingNonceAt(t *testing.T) { address := testutils.NewAddress() - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -174,7 +174,7 @@ func TestEthClient_PendingNonceAt(t *testing.T) { resp.Result = `"0x100"` } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -206,7 +206,7 @@ func TestEthClient_BalanceAt(t *testing.T) { for _, test := range tests { test := test t.Run(test.name, func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -221,7 +221,7 @@ func TestEthClient_BalanceAt(t *testing.T) { resp.Result = `"` + hexutil.EncodeBig(test.balance) + `"` } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -239,7 +239,7 @@ func TestEthClient_BalanceAt(t *testing.T) { func TestEthClient_LatestBlockHeight(t *testing.T) { t.Parallel() - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -254,7 +254,7 @@ func TestEthClient_LatestBlockHeight(t *testing.T) { } resp.Result = `"0x100"` return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -289,7 +289,7 @@ func TestEthClient_GetERC20Balance(t *testing.T) { functionSelector := evmtypes.HexToFunctionSelector(client.BALANCE_OF_ADDRESS_FUNCTION_SELECTOR) // balanceOf(address) txData := utils.ConcatBytes(functionSelector.Bytes(), common.LeftPadBytes(userAddress.Bytes(), utils.EVMWordByteLen)) - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -312,8 +312,7 @@ func TestEthClient_GetERC20Balance(t *testing.T) { resp.Result = `"` + hexutil.EncodeBig(test.balance) + `"` } return - - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -370,7 +369,7 @@ func TestEthClient_HeaderByNumber(t *testing.T) { for _, test := range tests { test := test t.Run(test.name, func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -392,7 +391,7 @@ func TestEthClient_HeaderByNumber(t *testing.T) { resp.Result = test.rpcResp } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -420,7 +419,7 @@ func TestEthClient_SendTransaction_NoSecondaryURL(t *testing.T) { tx := types.NewTransaction(uint64(42), testutils.NewAddress(), big.NewInt(142), 242, big.NewInt(342), []byte{1, 2, 3}) - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -435,7 +434,7 @@ func TestEthClient_SendTransaction_NoSecondaryURL(t *testing.T) { } resp.Result = `"` + tx.Hash().Hex() + `"` return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -452,7 +451,7 @@ func TestEthClient_SendTransaction_WithSecondaryURLs(t *testing.T) { tx := types.NewTransaction(uint64(42), testutils.NewAddress(), big.NewInt(142), 242, big.NewInt(342), []byte{1, 2, 3}) - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -465,7 +464,7 @@ func TestEthClient_SendTransaction_WithSecondaryURLs(t *testing.T) { resp.Result = `"` + tx.Hash().Hex() + `"` } return - }) + }).WSURL().String() rpcSrv := rpc.NewServer() t.Cleanup(rpcSrv.Stop) @@ -498,7 +497,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { tx := types.NewTransaction(uint64(42), testutils.NewAddress(), big.NewInt(142), 242, big.NewInt(342), []byte{1, 2, 3}) t.Run("returns Fatal error type when error message is fatal", func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -512,7 +511,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { resp.Error.Message = "invalid sender" } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -526,7 +525,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { }) t.Run("returns TransactionAlreadyKnown error type when error message is nonce too low", func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -540,7 +539,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { resp.Error.Message = "nonce too low" } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -554,7 +553,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { }) t.Run("returns Successful error type when there is no error message", func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -567,7 +566,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { resp.Result = `"` + tx.Hash().Hex() + `"` } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -581,7 +580,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { }) t.Run("returns Underpriced error type when transaction is terminally underpriced", func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -595,7 +594,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { resp.Error.Message = "transaction underpriced" } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -609,7 +608,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { }) t.Run("returns Unsupported error type when error message is queue full", func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -623,7 +622,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { resp.Error.Message = "queue full" } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -637,7 +636,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { }) t.Run("returns Retryable error type when there is a transaction gap", func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -651,7 +650,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { resp.Error.Message = "NonceGap" } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -665,7 +664,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { }) t.Run("returns InsufficientFunds error type when the sender address doesn't have enough funds", func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -679,7 +678,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { resp.Error.Message = "insufficient funds for transfer" } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -693,7 +692,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { }) t.Run("returns ExceedsFeeCap error type when gas price is too high for the node", func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -707,7 +706,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { resp.Error.Message = "Transaction fee cap exceeded" } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -721,7 +720,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { }) t.Run("returns Unknown error type when the error can't be categorized", func(t *testing.T) { - wsURL := cltest.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, &cltest.FixtureChainID, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -735,7 +734,7 @@ func TestEthClient_SendTransactionReturnCode(t *testing.T) { resp.Error.Message = "some random error" } return - }) + }).WSURL().String() clients := mustNewClients(t, wsURL) for _, ethClient := range clients { @@ -770,7 +769,7 @@ func TestEthClient_SubscribeNewHead(t *testing.T) { defer cancel() chainId := big.NewInt(123456) - wsURL := cltest.NewWSServer(t, chainId, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + wsURL := testutils.NewWSServer(t, chainId, func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { if method == "eth_unsubscribe" { resp.Result = "true" return @@ -781,7 +780,7 @@ func TestEthClient_SubscribeNewHead(t *testing.T) { resp.Notify = headResult } return - }) + }).WSURL().String() clients := mustNewClientsWithChainID(t, wsURL, chainId) for _, ethClient := range clients { diff --git a/core/chains/evm/client/pool_test.go b/core/chains/evm/client/pool_test.go index 15a6484756d..75d38d01a4f 100644 --- a/core/chains/evm/client/pool_test.go +++ b/core/chains/evm/client/pool_test.go @@ -211,7 +211,7 @@ type chainIDResps struct { } func (r *chainIDResps) newNode(t *testing.T, nodeChainID int64) evmclient.Node { - ws := cltest.NewWSServer(t, big.NewInt(r.ws.chainID), func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { + ws := testutils.NewWSServer(t, big.NewInt(r.ws.chainID), func(method string, params gjson.Result) (resp testutils.JSONRPCResponse) { switch method { case "eth_subscribe": resp.Result = `"0x00"` @@ -223,7 +223,7 @@ func (r *chainIDResps) newNode(t *testing.T, nodeChainID int64) evmclient.Node { } t.Errorf("Unexpected method call: %s(%s)", method, params) return - }) + }).WSURL().String() wsURL, err := url.Parse(ws) require.NoError(t, err) diff --git a/core/chains/evm/txmgr/broadcaster_test.go b/core/chains/evm/txmgr/broadcaster_test.go index d1e26c6c969..43f2fdb8cac 100644 --- a/core/chains/evm/txmgr/broadcaster_test.go +++ b/core/chains/evm/txmgr/broadcaster_test.go @@ -195,7 +195,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { }) t.Run("eth_txes exist for a different from address", func(t *testing.T) { - cltest.MustCreateUnstartedTx(t, txStore, otherAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, otherAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) assert.NoError(t, err) assert.False(t, retryable) @@ -383,7 +383,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { return tx.Nonce() == uint64(343) && tx.Value().Cmp(big.NewInt(242)) == 0 }), fromAddress).Return(commonclient.Successful, nil).Once() - etx := cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, []byte{42, 42, 0}, gasLimit, big.Int(assets.NewEthValue(242)), &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, []byte{42, 42, 0}, gasLimit, big.Int(assets.NewEthValue(242)), &cltest.FixtureChainID) // Do the thing { retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) @@ -448,7 +448,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { return false }), "latest").Return(nil).Once() - ethTx := cltest.MustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, &cltest.FixtureChainID) + ethTx := mustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, &cltest.FixtureChainID) { retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) @@ -470,9 +470,9 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { return fmt.Sprintf("%s", callarg["value"]) == "0x21e" // 542 }), "latest").Return(errors.New("this is not a revert, something unexpected went wrong")).Once() - ethTx := cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, - cltest.EvmTxRequestWithChecker(checker), - cltest.EvmTxRequestWithValue(big.Int(assets.NewEthValue(542)))) + ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, + txRequestWithChecker(checker), + txRequestWithValue(big.Int(assets.NewEthValue(542)))) { retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) @@ -495,9 +495,9 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) { return fmt.Sprintf("%s", callarg["value"]) == "0x282" // 642 }), "latest").Return(&jerr).Once() - ethTx := cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, - cltest.EvmTxRequestWithChecker(checker), - cltest.EvmTxRequestWithValue(big.Int(assets.NewEthValue(642)))) + ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, + txRequestWithChecker(checker), + txRequestWithValue(big.Int(assets.NewEthValue(642)))) { retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) assert.NoError(t, err) @@ -537,9 +537,9 @@ func TestEthBroadcaster_TransmitChecking(t *testing.T) { return tx.Nonce() == 0 && tx.Value().Cmp(big.NewInt(442)) == 0 }), fromAddress).Return(commonclient.Successful, nil).Once() - ethTx := cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, - cltest.EvmTxRequestWithValue(big.Int(assets.NewEthValue(442))), - cltest.EvmTxRequestWithChecker(checker)) + ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, + txRequestWithValue(big.Int(assets.NewEthValue(442))), + txRequestWithChecker(checker)) { retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) assert.NoError(t, err) @@ -560,9 +560,9 @@ func TestEthBroadcaster_TransmitChecking(t *testing.T) { return tx.Nonce() == 1 && tx.Value().Cmp(big.NewInt(442)) == 0 }), fromAddress).Return(commonclient.Successful, nil).Once() - ethTx := cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, - cltest.EvmTxRequestWithValue(big.Int(assets.NewEthValue(442))), - cltest.EvmTxRequestWithChecker(checker)) + ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, + txRequestWithValue(big.Int(assets.NewEthValue(442))), + txRequestWithChecker(checker)) { retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) assert.NoError(t, err) @@ -579,7 +579,7 @@ func TestEthBroadcaster_TransmitChecking(t *testing.T) { // Checker will return a fatal error checkerFactory.err = errors.New("fatal checker error") - ethTx := cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, cltest.EvmTxRequestWithChecker(checker)) + ethTx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, txRequestWithChecker(checker)) { retryable, err := eb.ProcessUnstartedTxs(testutils.Context(t), fromAddress) assert.NoError(t, err) @@ -635,7 +635,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_OptimisticLockingOnEthTx(t *testi require.NoError(t, eb.Start(testutils.Context(t))) t.Cleanup(func() { assert.NoError(t, eb.Close()) }) - cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) go func() { select { @@ -688,7 +688,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success_WithMultiplier(t *testing FeeLimit: 1231, Strategy: txmgrcommon.NewSendEveryStrategy(), } - cltest.MustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, &cltest.FixtureChainID) + mustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, &cltest.FixtureChainID) // Do the thing { @@ -758,7 +758,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { // Crashed right after we commit the database transaction that saved // the nonce to the eth_tx so evm.key_states.next_nonce has not been // incremented yet - inProgressEthTx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) + inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == uint64(firstNonce) @@ -794,7 +794,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false) // Crashed right after we commit the database transaction that saved the nonce to the eth_tx - inProgressEthTx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) + inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == uint64(firstNonce) @@ -830,7 +830,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false) // Crashed right after we commit the database transaction that saved the nonce to the eth_tx - inProgressEthTx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) + inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == uint64(firstNonce) @@ -865,7 +865,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false) // Crashed right after we commit the database transaction that saved the nonce to the eth_tx - inProgressEthTx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) + inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == uint64(firstNonce) @@ -902,7 +902,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false) // Crashed right after we commit the database transaction that saved the nonce to the eth_tx - inProgressEthTx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) + inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == uint64(firstNonce) @@ -943,7 +943,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_ResumingFromCrash(t *testing.T) { eb := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg, &testCheckerFactory{}, false) // Crashed right after we commit the database transaction that saved the nonce to the eth_tx - inProgressEthTx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) + inProgressEthTx := mustInsertInProgressEthTxWithAttempt(t, txStore, firstNonce, fromAddress) require.Len(t, inProgressEthTx.TxAttempts, 1) attempt := inProgressEthTx.TxAttempts[0] @@ -1009,7 +1009,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { require.NoError(t, utils.JustError(db.Exec(`SET CONSTRAINTS pipeline_runs_pipeline_spec_id_fkey DEFERRED`))) t.Run("if external wallet sent a transaction from the account and now the nonce is one higher than it should be and we got replacement underpriced then we assume a previous transaction of ours was the one that succeeded, and hand off to EthConfirmer", func(t *testing.T) { - cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) // First send, replacement underpriced ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == uint64(0) @@ -1047,7 +1047,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { localNextNonce := getLocalNextNonce(t, eb, fromAddress) t.Run("without callback", func(t *testing.T) { - etx := cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.Fatal, errors.New(fatalErrorExample)).Once() @@ -1151,7 +1151,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("geth Client fails with error indicating that the transaction was too expensive", func(t *testing.T) { TxFeeExceedsCapError := "tx fee (1.10 ether) exceeds the configured cap (1.00 ether)" localNextNonce := getLocalNextNonce(t, eb, fromAddress) - etx := cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.ExceedsMaxFee, errors.New(TxFeeExceedsCapError)).Twice() @@ -1209,7 +1209,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("eth Client call fails with an unexpected random error, and transaction was not accepted into mempool", func(t *testing.T) { retryableErrorExample := "some unknown error" localNextNonce := getLocalNextNonce(t, eb, fromAddress) - etx := cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == uint64(localNextNonce) }), fromAddress).Return(commonclient.Unknown, errors.New(retryableErrorExample)).Once() @@ -1261,7 +1261,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("eth client call fails with an unexpected random error, and the nonce check also subsequently fails", func(t *testing.T) { retryableErrorExample := "some unknown error" localNextNonce := getLocalNextNonce(t, eb, fromAddress) - etx := cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == uint64(localNextNonce) }), fromAddress).Return(commonclient.Unknown, errors.New(retryableErrorExample)).Once() @@ -1313,7 +1313,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("eth Client call fails with an unexpected random error, and transaction was accepted into mempool", func(t *testing.T) { retryableErrorExample := "some strange RPC returns an unexpected thing" localNextNonce := getLocalNextNonce(t, eb, fromAddress) - etx := cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.Unknown, errors.New(retryableErrorExample)).Once() @@ -1345,7 +1345,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { // This is a configuration error by the node operator, since it means they set the base gas level too low. underpricedError := "transaction underpriced" localNextNonce := getLocalNextNonce(t, eb, fromAddress) - etx := cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) // First was underpriced ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { @@ -1462,7 +1462,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { })) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(localNextNonce), nil).Once() eb2 := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg2, &testCheckerFactory{}, false) - cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) // First was underpriced ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { @@ -1482,7 +1482,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("eth tx is left in progress if eth node returns insufficient eth", func(t *testing.T) { insufficientEthError := "insufficient funds for transfer" localNextNonce := getLocalNextNonce(t, eb, fromAddress) - etx := cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.InsufficientFunds, errors.New(insufficientEthError)).Once() @@ -1512,7 +1512,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { t.Run("eth tx is left in progress if nonce is too high", func(t *testing.T) { localNextNonce := getLocalNextNonce(t, eb, fromAddress) nonceGapError := "NonceGap, Future nonce. Expected nonce: " + strconv.FormatUint(localNextNonce, 10) - etx := cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { return tx.Nonce() == localNextNonce }), fromAddress).Return(commonclient.Retryable, errors.New(nonceGapError)).Once() @@ -1554,7 +1554,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { localNextNonce := getLocalNextNonce(t, eb, fromAddress) ethClient.On("PendingNonceAt", mock.Anything, fromAddress).Return(uint64(localNextNonce), nil).Once() eb2 := NewTestEthBroadcaster(t, txStore, ethClient, ethKeyStore, evmcfg2, &testCheckerFactory{}, false) - cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) underpricedError := "transaction underpriced" localNextNonce = getLocalNextNonce(t, eb, fromAddress) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *gethTypes.Transaction) bool { @@ -1576,7 +1576,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Errors(t *testing.T) { // This is a configuration error by the node operator, since it means they set the base gas level too low. underpricedError := "transaction underpriced" localNextNonce := getLocalNextNonce(t, eb, fromAddress) - cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) // Check gas tip cap verification evmcfg2 := evmtest.NewChainScopedConfig(t, configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) { @@ -1650,7 +1650,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_KeystoreErrors(t *testing.T) { require.NoError(t, err) t.Run("tx signing fails", func(t *testing.T) { - etx := cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) + etx := mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, gasLimit, value, &cltest.FixtureChainID) tx := *gethTypes.NewTx(&gethTypes.LegacyTx{}) kst.On("SignTx", fromAddress, diff --git a/core/chains/evm/txmgr/confirmer_test.go b/core/chains/evm/txmgr/confirmer_test.go index 60d0648a541..f5889b06649 100644 --- a/core/chains/evm/txmgr/confirmer_test.go +++ b/core/chains/evm/txmgr/confirmer_test.go @@ -38,6 +38,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" + "github.com/smartcontractkit/chainlink/v2/core/services/keystore" ksmocks "github.com/smartcontractkit/chainlink/v2/core/services/keystore/mocks" "github.com/smartcontractkit/chainlink/v2/core/utils" ) @@ -84,7 +85,7 @@ func newInProgressLegacyEthTxAttempt(t *testing.T, etxID int64, gasPrice ...int6 } func mustInsertInProgressEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress gethCommon.Address) txmgr.Tx { - etx := cltest.NewEthTx(t, fromAddress) + etx := cltest.NewEthTx(fromAddress) etx.State = txmgrcommon.TxInProgress n := evmtypes.Nonce(nonce) etx.Sequence = &n @@ -94,7 +95,7 @@ func mustInsertInProgressEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, nonce } func mustInsertConfirmedEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress gethCommon.Address) txmgr.Tx { - etx := cltest.NewEthTx(t, fromAddress) + etx := cltest.NewEthTx(fromAddress) etx.State = txmgrcommon.TxConfirmed n := evmtypes.Nonce(nonce) etx.Sequence = &n @@ -111,7 +112,7 @@ func TestEthConfirmer_Lifecycle(t *testing.T) { db := pgtest.NewSqlxDB(t) config := newTestChainScopedConfig(t) - txStore := cltest.NewTxStore(t, db, config.Database()) + txStore := newTxStore(t, db, config.Database()) ethClient := evmtest.NewEthClientMockWithDefaultChain(t) ethKeyStore := cltest.NewKeyStore(t, db, config.Database()).Eth() @@ -187,21 +188,21 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) nonce := int64(0) ctx := testutils.Context(t) blockNum := int64(0) t.Run("only finds eth_txes in unconfirmed state with at least one broadcast attempt", func(t *testing.T) { - cltest.MustInsertFatalErrorEthTx(t, txStore, fromAddress) + mustInsertFatalErrorEthTx(t, txStore, fromAddress) mustInsertInProgressEthTx(t, txStore, nonce, fromAddress) nonce++ cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, nonce, 1, fromAddress) nonce++ - cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, nonce, fromAddress) + mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, nonce, fromAddress) nonce++ - cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, config.EVM().ChainID()) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, config.EVM().ChainID()) // Do the thing require.NoError(t, ec.CheckForReceipts(ctx, blockNum)) @@ -450,7 +451,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { require.Len(t, attempt3_1.Receipts, 0) }) t.Run("handles case where eth_receipt already exists somehow", func(t *testing.T) { - ethReceipt := cltest.MustInsertEthReceipt(t, txStore, 42, utils.NewHash(), attempt3_1.Hash) + ethReceipt := mustInsertEthReceipt(t, txStore, 42, utils.NewHash(), attempt3_1.Hash) txmReceipt := evmtypes.Receipt{ TxHash: attempt3_1.Hash, BlockHash: ethReceipt.BlockHash, @@ -604,7 +605,7 @@ func TestEthConfirmer_CheckForReceipts_batching(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 0, fromAddress) @@ -664,7 +665,7 @@ func TestEthConfirmer_CheckForReceipts_HandlesNonFwdTxsWithForwardingEnabled(t * evmcfg := evmtest.NewChainScopedConfig(t, cfg) _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // tx is not forwarded and doesn't have meta set. EthConfirmer should handle nil meta values etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 0, fromAddress) @@ -717,7 +718,7 @@ func TestEthConfirmer_CheckForReceipts_only_likely_confirmed(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) var attempts []txmgr.TxAttempt @@ -771,7 +772,7 @@ func TestEthConfirmer_CheckForReceipts_should_not_check_for_likely_unconfirmed(t ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ctx := testutils.Context(t) etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 1, fromAddress) @@ -802,7 +803,7 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt_scoped_to_key(t ethClient.On("SequenceAt", mock.Anything, mock.Anything, mock.Anything).Return(evmtypes.Nonce(20), nil) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -869,7 +870,7 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1129,7 +1130,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1137,18 +1138,18 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt(t *testing.T) { // eth_txes with nonce 1 has two attempts, the later attempt with higher gas fees // eth_txes with nonce 2 has one attempt originalBroadcastAt := time.Unix(1616509100, 0) - etx0 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 0, 1, originalBroadcastAt, fromAddress) attempt0_2 := newBroadcastLegacyEthTxAttempt(t, etx0.ID, int64(2)) require.NoError(t, txStore.InsertTxAttempt(&attempt0_2)) - etx1 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx1 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 1, 1, originalBroadcastAt, fromAddress) attempt1_2 := newBroadcastLegacyEthTxAttempt(t, etx1.ID, int64(2)) require.NoError(t, txStore.InsertTxAttempt(&attempt1_2)) - etx2 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx2 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 2, 1, originalBroadcastAt, fromAddress) attempt2_1 := etx2.TxAttempts[0] - etx3 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx3 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 3, 1, originalBroadcastAt, fromAddress) attempt3_1 := etx3.TxAttempts[0] @@ -1208,7 +1209,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_batchSendTransactions_fails(t evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1216,15 +1217,15 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_batchSendTransactions_fails(t // eth_txes with nonce 1 has two attempts, the later attempt with higher gas fees // eth_txes with nonce 2 has one attempt originalBroadcastAt := time.Unix(1616509100, 0) - etx0 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 0, 1, originalBroadcastAt, fromAddress) attempt0_2 := newBroadcastLegacyEthTxAttempt(t, etx0.ID, int64(2)) require.NoError(t, txStore.InsertTxAttempt(&attempt0_2)) - etx1 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx1 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 1, 1, originalBroadcastAt, fromAddress) attempt1_2 := newBroadcastLegacyEthTxAttempt(t, etx1.ID, int64(2)) require.NoError(t, txStore.InsertTxAttempt(&attempt1_2)) - etx2 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx2 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 2, 1, originalBroadcastAt, fromAddress) attempt2_1 := etx2.TxAttempts[0] @@ -1272,7 +1273,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_smallEvmRPCBatchSize_middleBa evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1280,15 +1281,15 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_smallEvmRPCBatchSize_middleBa // eth_txes with nonce 1 has two attempts, the later attempt with higher gas fees // eth_txes with nonce 2 has one attempt originalBroadcastAt := time.Unix(1616509100, 0) - etx0 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 0, 1, originalBroadcastAt, fromAddress) attempt0_2 := newBroadcastLegacyEthTxAttempt(t, etx0.ID, int64(2)) require.NoError(t, txStore.InsertTxAttempt(&attempt0_2)) - etx1 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx1 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 1, 1, originalBroadcastAt, fromAddress) attempt1_2 := newBroadcastLegacyEthTxAttempt(t, etx1.ID, int64(2)) require.NoError(t, txStore.InsertTxAttempt(&attempt1_2)) - etx2 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx2 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 2, 1, originalBroadcastAt, fromAddress) // Expect eth_sendRawTransaction in 3 batches. First batch will pass, 2nd will fail, 3rd never attempted. @@ -1354,7 +1355,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { lggr := logger.TestLogger(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) t.Run("returns nothing when there are no transactions", func(t *testing.T) { etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) @@ -1416,7 +1417,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { assert.Len(t, etxs, 0) }) - etxWithoutAttempts := cltest.NewEthTx(t, fromAddress) + etxWithoutAttempts := cltest.NewEthTx(fromAddress) { n := evmtypes.Nonce(nonce) etxWithoutAttempts.Sequence = &n @@ -1577,13 +1578,13 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { attempt4_2.TxFee = gas.EvmFee{Legacy: assets.NewWeiI(40000)} require.NoError(t, txStore.InsertTxAttempt(&attempt4_2)) - etx5 := cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, nonce, fromAddress) + etx5 := mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, nonce, fromAddress) nonce++ // This etx has one attempt that is too new, which would exclude it from // the gas bumping query, but it should still be caught by the insufficient // eth query - etx6 := cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, nonce, fromAddress) + etx6 := mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, nonce, fromAddress) attempt6_2 := newBroadcastLegacyEthTxAttempt(t, etx3.ID) attempt6_2.BroadcastBeforeBlockNum = &tooNew attempt6_2.TxFee = gas.EvmFee{Legacy: assets.NewWeiI(30001)} @@ -1696,7 +1697,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WithConnectivityCheck(t *testing nonce := int64(0) originalBroadcastAt := time.Unix(1616509100, 0) - etx := cltest.MustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, nonce, fromAddress, originalBroadcastAt) + etx := mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, nonce, fromAddress, originalBroadcastAt) attempt1 := etx.TxAttempts[0] var dbAttempt txmgr.DbEthTxAttempt dbAttempt.FromTxAttempt(&attempt1) @@ -1735,7 +1736,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { addresses := []gethCommon.Address{fromAddress} kst.On("EnabledAddressesForChain", &cltest.FixtureChainID).Return(addresses, nil).Maybe() // Use a mock keystore for this test - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) currentHead := int64(30) oldEnough := int64(19) nonce := int64(0) @@ -2205,7 +2206,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.NewWeiI(60500000000) }) newCfg := evmtest.NewChainScopedConfig(t, gcfg) - ec2 := cltest.NewEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) + ec2 := newEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return evmtypes.Nonce(tx.Nonce()) == *etx3.Sequence && gasPrice.Cmp(tx.GasPrice()) == 0 @@ -2235,7 +2236,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.NewWeiI(60480000000) }) newCfg := evmtest.NewChainScopedConfig(t, gcfg) - ec2 := cltest.NewEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) + ec2 := newEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return evmtypes.Nonce(tx.Nonce()) == *etx3.Sequence && gasPrice.Cmp(tx.GasPrice()) == 0 @@ -2256,7 +2257,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }) // The EIP-1559 etx and attempt - etx4 := cltest.MustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, nonce, fromAddress) + etx4 := mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, nonce, fromAddress) attempt4_1 := etx4.TxAttempts[0] require.NoError(t, db.Get(&dbAttempt, `UPDATE evm.tx_attempts SET broadcast_before_block_num=$1, gas_tip_cap=$2, gas_fee_cap=$3 WHERE id=$4 RETURNING *`, oldEnough, assets.GWei(35), assets.GWei(100), attempt4_1.ID)) @@ -2303,7 +2304,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.GWei(1000) }) newCfg := evmtest.NewChainScopedConfig(t, gcfg) - ec2 := cltest.NewEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) + ec2 := newEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) // Third attempt failed to bump, resubmits old one instead ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { @@ -2389,10 +2390,10 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh t.Run("terminally underpriced transaction with in_progress attempt is retried with more gas", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) originalBroadcastAt := time.Unix(1616509100, 0) - etx := cltest.MustInsertUnconfirmedEthTxWithAttemptState(t, txStore, nonce, fromAddress, txmgrtypes.TxAttemptInProgress, originalBroadcastAt) + etx := mustInsertUnconfirmedEthTxWithAttemptState(t, txStore, nonce, fromAddress, txmgrtypes.TxAttemptInProgress, originalBroadcastAt) require.Equal(t, originalBroadcastAt, *etx.BroadcastAt) nonce++ attempt := etx.TxAttempts[0] @@ -2413,7 +2414,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh t.Run("multiple gas bumps with existing broadcast attempts are retried with more gas until success in legacy mode", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) etx := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, nonce, fromAddress) nonce++ @@ -2445,9 +2446,9 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh t.Run("multiple gas bumps with existing broadcast attempts are retried with more gas until success in EIP-1559 mode", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) - etx := cltest.MustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, nonce, fromAddress) + etx := mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, nonce, fromAddress) nonce++ dxFeeAttempt := etx.TxAttempts[0] var dbAttempt txmgr.DbEthTxAttempt @@ -2510,7 +2511,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { insufficientEthError := errors.New("insufficient funds for gas * price + value") t.Run("saves attempt with state 'insufficient_eth' if eth node returns this error", func(t *testing.T) { - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) expectedBumpedGasPrice := big.NewInt(20000000000) require.Greater(t, expectedBumpedGasPrice.Int64(), attempt1_1.TxFee.Legacy.ToInt().Int64()) @@ -2536,7 +2537,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { }) t.Run("does not bump gas when previous error was 'out of eth', instead resubmits existing transaction", func(t *testing.T) { - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) expectedBumpedGasPrice := big.NewInt(20000000000) require.Greater(t, expectedBumpedGasPrice.Int64(), attempt1_1.TxFee.Legacy.ToInt().Int64()) @@ -2561,7 +2562,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { }) t.Run("saves the attempt as broadcast after node wallet has been topped up with sufficient balance", func(t *testing.T) { - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) expectedBumpedGasPrice := big.NewInt(20000000000) require.Greater(t, expectedBumpedGasPrice.Int64(), attempt1_1.TxFee.Legacy.ToInt().Int64()) @@ -2593,11 +2594,11 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { c.EVM[0].GasEstimator.BumpTxDepth = ptr(uint32(depth)) }) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) for i := 0; i < etxCount; i++ { n := nonce - cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, nonce, fromAddress) + mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, nonce, fromAddress) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(n) }), fromAddress).Return(commonclient.Successful, nil).Once() @@ -2628,7 +2629,7 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) config := newTestChainScopedConfig(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) head := evmtypes.Head{ Hash: utils.NewHash(), @@ -2661,7 +2662,7 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { t.Run("does nothing to confirmed transactions with receipts within head height of the chain and included in the chain", func(t *testing.T) { etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 2, 1, fromAddress) - cltest.MustInsertEthReceipt(t, txStore, head.Number, head.Hash, etx.TxAttempts[0].Hash) + mustInsertEthReceipt(t, txStore, head.Number, head.Hash, etx.TxAttempts[0].Hash) // Do the thing require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) @@ -2674,7 +2675,7 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { t.Run("does nothing to confirmed transactions that only have receipts older than the start of the chain", func(t *testing.T) { etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 3, 1, fromAddress) // Add receipt that is older than the lowest block of the chain - cltest.MustInsertEthReceipt(t, txStore, head.Parent.Parent.Number-1, utils.NewHash(), etx.TxAttempts[0].Hash) + mustInsertEthReceipt(t, txStore, head.Parent.Parent.Number-1, utils.NewHash(), etx.TxAttempts[0].Hash) // Do the thing require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) @@ -2688,7 +2689,7 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 4, 1, fromAddress) attempt := etx.TxAttempts[0] // Include one within head height but a different block hash - cltest.MustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attempt.Hash) + mustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attempt.Hash) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { atx, err := txmgr.GetGethSignedTx(attempt.SignedRawTx) @@ -2713,9 +2714,9 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { attempt := etx.TxAttempts[0] attemptHash := attempt.Hash // Add receipt that is older than the lowest block of the chain - cltest.MustInsertEthReceipt(t, txStore, head.Parent.Parent.Number-1, utils.NewHash(), attemptHash) + mustInsertEthReceipt(t, txStore, head.Parent.Parent.Number-1, utils.NewHash(), attemptHash) // Include one within head height but a different block hash - cltest.MustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attemptHash) + mustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attemptHash) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.Anything, fromAddress).Return( commonclient.Successful, nil).Once() @@ -2745,9 +2746,9 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(&attempt3)) // Receipt is within head height but a different block hash - cltest.MustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attempt2.Hash) + mustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attempt2.Hash) // Receipt is within head height but a different block hash - cltest.MustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attempt3.Hash) + mustInsertEthReceipt(t, txStore, head.Parent.Number, utils.NewHash(), attempt3.Hash) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { s, err := txmgr.GetGethSignedTx(attempt3.SignedRawTx) @@ -2774,7 +2775,7 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 7, 1, fromAddress) attempt := etx.TxAttempts[0] // Add receipt that is higher than head - cltest.MustInsertEthReceipt(t, txStore, head.Number+1, utils.NewHash(), attempt.Hash) + mustInsertEthReceipt(t, txStore, head.Number+1, utils.NewHash(), attempt.Hash) require.NoError(t, ec.EnsureConfirmedTransactionsInLongestChain(testutils.Context(t), &head)) @@ -2799,7 +2800,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) config := newTestChainScopedConfig(t) - cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, config.EVM().ChainID()) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, config.EVM().ChainID()) mustInsertInProgressEthTx(t, txStore, 0, fromAddress) etx1 := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 1, fromAddress) etx2 := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 2, fromAddress) @@ -2809,7 +2810,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("rebroadcasts one eth_tx if it falls within in nonce range", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(*etx1.Sequence) && @@ -2824,7 +2825,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("uses default gas limit if overrideGasLimit is 0", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(*etx1.Sequence) && @@ -2839,7 +2840,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("rebroadcasts several eth_txes in nonce range", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(*etx1.Sequence) && tx.GasPrice().Int64() == gasPriceWei.Legacy.Int64() && tx.Gas() == uint64(overrideGasLimit) @@ -2853,7 +2854,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("broadcasts zero transactions if eth_tx doesn't exist for that nonce", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(1) @@ -2879,7 +2880,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("zero transactions use default gas limit if override wasn't specified", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) + ec := newEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(0) && tx.GasPrice().Int64() == gasPriceWei.Legacy.Int64() && uint32(tx.Gas()) == config.EVM().GasEstimator().LimitDefault() @@ -2923,7 +2924,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { pgtest.MustExec(t, db, `SET CONSTRAINTS pipeline_runs_pipeline_spec_id_fkey DEFERRED`) t.Run("doesn't process task runs that are not suspended (possibly already previously resumed)", func(t *testing.T) { - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(uuid.UUID, interface{}, error) error { + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(uuid.UUID, interface{}, error) error { t.Fatal("No value expected") return nil }) @@ -2932,7 +2933,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { tr := cltest.MustInsertUnfinishedPipelineTaskRun(t, db, run.ID) etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 1, 1, fromAddress) - cltest.MustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, etx.TxAttempts[0].Hash) + mustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, etx.TxAttempts[0].Hash) // Setting both signal_callback and callback_completed to TRUE to simulate a completed pipeline task // It would only be in a state past suspended if the resume callback was called and callback_completed was set to TRUE pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE, callback_completed = TRUE WHERE id = $3`, &tr.ID, minConfirmations, etx.ID) @@ -2942,7 +2943,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { }) t.Run("doesn't process task runs where the receipt is younger than minConfirmations", func(t *testing.T) { - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(uuid.UUID, interface{}, error) error { + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(uuid.UUID, interface{}, error) error { t.Fatal("No value expected") return nil }) @@ -2951,7 +2952,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { tr := cltest.MustInsertUnfinishedPipelineTaskRun(t, db, run.ID) etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 2, 1, fromAddress) - cltest.MustInsertEthReceipt(t, txStore, head.Number, head.Hash, etx.TxAttempts[0].Hash) + mustInsertEthReceipt(t, txStore, head.Number, head.Hash, etx.TxAttempts[0].Hash) pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE WHERE id = $3`, &tr.ID, minConfirmations, etx.ID) @@ -2963,7 +2964,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { ch := make(chan interface{}) nonce := evmtypes.Nonce(3) var err error - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(id uuid.UUID, value interface{}, thisErr error) error { + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(id uuid.UUID, value interface{}, thisErr error) error { err = thisErr ch <- value return nil @@ -2975,7 +2976,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, int64(nonce), 1, fromAddress) pgtest.MustExec(t, db, `UPDATE evm.txes SET meta='{"FailOnRevert": true}'`) - receipt := cltest.MustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, etx.TxAttempts[0].Hash) + receipt := mustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, etx.TxAttempts[0].Hash) pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE WHERE id = $3`, &tr.ID, minConfirmations, etx.ID) @@ -3007,7 +3008,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { ch := make(chan interface{}) nonce := evmtypes.Nonce(4) var err error - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(id uuid.UUID, value interface{}, thisErr error) error { + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(id uuid.UUID, value interface{}, thisErr error) error { err = thisErr ch <- value return nil @@ -3021,7 +3022,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { pgtest.MustExec(t, db, `UPDATE evm.txes SET meta='{"FailOnRevert": true}'`) // receipt is not passed through as a value since it reverted and caused an error - cltest.MustInsertRevertedEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, etx.TxAttempts[0].Hash) + mustInsertRevertedEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, etx.TxAttempts[0].Hash) pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE WHERE id = $3`, &tr.ID, minConfirmations, etx.ID) @@ -3049,7 +3050,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { t.Run("does not mark callback complete if callback fails", func(t *testing.T) { nonce := evmtypes.Nonce(5) - ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(uuid.UUID, interface{}, error) error { + ec := newEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(uuid.UUID, interface{}, error) error { return errors.New("error") }) @@ -3057,7 +3058,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { tr := cltest.MustInsertUnfinishedPipelineTaskRun(t, db, run.ID) etx := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, int64(nonce), 1, fromAddress) - cltest.MustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, etx.TxAttempts[0].Hash) + mustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, etx.TxAttempts[0].Hash) pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE WHERE id = $3`, &tr.ID, minConfirmations, etx.ID) err := ec.ResumePendingTaskRuns(testutils.Context(t), &head) @@ -3071,3 +3072,14 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { } func ptr[T any](t T) *T { return &t } + +func newEthConfirmer(t testing.TB, txStore txmgr.EvmTxStore, ethClient client.Client, config evmconfig.ChainScopedConfig, ks keystore.Eth, fn txmgrcommon.ResumeCallback) *txmgr.Confirmer { + lggr := logger.TestLogger(t) + ge := config.EVM().GasEstimator() + estimator := gas.NewWrappedEvmEstimator(gas.NewFixedPriceEstimator(ge, ge.BlockHistory(), lggr), ge.EIP1559DynamicFees(), nil) + txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, ks, estimator) + ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(ge), config.EVM().Transactions(), config.Database(), ks, txBuilder, lggr) + ec.SetResumeCallback(fn) + require.NoError(t, ec.Start(testutils.Context(t))) + return ec +} diff --git a/core/chains/evm/txmgr/evm_tx_store_test.go b/core/chains/evm/txmgr/evm_tx_store_test.go index 73bfc6fc85a..15417a43096 100644 --- a/core/chains/evm/txmgr/evm_tx_store_test.go +++ b/core/chains/evm/txmgr/evm_tx_store_test.go @@ -52,7 +52,7 @@ func TestORM_TransactionsWithAttempts(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(&attempt)) // tx 3 has no attempts - cltest.MustCreateUnstartedGeneratedTx(t, txStore, from, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, from, &cltest.FixtureChainID) var count int err := db.Get(&count, `SELECT count(*) FROM evm.txes`) @@ -97,7 +97,7 @@ func TestORM_Transactions(t *testing.T) { require.NoError(t, txStore.InsertTxAttempt(&attempt)) // tx 3 has no attempts - cltest.MustCreateUnstartedGeneratedTx(t, txStore, from, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, from, &cltest.FixtureChainID) var count int err := db.Get(&count, `SELECT count(*) FROM evm.txes`) @@ -125,7 +125,7 @@ func TestORM(t *testing.T) { var etx txmgr.Tx t.Run("InsertTx", func(t *testing.T) { - etx = cltest.NewEthTx(t, fromAddress) + etx = cltest.NewEthTx(fromAddress) require.NoError(t, orm.InsertTx(&etx)) assert.Greater(t, int(etx.ID), 0) cltest.AssertCount(t, db, "evm.txes", 1) @@ -147,7 +147,7 @@ func TestORM(t *testing.T) { }) var r txmgr.Receipt t.Run("InsertReceipt", func(t *testing.T) { - r = cltest.NewEthReceipt(t, 42, utils.NewHash(), attemptD.Hash, 0x1) + r = newEthReceipt(42, utils.NewHash(), attemptD.Hash, 0x1) id, err := orm.InsertReceipt(&r.Receipt) r.ID = id require.NoError(t, err) @@ -203,12 +203,12 @@ func TestORM_FindTxAttemptConfirmedByTxIDs(t *testing.T) { require.NoError(t, orm.InsertTxAttempt(&attempt)) // add receipt for the second attempt - r := cltest.NewEthReceipt(t, 4, utils.NewHash(), attempt.Hash, 0x1) + r := newEthReceipt(4, utils.NewHash(), attempt.Hash, 0x1) _, err := orm.InsertReceipt(&r.Receipt) require.NoError(t, err) // tx 3 has no attempts - cltest.MustCreateUnstartedGeneratedTx(t, orm, from, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, orm, from, &cltest.FixtureChainID) cltest.MustInsertUnconfirmedEthTx(t, orm, 3, from) // tx4 cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, orm, 4, from) // tx5 @@ -252,7 +252,7 @@ func TestORM_FindTxAttemptsRequiringResend(t *testing.T) { // Mix up the insert order to assure that they come out sorted by nonce not implicitly or by ID e1 := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 1, fromAddress, time.Unix(1616509200, 0)) - e3 := cltest.MustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, 3, fromAddress, time.Unix(1616509400, 0)) + e3 := mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, 3, fromAddress, time.Unix(1616509400, 0)) e0 := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 0, fromAddress, time.Unix(1616509100, 0)) e2 := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 2, fromAddress, time.Unix(1616509300, 0)) @@ -331,7 +331,7 @@ func TestORM_UpdateBroadcastAts(t *testing.T) { t.Run("does not update when broadcast_at is NULL", func(t *testing.T) { t.Parallel() - etx := cltest.MustCreateUnstartedGeneratedTx(t, orm, fromAddress, &cltest.FixtureChainID) + etx := mustCreateUnstartedGeneratedTx(t, orm, fromAddress, &cltest.FixtureChainID) var nullTime *time.Time assert.Equal(t, nullTime, etx.BroadcastAt) @@ -349,7 +349,7 @@ func TestORM_UpdateBroadcastAts(t *testing.T) { t.Parallel() time1 := time.Now() - etx := cltest.NewEthTx(t, fromAddress) + etx := cltest.NewEthTx(fromAddress) etx.Sequence = new(evmtypes.Nonce) etx.State = txmgrcommon.TxUnconfirmed etx.BroadcastAt = &time1 @@ -446,7 +446,7 @@ func TestORM_FindTxAttemptsConfirmedMissingReceipt(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) originalBroadcastAt := time.Unix(1616509100, 0) - etx0 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 0, 1, originalBroadcastAt, fromAddress) attempts, err := txStore.FindTxAttemptsConfirmedMissingReceipt(testutils.Context(t), ethClient.ConfiguredChainID()) @@ -468,7 +468,7 @@ func TestORM_UpdateTxsUnconfirmed(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) originalBroadcastAt := time.Unix(1616509100, 0) - etx0 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 0, 1, originalBroadcastAt, fromAddress) assert.Equal(t, etx0.State, txmgrcommon.TxConfirmedMissingReceipt) require.NoError(t, txStore.UpdateTxsUnconfirmed(testutils.Context(t), []int64{etx0.ID})) @@ -489,7 +489,7 @@ func TestORM_FindTxAttemptsRequiringReceiptFetch(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) originalBroadcastAt := time.Unix(1616509100, 0) - etx0 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 0, 1, originalBroadcastAt, fromAddress) attempts, err := txStore.FindTxAttemptsRequiringReceiptFetch(testutils.Context(t), ethClient.ConfiguredChainID()) @@ -510,7 +510,7 @@ func TestORM_SaveFetchedReceipts(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) originalBroadcastAt := time.Unix(1616509100, 0) - etx0 := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + etx0 := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( t, txStore, 0, 1, originalBroadcastAt, fromAddress) require.Len(t, etx0.TxAttempts, 1) @@ -552,7 +552,7 @@ func TestORM_MarkAllConfirmedMissingReceipt(t *testing.T) { assert.Equal(t, txmgrcommon.TxUnconfirmed, etx0.State) // create transaction 1 (nonce 1) that is confirmed (block 77) - etx1 := cltest.MustInsertConfirmedEthTxBySaveFetchedReceipts(t, txStore, fromAddress, int64(1), int64(77), *ethClient.ConfiguredChainID()) + etx1 := mustInsertConfirmedEthTxBySaveFetchedReceipts(t, txStore, fromAddress, int64(1), int64(77), *ethClient.ConfiguredChainID()) assert.Equal(t, etx1.State, txmgrcommon.TxConfirmed) // mark transaction 0 confirmed_missing_receipt @@ -608,7 +608,7 @@ func TestORM_GetInProgressTxAttempts(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) // insert etx with attempt - etx := cltest.MustInsertUnconfirmedEthTxWithAttemptState(t, txStore, int64(7), fromAddress, txmgrtypes.TxAttemptInProgress) + etx := mustInsertUnconfirmedEthTxWithAttemptState(t, txStore, int64(7), fromAddress, txmgrtypes.TxAttemptInProgress) // fetch attempt attempts, err := txStore.GetInProgressTxAttempts(testutils.Context(t), fromAddress, ethClient.ConfiguredChainID()) @@ -653,7 +653,7 @@ func TestORM_FindTxesPendingCallback(t *testing.T) { etx1 := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 3, 1, fromAddress) pgtest.MustExec(t, db, `UPDATE evm.txes SET meta='{"FailOnRevert": true}'`) attempt1 := etx1.TxAttempts[0] - cltest.MustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, attempt1.Hash) + mustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, attempt1.Hash) pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE WHERE id = $3`, &tr1.ID, minConfirmations, etx1.ID) // Callback to pipeline service completed. Should be ignored @@ -662,7 +662,7 @@ func TestORM_FindTxesPendingCallback(t *testing.T) { etx2 := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 4, 1, fromAddress) pgtest.MustExec(t, db, `UPDATE evm.txes SET meta='{"FailOnRevert": false}'`) attempt2 := etx2.TxAttempts[0] - cltest.MustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, attempt2.Hash) + mustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, attempt2.Hash) pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE, callback_completed = TRUE WHERE id = $3`, &tr2.ID, minConfirmations, etx2.ID) // Suspended run younger than minConfirmations. Should be ignored @@ -672,13 +672,13 @@ func TestORM_FindTxesPendingCallback(t *testing.T) { etx3 := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 5, 1, fromAddress) pgtest.MustExec(t, db, `UPDATE evm.txes SET meta='{"FailOnRevert": false}'`) attempt3 := etx3.TxAttempts[0] - cltest.MustInsertEthReceipt(t, txStore, head.Number, head.Hash, attempt3.Hash) + mustInsertEthReceipt(t, txStore, head.Number, head.Hash, attempt3.Hash) pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2, signal_callback = TRUE WHERE id = $3`, &tr3.ID, minConfirmations, etx3.ID) // Tx not marked for callback. Should be ignore etx4 := cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 6, 1, fromAddress) attempt4 := etx4.TxAttempts[0] - cltest.MustInsertEthReceipt(t, txStore, head.Number, head.Hash, attempt4.Hash) + mustInsertEthReceipt(t, txStore, head.Number, head.Hash, attempt4.Hash) pgtest.MustExec(t, db, `UPDATE evm.txes SET min_confirmations = $1 WHERE id = $2`, minConfirmations, etx4.ID) // Unconfirmed Tx without receipts. Should be ignored @@ -710,8 +710,8 @@ func Test_FindTxWithIdempotencyKey(t *testing.T) { t.Run("returns transaction if it exists", func(t *testing.T) { idempotencyKey := "777" cfg.EVM().ChainID() - etx := cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, big.NewInt(0), - cltest.EvmTxRequestWithIdempotencyKey(idempotencyKey)) + etx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, big.NewInt(0), + txRequestWithIdempotencyKey(idempotencyKey)) require.Equal(t, idempotencyKey, *etx.IdempotencyKey) res, err := txStore.FindTxWithIdempotencyKey(testutils.Context(t), idempotencyKey, big.NewInt(0)) @@ -756,7 +756,7 @@ func TestORM_UpdateTxForRebroadcast(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("delete all receipts for eth transaction", func(t *testing.T) { - etx := cltest.MustInsertConfirmedEthTxWithReceipt(t, txStore, fromAddress, 777, 1) + etx := mustInsertConfirmedEthTxWithReceipt(t, txStore, fromAddress, 777, 1) etx, err := txStore.FindTxWithAttempts(etx.ID) assert.NoError(t, err) // assert attempt state @@ -811,8 +811,8 @@ func TestORM_FindTransactionsConfirmedInBlockRange(t *testing.T) { } t.Run("find all transactions confirmed in range", func(t *testing.T) { - etx_8 := cltest.MustInsertConfirmedEthTxWithReceipt(t, txStore, fromAddress, 700, 8) - etx_9 := cltest.MustInsertConfirmedEthTxWithReceipt(t, txStore, fromAddress, 777, 9) + etx_8 := mustInsertConfirmedEthTxWithReceipt(t, txStore, fromAddress, 700, 8) + etx_9 := mustInsertConfirmedEthTxWithReceipt(t, txStore, fromAddress, 777, 9) etxes, err := txStore.FindTransactionsConfirmedInBlockRange(testutils.Context(t), head.Number, 8, ethClient.ConfiguredChainID()) require.NoError(t, err) @@ -834,7 +834,7 @@ func TestORM_SaveInsufficientEthAttempt(t *testing.T) { require.NoError(t, err) t.Run("updates attempt state", func(t *testing.T) { - etx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, 1, fromAddress) + etx := mustInsertInProgressEthTxWithAttempt(t, txStore, 1, fromAddress) now := time.Now() err = txStore.SaveInsufficientFundsAttempt(testutils.Context(t), defaultDuration, &etx.TxAttempts[0], now) @@ -858,7 +858,7 @@ func TestORM_SaveSentAttempt(t *testing.T) { require.NoError(t, err) t.Run("updates attempt state to 'broadcast'", func(t *testing.T) { - etx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, 1, fromAddress) + etx := mustInsertInProgressEthTxWithAttempt(t, txStore, 1, fromAddress) require.Nil(t, etx.BroadcastAt) now := time.Now() @@ -883,7 +883,7 @@ func TestORM_SaveConfirmedMissingReceiptAttempt(t *testing.T) { require.NoError(t, err) t.Run("updates attempt to 'broadcast' and transaction to 'confirm_missing_receipt'", func(t *testing.T) { - etx := cltest.MustInsertUnconfirmedEthTxWithAttemptState(t, txStore, 1, fromAddress, txmgrtypes.TxAttemptInProgress) + etx := mustInsertUnconfirmedEthTxWithAttemptState(t, txStore, 1, fromAddress, txmgrtypes.TxAttemptInProgress) now := time.Now() err = txStore.SaveConfirmedMissingReceiptAttempt(testutils.Context(t), defaultDuration, &etx.TxAttempts[0], now) @@ -906,7 +906,7 @@ func TestORM_DeleteInProgressAttempt(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("deletes in_progress attempt", func(t *testing.T) { - etx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, 1, fromAddress) + etx := mustInsertInProgressEthTxWithAttempt(t, txStore, 1, fromAddress) attempt := etx.TxAttempts[0] err := txStore.DeleteInProgressAttempt(testutils.Context(t), etx.TxAttempts[0]) @@ -942,7 +942,7 @@ func TestORM_SaveInProgressAttempt(t *testing.T) { }) t.Run("updates old attempt to in_progress when insufficient_eth", func(t *testing.T) { - etx := cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 23, fromAddress) + etx := mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 23, fromAddress) attempt := etx.TxAttempts[0] require.Equal(t, txmgrtypes.TxAttemptInsufficientFunds, attempt.State) require.NotEqual(t, 0, attempt.ID) @@ -972,7 +972,7 @@ func TestORM_FindTxsRequiringGasBump(t *testing.T) { currentBlockNum := int64(10) t.Run("gets txs requiring gas bump", func(t *testing.T) { - etx := cltest.MustInsertUnconfirmedEthTxWithAttemptState(t, txStore, 1, fromAddress, txmgrtypes.TxAttemptBroadcast) + etx := mustInsertUnconfirmedEthTxWithAttemptState(t, txStore, 1, fromAddress, txmgrtypes.TxAttemptBroadcast) err := txStore.SetBroadcastBeforeBlockNum(testutils.Context(t), currentBlockNum, ethClient.ConfiguredChainID()) require.NoError(t, err) @@ -985,7 +985,7 @@ func TestORM_FindTxsRequiringGasBump(t *testing.T) { assert.Equal(t, currentBlockNum, *attempts[0].BroadcastBeforeBlockNum) // this tx will not require gas bump - cltest.MustInsertUnconfirmedEthTxWithAttemptState(t, txStore, 2, fromAddress, txmgrtypes.TxAttemptBroadcast) + mustInsertUnconfirmedEthTxWithAttemptState(t, txStore, 2, fromAddress, txmgrtypes.TxAttemptBroadcast) err = txStore.SetBroadcastBeforeBlockNum(testutils.Context(t), currentBlockNum+1, ethClient.ConfiguredChainID()) require.NoError(t, err) @@ -1012,18 +1012,18 @@ func TestEthConfirmer_FindTxsRequiringResubmissionDueToInsufficientEth(t *testin _, otherAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) // Insert order is mixed up to test sorting - etx2 := cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 1, fromAddress) + etx2 := mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 1, fromAddress) etx3 := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 2, fromAddress) attempt3_2 := cltest.NewLegacyEthTxAttempt(t, etx3.ID) attempt3_2.State = txmgrtypes.TxAttemptInsufficientFunds attempt3_2.TxFee.Legacy = assets.NewWeiI(100) require.NoError(t, txStore.InsertTxAttempt(&attempt3_2)) - etx1 := cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, fromAddress) + etx1 := mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, fromAddress) // These should never be returned cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 3, fromAddress) cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, 4, 100, fromAddress) - cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, otherAddress) + mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, otherAddress) t.Run("returns all eth_txes with at least one attempt that is in insufficient_eth state", func(t *testing.T) { etxs, err := txStore.FindTxsRequiringResubmissionDueToInsufficientFunds(testutils.Context(t), fromAddress, &cltest.FixtureChainID) @@ -1073,7 +1073,7 @@ func TestORM_MarkOldTxesMissingReceiptAsErrored(t *testing.T) { // tx state should be confirmed missing receipt // attempt should be broadcast before cutoff time t.Run("successfully mark errored transactions", func(t *testing.T) { - etx := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 1, 7, time.Now(), fromAddress) + etx := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 1, 7, time.Now(), fromAddress) err := txStore.MarkOldTxesMissingReceiptAsErrored(testutils.Context(t), 10, 2, ethClient.ConfiguredChainID()) require.NoError(t, err) @@ -1084,7 +1084,7 @@ func TestORM_MarkOldTxesMissingReceiptAsErrored(t *testing.T) { }) t.Run("successfully mark errored transactions w/ qopt passing in sql.Tx", func(t *testing.T) { - etx := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 1, 7, time.Now(), fromAddress) + etx := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 1, 7, time.Now(), fromAddress) err := txStore.MarkOldTxesMissingReceiptAsErrored(testutils.Context(t), 10, 2, ethClient.ConfiguredChainID()) require.NoError(t, err) @@ -1105,7 +1105,7 @@ func TestORM_LoadEthTxesAttempts(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("load eth tx attempt", func(t *testing.T) { - etx := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 1, 7, time.Now(), fromAddress) + etx := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 1, 7, time.Now(), fromAddress) etx.TxAttempts = []txmgr.TxAttempt{} err := txStore.LoadTxesAttempts([]*txmgr.Tx{&etx}) @@ -1114,7 +1114,7 @@ func TestORM_LoadEthTxesAttempts(t *testing.T) { }) t.Run("load new attempt inserted in current postgres transaction", func(t *testing.T) { - etx := cltest.MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 3, 9, time.Now(), fromAddress) + etx := mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(t, txStore, 3, 9, time.Now(), fromAddress) etx.TxAttempts = []txmgr.TxAttempt{} q := pg.NewQ(db, logger.TestLogger(t), cfg.Database()) @@ -1154,7 +1154,7 @@ func TestORM_SaveReplacementInProgressAttempt(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("replace eth tx attempt", func(t *testing.T) { - etx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, 123, fromAddress) + etx := mustInsertInProgressEthTxWithAttempt(t, txStore, 123, fromAddress) oldAttempt := etx.TxAttempts[0] newAttempt := cltest.NewDynamicFeeEthTxAttempt(t, etx.ID) @@ -1180,7 +1180,7 @@ func TestORM_FindNextUnstartedTransactionFromAddress(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("cannot find unstarted tx", func(t *testing.T) { - cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, 13, fromAddress) + mustInsertInProgressEthTxWithAttempt(t, txStore, 13, fromAddress) resultEtx := new(txmgr.Tx) err := txStore.FindNextUnstartedTransactionFromAddress(testutils.Context(t), resultEtx, fromAddress, ethClient.ConfiguredChainID()) @@ -1188,7 +1188,7 @@ func TestORM_FindNextUnstartedTransactionFromAddress(t *testing.T) { }) t.Run("finds unstarted tx", func(t *testing.T) { - cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) resultEtx := new(txmgr.Tx) err := txStore.FindNextUnstartedTransactionFromAddress(testutils.Context(t), resultEtx, fromAddress, ethClient.ConfiguredChainID()) require.NoError(t, err) @@ -1206,7 +1206,7 @@ func TestORM_UpdateTxFatalError(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("update successful", func(t *testing.T) { - etx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, 13, fromAddress) + etx := mustInsertInProgressEthTxWithAttempt(t, txStore, 13, fromAddress) etxPretendError := null.StringFrom("no more toilet paper") etx.Error = etxPretendError @@ -1229,7 +1229,7 @@ func TestORM_UpdateTxAttemptInProgressToBroadcast(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) t.Run("update successful", func(t *testing.T) { - etx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, 13, fromAddress) + etx := mustInsertInProgressEthTxWithAttempt(t, txStore, 13, fromAddress) attempt := etx.TxAttempts[0] require.Equal(t, txmgrtypes.TxAttemptInProgress, attempt.State) @@ -1262,7 +1262,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { nonce := evmtypes.Nonce(123) t.Run("update successful", func(t *testing.T) { - etx := cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + etx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) etx.Sequence = &nonce attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) @@ -1276,7 +1276,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { }) t.Run("update fails because tx is removed", func(t *testing.T) { - etx := cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + etx := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) etx.Sequence = &nonce attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) @@ -1296,7 +1296,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { q = pg.NewQ(db, logger.TestLogger(t), cfg.Database()) t.Run("update replaces abandoned tx with same hash", func(t *testing.T) { - etx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, nonce, fromAddress) + etx := mustInsertInProgressEthTxWithAttempt(t, txStore, nonce, fromAddress) require.Len(t, etx.TxAttempts, 1) zero := models.MustNewDuration(time.Duration(0)) @@ -1314,7 +1314,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { err := txMgr.XXXTestAbandon(fromAddress) // mark transaction as abandoned require.NoError(t, err) - etx2 := cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + etx2 := mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) etx2.Sequence = &nonce attempt2 := cltest.NewLegacyEthTxAttempt(t, etx2.ID) attempt2.Hash = etx.TxAttempts[0].Hash @@ -1329,7 +1329,7 @@ func TestORM_UpdateTxUnstartedToInProgress(t *testing.T) { // Same flow as previous test, but without calling txMgr.Abandon() t.Run("duplicate tx hash disallowed in tx_eth_attempts", func(t *testing.T) { - etx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, nonce, fromAddress) + etx := mustInsertInProgressEthTxWithAttempt(t, txStore, nonce, fromAddress) require.Len(t, etx.TxAttempts, 1) etx.State = txmgrcommon.TxUnstarted @@ -1357,7 +1357,7 @@ func TestORM_GetTxInProgress(t *testing.T) { }) t.Run("get 1 in progress eth transaction", func(t *testing.T) { - etx := cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, 123, fromAddress) + etx := mustInsertInProgressEthTxWithAttempt(t, txStore, 123, fromAddress) etxResult, err := txStore.GetTxInProgress(testutils.Context(t), fromAddress) require.NoError(t, err) @@ -1382,7 +1382,7 @@ func TestORM_HasInProgressTransaction(t *testing.T) { }) t.Run("has in progress eth transaction", func(t *testing.T) { - cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, 123, fromAddress) + mustInsertInProgressEthTxWithAttempt(t, txStore, 123, fromAddress) exists, err := txStore.HasInProgressTransaction(testutils.Context(t), fromAddress, ethClient.ConfiguredChainID()) require.NoError(t, err) @@ -1422,9 +1422,9 @@ func TestORM_CountUnstartedTransactions(t *testing.T) { _, fromAddress := cltest.MustInsertRandomKey(t, ethKeyStore) _, otherAddress := cltest.MustInsertRandomKey(t, ethKeyStore) - cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) - cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) - cltest.MustCreateUnstartedGeneratedTx(t, txStore, otherAddress, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID) + mustCreateUnstartedGeneratedTx(t, txStore, otherAddress, &cltest.FixtureChainID) cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, 2, fromAddress) count, err := txStore.CountUnstartedTransactions(testutils.Context(t), fromAddress, &cltest.FixtureChainID) @@ -1456,7 +1456,7 @@ func TestORM_CheckTxQueueCapacity(t *testing.T) { // deliberately one extra to exceed limit for i := 0; i <= int(maxUnconfirmedTransactions); i++ { - cltest.MustCreateUnstartedTx(t, txStore, otherAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, otherAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) } t.Run("with eth_txes from another address returns nil", func(t *testing.T) { @@ -1465,7 +1465,7 @@ func TestORM_CheckTxQueueCapacity(t *testing.T) { }) for i := 0; i <= int(maxUnconfirmedTransactions); i++ { - cltest.MustInsertFatalErrorEthTx(t, txStore, otherAddress) + mustInsertFatalErrorEthTx(t, txStore, otherAddress) } t.Run("ignores fatally_errored transactions", func(t *testing.T) { @@ -1474,7 +1474,7 @@ func TestORM_CheckTxQueueCapacity(t *testing.T) { }) var n int64 - cltest.MustInsertInProgressEthTxWithAttempt(t, txStore, evmtypes.Nonce(n), fromAddress) + mustInsertInProgressEthTxWithAttempt(t, txStore, evmtypes.Nonce(n), fromAddress) n++ cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, n, fromAddress) n++ @@ -1496,7 +1496,7 @@ func TestORM_CheckTxQueueCapacity(t *testing.T) { }) for i := 0; i < int(maxUnconfirmedTransactions)-1; i++ { - cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) } t.Run("with fewer unstarted eth_txes than limit returns nil", func(t *testing.T) { @@ -1504,14 +1504,14 @@ func TestORM_CheckTxQueueCapacity(t *testing.T) { require.NoError(t, err) }) - cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) t.Run("with equal or more unstarted eth_txes than limit returns error", func(t *testing.T) { err := txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, maxUnconfirmedTransactions, &cltest.FixtureChainID) require.Error(t, err) require.Contains(t, err.Error(), fmt.Sprintf("cannot create transaction; too many unstarted transactions in the queue (2/%d). WARNING: Hitting EVM.Transactions.MaxQueued", maxUnconfirmedTransactions)) - cltest.MustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) + mustCreateUnstartedTx(t, txStore, fromAddress, toAddress, encodedPayload, feeLimit, value, &cltest.FixtureChainID) err = txStore.CheckTxQueueCapacity(testutils.Context(t), fromAddress, maxUnconfirmedTransactions, &cltest.FixtureChainID) require.Error(t, err) require.Contains(t, err.Error(), fmt.Sprintf("cannot create transaction; too many unstarted transactions in the queue (3/%d). WARNING: Hitting EVM.Transactions.MaxQueued", maxUnconfirmedTransactions)) @@ -1533,7 +1533,7 @@ func TestORM_CreateTransaction(t *testing.T) { db := pgtest.NewSqlxDB(t) cfg := configtest.NewGeneralConfig(t, nil) - txStore := cltest.NewTxStore(t, db, cfg.Database()) + txStore := newTxStore(t, db, cfg.Database()) kst := cltest.NewKeyStore(t, db, cfg.Database()) _, fromAddress := cltest.MustInsertRandomKey(t, kst.Eth()) @@ -1635,7 +1635,7 @@ func TestORM_PruneUnstartedTxQueue(t *testing.T) { db := pgtest.NewSqlxDB(t) cfg := newTestChainScopedConfig(t) - txStore := cltest.NewTxStore(t, db, cfg.Database()) + txStore := newTxStore(t, db, cfg.Database()) ethKeyStore := cltest.NewKeyStore(t, db, cfg.Database()).Eth() evmtest.NewEthClientMockWithDefaultChain(t) _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore) @@ -1644,7 +1644,7 @@ func TestORM_PruneUnstartedTxQueue(t *testing.T) { subject1 := uuid.New() strategy1 := txmgrcommon.NewDropOldestStrategy(subject1, uint32(5), cfg.Database().DefaultQueryTimeout()) for i := 0; i < 5; i++ { - cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, cltest.EvmTxRequestWithStrategy(strategy1)) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, txRequestWithStrategy(strategy1)) } testutils.AssertCountPerSubject(t, db, int64(5), subject1) }) @@ -1653,7 +1653,7 @@ func TestORM_PruneUnstartedTxQueue(t *testing.T) { subject2 := uuid.New() strategy2 := txmgrcommon.NewDropOldestStrategy(subject2, uint32(3), cfg.Database().DefaultQueryTimeout()) for i := 0; i < 5; i++ { - cltest.MustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, cltest.EvmTxRequestWithStrategy(strategy2)) + mustCreateUnstartedGeneratedTx(t, txStore, fromAddress, &cltest.FixtureChainID, txRequestWithStrategy(strategy2)) } testutils.AssertCountPerSubject(t, db, int64(3), subject2) }) diff --git a/core/chains/evm/txmgr/reaper_test.go b/core/chains/evm/txmgr/reaper_test.go index 20cc27a675f..67216c9fd15 100644 --- a/core/chains/evm/txmgr/reaper_test.go +++ b/core/chains/evm/txmgr/reaper_test.go @@ -64,7 +64,7 @@ func TestReaper_ReapTxes(t *testing.T) { }) // Confirmed in block number 5 - cltest.MustInsertConfirmedEthTxWithReceipt(t, txStore, from, nonce, 5) + mustInsertConfirmedEthTxWithReceipt(t, txStore, from, nonce, 5) t.Run("skips if threshold=0", func(t *testing.T) { config := txmgrmocks.NewReaperConfig(t) @@ -119,7 +119,7 @@ func TestReaper_ReapTxes(t *testing.T) { cltest.AssertCount(t, db, "evm.txes", 0) }) - cltest.MustInsertFatalErrorEthTx(t, txStore, from) + mustInsertFatalErrorEthTx(t, txStore, from) t.Run("deletes errored evm.txes that exceed the age threshold", func(t *testing.T) { config := txmgrmocks.NewReaperConfig(t) diff --git a/core/chains/evm/txmgr/txmgr_test.go b/core/chains/evm/txmgr/txmgr_test.go index e27cea137b5..bab18f445bf 100644 --- a/core/chains/evm/txmgr/txmgr_test.go +++ b/core/chains/evm/txmgr/txmgr_test.go @@ -1,6 +1,7 @@ package txmgr_test import ( + "bytes" "context" "encoding/json" "fmt" @@ -8,16 +9,19 @@ import ( "testing" "time" - gethcommon "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v4" "github.com/jmoiron/sqlx" txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" + txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types" commontxmmocks "github.com/smartcontractkit/chainlink/v2/common/txmgr/types/mocks" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" @@ -26,6 +30,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" + evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" @@ -34,6 +39,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/keystore" ksmocks "github.com/smartcontractkit/chainlink/v2/core/services/keystore/mocks" + "github.com/smartcontractkit/chainlink/v2/core/services/pg" "github.com/smartcontractkit/chainlink/v2/core/utils" ) @@ -145,7 +151,7 @@ func TestTxm_CreateTransaction(t *testing.T) { assert.Equal(t, subject, etx.Subject.UUID) }) - cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, fromAddress) + mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, fromAddress) t.Run("with queue at capacity does not insert eth_tx", func(t *testing.T) { evmConfig.MaxQueued = uint64(1) @@ -246,8 +252,8 @@ func TestTxm_CreateTransaction(t *testing.T) { // max uint256 is 1.1579209e+77 testDefaultGlobalSubID := crypto.Keccak256Hash([]byte("sub id")).String() jobID := int32(25) - requestID := gethcommon.HexToHash("abcd") - requestTxHash := gethcommon.HexToHash("dcba") + requestID := common.HexToHash("abcd") + requestTxHash := common.HexToHash("dcba") meta := &txmgr.TxMeta{ JobID: &jobID, RequestID: &requestID, @@ -393,7 +399,7 @@ func TestTxm_CreateTransaction_OutOfEth(t *testing.T) { payload := cltest.MustRandomBytes(t, 100) evmConfig.MaxQueued = uint64(1) - cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, otherKey.Address) + mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, otherKey.Address) strategy := newMockTxStrategy(t) strategy.On("Subject").Return(uuid.NullUUID{}) strategy.On("PruneQueue", mock.Anything, mock.Anything).Return(int64(0), nil) @@ -417,7 +423,7 @@ func TestTxm_CreateTransaction_OutOfEth(t *testing.T) { payload := cltest.MustRandomBytes(t, 100) evmConfig.MaxQueued = uint64(1) - cltest.MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, thisKey.Address) + mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t, txStore, 0, thisKey.Address) strategy := newMockTxStrategy(t) strategy.On("Subject").Return(uuid.NullUUID{}) strategy.On("PruneQueue", mock.Anything, mock.Anything).Return(int64(0), nil) @@ -471,7 +477,7 @@ func TestTxm_Lifecycle(t *testing.T) { evmConfig.ReaperThreshold = 1 * time.Hour evmConfig.ReaperInterval = 1 * time.Hour - kst.On("EnabledAddressesForChain", &cltest.FixtureChainID).Return([]gethcommon.Address{}, nil) + kst.On("EnabledAddressesForChain", &cltest.FixtureChainID).Return([]common.Address{}, nil) keyChangeCh := make(chan struct{}) unsub := cltest.NewAwaiter() @@ -495,9 +501,9 @@ func TestTxm_Lifecycle(t *testing.T) { keyState := cltest.MustGenerateRandomKeyState(t) - addr := []gethcommon.Address{keyState.Address.Address()} + addr := []common.Address{keyState.Address.Address()} kst.On("EnabledAddressesForChain", &cltest.FixtureChainID).Return(addr, nil) - ethClient.On("PendingNonceAt", mock.AnythingOfType("*context.cancelCtx"), gethcommon.Address{}).Return(uint64(0), nil).Maybe() + ethClient.On("PendingNonceAt", mock.AnythingOfType("*context.cancelCtx"), common.Address{}).Return(uint64(0), nil).Maybe() keyChangeCh <- struct{}{} require.NoError(t, txm.Close()) @@ -568,3 +574,244 @@ func TestTxm_Reset(t *testing.T) { assert.Equal(t, 0, count) }) } + +func newTxStore(t *testing.T, db *sqlx.DB, cfg pg.QConfig) txmgr.EvmTxStore { + return txmgr.NewTxStore(db, logger.TestLogger(t), cfg) +} + +func newEthReceipt(blockNumber int64, blockHash common.Hash, txHash common.Hash, status uint64) txmgr.Receipt { + transactionIndex := uint(cltest.NewRandomPositiveInt64()) + + receipt := evmtypes.Receipt{ + BlockNumber: big.NewInt(blockNumber), + BlockHash: blockHash, + TxHash: txHash, + TransactionIndex: transactionIndex, + Status: status, + } + + r := txmgr.Receipt{ + BlockNumber: blockNumber, + BlockHash: blockHash, + TxHash: txHash, + TransactionIndex: transactionIndex, + Receipt: receipt, + } + return r +} + +func mustInsertEthReceipt(t *testing.T, txStore txmgr.TestEvmTxStore, blockNumber int64, blockHash common.Hash, txHash common.Hash) txmgr.Receipt { + r := newEthReceipt(blockNumber, blockHash, txHash, 0x1) + id, err := txStore.InsertReceipt(&r.Receipt) + require.NoError(t, err) + r.ID = id + return r +} + +func mustInsertRevertedEthReceipt(t *testing.T, txStore txmgr.TestEvmTxStore, blockNumber int64, blockHash common.Hash, txHash common.Hash) txmgr.Receipt { + r := newEthReceipt(blockNumber, blockHash, txHash, 0x0) + id, err := txStore.InsertReceipt(&r.Receipt) + require.NoError(t, err) + r.ID = id + return r +} + +// Inserts into evm.receipts but does not update evm.txes or evm.tx_attempts +func mustInsertConfirmedEthTxWithReceipt(t *testing.T, txStore txmgr.TestEvmTxStore, fromAddress common.Address, nonce, blockNum int64) (etx txmgr.Tx) { + etx = cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, nonce, blockNum, fromAddress) + mustInsertEthReceipt(t, txStore, blockNum, utils.NewHash(), etx.TxAttempts[0].Hash) + return etx +} + +func mustInsertConfirmedEthTxBySaveFetchedReceipts(t *testing.T, txStore txmgr.TestEvmTxStore, fromAddress common.Address, nonce int64, blockNum int64, chainID big.Int) (etx txmgr.Tx) { + etx = cltest.MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, nonce, blockNum, fromAddress) + receipt := evmtypes.Receipt{ + TxHash: etx.TxAttempts[0].Hash, + BlockHash: utils.NewHash(), + BlockNumber: big.NewInt(nonce), + TransactionIndex: uint(1), + } + err := txStore.SaveFetchedReceipts(testutils.Context(t), []*evmtypes.Receipt{&receipt}, &chainID) + require.NoError(t, err) + return etx +} + +func mustInsertFatalErrorEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, fromAddress common.Address) txmgr.Tx { + etx := cltest.NewEthTx(fromAddress) + etx.Error = null.StringFrom("something exploded") + etx.State = txmgrcommon.TxFatalError + + require.NoError(t, txStore.InsertTx(&etx)) + return etx +} + +func mustInsertUnconfirmedEthTxWithAttemptState(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address, txAttemptState txmgrtypes.TxAttemptState, opts ...interface{}) txmgr.Tx { + etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, nonce, fromAddress, opts...) + attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) + + tx := types.NewTransaction(uint64(nonce), testutils.NewAddress(), big.NewInt(142), 242, big.NewInt(342), []byte{1, 2, 3}) + rlp := new(bytes.Buffer) + require.NoError(t, tx.EncodeRLP(rlp)) + attempt.SignedRawTx = rlp.Bytes() + + attempt.State = txAttemptState + require.NoError(t, txStore.InsertTxAttempt(&attempt)) + etx, err := txStore.FindTxWithAttempts(etx.ID) + require.NoError(t, err) + return etx +} + +func mustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address, opts ...interface{}) txmgr.Tx { + etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, nonce, fromAddress, opts...) + attempt := cltest.NewDynamicFeeEthTxAttempt(t, etx.ID) + + addr := testutils.NewAddress() + dtx := types.DynamicFeeTx{ + ChainID: big.NewInt(0), + Nonce: uint64(nonce), + GasTipCap: big.NewInt(1), + GasFeeCap: big.NewInt(1), + Gas: 242, + To: &addr, + Value: big.NewInt(342), + Data: []byte{2, 3, 4}, + } + tx := types.NewTx(&dtx) + rlp := new(bytes.Buffer) + require.NoError(t, tx.EncodeRLP(rlp)) + attempt.SignedRawTx = rlp.Bytes() + + attempt.State = txmgrtypes.TxAttemptBroadcast + require.NoError(t, txStore.InsertTxAttempt(&attempt)) + etx, err := txStore.FindTxWithAttempts(etx.ID) + require.NoError(t, err) + return etx +} + +func mustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address) txmgr.Tx { + timeNow := time.Now() + etx := cltest.NewEthTx(fromAddress) + + etx.BroadcastAt = &timeNow + etx.InitialBroadcastAt = &timeNow + n := evmtypes.Nonce(nonce) + etx.Sequence = &n + etx.State = txmgrcommon.TxUnconfirmed + require.NoError(t, txStore.InsertTx(&etx)) + attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) + + tx := types.NewTransaction(uint64(nonce), testutils.NewAddress(), big.NewInt(142), 242, big.NewInt(342), []byte{1, 2, 3}) + rlp := new(bytes.Buffer) + require.NoError(t, tx.EncodeRLP(rlp)) + attempt.SignedRawTx = rlp.Bytes() + + attempt.State = txmgrtypes.TxAttemptInsufficientFunds + require.NoError(t, txStore.InsertTxAttempt(&attempt)) + etx, err := txStore.FindTxWithAttempts(etx.ID) + require.NoError(t, err) + return etx +} + +func mustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( + t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, broadcastBeforeBlockNum int64, + broadcastAt time.Time, fromAddress common.Address) txmgr.Tx { + etx := cltest.NewEthTx(fromAddress) + + etx.BroadcastAt = &broadcastAt + etx.InitialBroadcastAt = &broadcastAt + n := evmtypes.Nonce(nonce) + etx.Sequence = &n + etx.State = txmgrcommon.TxConfirmedMissingReceipt + require.NoError(t, txStore.InsertTx(&etx)) + attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) + attempt.BroadcastBeforeBlockNum = &broadcastBeforeBlockNum + attempt.State = txmgrtypes.TxAttemptBroadcast + require.NoError(t, txStore.InsertTxAttempt(&attempt)) + etx.TxAttempts = append(etx.TxAttempts, attempt) + return etx +} + +func mustInsertInProgressEthTxWithAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce evmtypes.Nonce, fromAddress common.Address) txmgr.Tx { + etx := cltest.NewEthTx(fromAddress) + + etx.Sequence = &nonce + etx.State = txmgrcommon.TxInProgress + require.NoError(t, txStore.InsertTx(&etx)) + attempt := cltest.NewLegacyEthTxAttempt(t, etx.ID) + tx := types.NewTransaction(uint64(nonce), testutils.NewAddress(), big.NewInt(142), 242, big.NewInt(342), []byte{1, 2, 3}) + rlp := new(bytes.Buffer) + require.NoError(t, tx.EncodeRLP(rlp)) + attempt.SignedRawTx = rlp.Bytes() + attempt.State = txmgrtypes.TxAttemptInProgress + require.NoError(t, txStore.InsertTxAttempt(&attempt)) + etx, err := txStore.FindTxWithAttempts(etx.ID) + require.NoError(t, err) + return etx +} + +func mustCreateUnstartedGeneratedTx(t testing.TB, txStore txmgr.EvmTxStore, fromAddress common.Address, chainID *big.Int, opts ...func(*txmgr.TxRequest)) (tx txmgr.Tx) { + txRequest := txmgr.TxRequest{ + FromAddress: fromAddress, + } + + // Apply the default options + withDefaults()(&txRequest) + // Apply the optional parameters + for _, opt := range opts { + opt(&txRequest) + } + return mustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, chainID) +} + +func withDefaults() func(*txmgr.TxRequest) { + return func(tx *txmgr.TxRequest) { + tx.ToAddress = testutils.NewAddress() + tx.EncodedPayload = []byte{1, 2, 3} + tx.Value = big.Int(assets.NewEthValue(142)) + tx.FeeLimit = uint32(1000000000) + tx.Strategy = txmgrcommon.NewSendEveryStrategy() + // Set default values for other fields if needed + } +} + +func mustCreateUnstartedTx(t testing.TB, txStore txmgr.EvmTxStore, fromAddress common.Address, toAddress common.Address, encodedPayload []byte, gasLimit uint32, value big.Int, chainID *big.Int, opts ...interface{}) (tx txmgr.Tx) { + txRequest := txmgr.TxRequest{ + FromAddress: fromAddress, + ToAddress: toAddress, + EncodedPayload: encodedPayload, + Value: value, + FeeLimit: gasLimit, + Strategy: txmgrcommon.NewSendEveryStrategy(), + } + + return mustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, chainID) +} + +func mustCreateUnstartedTxFromEvmTxRequest(t testing.TB, txStore txmgr.EvmTxStore, txRequest txmgr.TxRequest, chainID *big.Int) (tx txmgr.Tx) { + tx, err := txStore.CreateTransaction(testutils.Context(t), txRequest, chainID) + require.NoError(t, err) + return tx +} + +func txRequestWithStrategy(strategy txmgrtypes.TxStrategy) func(*txmgr.TxRequest) { + return func(tx *txmgr.TxRequest) { + tx.Strategy = strategy + } +} + +func txRequestWithChecker(checker txmgr.TransmitCheckerSpec) func(*txmgr.TxRequest) { + return func(tx *txmgr.TxRequest) { + tx.Checker = checker + } +} +func txRequestWithValue(value big.Int) func(*txmgr.TxRequest) { + return func(tx *txmgr.TxRequest) { + tx.Value = value + } +} + +func txRequestWithIdempotencyKey(idempotencyKey string) func(*txmgr.TxRequest) { + return func(tx *txmgr.TxRequest) { + tx.IdempotencyKey = &idempotencyKey + } +} diff --git a/core/cmd/admin_commands_test.go b/core/cmd/admin_commands_test.go index 954e3577d3d..fc4c1b7e959 100644 --- a/core/cmd/admin_commands_test.go +++ b/core/cmd/admin_commands_test.go @@ -43,7 +43,7 @@ func TestShell_CreateUser(t *testing.T) { test := tt t.Run(test.name, func(t *testing.T) { set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.CreateUser, set, "") + flagSetApplyFromAction(client.CreateUser, set, "") require.NoError(t, set.Set("email", test.email)) require.NoError(t, set.Set("role", test.role)) @@ -83,7 +83,7 @@ func TestShell_ChangeRole(t *testing.T) { test := tt t.Run(test.name, func(t *testing.T) { set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.ChangeRole, set, "") + flagSetApplyFromAction(client.ChangeRole, set, "") require.NoError(t, set.Set("email", test.email)) require.NoError(t, set.Set("new-role", test.role)) @@ -118,7 +118,7 @@ func TestShell_DeleteUser(t *testing.T) { test := tt t.Run(test.name, func(t *testing.T) { set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteUser, set, "") + flagSetApplyFromAction(client.DeleteUser, set, "") require.NoError(t, set.Set("email", test.email)) c := cli.NewContext(nil, set, nil) @@ -138,7 +138,7 @@ func TestShell_ListUsers(t *testing.T) { require.NoError(t, app.AuthenticationProvider().CreateUser(&user)) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.ListUsers, set, "") + flagSetApplyFromAction(client.ListUsers, set, "") c := cli.NewContext(nil, set, nil) buffer := bytes.NewBufferString("") diff --git a/core/cmd/blocks_commands_test.go b/core/cmd/blocks_commands_test.go index a972df67d64..d0c0e118f9d 100644 --- a/core/cmd/blocks_commands_test.go +++ b/core/cmd/blocks_commands_test.go @@ -8,7 +8,6 @@ import ( "github.com/stretchr/testify/require" "github.com/urfave/cli" - "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/utils" ) @@ -24,7 +23,7 @@ func Test_ReplayFromBlock(t *testing.T) { client, _ := app.NewShellAndRenderer() set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.ReplayFromBlock, set, "") + flagSetApplyFromAction(client.ReplayFromBlock, set, "") //Incorrect block number require.NoError(t, set.Set("block-number", "0")) diff --git a/core/cmd/bridge_commands_test.go b/core/cmd/bridge_commands_test.go index 4f043ff87e8..fae5d68e678 100644 --- a/core/cmd/bridge_commands_test.go +++ b/core/cmd/bridge_commands_test.go @@ -111,7 +111,7 @@ func TestShell_ShowBridge(t *testing.T) { require.NoError(t, app.BridgeORM().CreateBridgeType(bt)) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.ShowBridge, set, "") + flagSetApplyFromAction(client.ShowBridge, set, "") require.NoError(t, set.Parse([]string{bt.Name.String()})) @@ -148,7 +148,7 @@ func TestShell_CreateBridge(t *testing.T) { test := tt t.Run(test.name, func(t *testing.T) { set := flag.NewFlagSet("bridge", 0) - cltest.FlagSetApplyFromAction(client.CreateBridge, set, "") + flagSetApplyFromAction(client.CreateBridge, set, "") require.NoError(t, set.Parse([]string{test.param})) @@ -177,7 +177,7 @@ func TestShell_RemoveBridge(t *testing.T) { require.NoError(t, err) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoveBridge, set, "") + flagSetApplyFromAction(client.RemoveBridge, set, "") require.NoError(t, set.Parse([]string{bt.Name.String()})) diff --git a/core/cmd/cosmos_keys_commands_test.go b/core/cmd/cosmos_keys_commands_test.go index 05a26fe84d7..2cab11379d0 100644 --- a/core/cmd/cosmos_keys_commands_test.go +++ b/core/cmd/cosmos_keys_commands_test.go @@ -95,7 +95,7 @@ func TestShell_CosmosKeys(t *testing.T) { require.NoError(t, err) requireCosmosKeyCount(t, app, 1) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(cmd.NewCosmosKeysClient(client).DeleteKey, set, "cosmos") + flagSetApplyFromAction(cmd.NewCosmosKeysClient(client).DeleteKey, set, "cosmos") strID := key.ID() require.NoError(tt, set.Set("yes", "true")) @@ -121,7 +121,7 @@ func TestShell_CosmosKeys(t *testing.T) { // Export test invalid id set := flag.NewFlagSet("test Cosmos export", 0) - cltest.FlagSetApplyFromAction(cmd.NewCosmosKeysClient(client).ExportKey, set, "cosmos") + flagSetApplyFromAction(cmd.NewCosmosKeysClient(client).ExportKey, set, "cosmos") require.NoError(tt, set.Parse([]string{"0"})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -135,7 +135,7 @@ func TestShell_CosmosKeys(t *testing.T) { // Export test set = flag.NewFlagSet("test Cosmos export", 0) - cltest.FlagSetApplyFromAction(cmd.NewCosmosKeysClient(client).ExportKey, set, "cosmos") + flagSetApplyFromAction(cmd.NewCosmosKeysClient(client).ExportKey, set, "cosmos") require.NoError(tt, set.Parse([]string{fmt.Sprint(key.ID())})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -150,7 +150,7 @@ func TestShell_CosmosKeys(t *testing.T) { requireCosmosKeyCount(t, app, 0) set = flag.NewFlagSet("test Cosmos import", 0) - cltest.FlagSetApplyFromAction(cmd.NewCosmosKeysClient(client).ImportKey, set, "cosmos") + flagSetApplyFromAction(cmd.NewCosmosKeysClient(client).ImportKey, set, "cosmos") require.NoError(tt, set.Parse([]string{keyName})) require.NoError(tt, set.Set("old-password", "../internal/fixtures/incorrect_password.txt")) diff --git a/core/cmd/cosmos_transaction_commands_test.go b/core/cmd/cosmos_transaction_commands_test.go index f54ccaf4a68..5b5454eed44 100644 --- a/core/cmd/cosmos_transaction_commands_test.go +++ b/core/cmd/cosmos_transaction_commands_test.go @@ -21,7 +21,6 @@ import ( "github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/params" "github.com/smartcontractkit/chainlink/v2/core/cmd" - "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/cosmostest" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/cosmoskey" @@ -93,7 +92,7 @@ func TestShell_SendCosmosCoins(t *testing.T) { require.NoError(t, err) set := flag.NewFlagSet("sendcosmoscoins", 0) - cltest.FlagSetApplyFromAction(client.CosmosSendNativeToken, set, "cosmos") + flagSetApplyFromAction(client.CosmosSendNativeToken, set, "cosmos") require.NoError(t, set.Set("id", chainID)) require.NoError(t, set.Parse([]string{nativeToken, tt.amount, from.Address.String(), to.Address.String()})) diff --git a/core/cmd/csa_keys_commands_test.go b/core/cmd/csa_keys_commands_test.go index 23749476ac8..869608fa72b 100644 --- a/core/cmd/csa_keys_commands_test.go +++ b/core/cmd/csa_keys_commands_test.go @@ -98,7 +98,7 @@ func TestShell_ImportExportCsaKey(t *testing.T) { // Export test invalid id set := flag.NewFlagSet("test CSA export", 0) - cltest.FlagSetApplyFromAction(client.ExportCSAKey, set, "") + flagSetApplyFromAction(client.ExportCSAKey, set, "") require.NoError(t, set.Parse([]string{"0"})) require.NoError(t, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -111,7 +111,7 @@ func TestShell_ImportExportCsaKey(t *testing.T) { // Export test set = flag.NewFlagSet("test CSA export", 0) - cltest.FlagSetApplyFromAction(client.ExportCSAKey, set, "") + flagSetApplyFromAction(client.ExportCSAKey, set, "") require.NoError(t, set.Parse([]string{fmt.Sprint(key.ID())})) require.NoError(t, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -127,7 +127,7 @@ func TestShell_ImportExportCsaKey(t *testing.T) { //Import test set = flag.NewFlagSet("test CSA import", 0) - cltest.FlagSetApplyFromAction(client.ImportCSAKey, set, "") + flagSetApplyFromAction(client.ImportCSAKey, set, "") require.NoError(t, set.Parse([]string{keyName})) require.NoError(t, set.Set("old-password", "../internal/fixtures/incorrect_password.txt")) diff --git a/core/cmd/dkgencrypt_keys_commands_test.go b/core/cmd/dkgencrypt_keys_commands_test.go index 61e343569cb..a7505ce46dc 100644 --- a/core/cmd/dkgencrypt_keys_commands_test.go +++ b/core/cmd/dkgencrypt_keys_commands_test.go @@ -94,7 +94,7 @@ func TestShell_DKGEncryptKeys(t *testing.T) { assert.NoError(tt, err) requireDKGEncryptKeyCount(tt, app, 1) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(cmd.NewDKGEncryptKeysClient(client).DeleteKey, set, "") + flagSetApplyFromAction(cmd.NewDKGEncryptKeysClient(client).DeleteKey, set, "") require.NoError(tt, set.Set("yes", "true")) @@ -122,7 +122,7 @@ func TestShell_DKGEncryptKeys(t *testing.T) { // Export test invalid id set := flag.NewFlagSet("test DKGEncrypt export", 0) - cltest.FlagSetApplyFromAction(cmd.NewDKGEncryptKeysClient(client).ExportKey, set, "") + flagSetApplyFromAction(cmd.NewDKGEncryptKeysClient(client).ExportKey, set, "") require.NoError(tt, set.Parse([]string{"0"})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -135,7 +135,7 @@ func TestShell_DKGEncryptKeys(t *testing.T) { // Export test set = flag.NewFlagSet("test DKGEncrypt export", 0) - cltest.FlagSetApplyFromAction(cmd.NewDKGEncryptKeysClient(client).ExportKey, set, "") + flagSetApplyFromAction(cmd.NewDKGEncryptKeysClient(client).ExportKey, set, "") require.NoError(tt, set.Parse([]string{fmt.Sprint(key.ID())})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -151,7 +151,7 @@ func TestShell_DKGEncryptKeys(t *testing.T) { //Import test set = flag.NewFlagSet("test DKGEncrypt import", 0) - cltest.FlagSetApplyFromAction(cmd.NewDKGEncryptKeysClient(client).ImportKey, set, "") + flagSetApplyFromAction(cmd.NewDKGEncryptKeysClient(client).ImportKey, set, "") require.NoError(tt, set.Parse([]string{keyName})) require.NoError(tt, set.Set("old-password", "../internal/fixtures/incorrect_password.txt")) diff --git a/core/cmd/dkgsign_keys_commands_test.go b/core/cmd/dkgsign_keys_commands_test.go index 27413e6ae7b..1948800d677 100644 --- a/core/cmd/dkgsign_keys_commands_test.go +++ b/core/cmd/dkgsign_keys_commands_test.go @@ -94,7 +94,7 @@ func TestShell_DKGSignKeys(t *testing.T) { assert.NoError(tt, err) requireDKGSignKeyCount(tt, app, 1) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(cmd.NewDKGSignKeysClient(client).DeleteKey, set, "") + flagSetApplyFromAction(cmd.NewDKGSignKeysClient(client).DeleteKey, set, "") require.NoError(tt, set.Set("yes", "true")) strID := key.ID() @@ -121,7 +121,7 @@ func TestShell_DKGSignKeys(t *testing.T) { // Export test invalid id set := flag.NewFlagSet("test DKGSign export", 0) - cltest.FlagSetApplyFromAction(cmd.NewDKGSignKeysClient(client).ExportKey, set, "") + flagSetApplyFromAction(cmd.NewDKGSignKeysClient(client).ExportKey, set, "") require.NoError(tt, set.Parse([]string{"0"})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -134,7 +134,7 @@ func TestShell_DKGSignKeys(t *testing.T) { // Export test set = flag.NewFlagSet("test DKGSign export", 0) - cltest.FlagSetApplyFromAction(cmd.NewDKGSignKeysClient(client).ExportKey, set, "") + flagSetApplyFromAction(cmd.NewDKGSignKeysClient(client).ExportKey, set, "") require.NoError(tt, set.Parse([]string{fmt.Sprint(key.ID())})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -149,7 +149,7 @@ func TestShell_DKGSignKeys(t *testing.T) { requireDKGSignKeyCount(tt, app, 0) set = flag.NewFlagSet("test DKGSign import", 0) - cltest.FlagSetApplyFromAction(cmd.NewDKGSignKeysClient(client).ImportKey, set, "") + flagSetApplyFromAction(cmd.NewDKGSignKeysClient(client).ImportKey, set, "") require.NoError(tt, set.Parse([]string{keyName})) require.NoError(tt, set.Set("old-password", "../internal/fixtures/incorrect_password.txt")) diff --git a/core/cmd/eth_keys_commands_test.go b/core/cmd/eth_keys_commands_test.go index 293a2d3f6da..3eb45e27bd0 100644 --- a/core/cmd/eth_keys_commands_test.go +++ b/core/cmd/eth_keys_commands_test.go @@ -191,7 +191,7 @@ func TestShell_CreateETHKey(t *testing.T) { id := big.NewInt(0) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.CreateETHKey, set, "") + flagSetApplyFromAction(client.CreateETHKey, set, "") require.NoError(t, set.Set("evm-chain-id", testutils.FixtureChainID.String())) @@ -224,7 +224,7 @@ func TestShell_DeleteETHKey(t *testing.T) { // Delete the key set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteETHKey, set, "") + flagSetApplyFromAction(client.DeleteETHKey, set, "") require.NoError(t, set.Set("yes", "true")) require.NoError(t, set.Parse([]string{key.Address.Hex()})) @@ -257,7 +257,7 @@ func TestShell_ImportExportETHKey_NoChains(t *testing.T) { ethKeyStore := app.GetKeyStore().Eth() set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") require.NoError(t, set.Set("file", "internal/fixtures/apicredentials")) require.NoError(t, set.Set("bypass-version-check", "true")) @@ -281,7 +281,7 @@ func TestShell_ImportExportETHKey_NoChains(t *testing.T) { defer os.RemoveAll(testdir) keyfilepath := filepath.Join(testdir, "key") set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.ExportETHKey, set, "") + flagSetApplyFromAction(client.ExportETHKey, set, "") require.NoError(t, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) require.NoError(t, set.Set("output", keyfilepath)) @@ -293,7 +293,7 @@ func TestShell_ImportExportETHKey_NoChains(t *testing.T) { // Delete the key set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteETHKey, set, "") + flagSetApplyFromAction(client.DeleteETHKey, set, "") require.NoError(t, set.Set("yes", "true")) require.NoError(t, set.Parse([]string{address})) @@ -308,7 +308,7 @@ func TestShell_ImportExportETHKey_NoChains(t *testing.T) { // Import the key set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.ImportETHKey, set, "") + flagSetApplyFromAction(client.ImportETHKey, set, "") require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String())) require.NoError(t, set.Set("old-password", "../internal/fixtures/incorrect_password.txt")) @@ -321,7 +321,7 @@ func TestShell_ImportExportETHKey_NoChains(t *testing.T) { r.Renders = nil set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.ListETHKeys, set, "") + flagSetApplyFromAction(client.ListETHKeys, set, "") c = cli.NewContext(nil, set, nil) err = client.ListETHKeys(c) require.NoError(t, err) @@ -332,7 +332,7 @@ func TestShell_ImportExportETHKey_NoChains(t *testing.T) { // Export test invalid id keyName := keyNameForTest(t) set = flag.NewFlagSet("test Eth export invalid id", 0) - cltest.FlagSetApplyFromAction(client.ExportETHKey, set, "") + flagSetApplyFromAction(client.ExportETHKey, set, "") require.NoError(t, set.Parse([]string{"999"})) require.NoError(t, set.Set("new-password", "../internal/fixtures/apicredentials")) @@ -365,7 +365,7 @@ func TestShell_ImportExportETHKey_WithChains(t *testing.T) { ethClient.On("LINKBalance", mock.Anything, mock.Anything, mock.Anything).Return(commonassets.NewLinkFromJuels(42), nil) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") require.NoError(t, set.Set("file", "internal/fixtures/apicredentials")) require.NoError(t, set.Set("bypass-version-check", "true")) @@ -389,7 +389,7 @@ func TestShell_ImportExportETHKey_WithChains(t *testing.T) { defer os.RemoveAll(testdir) keyfilepath := filepath.Join(testdir, "key") set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.ExportETHKey, set, "") + flagSetApplyFromAction(client.ExportETHKey, set, "") require.NoError(t, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) require.NoError(t, set.Set("output", keyfilepath)) @@ -401,7 +401,7 @@ func TestShell_ImportExportETHKey_WithChains(t *testing.T) { // Delete the key set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteETHKey, set, "") + flagSetApplyFromAction(client.DeleteETHKey, set, "") require.NoError(t, set.Set("yes", "true")) require.NoError(t, set.Parse([]string{address})) @@ -414,7 +414,7 @@ func TestShell_ImportExportETHKey_WithChains(t *testing.T) { // Import the key set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.ImportETHKey, set, "") + flagSetApplyFromAction(client.ImportETHKey, set, "") require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String())) require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String())) @@ -428,7 +428,7 @@ func TestShell_ImportExportETHKey_WithChains(t *testing.T) { r.Renders = nil set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.ListETHKeys, set, "") + flagSetApplyFromAction(client.ListETHKeys, set, "") c = cli.NewContext(nil, set, nil) err = client.ListETHKeys(c) require.NoError(t, err) @@ -439,7 +439,7 @@ func TestShell_ImportExportETHKey_WithChains(t *testing.T) { // Export test invalid id keyName := keyNameForTest(t) set = flag.NewFlagSet("test Eth export invalid id", 0) - cltest.FlagSetApplyFromAction(client.ExportETHKey, set, "") + flagSetApplyFromAction(client.ExportETHKey, set, "") require.NoError(t, set.Parse([]string{"999"})) require.NoError(t, set.Set("new-password", "../internal/fixtures/apicredentials")) diff --git a/core/cmd/evm_transaction_commands_test.go b/core/cmd/evm_transaction_commands_test.go index e071d875f03..6c079a12495 100644 --- a/core/cmd/evm_transaction_commands_test.go +++ b/core/cmd/evm_transaction_commands_test.go @@ -37,7 +37,7 @@ func TestShell_IndexTransactions(t *testing.T) { // page 1 set := flag.NewFlagSet("test transactions", 0) - cltest.FlagSetApplyFromAction(client.IndexTransactions, set, "") + flagSetApplyFromAction(client.IndexTransactions, set, "") require.NoError(t, set.Set("page", "1")) @@ -51,7 +51,7 @@ func TestShell_IndexTransactions(t *testing.T) { // page 2 which doesn't exist set = flag.NewFlagSet("test txattempts", 0) - cltest.FlagSetApplyFromAction(client.IndexTransactions, set, "") + flagSetApplyFromAction(client.IndexTransactions, set, "") require.NoError(t, set.Set("page", "2")) @@ -77,7 +77,7 @@ func TestShell_ShowTransaction(t *testing.T) { attempt := tx.TxAttempts[0] set := flag.NewFlagSet("test get tx", 0) - cltest.FlagSetApplyFromAction(client.ShowTransaction, set, "") + flagSetApplyFromAction(client.ShowTransaction, set, "") require.NoError(t, set.Parse([]string{attempt.Hash.String()})) @@ -101,7 +101,7 @@ func TestShell_IndexTxAttempts(t *testing.T) { // page 1 set := flag.NewFlagSet("test txattempts", 0) - cltest.FlagSetApplyFromAction(client.IndexTxAttempts, set, "") + flagSetApplyFromAction(client.IndexTxAttempts, set, "") require.NoError(t, set.Set("page", "1")) @@ -115,7 +115,7 @@ func TestShell_IndexTxAttempts(t *testing.T) { // page 2 which doesn't exist set = flag.NewFlagSet("test transactions", 0) - cltest.FlagSetApplyFromAction(client.IndexTxAttempts, set, "") + flagSetApplyFromAction(client.IndexTxAttempts, set, "") require.NoError(t, set.Set("page", "2")) @@ -158,7 +158,7 @@ func TestShell_SendEther_From_Txm(t *testing.T) { db := app.GetSqlxDB() set := flag.NewFlagSet("sendether", 0) - cltest.FlagSetApplyFromAction(client.SendEther, set, "") + flagSetApplyFromAction(client.SendEther, set, "") amount := "100.5" to := "0x342156c8d3bA54Abc67920d35ba1d1e67201aC9C" @@ -218,7 +218,7 @@ func TestShell_SendEther_From_Txm_WEI(t *testing.T) { db := app.GetSqlxDB() set := flag.NewFlagSet("sendether", 0) - cltest.FlagSetApplyFromAction(client.SendEther, set, "") + flagSetApplyFromAction(client.SendEther, set, "") require.NoError(t, set.Set("id", testutils.FixtureChainID.String())) require.NoError(t, set.Set("wei", "false")) diff --git a/core/cmd/forwarders_commands_test.go b/core/cmd/forwarders_commands_test.go index b08d94f64dc..179216b8e41 100644 --- a/core/cmd/forwarders_commands_test.go +++ b/core/cmd/forwarders_commands_test.go @@ -73,7 +73,7 @@ func TestShell_TrackEVMForwarder(t *testing.T) { // Create the fwdr set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.TrackForwarder, set, "") + flagSetApplyFromAction(client.TrackForwarder, set, "") require.NoError(t, set.Set("address", utils.RandomAddress().Hex())) require.NoError(t, set.Set("evm-chain-id", id.String())) @@ -92,7 +92,7 @@ func TestShell_TrackEVMForwarder(t *testing.T) { // Delete fwdr set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteForwarder, set, "") + flagSetApplyFromAction(client.DeleteForwarder, set, "") require.NoError(t, set.Parse([]string{createOutput.ID})) @@ -118,7 +118,7 @@ func TestShell_TrackEVMForwarder_BadAddress(t *testing.T) { // Create the fwdr set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.TrackForwarder, set, "") + flagSetApplyFromAction(client.TrackForwarder, set, "") require.NoError(t, set.Set("address", "0xWrongFormatAddress")) require.NoError(t, set.Set("evm-chain-id", id.String())) @@ -137,7 +137,7 @@ func TestShell_DeleteEVMForwarders_MissingFwdId(t *testing.T) { // Delete fwdr without id set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteForwarder, set, "") + flagSetApplyFromAction(client.DeleteForwarder, set, "") c := cli.NewContext(nil, set, nil) require.Equal(t, "must pass the forwarder id to be archived", client.DeleteForwarder(c).Error()) diff --git a/core/cmd/jobs_commands_test.go b/core/cmd/jobs_commands_test.go index b83b17f0be6..04908e18ff3 100644 --- a/core/cmd/jobs_commands_test.go +++ b/core/cmd/jobs_commands_test.go @@ -313,7 +313,7 @@ func TestShell_ListFindJobs(t *testing.T) { // Create the job fs := flag.NewFlagSet("", flag.ExitOnError) - cltest.FlagSetApplyFromAction(client.CreateJob, fs, "") + flagSetApplyFromAction(client.CreateJob, fs, "") require.NoError(t, fs.Parse([]string{getDirectRequestSpec()})) @@ -339,7 +339,7 @@ func TestShell_ShowJob(t *testing.T) { // Create the job fs := flag.NewFlagSet("", flag.ExitOnError) - cltest.FlagSetApplyFromAction(client.CreateJob, fs, "") + flagSetApplyFromAction(client.CreateJob, fs, "") require.NoError(t, fs.Parse([]string{getDirectRequestSpec()})) @@ -382,7 +382,7 @@ func TestShell_CreateJobV2(t *testing.T) { requireJobsCount(t, app.JobORM(), 0) fs := flag.NewFlagSet("", flag.ExitOnError) - cltest.FlagSetApplyFromAction(client.CreateJob, fs, "") + flagSetApplyFromAction(client.CreateJob, fs, "") nameAndExternalJobID := uuid.New() spec := fmt.Sprintf(ocrBootstrapSpec, nameAndExternalJobID, nameAndExternalJobID) @@ -413,7 +413,7 @@ func TestShell_DeleteJob(t *testing.T) { // Create the job fs := flag.NewFlagSet("", flag.ExitOnError) - cltest.FlagSetApplyFromAction(client.CreateJob, fs, "") + flagSetApplyFromAction(client.CreateJob, fs, "") require.NoError(t, fs.Parse([]string{getDirectRequestSpec()})) @@ -432,12 +432,12 @@ func TestShell_DeleteJob(t *testing.T) { // Must supply job id set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteJob, set, "") + flagSetApplyFromAction(client.DeleteJob, set, "") c := cli.NewContext(nil, set, nil) require.Equal(t, "must pass the job id to be archived", client.DeleteJob(c).Error()) set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteJob, set, "") + flagSetApplyFromAction(client.DeleteJob, set, "") require.NoError(t, set.Parse([]string{output.ID})) diff --git a/core/cmd/ocr2_keys_commands_test.go b/core/cmd/ocr2_keys_commands_test.go index 88ea426747e..dd2ac2544da 100644 --- a/core/cmd/ocr2_keys_commands_test.go +++ b/core/cmd/ocr2_keys_commands_test.go @@ -97,7 +97,7 @@ func TestShell_OCR2Keys(t *testing.T) { client, r := app.NewShellAndRenderer() set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.CreateOCR2KeyBundle, set, "") + flagSetApplyFromAction(client.CreateOCR2KeyBundle, set, "") require.NoError(tt, set.Parse([]string{"evm"})) @@ -119,7 +119,7 @@ func TestShell_OCR2Keys(t *testing.T) { require.NoError(t, err) requireOCR2KeyCount(t, app, 1) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteOCR2KeyBundle, set, "") + flagSetApplyFromAction(client.DeleteOCR2KeyBundle, set, "") require.NoError(tt, set.Parse([]string{key.ID()})) require.NoError(tt, set.Set("yes", "true")) @@ -147,7 +147,7 @@ func TestShell_OCR2Keys(t *testing.T) { // Export test invalid id set := flag.NewFlagSet("test OCR2 export", 0) - cltest.FlagSetApplyFromAction(client.ExportOCR2Key, set, "") + flagSetApplyFromAction(client.ExportOCR2Key, set, "") require.NoError(tt, set.Parse([]string{"0"})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/new_password.txt")) @@ -160,7 +160,7 @@ func TestShell_OCR2Keys(t *testing.T) { // Export set = flag.NewFlagSet("test OCR2 export", 0) - cltest.FlagSetApplyFromAction(client.ExportOCR2Key, set, "") + flagSetApplyFromAction(client.ExportOCR2Key, set, "") require.NoError(tt, set.Parse([]string{key.ID()})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/new_password.txt")) @@ -175,7 +175,7 @@ func TestShell_OCR2Keys(t *testing.T) { requireOCR2KeyCount(t, app, 0) set = flag.NewFlagSet("test OCR2 import", 0) - cltest.FlagSetApplyFromAction(client.ImportOCR2Key, set, "") + flagSetApplyFromAction(client.ImportOCR2Key, set, "") require.NoError(tt, set.Parse([]string{keyName})) require.NoError(tt, set.Set("old-password", "../internal/fixtures/new_password.txt")) diff --git a/core/cmd/ocr_keys_commands_test.go b/core/cmd/ocr_keys_commands_test.go index 2ae765d4d2a..aeda9006610 100644 --- a/core/cmd/ocr_keys_commands_test.go +++ b/core/cmd/ocr_keys_commands_test.go @@ -111,7 +111,7 @@ func TestShell_DeleteOCRKeyBundle(t *testing.T) { requireOCRKeyCount(t, app, 1) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteOCRKeyBundle, set, "") + flagSetApplyFromAction(client.DeleteOCRKeyBundle, set, "") require.NoError(t, set.Parse([]string{key.ID()})) require.NoError(t, set.Set("yes", "true")) @@ -140,7 +140,7 @@ func TestShell_ImportExportOCRKey(t *testing.T) { // Export test invalid id set := flag.NewFlagSet("test OCR export", 0) - cltest.FlagSetApplyFromAction(client.ExportOCRKey, set, "") + flagSetApplyFromAction(client.ExportOCRKey, set, "") require.NoError(t, set.Parse([]string{"0"})) require.NoError(t, set.Set("new-password", "../internal/fixtures/new_password.txt")) @@ -153,7 +153,7 @@ func TestShell_ImportExportOCRKey(t *testing.T) { // Export set = flag.NewFlagSet("test OCR export", 0) - cltest.FlagSetApplyFromAction(client.ExportOCRKey, set, "") + flagSetApplyFromAction(client.ExportOCRKey, set, "") require.NoError(t, set.Parse([]string{key.ID()})) require.NoError(t, set.Set("new-password", "../internal/fixtures/new_password.txt")) @@ -168,7 +168,7 @@ func TestShell_ImportExportOCRKey(t *testing.T) { requireOCRKeyCount(t, app, 0) set = flag.NewFlagSet("test OCR import", 0) - cltest.FlagSetApplyFromAction(client.ImportOCRKey, set, "") + flagSetApplyFromAction(client.ImportOCRKey, set, "") require.NoError(t, set.Parse([]string{keyName})) require.NoError(t, set.Set("old-password", "../internal/fixtures/new_password.txt")) diff --git a/core/cmd/p2p_keys_commands_test.go b/core/cmd/p2p_keys_commands_test.go index 0407c924575..683129fafa7 100644 --- a/core/cmd/p2p_keys_commands_test.go +++ b/core/cmd/p2p_keys_commands_test.go @@ -102,7 +102,7 @@ func TestShell_DeleteP2PKey(t *testing.T) { requireP2PKeyCount(t, app, 1) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteP2PKey, set, "") + flagSetApplyFromAction(client.DeleteP2PKey, set, "") require.NoError(t, set.Set("yes", "true")) @@ -132,7 +132,7 @@ func TestShell_ImportExportP2PKeyBundle(t *testing.T) { // Export test invalid id set := flag.NewFlagSet("test P2P export", 0) - cltest.FlagSetApplyFromAction(client.ExportP2PKey, set, "") + flagSetApplyFromAction(client.ExportP2PKey, set, "") require.NoError(t, set.Parse([]string{"0"})) require.NoError(t, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -145,7 +145,7 @@ func TestShell_ImportExportP2PKeyBundle(t *testing.T) { // Export test set = flag.NewFlagSet("test P2P export", 0) - cltest.FlagSetApplyFromAction(client.ExportP2PKey, set, "") + flagSetApplyFromAction(client.ExportP2PKey, set, "") require.NoError(t, set.Parse([]string{fmt.Sprint(key.ID())})) require.NoError(t, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -160,7 +160,7 @@ func TestShell_ImportExportP2PKeyBundle(t *testing.T) { requireP2PKeyCount(t, app, 0) set = flag.NewFlagSet("test P2P import", 0) - cltest.FlagSetApplyFromAction(client.ImportP2PKey, set, "") + flagSetApplyFromAction(client.ImportP2PKey, set, "") require.NoError(t, set.Parse([]string{keyName})) require.NoError(t, set.Set("old-password", "../internal/fixtures/incorrect_password.txt")) diff --git a/core/cmd/shell_local_test.go b/core/cmd/shell_local_test.go index 4d906214ef4..2dc182944d3 100644 --- a/core/cmd/shell_local_test.go +++ b/core/cmd/shell_local_test.go @@ -124,7 +124,7 @@ func TestShell_RunNodeWithPasswords(t *testing.T) { } set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RunNode, set, "") + flagSetApplyFromAction(client.RunNode, set, "") require.NoError(t, set.Set("password", test.pwdfile)) @@ -221,7 +221,7 @@ func TestShell_RunNodeWithAPICredentialsFile(t *testing.T) { } set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RunNode, set, "") + flagSetApplyFromAction(client.RunNode, set, "") require.NoError(t, set.Set("api", test.apiFile)) @@ -318,7 +318,7 @@ func TestShell_RebroadcastTransactions_Txm(t *testing.T) { beginningNonce := uint64(7) endingNonce := uint64(10) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(c.RebroadcastTransactions, set, "") + flagSetApplyFromAction(c.RebroadcastTransactions, set, "") require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String())) require.NoError(t, set.Set("beginningNonce", strconv.FormatUint(beginningNonce, 10))) @@ -397,7 +397,7 @@ func TestShell_RebroadcastTransactions_OutsideRange_Txm(t *testing.T) { } set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(c.RebroadcastTransactions, set, "") + flagSetApplyFromAction(c.RebroadcastTransactions, set, "") require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String())) require.NoError(t, set.Set("beginningNonce", strconv.FormatUint(uint64(beginningNonce), 10))) @@ -477,7 +477,7 @@ func TestShell_RebroadcastTransactions_AddressCheck(t *testing.T) { } set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RebroadcastTransactions, set, "") + flagSetApplyFromAction(client.RebroadcastTransactions, set, "") require.NoError(t, set.Set("evmChainID", testutils.FixtureChainID.String())) require.NoError(t, set.Set("address", fromAddress.Hex())) diff --git a/core/cmd/shell_remote_test.go b/core/cmd/shell_remote_test.go index 91b56ee53a4..6143d678a90 100644 --- a/core/cmd/shell_remote_test.go +++ b/core/cmd/shell_remote_test.go @@ -123,7 +123,7 @@ func TestShell_ReplayBlocks(t *testing.T) { client, _ := app.NewShellAndRenderer() set := flag.NewFlagSet("flagset", 0) - cltest.FlagSetApplyFromAction(client.ReplayFromBlock, set, "") + flagSetApplyFromAction(client.ReplayFromBlock, set, "") require.NoError(t, set.Set("block-number", "42")) require.NoError(t, set.Set("evm-chain-id", "12345678")) @@ -156,7 +156,7 @@ func TestShell_CreateExternalInitiator(t *testing.T) { client, _ := app.NewShellAndRenderer() set := flag.NewFlagSet("create", 0) - cltest.FlagSetApplyFromAction(client.CreateExternalInitiator, set, "") + flagSetApplyFromAction(client.CreateExternalInitiator, set, "") assert.NoError(t, set.Parse(test.args)) c := cli.NewContext(nil, set, nil) @@ -197,7 +197,7 @@ func TestShell_CreateExternalInitiator_Errors(t *testing.T) { initialExis := len(cltest.AllExternalInitiators(t, app.GetSqlxDB())) set := flag.NewFlagSet("create", 0) - cltest.FlagSetApplyFromAction(client.CreateExternalInitiator, set, "") + flagSetApplyFromAction(client.CreateExternalInitiator, set, "") assert.NoError(t, set.Parse(test.args)) c := cli.NewContext(nil, set, nil) @@ -228,7 +228,7 @@ func TestShell_DestroyExternalInitiator(t *testing.T) { require.NoError(t, err) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteExternalInitiator, set, "") + flagSetApplyFromAction(client.DeleteExternalInitiator, set, "") require.NoError(t, set.Parse([]string{exi.Name})) @@ -246,7 +246,7 @@ func TestShell_DestroyExternalInitiator_NotFound(t *testing.T) { client, r := app.NewShellAndRenderer() set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteExternalInitiator, set, "") + flagSetApplyFromAction(client.DeleteExternalInitiator, set, "") require.NoError(t, set.Parse([]string{"bogus-ID"})) @@ -280,7 +280,7 @@ func TestShell_RemoteLogin(t *testing.T) { client := app.NewAuthenticatingShell(prompter) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") require.NoError(t, set.Set("file", test.file)) require.NoError(t, set.Set("bypass-version-check", "true")) @@ -318,7 +318,7 @@ func TestShell_RemoteBuildCompatibility(t *testing.T) { // Fails without bypass set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") require.NoError(t, set.Set("bypass-version-check", "false")) @@ -329,7 +329,7 @@ func TestShell_RemoteBuildCompatibility(t *testing.T) { // Defaults to false set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") c = cli.NewContext(nil, set, nil) err = client.RemoteLogin(c) assert.Error(t, err) @@ -425,7 +425,7 @@ func TestShell_ChangePassword(t *testing.T) { otherClient := app.NewAuthenticatingShell(prompter) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") require.NoError(t, set.Set("file", "../internal/fixtures/apicredentials")) require.NoError(t, set.Set("bypass-version-check", "true")) @@ -473,7 +473,7 @@ func TestShell_Profile_InvalidSecondsParam(t *testing.T) { client := app.NewAuthenticatingShell(prompter) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") require.NoError(t, set.Set("file", "../internal/fixtures/apicredentials")) require.NoError(t, set.Set("bypass-version-check", "true")) @@ -504,7 +504,7 @@ func TestShell_Profile(t *testing.T) { client := app.NewAuthenticatingShell(prompter) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") require.NoError(t, set.Set("file", "../internal/fixtures/apicredentials")) require.NoError(t, set.Set("bypass-version-check", "true")) @@ -595,7 +595,7 @@ func TestShell_RunOCRJob_HappyPath(t *testing.T) { require.NoError(t, err) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") require.NoError(t, set.Set("bypass-version-check", "true")) require.NoError(t, set.Parse([]string{strconv.FormatInt(int64(jb.ID), 10)})) @@ -613,7 +613,7 @@ func TestShell_RunOCRJob_MissingJobID(t *testing.T) { client, _ := app.NewShellAndRenderer() set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") require.NoError(t, set.Set("bypass-version-check", "true")) @@ -630,7 +630,7 @@ func TestShell_RunOCRJob_JobNotFound(t *testing.T) { client, _ := app.NewShellAndRenderer() set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.RemoteLogin, set, "") + flagSetApplyFromAction(client.RemoteLogin, set, "") require.NoError(t, set.Parse([]string{"1"})) require.NoError(t, set.Set("bypass-version-check", "true")) @@ -659,7 +659,7 @@ func TestShell_AutoLogin(t *testing.T) { client.HTTP = cmd.NewAuthenticatedHTTPClient(app.Logger, app.NewClientOpts(), client.CookieAuthenticator, sr) fs := flag.NewFlagSet("", flag.ExitOnError) - cltest.FlagSetApplyFromAction(client.ListJobs, fs, "") + flagSetApplyFromAction(client.ListJobs, fs, "") err := client.ListJobs(cli.NewContext(nil, fs, nil)) require.NoError(t, err) @@ -687,7 +687,7 @@ func TestShell_AutoLogin_AuthFails(t *testing.T) { client.HTTP = cmd.NewAuthenticatedHTTPClient(app.Logger, app.NewClientOpts(), client.CookieAuthenticator, sr) fs := flag.NewFlagSet("", flag.ExitOnError) - cltest.FlagSetApplyFromAction(client.ListJobs, fs, "") + flagSetApplyFromAction(client.ListJobs, fs, "") err := client.ListJobs(cli.NewContext(nil, fs, nil)) require.Error(t, err) } @@ -716,7 +716,7 @@ func TestShell_SetLogConfig(t *testing.T) { logLevel := "warn" set := flag.NewFlagSet("loglevel", 0) - cltest.FlagSetApplyFromAction(client.SetLogLevel, set, "") + flagSetApplyFromAction(client.SetLogLevel, set, "") require.NoError(t, set.Set("level", logLevel)) @@ -728,7 +728,7 @@ func TestShell_SetLogConfig(t *testing.T) { sqlEnabled := true set = flag.NewFlagSet("logsql", 0) - cltest.FlagSetApplyFromAction(client.SetLogSQL, set, "") + flagSetApplyFromAction(client.SetLogSQL, set, "") require.NoError(t, set.Set("enable", strconv.FormatBool(sqlEnabled))) c = cli.NewContext(nil, set, nil) @@ -739,7 +739,7 @@ func TestShell_SetLogConfig(t *testing.T) { sqlEnabled = false set = flag.NewFlagSet("logsql", 0) - cltest.FlagSetApplyFromAction(client.SetLogSQL, set, "") + flagSetApplyFromAction(client.SetLogSQL, set, "") require.NoError(t, set.Set("disable", "true")) c = cli.NewContext(nil, set, nil) diff --git a/core/cmd/shell_test.go b/core/cmd/shell_test.go index 2a8c2c55861..ade14aa0d8a 100644 --- a/core/cmd/shell_test.go +++ b/core/cmd/shell_test.go @@ -2,15 +2,20 @@ package cmd_test import ( "crypto/rand" + "flag" "fmt" "math/big" "os" "path/filepath" + "reflect" + "runtime" + "strings" "testing" "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/urfave/cli" "github.com/smartcontractkit/chainlink-solana/pkg/solana" solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" @@ -514,3 +519,47 @@ func TestSetupStarkNetRelayer(t *testing.T) { require.Error(t, err) }) } + +// flagSetApplyFromAction applies the flags from action to the flagSet. +// `parentCommand` will filter the app commands and only applies the flags if the command/subcommand has a parent with that name, if left empty no filtering is done +func flagSetApplyFromAction(action interface{}, flagSet *flag.FlagSet, parentCommand string) { + cliApp := cmd.Shell{} + app := cmd.NewApp(&cliApp) + + foundName := parentCommand == "" + actionFuncName := getFuncName(action) + + for _, command := range app.Commands { + flags := recursiveFindFlagsWithName(actionFuncName, command, parentCommand, foundName) + + for _, flag := range flags { + flag.Apply(flagSet) + } + } + +} + +func recursiveFindFlagsWithName(actionFuncName string, command cli.Command, parent string, foundName bool) []cli.Flag { + + if command.Action != nil { + if actionFuncName == getFuncName(command.Action) && foundName { + return command.Flags + } + } + + for _, subcommand := range command.Subcommands { + if !foundName { + foundName = strings.EqualFold(subcommand.Name, parent) + } + + found := recursiveFindFlagsWithName(actionFuncName, subcommand, parent, foundName) + if found != nil { + return found + } + } + return nil +} + +func getFuncName(i interface{}) string { + return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() +} diff --git a/core/cmd/solana_keys_commands_test.go b/core/cmd/solana_keys_commands_test.go index 32b44fc8947..e72343be45c 100644 --- a/core/cmd/solana_keys_commands_test.go +++ b/core/cmd/solana_keys_commands_test.go @@ -95,7 +95,7 @@ func TestShell_SolanaKeys(t *testing.T) { require.NoError(t, err) requireSolanaKeyCount(t, app, 1) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(cmd.NewSolanaKeysClient(client).DeleteKey, set, "solana") + flagSetApplyFromAction(cmd.NewSolanaKeysClient(client).DeleteKey, set, "solana") require.NoError(tt, set.Set("yes", "true")) @@ -122,7 +122,7 @@ func TestShell_SolanaKeys(t *testing.T) { // Export test invalid id set := flag.NewFlagSet("test Solana export", 0) - cltest.FlagSetApplyFromAction(cmd.NewSolanaKeysClient(client).ExportKey, set, "solana") + flagSetApplyFromAction(cmd.NewSolanaKeysClient(client).ExportKey, set, "solana") require.NoError(tt, set.Parse([]string{"0"})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -135,7 +135,7 @@ func TestShell_SolanaKeys(t *testing.T) { // Export test set = flag.NewFlagSet("test Solana export", 0) - cltest.FlagSetApplyFromAction(cmd.NewSolanaKeysClient(client).ExportKey, set, "solana") + flagSetApplyFromAction(cmd.NewSolanaKeysClient(client).ExportKey, set, "solana") require.NoError(tt, set.Parse([]string{fmt.Sprint(key.ID())})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -150,7 +150,7 @@ func TestShell_SolanaKeys(t *testing.T) { requireSolanaKeyCount(t, app, 0) set = flag.NewFlagSet("test Solana import", 0) - cltest.FlagSetApplyFromAction(cmd.NewSolanaKeysClient(client).ImportKey, set, "solana") + flagSetApplyFromAction(cmd.NewSolanaKeysClient(client).ImportKey, set, "solana") require.NoError(tt, set.Parse([]string{keyName})) require.NoError(tt, set.Set("old-password", "../internal/fixtures/incorrect_password.txt")) diff --git a/core/cmd/solana_transaction_commands_test.go b/core/cmd/solana_transaction_commands_test.go index f019616cb85..b190caec51b 100644 --- a/core/cmd/solana_transaction_commands_test.go +++ b/core/cmd/solana_transaction_commands_test.go @@ -21,7 +21,6 @@ import ( solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" "github.com/smartcontractkit/chainlink/v2/core/cmd" - "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" ) func TestShell_SolanaSendSol(t *testing.T) { @@ -69,7 +68,7 @@ func TestShell_SolanaSendSol(t *testing.T) { require.NoError(t, err) set := flag.NewFlagSet("sendsolcoins", 0) - cltest.FlagSetApplyFromAction(client.SolanaSendSol, set, "solana") + flagSetApplyFromAction(client.SolanaSendSol, set, "solana") require.NoError(t, set.Set("id", chainID)) require.NoError(t, set.Parse([]string{tt.amount, from.PublicKey().String(), to.PublicKey().String()})) diff --git a/core/cmd/starknet_keys_commands_test.go b/core/cmd/starknet_keys_commands_test.go index 17584eefe05..b1fa4d88f05 100644 --- a/core/cmd/starknet_keys_commands_test.go +++ b/core/cmd/starknet_keys_commands_test.go @@ -94,7 +94,7 @@ func TestShell_StarkNetKeys(t *testing.T) { require.NoError(t, err) requireStarkNetKeyCount(t, app, 1) set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(cmd.NewStarkNetKeysClient(client).DeleteKey, set, "starknet") + flagSetApplyFromAction(cmd.NewStarkNetKeysClient(client).DeleteKey, set, "starknet") require.NoError(tt, set.Set("yes", "true")) @@ -121,7 +121,7 @@ func TestShell_StarkNetKeys(t *testing.T) { // Export test invalid id set := flag.NewFlagSet("test StarkNet export", 0) - cltest.FlagSetApplyFromAction(cmd.NewStarkNetKeysClient(client).ExportKey, set, "starknet") + flagSetApplyFromAction(cmd.NewStarkNetKeysClient(client).ExportKey, set, "starknet") require.NoError(tt, set.Parse([]string{"0"})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -134,7 +134,7 @@ func TestShell_StarkNetKeys(t *testing.T) { // Export test set = flag.NewFlagSet("test StarkNet export", 0) - cltest.FlagSetApplyFromAction(cmd.NewStarkNetKeysClient(client).ExportKey, set, "starknet") + flagSetApplyFromAction(cmd.NewStarkNetKeysClient(client).ExportKey, set, "starknet") require.NoError(tt, set.Parse([]string{fmt.Sprint(key.ID())})) require.NoError(tt, set.Set("new-password", "../internal/fixtures/incorrect_password.txt")) @@ -149,7 +149,7 @@ func TestShell_StarkNetKeys(t *testing.T) { requireStarkNetKeyCount(t, app, 0) set = flag.NewFlagSet("test StarkNet import", 0) - cltest.FlagSetApplyFromAction(cmd.NewStarkNetKeysClient(client).ImportKey, set, "starknet") + flagSetApplyFromAction(cmd.NewStarkNetKeysClient(client).ImportKey, set, "starknet") require.NoError(tt, set.Parse([]string{keyName})) require.NoError(tt, set.Set("old-password", "../internal/fixtures/incorrect_password.txt")) diff --git a/core/cmd/vrf_keys_commands_test.go b/core/cmd/vrf_keys_commands_test.go index 20552604446..a061067771d 100644 --- a/core/cmd/vrf_keys_commands_test.go +++ b/core/cmd/vrf_keys_commands_test.go @@ -105,7 +105,7 @@ func TestShellVRF_CRUD(t *testing.T) { // Now do a hard delete and ensure its completely removes the key set := flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteVRFKey, set, "") + flagSetApplyFromAction(client.DeleteVRFKey, set, "") require.NoError(t, set.Parse([]string{k2.Compressed})) require.NoError(t, set.Set("hard", "true")) @@ -141,7 +141,7 @@ func TestVRF_ImportExport(t *testing.T) { // Export it, encrypted with cltest.Password instead keyName := "vrfkey1" set := flag.NewFlagSet("test VRF export", 0) - cltest.FlagSetApplyFromAction(client.ExportVRFKey, set, "") + flagSetApplyFromAction(client.ExportVRFKey, set, "") require.NoError(t, set.Parse([]string{k1.Compressed})) // Arguments require.NoError(t, set.Set("new-password", "../internal/fixtures/correct_password.txt")) @@ -157,7 +157,7 @@ func TestVRF_ImportExport(t *testing.T) { // Should error if we try to import a duplicate key importSet := flag.NewFlagSet("test VRF import", 0) - cltest.FlagSetApplyFromAction(client.ImportVRFKey, importSet, "") + flagSetApplyFromAction(client.ImportVRFKey, importSet, "") require.NoError(t, importSet.Parse([]string{keyName})) require.NoError(t, importSet.Set("old-password", "../internal/fixtures/correct_password.txt")) @@ -167,7 +167,7 @@ func TestVRF_ImportExport(t *testing.T) { // Lets delete the key and import it set = flag.NewFlagSet("test", 0) - cltest.FlagSetApplyFromAction(client.DeleteVRFKey, set, "") + flagSetApplyFromAction(client.DeleteVRFKey, set, "") require.NoError(t, set.Parse([]string{k1.Compressed})) require.NoError(t, set.Set("hard", "true")) diff --git a/core/internal/cltest/cltest.go b/core/internal/cltest/cltest.go index cf3f4f5c073..b1431bf0599 100644 --- a/core/internal/cltest/cltest.go +++ b/core/internal/cltest/cltest.go @@ -6,7 +6,6 @@ import ( crand "crypto/rand" "encoding/json" "errors" - "flag" "fmt" "io" "math/big" @@ -16,8 +15,6 @@ import ( "net/url" "os" "reflect" - "runtime" - "strings" "testing" "time" @@ -29,7 +26,6 @@ import ( "github.com/google/uuid" "github.com/gorilla/securecookie" "github.com/gorilla/sessions" - cryptop2p "github.com/libp2p/go-libp2p-core/crypto" p2ppeer "github.com/libp2p/go-libp2p-core/peer" "github.com/manyminds/api2go/jsonapi" "github.com/onsi/gomega" @@ -37,7 +33,6 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/tidwall/gjson" - "github.com/urfave/cli" "github.com/jmoiron/sqlx" @@ -46,7 +41,6 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/loop" "github.com/smartcontractkit/chainlink/v2/common/client" - txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr" commonmocks "github.com/smartcontractkit/chainlink/v2/common/types/mocks" "github.com/smartcontractkit/chainlink/v2/core/auth" "github.com/smartcontractkit/chainlink/v2/core/bridges" @@ -55,7 +49,6 @@ import ( evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" evmclimocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client/mocks" evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config" - "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas" httypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker/types" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" @@ -120,7 +113,6 @@ const ( var ( DefaultP2PPeerID p2pkey.PeerID FixtureChainID = *testutils.FixtureChainID - source rand.Source DefaultCosmosKey = cosmoskey.MustNewInsecure(keystest.NewRandReaderFromSeed(KeyBigIntSeed)) DefaultCSAKey = csakey.MustNewV2XXXTestingOnly(big.NewInt(KeyBigIntSeed)) @@ -147,13 +139,6 @@ func init() { fmt.Printf("[gin] %-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers) } - // Seed the random number generator, otherwise separate modules will take - // the same advisory locks when tested with `go test -p N` for N > 1 - seed := time.Now().UTC().UnixNano() - fmt.Printf("cltest random seed: %v\n", seed) - - // Also seed the local source - source = rand.NewSource(seed) defaultP2PPeerID, err := p2ppeer.Decode(configtest.DefaultPeerID) if err != nil { panic(err) @@ -201,22 +186,6 @@ func NewJobPipelineV2(t testing.TB, cfg pipeline.BridgeConfig, jpcfg JobPipeline } } -func NewEventBroadcaster(t testing.TB, dbURL url.URL) pg.EventBroadcaster { - lggr := logger.TestLogger(t) - return pg.NewEventBroadcaster(dbURL, 0, 0, lggr, uuid.New()) -} - -func NewEthConfirmer(t testing.TB, txStore txmgr.EvmTxStore, ethClient evmclient.Client, config evmconfig.ChainScopedConfig, ks keystore.Eth, fn txmgrcommon.ResumeCallback) *txmgr.Confirmer { - lggr := logger.TestLogger(t) - ge := config.EVM().GasEstimator() - estimator := gas.NewWrappedEvmEstimator(gas.NewFixedPriceEstimator(ge, ge.BlockHistory(), lggr), ge.EIP1559DynamicFees(), nil) - txBuilder := txmgr.NewEvmTxAttemptBuilder(*ethClient.ConfiguredChainID(), ge, ks, estimator) - ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(ge), config.EVM().Transactions(), config.Database(), ks, txBuilder, lggr) - ec.SetResumeCallback(fn) - require.NoError(t, ec.Start(testutils.Context(t))) - return ec -} - // TestApplication holds the test application and test servers type TestApplication struct { t testing.TB @@ -228,13 +197,6 @@ type TestApplication struct { Keys []ethkey.KeyV2 } -// NewWSServer starts a websocket server which invokes callback for each message received. -// If chainID is set, then eth_chainId calls will be automatically handled. -func NewWSServer(t *testing.T, chainID *big.Int, callback testutils.JSONRPCHandler) string { - server := testutils.NewWSServer(t, chainID, callback) - return server.WSURL().String() -} - // NewApplicationEVMDisabled creates a new application with default config but EVM disabled // Useful for testing controllers func NewApplicationEVMDisabled(t *testing.T) *TestApplication { @@ -1578,58 +1540,17 @@ func AssertRecordEventually(t *testing.T, db *sqlx.DB, model interface{}, stmt s }, testutils.WaitTimeout(t), DBPollingInterval).Should(gomega.BeTrue()) } -func MustSendingKeyStates(t *testing.T, ethKeyStore keystore.Eth, chainID *big.Int) []ethkey.State { - keys, err := ethKeyStore.EnabledKeysForChain(chainID) - require.NoError(t, err) - states, err := ethKeyStore.GetStatesForKeys(keys) - require.NoError(t, err) - return states -} - -func MustRandomP2PPeerID(t *testing.T) p2ppeer.ID { - reader := rand.New(source) - p2pPrivkey, _, err := cryptop2p.GenerateEd25519Key(reader) - require.NoError(t, err) - id, err := p2ppeer.IDFromPrivateKey(p2pPrivkey) - require.NoError(t, err) - return id -} - func MustWebURL(t *testing.T, s string) *models.WebURL { uri, err := url.Parse(s) require.NoError(t, err) return (*models.WebURL)(uri) } -func AssertPipelineTaskRunsSuccessful(t testing.TB, runs []pipeline.TaskRun) { - t.Helper() - for i, run := range runs { - require.True(t, run.Error.IsZero(), fmt.Sprintf("pipeline.Task run failed (idx: %v, dotID: %v, error: '%v')", i, run.GetDotID(), run.Error.ValueOrZero())) - } -} - -func AssertPipelineTaskRunsErrored(t testing.TB, runs []pipeline.TaskRun) { - t.Helper() - for i, run := range runs { - require.False(t, run.Error.IsZero(), fmt.Sprintf("expected pipeline.Task run to have failed, but it succeeded (idx: %v, dotID: %v, output: '%v')", i, run.GetDotID(), run.Output)) - } -} - func NewTestChainScopedConfig(t testing.TB) evmconfig.ChainScopedConfig { cfg := configtest.NewGeneralConfig(t, nil) return evmtest.NewChainScopedConfig(t, cfg) } -func MustGetStateForKey(t testing.TB, kst keystore.Eth, key ethkey.KeyV2) ethkey.State { - state, err := kst.GetStateForKey(key) - require.NoError(t, err) - return state -} - -func NewTxStore(t *testing.T, db *sqlx.DB, cfg pg.QConfig) txmgr.EvmTxStore { - return txmgr.NewTxStore(db, logger.TestLogger(t), cfg) -} - func NewTestTxStore(t *testing.T, db *sqlx.DB, cfg pg.QConfig) txmgr.TestEvmTxStore { return txmgr.NewTxStore(db, logger.TestLogger(t), cfg) } @@ -1647,47 +1568,3 @@ func ClearDBTables(t *testing.T, db *sqlx.DB, tables ...string) { err = tx.Commit() require.NoError(t, err) } - -// FlagSetApplyFromAction applies the flags from action to the flagSet. -// `parentCommand` will filter the app commands and only applies the flags if the command/subcommand has a parent with that name, if left empty no filtering is done -func FlagSetApplyFromAction(action interface{}, flagSet *flag.FlagSet, parentCommand string) { - cliApp := cmd.Shell{} - app := cmd.NewApp(&cliApp) - - foundName := parentCommand == "" - actionFuncName := getFuncName(action) - - for _, command := range app.Commands { - flags := recursiveFindFlagsWithName(actionFuncName, command, parentCommand, foundName) - - for _, flag := range flags { - flag.Apply(flagSet) - } - } - -} - -func recursiveFindFlagsWithName(actionFuncName string, command cli.Command, parent string, foundName bool) []cli.Flag { - - if command.Action != nil { - if actionFuncName == getFuncName(command.Action) && foundName { - return command.Flags - } - } - - for _, subcommand := range command.Subcommands { - if !foundName { - foundName = strings.EqualFold(subcommand.Name, parent) - } - - found := recursiveFindFlagsWithName(actionFuncName, subcommand, parent, foundName) - if found != nil { - return found - } - } - return nil -} - -func getFuncName(i interface{}) string { - return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() -} diff --git a/core/internal/cltest/event_websocket_server.go b/core/internal/cltest/event_websocket_server.go deleted file mode 100644 index 64b3e90cd81..00000000000 --- a/core/internal/cltest/event_websocket_server.go +++ /dev/null @@ -1,154 +0,0 @@ -package cltest - -import ( - "net/http" - "net/http/httptest" - "net/url" - "sync" - "testing" - - "github.com/pkg/errors" - - "github.com/gorilla/websocket" -) - -// EventWebSocketServer is a web socket server designed specifically for testing -type EventWebSocketServer struct { - *httptest.Server - mutex *sync.RWMutex // shared mutex for safe access to arrays/maps. - t *testing.T - connections []*websocket.Conn - Connected chan struct{} - Disconnected chan struct{} - ReceivedText chan string - ReceivedBinary chan []byte - URL *url.URL -} - -// NewEventWebSocketServer returns a new EventWebSocketServer -func NewEventWebSocketServer(t *testing.T) (*EventWebSocketServer, func()) { - server := &EventWebSocketServer{ - mutex: &sync.RWMutex{}, - t: t, - Connected: make(chan struct{}, 1), // have buffer of one for easier assertions after the event - Disconnected: make(chan struct{}, 1), // have buffer of one for easier assertions after the event - ReceivedText: make(chan string, 100), - ReceivedBinary: make(chan []byte, 100), - } - - server.Server = httptest.NewServer(http.HandlerFunc(server.handler)) - u, err := url.Parse(server.Server.URL) - if err != nil { - t.Fatal("EventWebSocketServer: ", err) - } - u.Scheme = "ws" - server.URL = u - return server, func() { - server.Close() - } -} - -func (wss EventWebSocketServer) ConnectionsCount() int { - wss.mutex.RLock() - defer wss.mutex.RUnlock() - return len(wss.connections) -} - -// Broadcast sends a message to every web socket client connected to the EventWebSocketServer -func (wss *EventWebSocketServer) Broadcast(message string) error { - wss.mutex.RLock() - defer wss.mutex.RUnlock() - for _, connection := range wss.connections { - err := connection.WriteMessage(websocket.TextMessage, []byte(message)) - if err != nil { - return errors.Wrap(err, "error writing message to connection") - } - } - - return nil -} - -// WriteCloseMessage tells connected clients to disconnect. -// Useful to emulate that the websocket server is shutting down without -// actually shutting down. -// This overcomes httptest.Server's inability to restart on the same URL:port. -func (wss *EventWebSocketServer) WriteCloseMessage() { - wss.mutex.RLock() - for _, connection := range wss.connections { - err := connection.WriteMessage( - websocket.CloseMessage, - websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) - if err != nil { - wss.t.Error(err) - } - } - wss.mutex.RUnlock() -} - -var ( - upgrader = websocket.Upgrader{ - CheckOrigin: func(r *http.Request) bool { return true }, - } - - closeCodes = []int{websocket.CloseNormalClosure, websocket.CloseAbnormalClosure} -) - -func (wss *EventWebSocketServer) handler(w http.ResponseWriter, r *http.Request) { - var err error - conn, err := upgrader.Upgrade(w, r, nil) - if err != nil { - wss.t.Fatal("EventWebSocketServer Upgrade: ", err) - } - - wss.addConnection(conn) - for { - messageType, payload, err := conn.ReadMessage() // we only read - if websocket.IsCloseError(err, closeCodes...) { - wss.removeConnection(conn) - return - } - if err != nil { - wss.t.Fatal("EventWebSocketServer ReadMessage: ", err) - } - - if messageType == websocket.TextMessage { - select { - case wss.ReceivedText <- string(payload): - default: - } - } else if messageType == websocket.BinaryMessage { - select { - case wss.ReceivedBinary <- payload: - default: - } - } else { - wss.t.Fatal("EventWebSocketServer UnsupportedMessageType: ", messageType) - } - } -} - -func (wss *EventWebSocketServer) addConnection(conn *websocket.Conn) { - wss.mutex.Lock() - wss.connections = append(wss.connections, conn) - wss.mutex.Unlock() - select { // broadcast connected event - case wss.Connected <- struct{}{}: - default: - } -} - -func (wss *EventWebSocketServer) removeConnection(conn *websocket.Conn) { - newc := []*websocket.Conn{} - wss.mutex.Lock() - for _, connection := range wss.connections { - if connection != conn { - newc = append(newc, connection) - } - } - wss.connections = newc - wss.mutex.Unlock() - select { // broadcast disconnected event - case wss.Disconnected <- struct{}{}: - default: - } -} diff --git a/core/internal/cltest/factories.go b/core/internal/cltest/factories.go index 741afe828f9..46014c4e04f 100644 --- a/core/internal/cltest/factories.go +++ b/core/internal/cltest/factories.go @@ -134,7 +134,7 @@ func EmptyCLIContext() *cli.Context { return cli.NewContext(nil, set, nil) } -func NewEthTx(t *testing.T, fromAddress common.Address) txmgr.Tx { +func NewEthTx(fromAddress common.Address) txmgr.Tx { return txmgr.Tx{ FromAddress: fromAddress, ToAddress: testutils.NewAddress(), @@ -156,7 +156,7 @@ func MustInsertUnconfirmedEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, nonc chainID = v } } - etx := NewEthTx(t, fromAddress) + etx := NewEthTx(fromAddress) etx.BroadcastAt = &broadcastAt etx.InitialBroadcastAt = &broadcastAt @@ -184,95 +184,9 @@ func MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t *testing.T, txStore return etx } -func MustInsertUnconfirmedEthTxWithAttemptState(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address, txAttemptState txmgrtypes.TxAttemptState, opts ...interface{}) txmgr.Tx { - etx := MustInsertUnconfirmedEthTx(t, txStore, nonce, fromAddress, opts...) - attempt := NewLegacyEthTxAttempt(t, etx.ID) - - tx := types.NewTransaction(uint64(nonce), testutils.NewAddress(), big.NewInt(142), 242, big.NewInt(342), []byte{1, 2, 3}) - rlp := new(bytes.Buffer) - require.NoError(t, tx.EncodeRLP(rlp)) - attempt.SignedRawTx = rlp.Bytes() - - attempt.State = txAttemptState - require.NoError(t, txStore.InsertTxAttempt(&attempt)) - etx, err := txStore.FindTxWithAttempts(etx.ID) - require.NoError(t, err) - return etx -} - -func MustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address, opts ...interface{}) txmgr.Tx { - etx := MustInsertUnconfirmedEthTx(t, txStore, nonce, fromAddress, opts...) - attempt := NewDynamicFeeEthTxAttempt(t, etx.ID) - - addr := testutils.NewAddress() - dtx := types.DynamicFeeTx{ - ChainID: big.NewInt(0), - Nonce: uint64(nonce), - GasTipCap: big.NewInt(1), - GasFeeCap: big.NewInt(1), - Gas: 242, - To: &addr, - Value: big.NewInt(342), - Data: []byte{2, 3, 4}, - } - tx := types.NewTx(&dtx) - rlp := new(bytes.Buffer) - require.NoError(t, tx.EncodeRLP(rlp)) - attempt.SignedRawTx = rlp.Bytes() - - attempt.State = txmgrtypes.TxAttemptBroadcast - require.NoError(t, txStore.InsertTxAttempt(&attempt)) - etx, err := txStore.FindTxWithAttempts(etx.ID) - require.NoError(t, err) - return etx -} - -func MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, fromAddress common.Address) txmgr.Tx { - timeNow := time.Now() - etx := NewEthTx(t, fromAddress) - - etx.BroadcastAt = &timeNow - etx.InitialBroadcastAt = &timeNow - n := evmtypes.Nonce(nonce) - etx.Sequence = &n - etx.State = txmgrcommon.TxUnconfirmed - require.NoError(t, txStore.InsertTx(&etx)) - attempt := NewLegacyEthTxAttempt(t, etx.ID) - - tx := types.NewTransaction(uint64(nonce), testutils.NewAddress(), big.NewInt(142), 242, big.NewInt(342), []byte{1, 2, 3}) - rlp := new(bytes.Buffer) - require.NoError(t, tx.EncodeRLP(rlp)) - attempt.SignedRawTx = rlp.Bytes() - - attempt.State = txmgrtypes.TxAttemptInsufficientFunds - require.NoError(t, txStore.InsertTxAttempt(&attempt)) - etx, err := txStore.FindTxWithAttempts(etx.ID) - require.NoError(t, err) - return etx -} - -func MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt( - t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, broadcastBeforeBlockNum int64, - broadcastAt time.Time, fromAddress common.Address) txmgr.Tx { - etx := NewEthTx(t, fromAddress) - - etx.BroadcastAt = &broadcastAt - etx.InitialBroadcastAt = &broadcastAt - n := evmtypes.Nonce(nonce) - etx.Sequence = &n - etx.State = txmgrcommon.TxConfirmedMissingReceipt - require.NoError(t, txStore.InsertTx(&etx)) - attempt := NewLegacyEthTxAttempt(t, etx.ID) - attempt.BroadcastBeforeBlockNum = &broadcastBeforeBlockNum - attempt.State = txmgrtypes.TxAttemptBroadcast - require.NoError(t, txStore.InsertTxAttempt(&attempt)) - etx.TxAttempts = append(etx.TxAttempts, attempt) - return etx -} - func MustInsertConfirmedEthTxWithLegacyAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce int64, broadcastBeforeBlockNum int64, fromAddress common.Address) txmgr.Tx { timeNow := time.Now() - etx := NewEthTx(t, fromAddress) + etx := NewEthTx(fromAddress) etx.BroadcastAt = &timeNow etx.InitialBroadcastAt = &timeNow @@ -288,91 +202,6 @@ func MustInsertConfirmedEthTxWithLegacyAttempt(t *testing.T, txStore txmgr.TestE return etx } -func MustInsertInProgressEthTxWithAttempt(t *testing.T, txStore txmgr.TestEvmTxStore, nonce evmtypes.Nonce, fromAddress common.Address) txmgr.Tx { - etx := NewEthTx(t, fromAddress) - - etx.Sequence = &nonce - etx.State = txmgrcommon.TxInProgress - require.NoError(t, txStore.InsertTx(&etx)) - attempt := NewLegacyEthTxAttempt(t, etx.ID) - tx := types.NewTransaction(uint64(nonce), testutils.NewAddress(), big.NewInt(142), 242, big.NewInt(342), []byte{1, 2, 3}) - rlp := new(bytes.Buffer) - require.NoError(t, tx.EncodeRLP(rlp)) - attempt.SignedRawTx = rlp.Bytes() - attempt.State = txmgrtypes.TxAttemptInProgress - require.NoError(t, txStore.InsertTxAttempt(&attempt)) - etx, err := txStore.FindTxWithAttempts(etx.ID) - require.NoError(t, err) - return etx -} - -func MustCreateUnstartedGeneratedTx(t testing.TB, txStore txmgr.EvmTxStore, fromAddress common.Address, chainID *big.Int, opts ...func(*txmgr.TxRequest)) (tx txmgr.Tx) { - txRequest := txmgr.TxRequest{ - FromAddress: fromAddress, - } - - // Apply the default options - WithDefaults()(&txRequest) - // Apply the optional parameters - for _, opt := range opts { - opt(&txRequest) - } - return MustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, chainID) -} - -func WithDefaults() func(*txmgr.TxRequest) { - return func(tx *txmgr.TxRequest) { - tx.ToAddress = testutils.NewAddress() - tx.EncodedPayload = []byte{1, 2, 3} - tx.Value = big.Int(assets.NewEthValue(142)) - tx.FeeLimit = uint32(1000000000) - tx.Strategy = txmgrcommon.NewSendEveryStrategy() - // Set default values for other fields if needed - } -} - -func EvmTxRequestWithStrategy(strategy txmgrtypes.TxStrategy) func(*txmgr.TxRequest) { - return func(tx *txmgr.TxRequest) { - tx.Strategy = strategy - } -} - -func EvmTxRequestWithChecker(checker txmgr.TransmitCheckerSpec) func(*txmgr.TxRequest) { - return func(tx *txmgr.TxRequest) { - tx.Checker = checker - } -} -func EvmTxRequestWithValue(value big.Int) func(*txmgr.TxRequest) { - return func(tx *txmgr.TxRequest) { - tx.Value = value - } -} - -func EvmTxRequestWithIdempotencyKey(idempotencyKey string) func(*txmgr.TxRequest) { - return func(tx *txmgr.TxRequest) { - tx.IdempotencyKey = &idempotencyKey - } -} - -func MustCreateUnstartedTx(t testing.TB, txStore txmgr.EvmTxStore, fromAddress common.Address, toAddress common.Address, encodedPayload []byte, gasLimit uint32, value big.Int, chainID *big.Int, opts ...interface{}) (tx txmgr.Tx) { - txRequest := txmgr.TxRequest{ - FromAddress: fromAddress, - ToAddress: toAddress, - EncodedPayload: encodedPayload, - Value: value, - FeeLimit: gasLimit, - Strategy: txmgrcommon.NewSendEveryStrategy(), - } - - return MustCreateUnstartedTxFromEvmTxRequest(t, txStore, txRequest, chainID) -} - -func MustCreateUnstartedTxFromEvmTxRequest(t testing.TB, txStore txmgr.EvmTxStore, txRequest txmgr.TxRequest, chainID *big.Int) (tx txmgr.Tx) { - tx, err := txStore.CreateTransaction(testutils.Context(t), txRequest, chainID) - require.NoError(t, err) - return tx -} - func NewLegacyEthTxAttempt(t *testing.T, etxID int64) txmgr.TxAttempt { gasPrice := assets.NewWeiI(1) return txmgr.TxAttempt{ @@ -406,72 +235,6 @@ func NewDynamicFeeEthTxAttempt(t *testing.T, etxID int64) txmgr.TxAttempt { } } -func NewEthReceipt(t *testing.T, blockNumber int64, blockHash common.Hash, txHash common.Hash, status uint64) txmgr.Receipt { - transactionIndex := uint(NewRandomPositiveInt64()) - - receipt := evmtypes.Receipt{ - BlockNumber: big.NewInt(blockNumber), - BlockHash: blockHash, - TxHash: txHash, - TransactionIndex: transactionIndex, - Status: status, - } - - r := txmgr.Receipt{ - BlockNumber: blockNumber, - BlockHash: blockHash, - TxHash: txHash, - TransactionIndex: transactionIndex, - Receipt: receipt, - } - return r -} - -func MustInsertEthReceipt(t *testing.T, txStore txmgr.TestEvmTxStore, blockNumber int64, blockHash common.Hash, txHash common.Hash) txmgr.Receipt { - r := NewEthReceipt(t, blockNumber, blockHash, txHash, 0x1) - id, err := txStore.InsertReceipt(&r.Receipt) - require.NoError(t, err) - r.ID = id - return r -} - -func MustInsertRevertedEthReceipt(t *testing.T, txStore txmgr.TestEvmTxStore, blockNumber int64, blockHash common.Hash, txHash common.Hash) txmgr.Receipt { - r := NewEthReceipt(t, blockNumber, blockHash, txHash, 0x0) - id, err := txStore.InsertReceipt(&r.Receipt) - require.NoError(t, err) - r.ID = id - return r -} - -// Inserts into evm.receipts but does not update evm.txes or evm.tx_attempts -func MustInsertConfirmedEthTxWithReceipt(t *testing.T, txStore txmgr.TestEvmTxStore, fromAddress common.Address, nonce, blockNum int64) (etx txmgr.Tx) { - etx = MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, nonce, blockNum, fromAddress) - MustInsertEthReceipt(t, txStore, blockNum, utils.NewHash(), etx.TxAttempts[0].Hash) - return etx -} - -func MustInsertConfirmedEthTxBySaveFetchedReceipts(t *testing.T, txStore txmgr.TestEvmTxStore, fromAddress common.Address, nonce int64, blockNum int64, chainID big.Int) (etx txmgr.Tx) { - etx = MustInsertConfirmedEthTxWithLegacyAttempt(t, txStore, nonce, blockNum, fromAddress) - receipt := evmtypes.Receipt{ - TxHash: etx.TxAttempts[0].Hash, - BlockHash: utils.NewHash(), - BlockNumber: big.NewInt(nonce), - TransactionIndex: uint(1), - } - err := txStore.SaveFetchedReceipts(testutils.Context(t), []*evmtypes.Receipt{&receipt}, &chainID) - require.NoError(t, err) - return etx -} - -func MustInsertFatalErrorEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, fromAddress common.Address) txmgr.Tx { - etx := NewEthTx(t, fromAddress) - etx.Error = null.StringFrom("something exploded") - etx.State = txmgrcommon.TxFatalError - - require.NoError(t, txStore.InsertTx(&etx)) - return etx -} - type RandomKey struct { Nonce int64 Disabled bool @@ -500,7 +263,8 @@ func (r RandomKey) MustInsert(t testing.TB, keystore keystore.Eth) (ethkey.KeyV2 func (r RandomKey) MustInsertWithState(t testing.TB, keystore keystore.Eth) (ethkey.State, common.Address) { k, address := r.MustInsert(t, keystore) - state := MustGetStateForKey(t, keystore, k) + state, err := keystore.GetStateForKey(k) + require.NoError(t, err) return state, address } diff --git a/core/internal/features/features_test.go b/core/internal/features/features_test.go index 7749b173c55..35fd3a31ff8 100644 --- a/core/internal/features/features_test.go +++ b/core/internal/features/features_test.go @@ -429,7 +429,7 @@ func TestIntegration_DirectRequest(t *testing.T) { pipelineRuns := cltest.WaitForPipelineComplete(t, 0, j.ID, 1, 14, app.JobORM(), testutils.WaitTimeout(t)/2, time.Second) pipelineRun := pipelineRuns[0] - cltest.AssertPipelineTaskRunsSuccessful(t, pipelineRun.PipelineTaskRuns) + assertPipelineTaskRunsSuccessful(t, pipelineRun.PipelineTaskRuns) assertPricesUint256(t, big.NewInt(61464), big.NewInt(50707), big.NewInt(6381886), operatorContracts.multiWord) nameAndExternalJobID = uuid.New() @@ -454,7 +454,7 @@ func TestIntegration_DirectRequest(t *testing.T) { pipelineRuns = cltest.WaitForPipelineComplete(t, 0, jobSingleWord.ID, 1, 8, app.JobORM(), testutils.WaitTimeout(t), time.Second) pipelineRun = pipelineRuns[0] - cltest.AssertPipelineTaskRunsSuccessful(t, pipelineRun.PipelineTaskRuns) + assertPipelineTaskRunsSuccessful(t, pipelineRun.PipelineTaskRuns) v, err := operatorContracts.singleWord.CurrentPriceInt(nil) require.NoError(t, err) assert.Equal(t, big.NewInt(61464), v) @@ -535,7 +535,7 @@ observationSource = """ // The run should have succeeded but with the receipt detailing the reverted transaction pipelineRun := pipelineRuns[0] - cltest.AssertPipelineTaskRunsSuccessful(t, pipelineRun.PipelineTaskRuns) + assertPipelineTaskRunsSuccessful(t, pipelineRun.PipelineTaskRuns) outputs := pipelineRun.Outputs.Val.([]interface{}) require.Len(t, outputs, 1) @@ -581,7 +581,7 @@ observationSource = """ // The run should have failed as a revert pipelineRun := pipelineRuns[0] - cltest.AssertPipelineTaskRunsErrored(t, pipelineRun.PipelineTaskRuns) + assertPipelineTaskRunsErrored(t, pipelineRun.PipelineTaskRuns) }) t.Run("with FailOnRevert disabled, run succeeds with output being reverted receipt", func(t *testing.T) { @@ -619,7 +619,7 @@ observationSource = """ // The run should have succeeded but with the receipt detailing the reverted transaction pipelineRun := pipelineRuns[0] - cltest.AssertPipelineTaskRunsSuccessful(t, pipelineRun.PipelineTaskRuns) + assertPipelineTaskRunsSuccessful(t, pipelineRun.PipelineTaskRuns) outputs := pipelineRun.Outputs.Val.([]interface{}) require.Len(t, outputs, 1) @@ -1454,3 +1454,17 @@ func assertPricesUint256(t *testing.T, usd, eur, jpy *big.Int, consumer *multiwo } func ptr[T any](v T) *T { return &v } + +func assertPipelineTaskRunsSuccessful(t testing.TB, runs []pipeline.TaskRun) { + t.Helper() + for i, run := range runs { + require.True(t, run.Error.IsZero(), fmt.Sprintf("pipeline.Task run failed (idx: %v, dotID: %v, error: '%v')", i, run.GetDotID(), run.Error.ValueOrZero())) + } +} + +func assertPipelineTaskRunsErrored(t testing.TB, runs []pipeline.TaskRun) { + t.Helper() + for i, run := range runs { + require.False(t, run.Error.IsZero(), fmt.Sprintf("expected pipeline.Task run to have failed, but it succeeded (idx: %v, dotID: %v, output: '%v')", i, run.GetDotID(), run.Output)) + } +} diff --git a/core/services/ocrcommon/discoverer_database_test.go b/core/services/ocrcommon/discoverer_database_test.go index 2300316092d..ff1a931b017 100644 --- a/core/services/ocrcommon/discoverer_database_test.go +++ b/core/services/ocrcommon/discoverer_database_test.go @@ -1,23 +1,24 @@ package ocrcommon_test import ( + "crypto/rand" "testing" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon" - + cryptop2p "github.com/libp2p/go-libp2p-core/crypto" + p2ppeer "github.com/libp2p/go-libp2p-core/peer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" + "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" + "github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon" ) func Test_DiscovererDatabase(t *testing.T) { db := pgtest.NewSqlDB(t) - localPeerID1 := cltest.MustRandomP2PPeerID(t) - localPeerID2 := cltest.MustRandomP2PPeerID(t) + localPeerID1 := mustRandomP2PPeerID(t) + localPeerID2 := mustRandomP2PPeerID(t) dd1 := ocrcommon.NewDiscovererDatabase(db, localPeerID1) dd2 := ocrcommon.NewDiscovererDatabase(db, localPeerID2) @@ -81,3 +82,11 @@ func Test_DiscovererDatabase(t *testing.T) { }) } + +func mustRandomP2PPeerID(t *testing.T) p2ppeer.ID { + p2pPrivkey, _, err := cryptop2p.GenerateEd25519Key(rand.Reader) + require.NoError(t, err) + id, err := p2ppeer.IDFromPrivateKey(p2pPrivkey) + require.NoError(t, err) + return id +} diff --git a/core/services/pg/event_broadcaster_test.go b/core/services/pg/event_broadcaster_test.go index a82e26e0589..41dcbb0176f 100644 --- a/core/services/pg/event_broadcaster_test.go +++ b/core/services/pg/event_broadcaster_test.go @@ -5,20 +5,20 @@ import ( "testing" "time" - "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" - "github.com/smartcontractkit/chainlink/v2/core/services/pg" - + "github.com/google/uuid" "github.com/onsi/gomega" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink/v2/core/internal/cltest" "github.com/smartcontractkit/chainlink/v2/core/internal/cltest/heavyweight" + "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" + "github.com/smartcontractkit/chainlink/v2/core/logger" + "github.com/smartcontractkit/chainlink/v2/core/services/pg" ) func TestEventBroadcaster(t *testing.T) { config, _ := heavyweight.FullTestDBNoFixturesV2(t, nil) - eventBroadcaster := cltest.NewEventBroadcaster(t, config.Database().URL()) + eventBroadcaster := pg.NewEventBroadcaster(config.Database().URL(), 0, 0, logger.TestLogger(t), uuid.New()) require.NoError(t, eventBroadcaster.Start(testutils.Context(t))) t.Cleanup(func() { require.NoError(t, eventBroadcaster.Close()) })