Merge bitcoin/bitcoin#31599: qa: Improve framework.generate* enforcement (#31403 follow-up)
Some checks failed
CI / test each commit (push) Has been cancelled
CI / macOS 14 native, arm64, no depends, sqlite only, gui (push) Has been cancelled
CI / macOS 14 native, arm64, fuzz (push) Has been cancelled
CI / Win64 native, VS 2022 (push) Has been cancelled
CI / Win64 native fuzz, VS 2022 (push) Has been cancelled
CI / ASan + LSan + UBSan + integer, no depends, USDT (push) Has been cancelled

1b51616f2e test: improve rogue calls in mining functions (i-am-yuvi)

Pull request description:

  #31403 follow-up, see [comment](https://github.com/bitcoin/bitcoin/pull/31403#pullrequestreview-2498806354)

  - Rename `invalid_call` parameter to `called_by_framework` in `generateblock`, `generatetoaddress` and `generatetodescriptor` mining methods to better express its intended usage.
  - Add explicit assertion message clarifying that these functions should only be called by TestFramework itself to maintain proper node synchronization.

ACKs for top commit:
  maflcko:
    lgtm ACK 1b51616f2e
  achow101:
    ACK 1b51616f2e
  hodlinator:
    re-ACK 1b51616f2e
  Prabhat1308:
    ACK [1b51616](1b51616f2e)

Tree-SHA512: 56832626fe54dcaa07dacb4f9c960c0a83fad3fb12272155114ac697856c59b7f44805e1152eddeec7a5e8f7daf487382dc01b5b9ae2e74b62b2df6bd1f81f77
This commit is contained in:
Ava Chow 2025-01-24 18:33:14 -05:00
commit 0a931a9787
No known key found for this signature in database
GPG key ID: 17565732E08E5E41
2 changed files with 10 additions and 10 deletions

View file

@ -725,22 +725,22 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
pass
def generate(self, generator, *args, sync_fun=None, **kwargs):
blocks = generator.generate(*args, invalid_call=False, **kwargs)
blocks = generator.generate(*args, called_by_framework=True, **kwargs)
sync_fun() if sync_fun else self.sync_all()
return blocks
def generateblock(self, generator, *args, sync_fun=None, **kwargs):
blocks = generator.generateblock(*args, invalid_call=False, **kwargs)
blocks = generator.generateblock(*args, called_by_framework=True, **kwargs)
sync_fun() if sync_fun else self.sync_all()
return blocks
def generatetoaddress(self, generator, *args, sync_fun=None, **kwargs):
blocks = generator.generatetoaddress(*args, invalid_call=False, **kwargs)
blocks = generator.generatetoaddress(*args, called_by_framework=True, **kwargs)
sync_fun() if sync_fun else self.sync_all()
return blocks
def generatetodescriptor(self, generator, *args, sync_fun=None, **kwargs):
blocks = generator.generatetodescriptor(*args, invalid_call=False, **kwargs)
blocks = generator.generatetodescriptor(*args, called_by_framework=True, **kwargs)
sync_fun() if sync_fun else self.sync_all()
return blocks

View file

@ -352,16 +352,16 @@ class TestNode():
self.log.debug("TestNode.generate() dispatches `generate` call to `generatetoaddress`")
return self.generatetoaddress(nblocks=nblocks, address=self.get_deterministic_priv_key().address, maxtries=maxtries, **kwargs)
def generateblock(self, *args, invalid_call, **kwargs):
assert not invalid_call
def generateblock(self, *args, called_by_framework, **kwargs):
assert called_by_framework, "Direct call of this mining RPC is discouraged. Please use one of the self.generate* methods on the test framework, which sync the nodes to avoid intermittent test issues. You may use sync_fun=self.no_op to disable the sync explicitly."
return self.__getattr__('generateblock')(*args, **kwargs)
def generatetoaddress(self, *args, invalid_call, **kwargs):
assert not invalid_call
def generatetoaddress(self, *args, called_by_framework, **kwargs):
assert called_by_framework, "Direct call of this mining RPC is discouraged. Please use one of the self.generate* methods on the test framework, which sync the nodes to avoid intermittent test issues. You may use sync_fun=self.no_op to disable the sync explicitly."
return self.__getattr__('generatetoaddress')(*args, **kwargs)
def generatetodescriptor(self, *args, invalid_call, **kwargs):
assert not invalid_call
def generatetodescriptor(self, *args, called_by_framework, **kwargs):
assert called_by_framework, "Direct call of this mining RPC is discouraged. Please use one of the self.generate* methods on the test framework, which sync the nodes to avoid intermittent test issues. You may use sync_fun=self.no_op to disable the sync explicitly."
return self.__getattr__('generatetodescriptor')(*args, **kwargs)
def setmocktime(self, timestamp):