def run_test(self): print "Mining blocks..." self.nodes[0].generate(1) do_not_shield_taddr = self.nodes[0].getnewaddress() self.nodes[0].generate(4) walletinfo = self.nodes[0].getwalletinfo() assert_equal(walletinfo['immature_balance'], summSubsidy_premine(5)) assert_equal(walletinfo['balance'], 0) self.sync_all() self.nodes[2].generate(1) self.nodes[2].getnewaddress() self.nodes[2].generate(1) self.nodes[2].getnewaddress() self.nodes[2].generate(1) self.sync_all() self.nodes[1].generate(101) self.sync_all() assert_equal(self.nodes[0].getbalance(), summSubsidy_premine(5)) assert_equal(self.nodes[1].getbalance(), summSubsidy_noPremine(1)) assert_equal(self.nodes[2].getbalance(), summSubsidy_noPremine(3)) # Prepare to send taddr->zaddr mytaddr = self.nodes[0].getnewaddress() myzaddr = self.nodes[0].z_getnewaddress() # Shielding will fail when trying to spend from watch-only address self.nodes[2].importaddress(mytaddr) try: self.nodes[2].z_shieldcoinbase(mytaddr, myzaddr) except JSONRPCException, e: errorString = e.error['message']
def run_test (self): print "Mining blocks..." self.nodes[0].generate(4) self.sync_all() self.nodes[1].generate(101) self.sync_all() assert_equal(self.nodes[0].getbalance(), summSubsidy_premine(4)) txid0 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11) txid1 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 10) self.sync_all() self.nodes[0].generate(1) self.sync_all() txid2 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 11) txid3 = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 5) tx0 = self.nodes[0].gettransaction(txid0) assert_equal(tx0['txid'], txid0) # tx0 must be available (confirmed) tx1 = self.nodes[0].gettransaction(txid1) assert_equal(tx1['txid'], txid1) # tx1 must be available (confirmed) tx2 = self.nodes[0].gettransaction(txid2) assert_equal(tx2['txid'], txid2) # tx2 must be available (unconfirmed) tx3 = self.nodes[0].gettransaction(txid3) assert_equal(tx3['txid'], txid3) # tx3 must be available (unconfirmed) # restart crypticcoind self.nodes[0].stop() bitcoind_processes[0].wait() self.nodes[0] = start_node(0,self.options.tmpdir) tx3 = self.nodes[0].gettransaction(txid3) assert_equal(tx3['txid'], txid3) # tx must be available (unconfirmed) self.nodes[0].stop() bitcoind_processes[0].wait() # restart crypticcoind with zapwallettxes self.nodes[0] = start_node(0,self.options.tmpdir, ["-zapwallettxes=1"]) aException = False try: tx3 = self.nodes[0].gettransaction(txid3) except JSONRPCException,e: print e aException = True
def run_test(self): print "Mining blocks..." self.nodes[0].generate(4) walletinfo = self.nodes[0].getwalletinfo() assert_equal(walletinfo['immature_balance'], summSubsidy_premine(4)) assert_equal(walletinfo['balance'], 0) self.sync_all() self.nodes[2].generate(3) self.sync_all() self.nodes[1].generate(101) self.sync_all() assert_equal(self.nodes[0].getbalance(), summSubsidy_premine(4)) assert_equal(self.nodes[1].getbalance(), summSubsidy_noPremine(1)) assert_equal(self.nodes[2].getbalance(), summSubsidy_noPremine(3)) mytaddr = self.nodes[0].getnewaddress() myzaddr = self.nodes[0].z_getnewaddress() # Check that Node 2 has payment disclosure disabled. try: self.nodes[2].z_getpaymentdisclosure("invalidtxid", 0, 0) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("payment disclosure is disabled" in errorString) # Check that Node 0 returns an error for an unknown txid try: self.nodes[0].z_getpaymentdisclosure("invalidtxid", 0, 0) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("No information available about transaction" in errorString) # Shield coinbase utxos from node 0 of value N, standard fee of 0.00010000 sentAmount = Decimal(summSubsidy_premine(4)) - Decimal('0.0001') recipients = [{"address": myzaddr, "amount": sentAmount}] myopid = self.nodes[0].z_sendmany(mytaddr, recipients) txid = wait_and_assert_operationid_status(self.nodes[0], myopid) # Check the tx has joinsplits assert (len(self.nodes[0].getrawtransaction("" + txid, 1)["vjoinsplit"]) > 0) # Sync mempools self.sync_all() # Confirm that you can't create a payment disclosure for an unconfirmed tx try: self.nodes[0].z_getpaymentdisclosure(txid, 0, 0) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("Transaction has not been confirmed yet" in errorString) try: self.nodes[1].z_getpaymentdisclosure(txid, 0, 0) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("Transaction has not been confirmed yet" in errorString) # Mine tx self.nodes[0].generate(1) self.sync_all() # Confirm that Node 1 cannot create a payment disclosure for a transaction which does not impact its wallet try: self.nodes[1].z_getpaymentdisclosure(txid, 0, 0) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("Transaction does not belong to the wallet" in errorString) # Check that an invalid joinsplit index is rejected try: self.nodes[0].z_getpaymentdisclosure(txid, 1, 0) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("Invalid js_index" in errorString) try: self.nodes[0].z_getpaymentdisclosure(txid, -1, 0) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("Invalid js_index" in errorString) # Check that an invalid output index is rejected try: self.nodes[0].z_getpaymentdisclosure(txid, 0, 2) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("Invalid output_index" in errorString) try: self.nodes[0].z_getpaymentdisclosure(txid, 0, -1) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("Invalid output_index" in errorString) # Ask Node 0 to create and validate a payment disclosure for output 0 message = "Here is proof of my payment!" pd = self.nodes[0].z_getpaymentdisclosure(txid, 0, 0, message) result = self.nodes[0].z_validatepaymentdisclosure(pd) assert (result["valid"]) output_value_sum = Decimal(result["value"]) # Ask Node 1 to confirm the payment disclosure is valid result = self.nodes[1].z_validatepaymentdisclosure(pd) assert (result["valid"]) assert_equal(result["message"], message) assert_equal(result["value"], output_value_sum) # Confirm that payment disclosure begins with prefix zpd: assert (pd.startswith("zpd:")) # Confirm that payment disclosure without prefix zpd: fails validation try: self.nodes[1].z_validatepaymentdisclosure(pd[4:]) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("payment disclosure prefix not found" in errorString) # Check that total value of output index 0 and index 1 should equal shielding amount of 40 less standard fee. pd = self.nodes[0].z_getpaymentdisclosure(txid, 0, 1) result = self.nodes[0].z_validatepaymentdisclosure(pd) output_value_sum += Decimal(result["value"]) assert_equal(output_value_sum, sentAmount) # Create a z->z transaction, sending shielded funds from node 0 to node 1 node1zaddr = self.nodes[1].z_getnewaddress() recipients = [{"address": node1zaddr, "amount": Decimal('1')}] myopid = self.nodes[0].z_sendmany(myzaddr, recipients) txid = wait_and_assert_operationid_status(self.nodes[0], myopid) self.sync_all() self.nodes[0].generate(1) self.sync_all() # Confirm that Node 0 can create a valid payment disclosure pd = self.nodes[0].z_getpaymentdisclosure(txid, 0, 0, "a message of your choice") result = self.nodes[0].z_validatepaymentdisclosure(pd) assert (result["valid"]) # Confirm that Node 1, even as recipient of shielded funds, cannot create a payment disclosure # as the transaction was created by Node 0 and Node 1's payment disclosure database does not # contain the necessary data to do so, where the data would only have been available on Node 0 # when executing z_shieldcoinbase. try: self.nodes[1].z_getpaymentdisclosure(txid, 0, 0) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ( "Could not find payment disclosure info for the given joinsplit output" in errorString) # Payment disclosures cannot be created for transparent transactions. txid = self.nodes[2].sendtoaddress(mytaddr, 1.0) self.sync_all() # No matter the type of transaction, if it has not been confirmed, it is ignored. try: self.nodes[0].z_getpaymentdisclosure(txid, 0, 0) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("Transaction has not been confirmed yet" in errorString) self.nodes[0].generate(1) self.sync_all() # Confirm that a payment disclosure can only be generated for a shielded transaction. try: self.nodes[0].z_getpaymentdisclosure(txid, 0, 0) assert (False) except JSONRPCException as e: errorString = e.error['message'] assert ("Transaction is not a shielded transaction" in errorString)
def run_test(self): print "Mining blocks..." self.nodes[0].generate(1) do_not_shield_taddr = self.nodes[0].getnewaddress() self.nodes[0].generate(4) walletinfo = self.nodes[0].getwalletinfo() assert_equal(walletinfo['immature_balance'], summSubsidy_premine(5)) assert_equal(walletinfo['balance'], 0) self.sync_all() self.nodes[2].generate(1) self.nodes[2].getnewaddress() self.nodes[2].generate(1) self.nodes[2].getnewaddress() self.nodes[2].generate(1) self.sync_all() self.nodes[1].generate(101) self.sync_all() assert_equal(self.nodes[0].getbalance(), summSubsidy_premine(5)) assert_equal(self.nodes[1].getbalance(), summSubsidy_noPremine(1)) assert_equal(self.nodes[2].getbalance(), summSubsidy_noPremine(3)) # Shield the coinbase myzaddr = self.nodes[0].z_getnewaddress() result = self.nodes[0].z_shieldcoinbase("*", myzaddr, 0) wait_and_assert_operationid_status(self.nodes[0], result['opid']) self.sync_all() self.nodes[1].generate(1) self.sync_all() # Prepare some UTXOs and notes for merging mytaddr = self.nodes[0].getnewaddress() mytaddr2 = self.nodes[0].getnewaddress() mytaddr3 = self.nodes[0].getnewaddress() result = self.nodes[0].z_sendmany(myzaddr, [ { 'address': do_not_shield_taddr, 'amount': 10 }, { 'address': mytaddr, 'amount': 10 }, { 'address': mytaddr2, 'amount': 10 }, { 'address': mytaddr3, 'amount': 10 }, ], 1, 0) wait_and_assert_operationid_status(self.nodes[0], result) self.sync_all() self.nodes[1].generate(1) self.sync_all() # Merging will fail because from arguments need to be in an array try: self.nodes[0].z_mergetoaddress("*", myzaddr) assert (False) except JSONRPCException, e: errorString = e.error['message']
def run_test(self): print "Mining blocks..." self.nodes[0].generate(4) walletinfo = self.nodes[0].getwalletinfo() assert_equal(walletinfo['immature_balance'], summSubsidy_premine(4)) assert_equal(walletinfo['balance'], 0) self.sync_all() self.nodes[1].generate(101) self.sync_all() assert_equal(self.nodes[0].getbalance(), summSubsidy_premine(4)) assert_equal(self.nodes[1].getbalance(), summSubsidy_noPremine(1)) assert_equal(self.nodes[2].getbalance(), summSubsidy_noPremine(0)) assert_equal(self.nodes[0].getbalance("*"), summSubsidy_premine(4)) assert_equal(self.nodes[1].getbalance("*"), summSubsidy_noPremine(1)) assert_equal(self.nodes[2].getbalance("*"), summSubsidy_noPremine(0)) # Send 21 CRYP from 0 to 2 using sendtoaddress call. # Second transaction will be child of first, and will require a fee self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), getBlockSubsidy_noPremine() + 1) self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), getBlockSubsidy_noPremine()) spent = getBlockSubsidy_noPremine() * 2 + 1 walletinfo = self.nodes[0].getwalletinfo() assert_equal(walletinfo['immature_balance'], 0) # Have node0 mine a block, thus it will collect its own fee. self.sync_all() self.nodes[0].generate(1) self.sync_all() # Have node1 generate 100 blocks (so node0 can recover the fee) self.nodes[1].generate(100) self.sync_all() node0income = summSubsidy_premine(5) # node0 should end up with summSubsidy_premine(5) CRYP in block rewards plus fees, but # minus the 21 plus fees sent to node2 assert_equal(self.nodes[0].getbalance(), node0income - spent) assert_equal(self.nodes[2].getbalance(), spent) assert_equal(self.nodes[0].getbalance("*"), node0income - spent) assert_equal(self.nodes[2].getbalance("*"), spent) return # not fixed # Node0 should have three unspent outputs. # Create a couple of transactions to send them to node2, submit them through # node1, and make sure both node0 and node2 pick them up properly: node0utxos = self.nodes[0].listunspent(1) assert_equal(len(node0utxos), 3) # Check 'generated' field of listunspent # Node 0: has one coinbase utxo and two regular utxos assert_equal( sum(int(uxto["generated"] is True) for uxto in node0utxos), 1) # Node 1: has 101 coinbase utxos and no regular utxos node1utxos = self.nodes[1].listunspent(1) assert_equal(len(node1utxos), 101) assert_equal( sum(int(uxto["generated"] is True) for uxto in node1utxos), 101) # Node 2: has no coinbase utxos and two regular utxos node2utxos = self.nodes[2].listunspent(1) assert_equal(len(node2utxos), 2) assert_equal( sum(int(uxto["generated"] is True) for uxto in node2utxos), 0) # Catch an attempt to send a transaction with an absurdly high fee. # Send 1.0 from an utxo of value 10.0 but don't specify a change output, so then # the change of 9.0 becomes the fee, which is greater than estimated fee of 0.0019. inputs = [] outputs = {} for utxo in node2utxos: if utxo["amount"] == Decimal("10.0"): break assert_equal(utxo["amount"], Decimal("10.0")) inputs.append({"txid": utxo["txid"], "vout": utxo["vout"]}) outputs[self.nodes[2].getnewaddress("")] = Decimal("1.0") raw_tx = self.nodes[2].createrawtransaction(inputs, outputs) signed_tx = self.nodes[2].signrawtransaction(raw_tx) try: self.nodes[2].sendrawtransaction(signed_tx["hex"]) except JSONRPCException, e: errorString = e.error['message']
def run_test(self): print "Mining blocks..." self.nodes[0].generate(4) walletinfo = self.nodes[0].getwalletinfo() assert_equal(walletinfo['immature_balance'], summSubsidy_premine(4)) assert_equal(walletinfo['balance'], 0) self.sync_all() self.nodes[1].generate(102) self.sync_all() assert_equal(self.nodes[0].getbalance(), summSubsidy_premine(4)) assert_equal(self.nodes[1].getbalance(), summSubsidy_noPremine(2)) assert_equal(self.nodes[2].getbalance(), summSubsidy_noPremine(0)) # At this point in time, commitment tree is the empty root # Node 0 creates a joinsplit transaction mytaddr0 = self.nodes[0].getnewaddress() myzaddr0 = self.nodes[0].z_getnewaddress() recipients = [] recipients.append({ "address": myzaddr0, "amount": Decimal(getBlockSubsidy_noPremine()) - Decimal('0.0001') }) myopid = self.nodes[0].z_sendmany(mytaddr0, recipients) wait_and_assert_operationid_status(self.nodes[0], myopid) # Sync up mempools and mine the transaction. All nodes have the same anchor. self.sync_all() self.nodes[0].generate(1) self.sync_all() # Stop nodes. stop_nodes(self.nodes) wait_bitcoinds() # Relaunch nodes and partition network into two: # A: node 0 # B: node 1, 2 self.nodes = start_nodes( 3, self.options.tmpdir, extra_args=[['-regtestprotectcoinbase', '-debug=zrpc']] * 3) connect_nodes_bi(self.nodes, 1, 2) # Partition B, node 1 mines an empty block self.nodes[1].generate(1) # Partition A, node 0 creates a joinsplit transaction recipients = [] recipients.append({ "address": myzaddr0, "amount": Decimal(getBlockSubsidy_noPremine()) - Decimal('0.0001') }) myopid = self.nodes[0].z_sendmany(mytaddr0, recipients) txid = wait_and_assert_operationid_status(self.nodes[0], myopid) rawhex = self.nodes[0].getrawtransaction(txid) # Partition A, node 0 mines a block with the transaction self.nodes[0].generate(1) # Partition B, node 1 mines the same joinsplit transaction txid2 = self.nodes[1].sendrawtransaction(rawhex) assert_equal(txid, txid2) self.nodes[1].generate(1) # Check that Partition B is one block ahead and that they have different tips assert_equal(self.nodes[0].getblockcount() + 1, self.nodes[1].getblockcount()) assert (self.nodes[0].getbestblockhash() != self.nodes[1].getbestblockhash()) # Shut down all nodes so any in-memory state is saved to disk stop_nodes(self.nodes) wait_bitcoinds() # Relaunch nodes and reconnect the entire network self.nodes = start_nodes( 3, self.options.tmpdir, extra_args=[['-regtestprotectcoinbase', '-debug=zrpc']] * 3) connect_nodes_bi(self.nodes, 0, 1) connect_nodes_bi(self.nodes, 1, 2) connect_nodes_bi(self.nodes, 0, 2) # Mine a new block and let it propagate self.nodes[1].generate(1) # Due to a bug in v1.0.0-1.0.3, node 0 will die with a tree root assertion, so sync_all() will throw an exception. self.sync_all() # v1.0.4 will reach here safely assert_equal(self.nodes[0].getbestblockhash(), self.nodes[1].getbestblockhash()) assert_equal(self.nodes[1].getbestblockhash(), self.nodes[2].getbestblockhash())