def issue_mempool_test(self):
        self.log.info(
            "Testing (issue_mempool_test) mempool state after asset issuance on two chains(only one is mined, the other is in the mempool), and then connecting the nodes together"
        )
        n0, n1 = self.nodes[0], self.nodes[1]

        disconnect_all_nodes(self.nodes)

        asset_name = "MEMPOOL"

        # Issue asset on chain 1 and mine it into the blocks
        n0.issue(asset_name)
        n0.generate(15)

        # Issue asset on chain 2 but keep it in the mempool. No mining
        n1.issue(asset_name)

        connect_all_nodes_bi(self.nodes, True)

        # Assert that the reorg was successful
        assert_equal(n0.getblockcount(), n1.getblockcount())
        assert_equal(n0.getbestblockhash(), n1.getbestblockhash())

        # Verify that the mempool are empty ( No extra transactions from the old chain made it into the mempool)
        assert_equal(0, n1.getmempoolinfo()['size'])
        assert_equal(0, n0.getmempoolinfo()['size'])
示例#2
0
    def setup_network(self):
        """Make this a fully connected network"""
        self.log.info("Running setup_network")
        self.setup_nodes()

        # Connect every node to every other
        connect_all_nodes_bi(self.nodes)
        self.sync_all()
示例#3
0
    def setup_network(self):
        self.add_nodes(2, [
            # Nodes 0/1 are "wallet" nodes
            ["-assetindex"],
            ["-assetindex"]])

        self.start_nodes()

        connect_all_nodes_bi(self.nodes)

        self.sync_all()
    def issue_mempool_test_extended_sub(self):
        self.log.info(
            "Testing (issue_mempool_test) mempool state after asset issuance on two chains(only one is mined, the other is in the mempool), and then connecting the nodes together"
        )
        n0, n1 = self.nodes[0], self.nodes[1]

        disconnect_all_nodes(self.nodes)

        asset_name = "MEMPOOL_3"

        # Issue asset on chain 1 and mine it into the blocks
        n0.issue(asset_name)
        n0.generate(15)

        # Issue asset on chain 2 but keep it in the mempool. No mining
        n1.issue(asset_name)

        # Mine a block on n1 chain
        n1.generate(1)

        # Issue sub assets and unique assets but only have it in the mempool
        n1.issue(asset_name + '/SUB')
        n1.issue(asset_name + '/SUB/1')
        n1.issue(asset_name + '/SUB/2')
        n1.issue(asset_name + '/SUB/3')
        n1.issue(asset_name + '/SUB/4')
        n1.issue(asset_name + '/SUB/5')
        n1.issue(asset_name + '/SUB/6')
        n1.issue(asset_name + '/SUB#1')
        n1.issue(asset_name + '/SUB#2')
        n1.issue(asset_name + '/SUB#3')
        n1.issue(asset_name + '/SUB#4')
        n1.issue(asset_name + '/SUB#5')
        n1.issue(asset_name + '/SUB#6')
        n1.issue(asset_name + '/SUB#7')
        n1.issue(asset_name + '/SUB/SUB')
        n1.issue(asset_name + '/SUB/SUB/SUB')
        n1.issue(asset_name + '/SUB/SUB/SUB/SUB')
        assert_equal(17, n1.getmempoolinfo()['size'])

        connect_all_nodes_bi(self.nodes, True)

        # Assert that the reorg was successful
        assert_equal(n0.getblockcount(), n1.getblockcount())
        assert_equal(n0.getbestblockhash(), n1.getbestblockhash())

        # Verify that the mempools are empty ( No extra transactions from the old chain made it into the mempool)
        assert_equal(0, n1.getmempoolinfo()['size'])
        assert_equal(0, n0.getmempoolinfo()['size'])
    def issue_mempool_test_extended(self):
        self.log.info(
            "Testing (issue_mempool_test_extended) mempool state after, asset issuance, reissue, transfer, issue sub asset, getting reorged, with asset override on other chain"
        )
        n0, n1 = self.nodes[0], self.nodes[1]

        disconnect_all_nodes(self.nodes)
        # Create new asset for testing
        asset_name = "MEMPOOL_2"
        n0.issue(asset_name)
        n0.generate(15)

        # Reissue that asset
        address1 = n0.getnewaddress()
        n0.reissue(asset_name=asset_name,
                   qty=2000,
                   to_address=address1,
                   change_address='',
                   reissuable=True,
                   new_units=-1)
        n0.generate(15)

        # Get a transfer address
        n1_address = n1.getnewaddress()

        # Transfer the asset
        n0.transfer(asset_name, 2, n1_address)

        # Issue sub asset
        n0.issue(asset_name + '/SUB')
        n0.generate(15)

        # Issue the same asset on the other node
        n1.issue(asset_name)

        # Create enough blocks so that n0 will reorg to n1 chain
        n1.generate(55)

        # Connect the nodes, a reorg should occur
        connect_all_nodes_bi(self.nodes, True)

        # Asset the reorg occurred
        assert_equal(n0.getblockcount(), n1.getblockcount())
        assert_equal(n0.getbestblockhash(), n1.getbestblockhash())

        # Verify that the mempool are empty ( No extra transactions from the old chain made it into the mempool)
        assert_equal(0, n1.getmempoolinfo()['size'])
        assert_equal(0, n0.getmempoolinfo()['size'])
    def reorg_chain_state_test(self):
        self.log.info("Testing issue reorg to invalid chain...")
        n0, n1 = self.nodes[0], self.nodes[1]

        disconnect_all_nodes(self.nodes)

        # Mine 40 blocks
        n0.generate(40)
        node_0_hash = n0.getbestblockhash()
        node_0_height = n0.getblockcount()

        # Mine 44 blocks on chain 2
        n1.generate(20)
        node_1_hash_20 = n1.getbestblockhash()
        node_1_height_20 = n1.getblockcount()

        n1.generate(24)
        node_1_hash_44 = n1.getbestblockhash()
        node_1_height_44 = n1.getblockcount()

        # Do some validity checks, make sure we have separate chains
        assert_equal(True, node_0_hash is not n1.getbestblockhash())
        assert_equal(True, (node_1_height_44 - node_0_height) == 4)

        # Connect the nodes together, and force a reorg to occur
        connect_all_nodes_bi(self.nodes, True)

        node_0_hash_after_reorg = n0.getbestblockhash()
        node_0_height_after_reorg = n0.getblockcount()

        # Uncomment to debug
        # self.log.info('Node 0 after reorg ' + str(node_0_height_after_reorg) + ' ' + node_0_hash_after_reorg)
        # self.log.info('Node 1 after reorg ' + str(node_1_height_44) + ' ' + node_1_hash_44)

        # Make sure the reorg was successful
        assert_equal(True, node_0_hash_after_reorg == node_1_hash_44)
        assert_equal(True, node_0_height_after_reorg == node_1_height_44)

        # Invalidate node 1 block height at 20
        n0.invalidateblock(node_1_hash_20)

        # When node0 invalidated the block, it should automatically connect to the longest valid chain
        # which is the chain that node0 mined at the start of the test
        node_0_hash_invalidated = n0.getbestblockhash()
        node_0_height_invalidated = n0.getblockcount()
        assert_equal(True, node_0_height == node_0_height_invalidated)
        assert_equal(True, node_0_hash == node_0_hash_invalidated)
示例#7
0
    def issue_reorg_test(self):
        self.log.info("Testing issue reorg 2...")
        n0, n1 = self.nodes[0], self.nodes[1]

        disconnect_all_nodes(self.nodes)

        asset_name = "DOUBLE_TROUBLE"

        # Issue asset on chain 1
        n0.issue(asset_name)
        n0.generate(15)

        # Issue asset on chain 2
        n1.generate(5)
        n1.issue(asset_name)
        n1.generate(5)

        # Do some validity checks, make sure we have separate chains
        node_0_hash = n0.getbestblockhash()
        node_0_height = n0.getblockcount()

        # They should each on their chains the asset DOUBLE_TROUBLE and DOUBLE_TROUBLE!
        assert_equal(True, n0.listmyassets() == n1.listmyassets())
        assert_equal(True, node_0_hash is not n1.getbestblockhash())

        # Uncomment to debug
        # self.log.info(f"{n0.getblockcount()}: {n0.getbestblockhash()}")
        # self.log.info(f"{n1.getblockcount()}: {n1.getbestblockhash()}")
        # self.log.info(n0.listmyassets())
        # self.log.info(n1.listmyassets())
        # Connect the nodes together, and force a reorg to occur
        connect_all_nodes_bi(self.nodes, True)

        # Uncomment to debug
        # self.log.info(f"{n0.getblockcount()}: {n0.getbestblockhash()}")
        # self.log.info(f"{n1.getblockcount()}: {n1.getbestblockhash()}")
        # self.log.info(n0.listmyassets())
        # self.log.info(n1.listmyassets())

        # Verify that node1 reorged to the node0 chain and that node0 has the asset and not node1
        assert_equal(node_0_height, n1.getblockcount())
        assert_equal(node_0_hash, n1.getbestblockhash())
        assert_equal(True, n0.listmyassets() != n1.listmyassets())

        # Disconnect all nodes
        disconnect_all_nodes(self.nodes)

        # Issue second asset on chain 1 and mine 5 blocks
        n0.issue(asset_name + '2')
        n0.generate(5)

        # Mine 5 blocks, issue second asset on chain 2, mine 5 more blocks, giving node1 more chain weight
        n1.generate(5)
        n1.issue(asset_name + '2')
        n1.generate(5)

        node_1_hash = n1.getbestblockhash()
        node_1_height = n1.getblockcount()
        assert_equal(True, n0.getbestblockhash() is not node_1_hash)
        assert_equal(True, n0.listmyassets('DOUBLE_TROUBLE2*') == n1.listmyassets('DOUBLE_TROUBLE2*'))

        # Connect the nodes together, and force a reorg to occur
        connect_all_nodes_bi(self.nodes, True)

        # Verify that node0 reorged to the node1 chain and that node1 has the asset and not node0
        assert_equal(n0.getblockcount(), node_1_height)
        assert_equal(n0.getbestblockhash(), node_1_hash)
        assert_equal(True, n0.listmyassets() != n1.listmyassets())