Merge #16329: test: Add tests for getblockchaininfo.softforks

faf6caf4da test: Add tests for getblockchaininfo.softforks (MarcoFalke)

Pull request description:

ACKs for top commit:
  laanwj:
    Code review ACK faf6caf4da

Tree-SHA512: 8a0bb3b648f18fdba7a36a960d70c6217fd7312cf2ef52b3b911be0d7f1d27c5c50856946d7e6cb81d96c081913b7308cc5f9d89af34518439ff4ada024441da
This commit is contained in:
MarcoFalke 2019-07-03 12:11:39 -04:00
commit 1381ddbcfc
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25
2 changed files with 37 additions and 0 deletions

View file

@ -64,9 +64,23 @@ class BIP65Test(BitcoinTestFramework):
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def test_cltv_info(self, *, is_active):
assert_equal(
next(s for s in self.nodes[0].getblockchaininfo()['softforks'] if s['id'] == 'bip65'),
{
"id": "bip65",
"version": 4,
"reject": {
"status": is_active
}
},
)
def run_test(self):
self.nodes[0].add_p2p_connection(P2PInterface())
self.test_cltv_info(is_active=False)
self.log.info("Mining %d blocks", CLTV_HEIGHT - 2)
self.coinbase_txids = [self.nodes[0].getblock(b)['tx'][0] for b in self.nodes[0].generate(CLTV_HEIGHT - 2)]
self.nodeaddress = self.nodes[0].getnewaddress()
@ -86,7 +100,9 @@ class BIP65Test(BitcoinTestFramework):
block.hashMerkleRoot = block.calc_merkle_root()
block.solve()
self.test_cltv_info(is_active=False)
self.nodes[0].p2p.send_and_ping(msg_block(block))
self.test_cltv_info(is_active=False) # Not active as of current tip, but next block must obey rules
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
self.log.info("Test that blocks must now be at least version 4")
@ -135,7 +151,9 @@ class BIP65Test(BitcoinTestFramework):
block.hashMerkleRoot = block.calc_merkle_root()
block.solve()
self.test_cltv_info(is_active=False) # Not active as of current tip, but next block must obey rules
self.nodes[0].p2p.send_and_ping(msg_block(block))
self.test_cltv_info(is_active=True) # Active as of current tip
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256)

View file

@ -51,9 +51,23 @@ class BIP66Test(BitcoinTestFramework):
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def test_dersig_info(self, *, is_active):
assert_equal(
next(s for s in self.nodes[0].getblockchaininfo()['softforks'] if s['id'] == 'bip66'),
{
"id": "bip66",
"version": 3,
"reject": {
"status": is_active
}
},
)
def run_test(self):
self.nodes[0].add_p2p_connection(P2PInterface())
self.test_dersig_info(is_active=False)
self.log.info("Mining %d blocks", DERSIG_HEIGHT - 2)
self.coinbase_txids = [self.nodes[0].getblock(b)['tx'][0] for b in self.nodes[0].generate(DERSIG_HEIGHT - 2)]
self.nodeaddress = self.nodes[0].getnewaddress()
@ -74,7 +88,9 @@ class BIP66Test(BitcoinTestFramework):
block.rehash()
block.solve()
self.test_dersig_info(is_active=False)
self.nodes[0].p2p.send_and_ping(msg_block(block))
self.test_dersig_info(is_active=False) # Not active as of current tip, but next block must obey rules
assert_equal(self.nodes[0].getbestblockhash(), block.hash)
self.log.info("Test that blocks must now be at least version 3")
@ -128,8 +144,11 @@ class BIP66Test(BitcoinTestFramework):
block.rehash()
block.solve()
self.test_dersig_info(is_active=False) # Not active as of current tip, but next block must obey rules
self.nodes[0].p2p.send_and_ping(msg_block(block))
self.test_dersig_info(is_active=True) # Active as of current tip
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256)
if __name__ == '__main__':
BIP66Test().main()