Changeset View
Changeset View
Standalone View
Standalone View
contrib/devtools/chainparams/test_make_chainparams.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2019 The Bitcoin developers | # Copyright (c) 2019 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
import unittest | import unittest | ||||
from make_chainparams import main as GenerateChainParams | from make_chainparams import main as GenerateChainParams | ||||
class MockRPC: | class MockRPC: | ||||
def __init__(self, test, chain, numBlocks, expectedBlock, blockHash, chainWork): | def __init__(self, test, chain, numBlocks, | ||||
expectedBlock, blockHash, chainWork): | |||||
self.test = test | self.test = test | ||||
self.chain = chain | self.chain = chain | ||||
self.numBlocks = numBlocks | self.numBlocks = numBlocks | ||||
self.expectedBlock = expectedBlock | self.expectedBlock = expectedBlock | ||||
self.blockHash = blockHash | self.blockHash = blockHash | ||||
self.chainWork = chainWork | self.chainWork = chainWork | ||||
def getblockchaininfo(self): | def getblockchaininfo(self): | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | def getblockheader(self, blockHash): | ||||
"chainwork": "000000000000000000000000000000000000000000f4c5e639fa012518a48a57", | "chainwork": "000000000000000000000000000000000000000000f4c5e639fa012518a48a57", | ||||
"previousblockhash": "00000000000000000307b45e4a6cf8d49e70b9012ea1d72a5ce334a4213f66bd", | "previousblockhash": "00000000000000000307b45e4a6cf8d49e70b9012ea1d72a5ce334a4213f66bd", | ||||
} | } | ||||
class MockFailRPC(MockRPC): | class MockFailRPC(MockRPC): | ||||
# Provides a fail counter to fail after the Nth RPC command | # Provides a fail counter to fail after the Nth RPC command | ||||
def __init__(self, test, chain, numBlocks, expectedBlock, blockHash, chainWork, failCounter): | def __init__(self, test, chain, numBlocks, expectedBlock, | ||||
blockHash, chainWork, failCounter): | |||||
super().__init__(test, chain, numBlocks, expectedBlock, blockHash, chainWork) | super().__init__(test, chain, numBlocks, expectedBlock, blockHash, chainWork) | ||||
self.failCounter = failCounter | self.failCounter = failCounter | ||||
def checkFailCounter(self): | def checkFailCounter(self): | ||||
self.failCounter -= 1 | self.failCounter -= 1 | ||||
if self.failCounter < 0: | if self.failCounter < 0: | ||||
raise Exception("""error code: -99 | raise Exception("""error code: -99 | ||||
error message: | error message: | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |