def run_test (self): createPoSStacks ([self.node], self.nodes) generatePoSBlocks (self.nodes, 0, 125) sync_blocks(self.nodes) self.nodes.append(start_node(1, self.options.tmpdir, extra_args=self.config_args)) connect_nodes_bi(self.nodes,0,1) sync_blocks(self.nodes) staker_node = self.nodes[0] auditor_node = self.nodes[1] print("Verifying chain...") auditor_node.verifychain() print("Chain verified") print("Verifying utxos...") self.check_utxos(staker_node,auditor_node) print("Finished checking utxos") print("Disconnecting chain...") hash = auditor_node.getblockhash(110) auditor_node.invalidateblock(hash) auditor_node.verifychain() print("Chain verified") print("Reconnecting chain...") auditor_node.reconsiderblock(hash) auditor_node.verifychain() print("Chain verified")
def run_test (self): # Advance to PoS blocks to make sure we have the correct # fee rules active. print ("Advancing to PoS blocks...") createPoSStacks ([self.node], self.nodes) generatePoSBlocks (self.nodes, 0, 100) # Test sending OP_META transactions with a size around the limit # for being a standard transaction. Larger ones are still valid # for inside a block, just not accepted to the mempool by default. print ("Testing OP_META standardness size limit...") utxos = self.node.listunspent () standard, txid1 = self.build_op_meta_tx (utxos, b"x" * 599, Decimal ('0.1')) nonstandard, txid2 = self.build_op_meta_tx (utxos, b"x" * 600, Decimal ('0.1')) self.node.sendrawtransaction (standard) assert_raises (JSONRPCException, self.node.sendrawtransaction, nonstandard) self.node.generateblock ({"extratx": [nonstandard]}) self.check_confirmed ([txid1, txid2]) # More than one OP_META output is not standard in any case. print ("Testing multiple OP_META outputs...") utxos = self.node.listunspent () nonstandard, txid = self.build_op_meta_tx (utxos, [b"abc", b"def"], Decimal ('0.1')) assert_raises (JSONRPCException, self.node.sendrawtransaction, nonstandard) self.node.generateblock ({"extratx": [nonstandard]}) self.check_confirmed (txid) # Check what fee is required for small and large OP_META transactions. print ("Checking required fees...") utxos = self.node.listunspent () for p in [b"x", b"x" * 599]: fee = self.find_min_fee (utxos, p) print ("For payload size %d: %.8f DIVI" % (len (p), fee))
def run_test(self): createPoSStacks([self.node], self.nodes) generatePoSBlocks(self.nodes, 0, 125) sync_blocks(self.nodes) secondCoinstake, txid1 = self.build_coinstake_tx() thirdCoinstake, txid2 = self.build_coinstake_tx() assert_raises(JSONRPCException, self.node.generateblock, {"extratx": [secondCoinstake]}) self.check_unconfirmed([txid1, txid2]) assert_raises(JSONRPCException, self.node.generateblock, {"extratx": [secondCoinstake, thirdCoinstake]}) self.check_unconfirmed([txid1, txid2])
def run_test(self): createPoSStacks([self.nodes[0], self.nodes[1]], self.nodes) self.fund_masternodes() self.start_masternodes() # Run initial masternode sync. Also, for payments to be active, we # need at least 100 blocks and the masternodes need to be active # for 8'000 seconds. print("Running initial masternode sync...") self.wait_for_mnsync_on_nodes(updateMockTime=True) for _ in range(100): self.nodes[1].setgenerate(1) self.advance_time(100) for n in self.nodes: assert_equal(n.getmasternodecount()["inqueue"], 6) # Lottery blocks are every 10th on regtest, and treasury blocks the # ones after them. We want to test masternode rewards mainly, so # make sure the next couple of blocks are neither type. We get the # current block height, and then generate more blocks so that we # end up with a height that is 1 mod 10; that then means the next # block is mod 2 and so the next couple of blocks are neither type # of special payment. cnt = self.nodes[1].getblockcount() self.nodes[1].setgenerate(11 - (cnt % 10)) assert_equal(self.nodes[1].getblockcount() % 10, 1) sync_blocks(self.nodes) # After ten minutes, the blockchain is considered no longer synced # if the node is restarted (but if not, then the value is cached # and remains true during the process' life). # # Make sure that it is fine to generate blocks even after then # with a node that is still masternode synced. print("Generating block with mn synced node...") self.time_out_blockchain_sync() self.nodes[1].setgenerate(1) sync_blocks(self.nodes) self.wait_for_mnsync_on_nodes(updateMockTime=True) # Similarly, it should also work to generate blocks with a restarted # node that does not consider itself mn synced. It still has the # cached list of masternodes and will thus set the right payment. print("Generating block with not mn synced node...") self.time_out_blockchain_sync() assert_greater_than(len(self.nodes[0].listmasternodes()), 0) self.nodes[0].setgenerate(1) sync_blocks(self.nodes) self.wait_for_mnsync_on_nodes(updateMockTime=True) # If we restart the node and remove the masternode cache, it won't # have a list of masternodes (as it will also not process any messages) # and will thus not produce a valid block. print("Generating block with node without masternode list...") stop_node(self.nodes[0], 0) self.nodes[0] = None for f in ["mncache.dat", "mnpayments.dat"]: os.remove(os.path.join(self.options.tmpdir, "node0", "regtest", f)) self.time_out_blockchain_sync() assert_equal(self.nodes[0].listmasternodes(), []) self.nodes[0].setgenerate(1) time.sleep(1) assert_equal(self.nodes[0].getblockcount(), self.nodes[1].getblockcount() + 1)
def run_test(self): # We need to activate PoS at least for some parts of the test. print("Activating PoS...") createPoSStacks(self.nodes, self.nodes) generatePoSBlocks(self.nodes, 0, 100) print("Spending vault as staker...") vault = self.fund_vault(self.nodes[0], self.nodes[1], 10) sync_mempools(self.nodes[:2]) generatePoSBlocks(self.nodes, 1, 1) addr = self.nodes[1].getnewaddress("stolen again") unsigned = self.nodes[1].createrawtransaction([vault], {addr: 9}) signed = self.nodes[1].signrawtransaction(unsigned) assert_raises(JSONRPCException, self.nodes[1].generateblock, {"extratx": [signed["hex"]]}) assert_equal(self.nodes[1].getbalance("stolen again"), 0) print("Spending vault as owner...") vault = self.fund_vault(self.nodes[0], self.nodes[1], 10) sync_mempools(self.nodes[:2]) generatePoSBlocks(self.nodes, 1, 1) addr = self.nodes[0].getnewaddress("unvaulted 2") unsigned = self.nodes[0].createrawtransaction([vault], {addr: 9}) self.sign_and_send(self.nodes[0], unsigned) sync_mempools(self.nodes) generatePoSBlocks(self.nodes, 1, 1) assert_equal(self.nodes[0].getbalance("unvaulted 2"), 9) print("Trying to steal as the staker...") vault = self.fund_vault(self.nodes[0], self.nodes[1], 10_000) sync_mempools(self.nodes[:2]) generatePoSBlocks(self.nodes, 1, 20) # Lottery blocks are every 10th on regtest, and treasury blocks # the ones after them (eqv 1 mod 10). We want to avoid them # so that we do not have to deal with the rewards payment. while (self.nodes[1].getblockcount() + 1) % 10 in [0, 1]: generatePoSBlocks(self.nodes, 1, 1) bestBlock = self.nodes[1].getblockheader( self.nodes[1].getbestblockhash()) set_node_times(self.nodes, bestBlock["time"] + 1_000) addr = self.nodes[1].getnewaddress("stolen by staking") # Correct staking rewards for the current block. stakingRewards = 456 outputs = [ { "": 0 }, { addr: 10_000 + stakingRewards }, ] stake = self.nodes[1].createrawtransaction([vault], outputs) stake = self.nodes[1].signrawtransaction(stake) assert_equal(stake["complete"], True) assert_raises(JSONRPCException, self.nodes[1].generateblock, {"coinstake": stake["hex"]}) assert_equal(self.nodes[1].getbalance("stolen by staking"), 0) print("Staking properly with the vault...") vaultOut = self.nodes[1].gettxout(vault["txid"], vault["vout"]) vaultScript = vaultOut["scriptPubKey"]["hex"] outputs = [ { "": 0 }, { vaultScript: 10_000 + stakingRewards }, ] stake = self.nodes[1].createrawtransaction([vault], outputs) stake = self.nodes[1].signrawtransaction(stake) assert_equal(stake["complete"], True) self.nodes[1].generateblock({"coinstake": stake["hex"]})