test: improve rogue calls in mining functions

This commit is contained in:
i-am-yuvi 2025-01-03 19:09:03 +05:30
parent 41a2ce9b7d
commit 1b51616f2e
2 changed files with 10 additions and 10 deletions

View file

@ -716,22 +716,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):