Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_feature_minerfund.py
Show All 15 Lines | |||||
from decimal import Decimal | from decimal import Decimal | ||||
AXION_ACTIVATION_TIME = 2000000600 | AXION_ACTIVATION_TIME = 2000000600 | ||||
MINER_FUND_RATIO = 8 | MINER_FUND_RATIO = 8 | ||||
MINER_FUND_ADDR = 'bchreg:pqnqv9lt7e5vjyp0w88zf2af0l92l8rxdgd35g0pkl' | MINER_FUND_ADDR = 'bchreg:pqnqv9lt7e5vjyp0w88zf2af0l92l8rxdgd35g0pkl' | ||||
MINER_FUND_ADDR_NEWPREFIX = 'abcreg:pqnqv9lt7e5vjyp0w88zf2af0l92l8rxdgyrm5ege8' | |||||
jasonbcox: Nit: Call the old one "legacy" and remove "new" from the current one. This is because we should… | |||||
class MinerFundTest(BitcoinTestFramework): | class MinerFundTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.extra_args = [[ | self.extra_args = [[ | ||||
'-enableminerfund', | '-enableminerfund', | ||||
'-axionactivationtime={}'.format(AXION_ACTIVATION_TIME), | '-axionactivationtime={}'.format(AXION_ACTIVATION_TIME), | ||||
]] | ]] | ||||
def test_validate_address_backwards_compatibility(self): | |||||
self.log.info( | |||||
"Testing CashAddr old prefix backward compatibility using the miner fund destination") | |||||
abcPrefixedAddress = MINER_FUND_ADDR_NEWPREFIX | |||||
backwardCompatiblePrefixAddress = MINER_FUND_ADDR | |||||
jasonbcoxUnsubmitted Not Done Inline Actionswhy create new variables here? jasonbcox: why create new variables here? | |||||
assert(self.nodes[0].validateaddress(abcPrefixedAddress)['isvalid']) | |||||
self.log.info("Address {} is valid".format(abcPrefixedAddress)) | |||||
assert(self.nodes[0].validateaddress( | |||||
backwardCompatiblePrefixAddress)['isvalid']) | |||||
self.log.info("Address {} is valid".format( | |||||
backwardCompatiblePrefixAddress)) | |||||
abcPrefixedAddressScriptPubKey = self.nodes[0].validateaddress(abcPrefixedAddress)[ | |||||
'scriptPubKey'] | |||||
assert_equal(abcPrefixedAddressScriptPubKey, self.nodes[0].validateaddress( | |||||
backwardCompatiblePrefixAddress)['scriptPubKey']) | |||||
self.log.info( | |||||
"Both addresses {} and {} share the {} scriptPubKey".format( | |||||
abcPrefixedAddress, | |||||
backwardCompatiblePrefixAddress, | |||||
abcPrefixedAddressScriptPubKey)) | |||||
def run_test(self): | def run_test(self): | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
address = node.get_deterministic_priv_key().address | address = node.get_deterministic_priv_key().address | ||||
self.log.info('Create some history') | self.log.info('Create some history') | ||||
for _ in range(0, 50): | for _ in range(0, 50): | ||||
node.generatetoaddress(1, address) | node.generatetoaddress(1, address) | ||||
Show All 21 Lines | def run_test(self): | ||||
# First block with the new rules. | # First block with the new rules. | ||||
node.generatetoaddress(1, address) | node.generatetoaddress(1, address) | ||||
# Now we send part of the coinbase to the fund. | # Now we send part of the coinbase to the fund. | ||||
coinbase = get_best_coinbase() | coinbase = get_best_coinbase() | ||||
assert_equal(len(coinbase['vout']), 2) | assert_equal(len(coinbase['vout']), 2) | ||||
assert_equal( | assert_equal( | ||||
coinbase['vout'][1]['scriptPubKey']['addresses'][0], | coinbase['vout'][1]['scriptPubKey']['addresses'][0], | ||||
MINER_FUND_ADDR) | MINER_FUND_ADDR_NEWPREFIX) | ||||
total = Decimal() | total = Decimal() | ||||
for o in coinbase['vout']: | for o in coinbase['vout']: | ||||
total += o['value'] | total += o['value'] | ||||
assert_equal(total, block_reward) | assert_equal(total, block_reward) | ||||
assert_greater_than_or_equal( | assert_greater_than_or_equal( | ||||
coinbase['vout'][1]['value'], | coinbase['vout'][1]['value'], | ||||
(MINER_FUND_RATIO * total) / 100) | (MINER_FUND_RATIO * total) / 100) | ||||
# Invalidate top block, submit a custom block that do not send anything | # Invalidate top block, submit a custom block that do not send anything | ||||
# to the fund and check it is rejected. | # to the fund and check it is rejected. | ||||
node.invalidateblock(node.getbestblockhash()) | node.invalidateblock(node.getbestblockhash()) | ||||
block_height = node.getblockcount() + 1 | block_height = node.getblockcount() + 1 | ||||
block = create_block( | block = create_block( | ||||
fork_block_hash, create_coinbase(block_height), AXION_ACTIVATION_TIME + 1, version=4) | fork_block_hash, create_coinbase(block_height), AXION_ACTIVATION_TIME + 1, version=4) | ||||
block.solve() | block.solve() | ||||
assert_equal(node.submitblock(ToHex(block)), 'bad-cb-minerfund') | assert_equal(node.submitblock(ToHex(block)), 'bad-cb-minerfund') | ||||
self.test_validate_address_backwards_compatibility() | |||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
MinerFundTest().main() | MinerFundTest().main() |
Nit: Call the old one "legacy" and remove "new" from the current one. This is because we should expect to remove the legacy option at some point, but we don't want to call ABC new going forward. This way you don't put off another refactor.