2019-12-04 07:41:16 -08:00
|
|
|
#!/usr/bin/env python3
|
2019-07-24 14:37:33 -07:00
|
|
|
# Copyright (c) 2019 The Zcash developers
|
|
|
|
# Distributed under the MIT software license, see the accompanying
|
2019-08-05 18:05:11 -07:00
|
|
|
# file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
2019-07-24 14:37:33 -07:00
|
|
|
|
2019-08-02 15:01:20 -07:00
|
|
|
from decimal import Decimal
|
2019-07-24 14:37:33 -07:00
|
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
|
|
from test_framework.util import (
|
|
|
|
assert_equal,
|
2019-08-02 15:01:20 -07:00
|
|
|
get_coinbase_address,
|
2019-07-24 14:37:33 -07:00
|
|
|
start_nodes,
|
2019-08-02 15:01:20 -07:00
|
|
|
wait_and_assert_operationid_status,
|
2019-07-24 14:37:33 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ShorterBlockTimes(BitcoinTestFramework):
|
2016-05-14 04:01:31 -07:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.num_nodes = 4
|
|
|
|
self.setup_clean_chain = True
|
|
|
|
|
2019-07-24 14:37:33 -07:00
|
|
|
def setup_nodes(self):
|
2016-05-14 04:01:31 -07:00
|
|
|
return start_nodes(self.num_nodes, self.options.tmpdir, [[
|
2019-08-05 13:52:34 -07:00
|
|
|
'-nuparams=2bb40e60:106', # Blossom
|
2016-05-14 04:01:31 -07:00
|
|
|
]] * self.num_nodes)
|
2019-07-24 14:37:33 -07:00
|
|
|
|
|
|
|
def run_test(self):
|
2019-12-04 07:41:16 -08:00
|
|
|
print("Mining blocks...")
|
2019-08-02 15:01:20 -07:00
|
|
|
self.nodes[0].generate(101)
|
2019-07-24 14:37:33 -07:00
|
|
|
self.sync_all()
|
|
|
|
|
|
|
|
# Sanity-check the block height
|
2019-08-02 15:01:20 -07:00
|
|
|
assert_equal(self.nodes[0].getblockcount(), 101)
|
|
|
|
|
|
|
|
node0_taddr = get_coinbase_address(self.nodes[0])
|
|
|
|
node0_zaddr = self.nodes[0].z_getnewaddress('sapling')
|
2019-12-09 21:14:55 -08:00
|
|
|
recipients = [{'address': node0_zaddr, 'amount': Decimal('10.0')}]
|
2019-12-11 19:50:25 -08:00
|
|
|
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, 0)
|
2019-08-02 15:01:20 -07:00
|
|
|
txid = wait_and_assert_operationid_status(self.nodes[0], myopid)
|
2019-08-05 13:52:34 -07:00
|
|
|
assert_equal(105, self.nodes[0].getrawtransaction(txid, 1)['expiryheight']) # Blossom activation - 1
|
2019-08-02 15:01:20 -07:00
|
|
|
self.sync_all()
|
2019-08-05 13:52:34 -07:00
|
|
|
self.nodes[0].generate(1)
|
|
|
|
self.sync_all()
|
|
|
|
assert_equal(10, Decimal(self.nodes[0].z_gettotalbalance()['private']))
|
2019-07-24 14:37:33 -07:00
|
|
|
|
2019-08-05 13:52:34 -07:00
|
|
|
self.nodes[0].generate(2)
|
|
|
|
self.sync_all()
|
2019-12-04 07:41:16 -08:00
|
|
|
print("Mining last pre-Blossom blocks")
|
2019-07-24 14:37:33 -07:00
|
|
|
# Activate blossom
|
|
|
|
self.nodes[1].generate(1)
|
|
|
|
self.sync_all()
|
2019-08-02 15:01:20 -07:00
|
|
|
# Check that we received a pre-Blossom mining reward
|
|
|
|
assert_equal(10, Decimal(self.nodes[1].getwalletinfo()['immature_balance']))
|
2019-07-24 14:37:33 -07:00
|
|
|
|
|
|
|
# After blossom activation the block reward will be halved
|
2019-12-04 07:41:16 -08:00
|
|
|
print("Mining first Blossom block")
|
2019-07-24 14:37:33 -07:00
|
|
|
self.nodes[1].generate(1)
|
|
|
|
self.sync_all()
|
2019-08-02 15:01:20 -07:00
|
|
|
# Check that we received an additional Blossom mining reward
|
2019-07-24 14:37:33 -07:00
|
|
|
assert_equal(15, self.nodes[1].getwalletinfo()['immature_balance'])
|
|
|
|
|
2019-08-02 15:01:20 -07:00
|
|
|
# Send and mine a transaction after activation
|
2019-12-11 19:50:25 -08:00
|
|
|
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, 0)
|
2019-08-02 15:01:20 -07:00
|
|
|
txid = wait_and_assert_operationid_status(self.nodes[0], myopid)
|
2019-08-05 13:52:34 -07:00
|
|
|
assert_equal(147, self.nodes[0].getrawtransaction(txid, 1)['expiryheight']) # height + 1 + 40
|
2021-08-05 12:54:47 -07:00
|
|
|
self.sync_all() # Ensure the transaction has propagated to node 1
|
2019-08-02 15:01:20 -07:00
|
|
|
self.nodes[1].generate(1)
|
|
|
|
self.sync_all()
|
|
|
|
assert_equal(20, Decimal(self.nodes[0].z_gettotalbalance()['private']))
|
|
|
|
|
2019-07-24 14:37:33 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
ShorterBlockTimes().main()
|