Skip to content

Commit

Permalink
Merge bitcoin#31599: qa: Improve framework.generate* enforcement (bit…
Browse files Browse the repository at this point in the history
…coin#31403 follow-up)

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

Pull request description:

  bitcoin#31403 follow-up, see [comment](bitcoin#31403 (review))

  - 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 1b51616
  achow101:
    ACK 1b51616
  hodlinator:
    re-ACK 1b51616
  Prabhat1308:
    ACK [1b51616](bitcoin@1b51616)

Tree-SHA512: 56832626fe54dcaa07dacb4f9c960c0a83fad3fb12272155114ac697856c59b7f44805e1152eddeec7a5e8f7daf487382dc01b5b9ae2e74b62b2df6bd1f81f77
  • Loading branch information
achow101 committed Jan 24, 2025
2 parents 4ac1efb + 1b51616 commit 0a931a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,22 +725,22 @@ def no_op(self):
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

Expand Down
12 changes: 6 additions & 6 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,16 @@ def generate(self, nblocks, maxtries=1000000, **kwargs):
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):
Expand Down

0 comments on commit 0a931a9

Please sign in to comment.