8000 test: Run feature_bip68_sequence.py with MiniWallet by miles170 · Pull Request #26657 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

test: Run feature_bip68_sequence.py with MiniWallet #26657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

miles170
Copy link
Contributor
@miles170 miles170 commented Dec 8, 2022

This PR enables one more of the non-wallet functional tests (feature_bip68_sequence.py) to be run even when no wallet is compiled in by using the MiniWallet instead, as proposed in #20078.

@miles170 miles170 marked this pull request as draft December 8, 2022 07:31
@miles170 miles170 force-pushed the test-feature_bip68_sequence-mini-wallet branch from df1c56d to 1852787 Compare December 8, 2022 07:35
@DrahtBot
Copy link
Contributor
DrahtBot commented Dec 8, 2022

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

Reviews

See the guideline for information on the revie 8000 w process.

Type Reviewers
ACK achow101, MarcoFalke

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26886 (test: add rescan utxos inside MiniWallet's initialization by kouloumos)
  • #26857 (OP_VAULT draft by jamesob)
  • #26625 (test: Run mempool_packages.py with MiniWallet by MarcoFalke)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@miles170 miles170 marked this pull request as ready for review December 8, 2022 07:36
@miles170 miles170 force-pushed the test-feature_bip68_sequence-mini-wallet branch from 1852787 to 192a00c Compare December 8, 2022 07:40
@DrahtBot DrahtBot added the Tests label Dec 8, 2022
@miles170 miles170 force-pushed the test-feature_bip68_sequence-mini-wallet branch from 192a00c to 9129265 Compare December 8, 2022 15:44
@miles170
Copy link
Contributor Author
miles170 commented Dec 8, 2022
8000

Force-pushed with taking suggestion #26657 (comment) and remove formatting fixes.

@miles170 miles170 marked this pull request as draft December 9, 2022 06:24
@miles170
Copy link
Contributor Author
miles170 commented Dec 9, 2022

interface_usdt_utxocache.py is failing due to test: Ignore spent utxos in MiniWallet rescan_utxos, I'm working on it.

It seems gettxout in MiniWallet.rescan_utxos calls GetCoin, which adds the UTXO to the temporary cache.
Do we have an alternative way to ignore spent utxos in MiniWallet rescan_utxos?

Or, to ensure that the mempool is cleared, could I replace self.wallet.rescan_utxos() with self.generate(self.wallet, 1)?

diff --git a/test/functional/feature_bip68_sequence.py b/test/functional/feature_bip68_sequence.py
index 379d04a1f..6030e7138 100755
--- a/test/functional/feature_bip68_sequence.py
+++ b/test/functional/feature_bip68_sequence.py
@@ -212,7 +212,7 @@ class BIP68Test(BitcoinTestFramework):
             else:
                 # This raw transaction should be accepted
                 self.wallet.sendrawtransaction(from_node=self.nodes[0], tx_hex=rawtx)
-                self.wallet.rescan_utxos()
+                self.generate(self.wallet, 1)
                 utxos = self.wallet.get_utxos(include_immature_coinbase=False)

     # Test that sequence locks on unconfirmed inputs must have nSequence

self.nodes[0].sendrawtransaction(rawtx)
utxos = self.nodes[0].listunspent()
self.wallet.sendrawtransaction(from_node=self.nodes[0], tx_hex=rawtx)
self.wallet.rescan_utxos()
Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed? wallet.sendrawtransaction should already account and scan the tx

Copy link
Contributor Author
@miles170 miles170 Dec 10, 2022

Choose a reason for hiding this comment

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

utxos = self.wallet.get_utxos() implies mark_as_spent=True, which means self._utxos is cleared.
wallet.sendrawtransaction only appends the tx to self._utxos, so we need self.wallet.rescan_utxos() to rescan unspent utxos.

If I remove utxos = self.wallet.get_utxos(), the test throw error.

2022-12-11T05:34:00.235000Z TestFramework (ERROR): Unexpected exception caught during testing
Traceback (most recent call last):
  File "/bitcoin/test/functional/test_framework/test_framework.py", line 134, in main
    self.run_test()
  File "/bitcoin/./test/functional/feature_bip68_sequence.py", line 73, in run_test
    self.test_sequence_lock_confirmed_inputs()
  File "/bitcoin/./test/functional/feature_bip68_sequence.py", line 202, in test_sequence_lock_confirmed_inputs
    tx.vin.append(CTxIn(COutPoint(int(utxos[j]["txid"], 16), utxos[j]["vout"]), nSequence=sequence_value))
IndexError: list index out of range

Copy link
Member

Choose a reason for hiding this comment

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

Ah, ok. So alternatively the wallet.sendrawtransaction could be dropped/reverted to just sendrawtransaction, because it is not needed to scan the tx.

@miles170 miles170 force-pushed the test-feature_bip68_sequence-mini-wallet branch from 9129265 to 8d2a0f5 Compare December 10, 2022 07:20
@miles170
Copy link
Contributor Author
miles170 commented Dec 10, 2022

Force-pushed with squash commits and replace test: Ignore spent utxos in MiniWallet rescan_utxos with test: Add "include mempool" flag to MiniWallet rescan_utxos

diff --git a/test/functional/test_framework/wallet.py b/test/functional/test_framework/wallet.py                                                                            
index 46b628ee3..52bfb0a2e 100644                                                     
--- a/test/functional/test_framework/wallet.py                                  
+++ b/test/functional/test_framework/wallet.py                                                                                                                                                 
@@ -118,14 +119,13 @@ class MiniWallet:                                               
     def get_balance(self):                                                           
         return sum(u['value'] for u in self._utxos)                                  
                                          
-    def rescan_utxos(self):                                                                                                                                                
+    def rescan_utxos(self, *, include_mempool=True):                                 
         """Drop all utxos and rescan the utxo set"""                                 
         self._utxos = []                                                             
         res = self._test_node.scantxoutset(action="start", scanobjects=[self.get_descriptor()])                                                                            
         assert_equal(True, res['success'])                                           
         for utxo in res['unspents']:                                                 
-            # Ignore utxo inside mempool                                             
-            if not self._test_node.gettxout(txid=utxo["txid"], n=utxo["vout"]):      
+            if not include_mempool and not self._test_node.gettxout(txid=utxo["txid"], n=utxo["vout"]):                                                                    
                 continue                                                                                                                                                   
             self._utxos.append(                                                                                                                                            
                 self._create_utxo(txid=utxo["txid"],                          

@miles170 miles170 marked this pull request as ready for review December 10, 2022 07:20
@miles170 miles170 force-pushed the test-feature_bip68_sequence-mini-wallet branch from 8d2a0f5 to 69f0f6b Compare December 12, 2022 12:44
@miles170
Copy link
Contributor Author
miles170 commented Dec 12, 2022

Force-pushed with taking suggestion #26657 (comment)

@miles170 miles170 force-pushed the test-feature_bip68_sequence-mini-wallet branch from 69f0f6b to cdda956 Compare December 14, 2022 01:20
@miles170
Copy link
Contributor Author

Force-pushed with taking suggestions #26657 (comment) and #26657 (comment)

@miles170 miles170 force-pushed the test-feature_bip68_sequence-mini-wallet branch from cdda956 to 572a445 Compare December 14, 2022 14:52
@miles170
Copy link
Contributor Author

Force-pushed with taking suggestions #26657 (comment) and #26657 (comment)

@miles170 miles170 force-pushed the test-feature_bip68_sequence-mini-wallet branch from 572a445 to 2512e1a Compare December 15, 2022 14:54
@miles170
Copy link
Contributor Author

Force-pushed with taking suggestions #26657 (comment) and #26657 (comment) and #26657 (comment)

@miles170
Copy link
Contributor Author
miles170 commented Jan 6, 2023

Force-pushed with taking suggestion discussion_r1062820833

@miles170 miles170 force-pushed the test-feature_bip68_sequence-mini-wallet branch from 2512e1a to 4159ccd Compare January 6, 2023 01:53
@DrahtBot DrahtBot mentioned this pull request Jan 9, 2023
@achow101
Copy link
Member

ACK 4159ccd

Copy link
Member
@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

Very nice. Thanks!

review ACK 4159ccd 🤸

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK 4159ccd03142899028019a7cb44ee4120e68505a 🤸
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUisvgv/YsGnHt+lU5rGQdwFN6eIUrKwK/0pjUAIaDIeOp/61fuwDrJc3MhNE+/j
3cAiUyvHTtwo3eWkvV9FdQ9V+gVNOoiBWG1yEJtZNoM/syt5uaMi4zUvs2CisODn
tlr0jDcMSBw0E0Dc/YEKkwWytysPER5kPQiCleuzUbWqYD/QVX3xUOXGf+a0rttX
DpuzTcUu5ojaZh4YMEBkgprStIADIdxE2WPb/0eXd1pmwD+TpvnjVA/uRICQAft5
pBcePzrFLuGqJCOdsg5Fw72JmXJh1RjuBnCiOGiFL/xN02QH4R5MY401RNaXZtYO
B8USAMS8mO8lJB45t7njTpp1KSgrOJN0RJyEbja6BTROzyi6JttFJVRx4vie2hea
jICFDu8hNAWrkvXDQXWf/KaUSLOaWITDtYLRdK4bfirNy1PxiFsUjBPkrn0KJgaG
xI2AaYpNQqV7Krprdm9sEJpO8lev89aL+TEwZv7i2DjZONJArSOEE/Rtmm0nbQEI
2t90dylY
=isq1
-----END PGP SIGNATURE-----

self.nodes[0].sendrawtransaction(rawtx)
utxos = self.nodes[0].listunspent()
self.wallet.sendrawtransaction(from_node=self.nodes[0], tx_hex=rawtx)
self.wallet.rescan_utxos()
Copy link
Member

Choose a reason for hiding this comment

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

Ah, ok. So alternatively the wallet.sendrawtransaction could be dropped/reverted to just sendrawtransaction, because it is not needed to scan the tx.

tx = tx_from_hex(rawtxfund)
mini_wallet = MiniWallet(self.nodes[1])
mini_wallet.rescan_utxos()
tx = mini_wallet.create_self_transfer()["tx"]
Copy link
Member

Choose a reason for hiding this comment

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

nit in the last commit (can be fixed in a follow-up):

  • MiniWallet shouldn't care about the node, so a single instance should suffice per test.
  • Maybe the send_self_transfer function can accept a version option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

May I create another PR to refactor those nits?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, if you agree with them and if the changes are possible (haven't checked myself)

@maflcko maflcko merged commit 599e941 into bitcoin:master Jan 16, 2023
@miles170 miles170 deleted the test-feature_bip68_sequence-mini-wallet branch January 16, 2023 15:35
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 16, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Apr 4, 2024
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.

4 participants
0