diff --git a/internal/node_client/node_client.go b/internal/node_client/node_client.go index fcc6b1c66..3fad29003 100644 --- a/internal/node_client/node_client.go +++ b/internal/node_client/node_client.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "runtime" - "strings" sdkTx "github.com/bitcoin-sv/go-sdk/transaction" "github.com/ordishs/go-bitcoin" @@ -51,8 +50,6 @@ func New(n *bitcoin.Bitcoind, opts ...func(client *NodeClient)) (NodeClient, err return node, nil } -var ErrTransactionNotInMempool = errors.New("Transaction not in mempool") - func (n NodeClient) GetMempoolAncestors(ctx context.Context, ids []string) ([]string, error) { _, span := tracing.StartTracing(ctx, "NodeClient_GetMempoolAncestors", n.tracingEnabled, n.tracingAttributes...) defer tracing.EndTracing(span) @@ -64,9 +61,9 @@ func (n NodeClient) GetMempoolAncestors(ctx context.Context, ids []string) ([]st nTx, err := n.bitcoinClient.GetMempoolAncestors(id, false) tracing.EndTracing(span) if err != nil { - if strings.Contains(err.Error(), "Transaction not in mempool") { - continue - } + //if strings.Contains(err.Error(), "Transaction not in mempool") { + // continue + //} return nil, errors.Join(ErrFailedToGetMempoolAncestors, err) } diff --git a/internal/node_client/node_client_test.go b/internal/node_client/node_client_test.go index 08de136c0..8c67612f2 100644 --- a/internal/node_client/node_client_test.go +++ b/internal/node_client/node_client_test.go @@ -157,9 +157,10 @@ func TestNodeClient(t *testing.T) { require.ErrorIs(t, err, node_client.ErrFailedToGetMempoolAncestors) // when - _, err = sut.GetMempoolAncestors(ctx, []string{"792bb5c0d5e4937572e6368dc713ba0b4935d27a7b7ac654c2b384d6c8b2fb89"}) + actual, err := sut.GetMempoolAncestors(ctx, []string{"792bb5c0d5e4937572e6368dc713ba0b4935d27a7b7ac654c2b384d6c8b2fb89"}) // tx id not existing in the mempool // then - require.ErrorIs(t, err, node_client.ErrTransactionNotInMempool) + require.NoError(t, err) + require.Empty(t, actual) }) } diff --git a/test/submit_01_single_test.go b/test/submit_01_single_test.go index 5897d4246..88c3bbfe3 100644 --- a/test/submit_01_single_test.go +++ b/test/submit_01_single_test.go @@ -571,10 +571,11 @@ func TestPostCumulativeFeesValidation(t *testing.T) { } tt := []struct { - name string - options validationOpts - lastTxFee uint64 - chainLong int + name string + options validationOpts + lastTxFee uint64 + chainLong int + minedAncestors int expectedStatusCode int expectedTxStatus string @@ -599,7 +600,7 @@ func TestPostCumulativeFeesValidation(t *testing.T) { expectedTxStatus: StatusSeenOnNetwork, }, { - name: "post txs chain with too low fee with cumulative fees validation", + name: "post txs chain with too low fee with cumulative fees validation", options: validationOpts{ performCumulativeFeesValidation: true, }, @@ -608,16 +609,36 @@ func TestPostCumulativeFeesValidation(t *testing.T) { expectedError: "arc error 473: transaction fee is too low\nminimum expected cumulative fee: 84, actual fee: 1", }, { - name: "post txs chain with suficient fee with cumulative fees validation", + name: "post txs chain with too low fee with cumulative fees validation - some ancestors are mined", + options: validationOpts{ + performCumulativeFeesValidation: true, + }, + lastTxFee: 1, + minedAncestors: 2, + expectedStatusCode: 473, + expectedError: "arc error 473: transaction fee is too low\nminimum expected cumulative fee: 84, actual fee: 1", + }, + { + name: "post txs chain with sufficient fee with cumulative fees validation", + options: validationOpts{ + performCumulativeFeesValidation: true, + }, + lastTxFee: 90, + expectedStatusCode: 200, + expectedTxStatus: StatusSeenOnNetwork, + }, + { + name: "post txs chain with sufficient fee with cumulative fees validation - some ancestors are mined", options: validationOpts{ performCumulativeFeesValidation: true, }, lastTxFee: 90, + minedAncestors: 2, expectedStatusCode: 200, expectedTxStatus: StatusSeenOnNetwork, }, { - name: "post txs chain with cumulative fees validation - chain too long - ignore it", + name: "post txs chain with cumulative fees validation - chain too long - ignore it", options: validationOpts{ performCumulativeFeesValidation: true, }, @@ -673,7 +694,7 @@ func TestPostCumulativeFeesValidation(t *testing.T) { Vout: 0, Address: address, ScriptPubKey: output.LockingScript.String(), - Amount: float64(float64(output.Satoshis) / 1e8), + Amount: float64(output.Satoshis) / 1e8, } tx, err := node_client.CreateTx(privateKey, address, utxo, zeroFee) @@ -715,6 +736,30 @@ func TestPostCumulativeFeesValidation(t *testing.T) { } } + txRequests := make([]TransactionRequest, 0) + for _, chain := range zeroFeeChains { + for _, tx := range chain { + rawTx, err := tx.EFHex() + require.NoError(t, err) + body := TransactionRequest{RawTx: rawTx} + txRequests = append(txRequests, body) + } + } + + for i, body := range txRequests { + if tc.minedAncestors > 0 && i == tc.minedAncestors { + node_client.Generate(t, bitcoind, 1) + } + + resp := postRequest[TransactionResponse](t, arcEndpointV1Tx, createPayload(t, body), + map[string]string{ + "X-WaitFor": StatusSeenOnNetwork, + "X-SkipFeeValidation": strconv.FormatBool(true), + }, 200) + + require.Equal(t, StatusSeenOnNetwork, resp.TxStatus) + } + // then // create last transaction var nodeUtxos []node_client.UnspentOutput