Skip to content

Commit 0a931a9

Browse files
committed
Merge bitcoin/bitcoin#31599: qa: Improve framework.generate* enforcement (#31403 follow-up)
1b51616 test: improve rogue calls in mining functions (i-am-yuvi) Pull request description: #31403 follow-up, see [comment](bitcoin/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/bitcoin@1b51616) Tree-SHA512: 56832626fe54dcaa07dacb4f9c960c0a83fad3fb12272155114ac697856c59b7f44805e1152eddeec7a5e8f7daf487382dc01b5b9ae2e74b62b2df6bd1f81f77
2 parents 4ac1efb + 1b51616 commit 0a931a9

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

test/functional/test_framework/test_framework.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -725,22 +725,22 @@ def no_op(self):
725725
pass
726726

727727
def generate(self, generator, *args, sync_fun=None, **kwargs):
728-
blocks = generator.generate(*args, invalid_call=False, **kwargs)
728+
blocks = generator.generate(*args, called_by_framework=True, **kwargs)
729729
sync_fun() if sync_fun else self.sync_all()
730730
return blocks
731731

732732
def generateblock(self, generator, *args, sync_fun=None, **kwargs):
733-
blocks = generator.generateblock(*args, invalid_call=False, **kwargs)
733+
blocks = generator.generateblock(*args, called_by_framework=True, **kwargs)
734734
sync_fun() if sync_fun else self.sync_all()
735735
return blocks
736736

737737
def generatetoaddress(self, generator, *args, sync_fun=None, **kwargs):
738-
blocks = generator.generatetoaddress(*args, invalid_call=False, **kwargs)
738+
blocks = generator.generatetoaddress(*args, called_by_framework=True, **kwargs)
739739
sync_fun() if sync_fun else self.sync_all()
740740
return blocks
741741

742742
def generatetodescriptor(self, generator, *args, sync_fun=None, **kwargs):
743-
blocks = generator.generatetodescriptor(*args, invalid_call=False, **kwargs)
743+
blocks = generator.generatetodescriptor(*args, called_by_framework=True, **kwargs)
744744
sync_fun() if sync_fun else self.sync_all()
745745
return blocks
746746

test/functional/test_framework/test_node.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,16 @@ def generate(self, nblocks, maxtries=1000000, **kwargs):
352352
self.log.debug("TestNode.generate() dispatches `generate` call to `generatetoaddress`")
353353
return self.generatetoaddress(nblocks=nblocks, address=self.get_deterministic_priv_key().address, maxtries=maxtries, **kwargs)
354354

355-
def generateblock(self, *args, invalid_call, **kwargs):
356-
assert not invalid_call
355+
def generateblock(self, *args, called_by_framework, **kwargs):
356+
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."
357357
return self.__getattr__('generateblock')(*args, **kwargs)
358358

359-
def generatetoaddress(self, *args, invalid_call, **kwargs):
360-
assert not invalid_call
359+
def generatetoaddress(self, *args, called_by_framework, **kwargs):
360+
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."
361361
return self.__getattr__('generatetoaddress')(*args, **kwargs)
362362

363-
def generatetodescriptor(self, *args, invalid_call, **kwargs):
364-
assert not invalid_call
363+
def generatetodescriptor(self, *args, called_by_framework, **kwargs):
364+
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."
365365
return self.__getattr__('generatetodescriptor')(*args, **kwargs)
366366

367367
def setmocktime(self, timestamp):

0 commit comments

Comments
 (0)