Skip to content

Conversation

akankshakashyap
Copy link
Contributor

@akankshakashyap akankshakashyap commented Jun 7, 2022

Made 2 changes to tests/functional/rpc_fundrawtransaction.py-

  1. Remove test_simple_two_coins - The current test_simple_two_coins and test_simple are identical and redundant. The test_simple_two_coins was changed in [QA] fix possible reorg issue in (fund)rawtransaction(s).py RPC test #6417 and asserts ensuring the use of two input coins were removed.
  2. Use changepos to get the change output - In test_address_reuse the code to get the change output assumes that a coin with a value > 2 BTC was used to fund the transaction, and therefore change value will be greater than 1 BTC. This can fail if previous tests add a small coin. fundrawtransaction directly gives the index of change output as changepos, we use this to get the change output more reliably and cleanly.

@akankshakashyap akankshakashyap changed the title Refactor rpc_fundrawtransaction.py test: Refactor rpc_fundrawtransaction.py Jun 7, 2022
@akankshakashyap akankshakashyap marked this pull request as ready for review June 7, 2022 11:06
@laanwj laanwj added the Tests label Jun 7, 2022
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0)
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5.0)

self.generate(self.nodes[0], 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you duplicate this self.generate(self.nodes[0], 1), any reason? You moved it to here but you also added it in L684.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, generate mines a block so it has been duplicated to confirm the transactions preceding it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only a suggestion, but I think this way would fit better.

diff --git a/test/functional/rpc_fundrawtransaction.py b/test/functional/rpc_fundrawtransaction.py
index 338c31eea..71fda6362 100755
--- a/test/functional/rpc_fundrawtransaction.py
+++ b/test/functional/rpc_fundrawtransaction.py
@@ -103,13 +103,7 @@ class RawTransactionsTest(BitcoinTestFramework):
         self.generate(self.nodes[2], 1)
         self.generate(self.nodes[0], 121)
 
-        # coins for simple tests
-        self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.5)
-        self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0)
-        self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5.0)
-
-        self.generate(self.nodes[0], 1)
-
+        self.test_watchonly()
         self.test_change_position()
         self.test_simple()
         self.test_simple_two_outputs()
@@ -132,7 +126,6 @@ class RawTransactionsTest(BitcoinTestFramework):
         self.test_many_inputs_fee()
         self.test_many_inputs_send()
         self.test_op_return()
-        self.test_watchonly()
         self.test_all_watched_funds()
         self.test_option_feerate()
         self.test_address_reuse()
@@ -681,6 +674,11 @@ class RawTransactionsTest(BitcoinTestFramework):
         self.nodes[0].lockunspent(False, [{"txid": self.watchonly_txid, "vout": self.watchonly_vout}])
 
         self.nodes[0].sendtoaddress(self.nodes[3].get_wallet_rpc(self.default_wallet_name).getnewaddress(), self.watchonly_amount / 10)
+                # coins for simple tests
+        self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.5)
+        self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 1.0)
+        self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5.0)
+
         self.generate(self.nodes[0], 1)
 
         inputs = []

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 8, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@maflcko
Copy link
Member

maflcko commented Jun 15, 2022

Looks like the test fails:

https://cirrus-ci.com/task/5430192075177984?logs=ci#L3248

 node0 2022-06-07T11:27:41.734273Z [httpworker.2] [wallet/scriptpubkeyman.h:247] [WalletLogPrintf] [default wallet] keypool keep 36 
 node0 2022-06-07T11:27:41.734327Z [httpworker.2] [wallet/wallet.h:795] [WalletLogPrintf] [default wallet] Fee Calculation: Fee:166 Bytes:166 Tgt:0 (requested 0) Reason:"PayTxFee set" Decay 0.00000: Estimation: (-1 - -1) 0.00% 0.0/(0.0 0 mem 0.0 out) Fail: (-1 - -1) 0.00% 0.0/(0.0 0 mem 0.0 out) 
 node0 2022-06-07T11:27:41.734346Z [httpworker.2] [wallet/wallet.h:795] [WalletLogPrintf] [default wallet] Fee non-grouped = 166, grouped = 166, using grouped 
 node0 2022-06-07T11:27:41.734397Z [httpworker.2] [wallet/wallet.h:795] [WalletLogPrintf] [default wallet] CommitTransaction: 
                                   CTransaction(hash=11555aeee3, ver=2, vin.size=1, vout.size=2, nLockTime=42)
                                       CTxIn(COutPoint(fa7b6ef92c, 0), scriptSig=160014d09cac8bd4236f5e4c, nSequence=4294967294)
                                       CScriptWitness(30440220022222b2401a269c4bb9728d33970cc2be9c3732cc40631d998c4a2ac57b90050220672604ebc282e8eaa8f38ef1e757a71b41c6074e87df803d5fb16e36fbd1dd9601, 03ecf6e8a92e3458899e1d03654f038f3651eeb35918b62d8bfc5e164f0a82f729)
                                       CTxOut(nValue=46.79999472, scriptPubKey=a91439bf4a58a40a2c02337843a515)
                                       CTxOut(nValue=1.10000000, scriptPubKey=a914c071d03bf92e1ed60a7ed31728)
 node0 2022-06-07T11:27:41.734467Z [httpworker.2] [wallet/wallet.h:795] [WalletLogPrintf] [default wallet] AddToWallet 11555aeee336a68ae3b9e3e702bc1f1e1b0f8da7ea3afc88a0c28a426f1379f3  newupdate 
 node0 2022-06-07T11:27:41.739028Z [httpworker.2] [wallet/wallet.h:795] [WalletLogPrintf] [default wallet] Submitting wtx 11555aeee336a68ae3b9e3e702bc1f1e1b0f8da7ea3afc88a0c28a426f1379f3 to mempool for relay 
 node0 2022-06-07T11:27:41.739523Z [httpworker.2] [txmempool.cpp:721] [check] [mempool] Checking mempool with 3 transactions and 3 inputs 
 node0 2022-06-07T11:27:41.739663Z [httpworker.2] [validationinterface.cpp:211] [TransactionAddedToMempool] [validation] Enqueuing TransactionAddedToMempool: txid=11555aeee336a68ae3b9e3e702bc1f1e1b0f8da7ea3afc88a0c28a426f1379f3 wtxid=beeef7d25f5dff35f739857b7850302fe8cb82c986ed81b4009d4c49c903a983 
 node0 2022-06-07T11:27:41.739698Z [httpworker.2] [txmempool.cpp:721] [check] [mempool] Checking mempool with 4 transactions and 4 inputs 
 node0 2022-06-07T11:27:41.739768Z [scheduler] [validationinterface.cpp:211] [operator()] [validation] TransactionAddedToMempool: txid=11555aeee336a68ae3b9e3e702bc1f1e1b0f8da7ea3afc88a0c28a426f1379f3 wtxid=beeef7d25f5dff35f739857b7850302fe8cb82c986ed81b4009d4c49c903a983 
 node0 2022-06-07T11:27:41.740066Z [scheduler] [wallet/wallet.h:795] [WalletLogPrintf] [default wallet] AddToWallet 11555aeee336a68ae3b9e3e702bc1f1e1b0f8da7ea3afc88a0c28a426f1379f3 
 node0 2022-06-07T11:27:41.740600Z [http] [httpserver.cpp:241] [http_request_cb] [http] Received a POST request for / from 127.0.0.1:40714 
 node0 2022-06-07T11:27:41.740671Z [httpworker.3] [rpc/request.cpp:179] [parse] [rpc] ThreadRPCServer method=getmempoolentry user=__cookie__ 
 test  2022-06-07T11:27:41.741000Z TestFramework (ERROR): Assertion failed 
                                   Traceback (most recent call last):
                                     File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/test_framework/test_framework.py", line 133, in main
                                       self.run_test()
                                     File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/rpc_fundrawtransaction.py", line 129, in run_test
                                       self.test_fee_4of5()
                                     File "/tmp/cirrus-ci-build/ci/scratch/build/bitcoin-i686-pc-linux-gnu/test/functional/rpc_fundrawtransaction.py", line 495, in test_fee_4of5
                                       assert feeDelta >= 0 and feeDelta <= self.fee_tolerance
                                   AssertionError

@akankshakashyap
Copy link
Contributor Author

Looks like the test fails:

The failing test is testing wether fundrawtransaction selects enough fees to cover the transaction after signing. Changes made in this PR should at most change the available coins inside the wallet.

I can't think of any reason for this test failing, other than there being some edge case in the fundrawtransaction's fees mechanism that these changes have chanced upon.

The current test_simple_two_coins and test_simple are identical and
redundant. The test_simple_two_coins was changed in pr#6417 and asserts
ensuring the use of two input coins were removed.
The current method assumes that a coin with value > 2 BTC was used to
fund the transaction, and therefore change will be greater than 1 BTC.
This can fail.

changepos allows us to get the change output much more reliably and
cleanly.
@akankshakashyap akankshakashyap force-pushed the refactor-rpc_fundrawtransaction.py branch from 1bddea8 to 00af305 Compare June 18, 2022 20:48
@akankshakashyap
Copy link
Contributor Author

rebased.

@akankshakashyap akankshakashyap force-pushed the refactor-rpc_fundrawtransaction.py branch from 00af305 to 25b9f2e Compare June 18, 2022 20:57
@maflcko
Copy link
Member

maflcko commented Jun 20, 2022

I don't know either why it happens. Though, this can not be merged with a failing test.

@akankshakashyap akankshakashyap force-pushed the refactor-rpc_fundrawtransaction.py branch from 25b9f2e to 3e5bc2c Compare June 20, 2022 18:02
@akankshakashyap
Copy link
Contributor Author

The failing test passed after removing the 3rd commit.

@maflcko
Copy link
Member

maflcko commented Jun 21, 2022

You'll have to adjust the pull request description?

@achow101
Copy link
Member

Closing this as it has not had a lot of conceptual support. If you are interested in continuing work on this, please leave a comment so that it can be reopened.

@achow101 achow101 closed this Oct 12, 2022
@maflcko
Copy link
Member

maflcko commented Oct 13, 2022

The changes look correct to me

@bitcoin bitcoin locked and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants