def run_test(self): posStart = 100 targetNumberOfBlocks = posStart + 100 minting_node = self.nodes[0] owner_node = self.nodes[1] print ("Setting up PoS coins...") ownerNodes = self.nodes[:-1] vaultNode = self.nodes[-1] createVaultPoSStacks(ownerNodes,vaultNode) self.sync_all() print ("Mining remaining PoW blocks...") missing = posStart - minting_node.getblockcount() assert missing > 0 minting_node.setgenerate(True, missing) self.sync_all() print ("Vault trying to mine PoS blocks now...") missing = targetNumberOfBlocks - minting_node.getblockcount() assert missing > 0 generatePoSBlocks(self.nodes, -1, missing) assert_equal(vaultNode.getblockcount(), targetNumberOfBlocks) fee = 100 assert_equal(owner_node.getwalletinfo()["unconfirmed_balance"],0) expectedMinimumUnconfirmedBalance = vaultNode.getcoinavailability()["Stakable"]-fee owner_node.reclaimvaultfunds(owner_node.getnewaddress(),expectedMinimumUnconfirmedBalance) assert_greater_than(owner_node.getwalletinfo()["unconfirmed_balance"],expectedMinimumUnconfirmedBalance)
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): posStart = 100 targetNumberOfBlocks = posStart + 100 minting_node = self.nodes[0] owner_node = self.nodes[1] print("Setting up PoS coins...") ownerNodes = self.nodes[:-1] vaultNode = self.nodes[-1] vault_encoding = createVaultPoSStacks(ownerNodes, vaultNode) self.sync_all() print("Mining remaining PoW blocks...") missing = posStart - minting_node.getblockcount() assert missing > 0 minting_node.setgenerate(True, missing) self.sync_all() print("Vault trying to mine PoS blocks now...") missing = targetNumberOfBlocks - minting_node.getblockcount() assert missing > 0 half_of_missing = int(missing / 2) generatePoSBlocks(self.nodes, -1, half_of_missing) assert_equal(targetNumberOfBlocks - minting_node.getblockcount(), half_of_missing) vaultNode.removevault(vault_encoding) assert_raises(JSONRPCException, generatePoSBlocks, self.nodes, -1, missing) assert_equal(targetNumberOfBlocks - minting_node.getblockcount(), half_of_missing)
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): miningNode = self.nodes[0] vaultNode = self.nodes[1] createVaultPoSStacks(self.nodes) self.sync_all() powBlocks = 100 # Mine missing PoW blocks cnt = miningNode.getblockcount() missingBlocks = max(powBlocks - cnt,0) generatePoSBlocks([miningNode], 0, missingBlocks) self.sync_all() sync_blocks(self.nodes) self.nodes[2].setgenerate(True,20) sync_blocks(self.nodes) # Send funds to vault self.sync_all() totalMined = 1250.0*float(powBlocks-25) intendedVaultedAmount = 8000.0 miningNodeAllocations = miningNode.getcoinavailability() managedFunds = miningNodeAllocations["Stakable"] - miningNodeAllocations["Spendable"] assert_near(miningNodeAllocations["Spendable"], totalMined,1.0) assert_near(miningNodeAllocations["Stakable"], totalMined,1.0) assert_near(miningNodeAllocations["Vaulted"], 0.0,1e-10) assert_equal(miningNodeAllocations["Spendable"]+managedFunds+miningNodeAllocations["Vaulted"], miningNode.getbalance()) vaultFundingData = miningNode.fundvault(vaultNode.getnewaddress(),intendedVaultedAmount) self.sync_all() sync_blocks(self.nodes) self.nodes[2].setgenerate(True,1) sync_blocks(self.nodes) # Miner node has funds as expected and sends to a vault node miningNodeAllocations = miningNode.getcoinavailability() managedFunds = miningNodeAllocations["Stakable"] - miningNodeAllocations["Spendable"] assert_near(miningNodeAllocations["Spendable"], totalMined - intendedVaultedAmount,5.0) assert_near(miningNodeAllocations["Stakable"], totalMined - intendedVaultedAmount,5.0) assert_near(miningNodeAllocations["Vaulted"], intendedVaultedAmount,1e-10) assert_equal(miningNodeAllocations["Spendable"] +managedFunds+ miningNodeAllocations["Vaulted"], miningNode.getbalance()) # Vault node has not accepted the responsibility to stake on behalf of the Miner node vaultNodeAllocations = vaultNode.getcoinavailability() assert_near(vaultNodeAllocations["Spendable"], 0.0,1e-10) assert_near(vaultNodeAllocations["Stakable"], 0.0,1e-10) assert_near(vaultNodeAllocations["Vaulted"], 0.0,1e-10) assert_equal(0.0, vaultNode.getbalance()) # Vault node has now accepted the responsibility to stake on behalf of the Miner node vaultEncoding = vaultFundingData["vault"] txhash = vaultFundingData["txhash"] vaultNode.addvault(vaultEncoding,txhash) vaultNodeAllocations = vaultNode.getcoinavailability() managedFunds = vaultNodeAllocations["Stakable"] - vaultNodeAllocations["Spendable"] assert_near(vaultNodeAllocations["Spendable"], 0.0,1e-10) assert_near(vaultNodeAllocations["Stakable"], intendedVaultedAmount,1e-10) assert_near(vaultNodeAllocations["Vaulted"], 0.0,1e-10) assert_equal(vaultNodeAllocations["Spendable"] +managedFunds+ vaultNodeAllocations["Vaulted"], vaultNode.getbalance())
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): miningNode = self.nodes[0] vaultNode = self.nodes[1] createVaultPoSStacks(self.nodes) self.sync_all() powBlocks = 100 # Mine missing PoW blocks cnt = miningNode.getblockcount() missingBlocks = max(powBlocks - cnt, 0) generatePoSBlocks([miningNode], 0, missingBlocks) self.sync_all() sync_blocks(self.nodes) self.nodes[2].setgenerate(20) sync_blocks(self.nodes) # Send funds to vault self.sync_all() totalMined = 1250.0 * float(powBlocks - 25) intendedVaultedAmount = 8000.0 miningNodeAllocations = miningNode.getcoinavailability() managedFunds = miningNodeAllocations[ "Stakable"] - miningNodeAllocations["Spendable"] assert_near(miningNodeAllocations["Spendable"], totalMined, 1.0) assert_near(miningNodeAllocations["Stakable"], totalMined, 1.0) assert_near(miningNodeAllocations["Vaulted"], 0.0, 1e-10) assert_equal( miningNodeAllocations["Spendable"] + managedFunds + miningNodeAllocations["Vaulted"], miningNode.getbalance()) vaultFundingData = miningNode.fundvault(vaultNode.getnewaddress(), intendedVaultedAmount) self.sync_all() sync_blocks(self.nodes) self.nodes[2].setgenerate(1) sync_blocks(self.nodes) # Miner node has funds as expected and sends to a vault node miningNodeAllocations = miningNode.getcoinavailability() managedFunds = miningNodeAllocations[ "Stakable"] - miningNodeAllocations["Spendable"] assert_near(miningNodeAllocations["Spendable"], totalMined - intendedVaultedAmount, 5.0) assert_near(miningNodeAllocations["Stakable"], totalMined - intendedVaultedAmount, 5.0) assert_near(miningNodeAllocations["Vaulted"], intendedVaultedAmount, 1e-10) assert_equal( miningNodeAllocations["Spendable"] + managedFunds + miningNodeAllocations["Vaulted"], miningNode.getbalance()) # Vault node has not accepted the responsibility to stake on behalf of the Miner node vaultNodeAllocations = vaultNode.getcoinavailability() assert_near(vaultNodeAllocations["Spendable"], 0.0, 1e-10) assert_near(vaultNodeAllocations["Stakable"], 0.0, 1e-10) assert_near(vaultNodeAllocations["Vaulted"], 0.0, 1e-10) assert_equal(0.0, vaultNode.getbalance()) # Vault node has now accepted the responsibility to stake on behalf of the Miner node vaultEncoding = vaultFundingData["vault"] txhash = vaultFundingData["txhash"] vaultNode.addvault(vaultEncoding, txhash) vaultNodeAllocations = vaultNode.getcoinavailability() managedFunds = vaultNodeAllocations["Stakable"] - vaultNodeAllocations[ "Spendable"] assert_near(vaultNodeAllocations["Spendable"], 0.0, 1e-10) assert_near(vaultNodeAllocations["Stakable"], intendedVaultedAmount, 1e-10) assert_near(vaultNodeAllocations["Vaulted"], 0.0, 1e-10) assert_equal( vaultNodeAllocations["Spendable"] + managedFunds + vaultNodeAllocations["Vaulted"], vaultNode.getbalance()) self.verify_vault_folder_recovers_state(intendedVaultedAmount) stop_node(vaultNode, 1) vaultScript = vaultFundingData["script"] self.nodes[1] = start_node( 1, self.options.tmpdir, ["-vault=1", "-whitelisted_vault=" + str(vaultScript)]) connect_nodes(self.nodes[1], 0) self.sync_all() miningNode.fundvault(vaultFundingData["vault"], intendedVaultedAmount) self.sync_all() assert_equal(vaultNode.getwalletinfo()["unconfirmed_balance"], Decimal(intendedVaultedAmount))
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"]})