Esempio n. 1
0
    def run_test(self):
        """Main test logic"""

        from pypopminer import MockMiner
        self.apm = MockMiner()
        self.addrs = [x.getnewaddress() for x in self.nodes]
        self.endorsed_length = 100

        assert_pop_state_equal(self.nodes)
        create_endorsed_chain(self.nodes[0], self.apm, self.endorsed_length,
                              self.addrs[0])
        self.sync_all(self.nodes, timeout=20)
        assert_pop_state_equal(self.nodes)

        checkblocks = 0  # all blocks
        # 0, 1, 2, 3, 4
        for checklevel in range(5):
            self.log.info("checkblocks={} checklevel={}".format(
                checkblocks, checklevel))
            self.restart_node(0,
                              extra_args=[
                                  "-checkblocks={}".format(checkblocks),
                                  "-checklevel={}".format(checklevel)
                              ])
            time.sleep(10)
            self.sync_all(self.nodes, timeout=60)
            assert_pop_state_equal(self.nodes)
            self.log.info("success")
    def run_test(self):
        """Main test logic"""

        self.sync_all(self.nodes)

        from pypopminer import MockMiner
        self.apm = MockMiner()

        addr0 = self.nodes[0].getnewaddress()
        self.log.info("node0 endorses block 5")
        self.nodes[0].generate(nblocks=10)
        atvid = endorse_block(self.nodes[0], self.apm, 5, addr0)

        self.sync_pop_mempools(self.nodes, timeout=20)
        self.log.info("nodes[0,1] have syncd pop mempools")

        rawpopmempool1 = self.nodes[1].getrawpopmempool()
        assert atvid in rawpopmempool1['atvs']
        self.log.info("node1 contains atv1 in its pop mempool")

        self.restart_node(1)
        self.log.info("node1 has been restarted")
        rawpopmempool1 = self.nodes[1].getrawpopmempool()
        assert atvid not in rawpopmempool1['atvs']
        self.log.info("node1 does not contain atv1 in its pop mempool after restart")

        connect_nodes(self.nodes[0], 1)
        self.log.info("node1 connect to node0")

        self.sync_pop_mempools(self.nodes, timeout=20)
        self.log.info("nodes[0,1] have syncd pop mempools")

        rawpopmempool1 = self.nodes[1].getrawpopmempool()
        assert atvid in rawpopmempool1['atvs']
Esempio n. 3
0
 def run_test(self):
     """Main test logic"""
     from pypopminer import MockMiner
     self.apm = MockMiner()
     self._cannot_endorse()
     self.restart_node(0)
     self._can_endorse()
Esempio n. 4
0
    def run_test(self):
        """Main test logic"""

        self.sync_all(self.nodes)

        from pypopminer import MockMiner
        self.apm = MockMiner()

        self._restart_init_test()
Esempio n. 5
0
def main():
    parser = argparse.ArgumentParser(prog=os.path.basename(sys.argv[0]),
                                     usage='python3 %(prog)s [options]')
    parser.add_argument(
        '--url',
        default='http://127.0.0.1:18443',
        nargs='?',
        help='vBTC JSON RPC url (default: "http://127.0.0.1:18443")')
    parser.add_argument('--user', help='vBTC JSON RPC username')
    parser.add_argument('--password', help='vBTC JSON RPC password')
    parser.add_argument(
        '--max-blocks',
        type=int,
        default=100,
        nargs='?',
        help='Testing stops when height reaches this value (default: 100)')
    parser.add_argument(
        '--max-hours',
        type=int,
        default=1,
        nargs='?',
        help=
        'Testing stops when execution time in hours reaches this value (default: 1)'
    )
    parser.add_argument(
        '--seed',
        type=int,
        nargs='?',
        help='Seed to instantiate random generator with (default: random)')
    args = parser.parse_args()

    if args.user is None or args.password is None:
        print('Error: --user and --password should be specified')
        parser.print_help()
        sys.exit(2)

    node = JsonRpcApi(args.url, args.user, args.password)
    apm = MockMiner()
    max_blocks = args.max_blocks
    max_hours = args.max_hours
    seed = args.seed or randrange(sys.maxsize)

    print('Load test starting')
    print('- Max height: {} blocks'.format(max_blocks))
    print('- Max execution time: {} hours'.format(max_hours))
    print('- Seed: {}'.format(seed))

    try:
        blocks, elapsed = load_test(node, apm, max_blocks, max_hours, seed)

        print('Load test finished')
        print('- Height: {} blocks'.format(blocks))
        print('- Execution time: {:.3f} sec'.format(elapsed))

    except Exception as e:
        print('Load test failed')
        print('Error: {}'.format(e))
Esempio n. 6
0
    def run_test(self):
        """Main test logic"""

        self.sync_all(self.nodes)

        from pypopminer import MockMiner
        self.apm = MockMiner()

        self._case1_endorse_keystone_get_paid()
Esempio n. 7
0
    def run_test(self):
        """Main test logic"""

        self.sync_all(self.nodes)

        from pypopminer import MockMiner
        self.apm = MockMiner()

        self._check_pop_sync()
    def run_test(self):
        """Main test logic"""

        self.nodes[0].generate(nblocks=10)
        self.sync_all(self.nodes)

        from pypopminer import MockMiner
        self.apm = MockMiner()

        self._test_mempool_reorg_case()
    def run_test(self):
        """Main test logic"""

        self.sync_all(self.nodes[0:4])

        from pypopminer import MockMiner
        self.apm = MockMiner()

        self._shorter_endorsed_chain_wins()
        self._4_chains_converge()
Esempio n. 10
0
    def run_test(self):
        """Main test logic"""

        self.nodes[0].generate(nblocks=10)
        self.sync_all(self.nodes)

        from pypopminer import MockMiner
        self.apm = MockMiner()

        self._run_sync_case()

        self.restart_node(0)
        self._run_sync_after_generating()
Esempio n. 11
0
    def run_test(self):
        """Main test logic"""

        self.nodes[0].generate(nblocks=10)
        self.sync_all(self.nodes)

        from pypopminer import MockMiner
        self.apm = MockMiner()

        self._test_case_vbk(113)
        self._test_case_vbk(236)
        self._test_case_vbk(75)

        self._test_case_atv(42)
        self._test_case_atv(135)
        self._test_case_atv(25)
Esempio n. 12
0
    def run_test(self):
        """Main test logic"""

        self.nodes[0].generate(nblocks=10)
        self.sync_all(self.nodes)

        from pypopminer import MockMiner
        self.apm = MockMiner()

        self.cases = [msg_offer_atv, msg_get_atv]

        for i, case in enumerate(self.cases):
            self._run_case(case, i)
            self.restart_node(0)

        self._run_case2()

        self.restart_node(0)
        self._run_case3()
    def test_mock_miner_can_produce_publications(self):
        from pypopminer import MockMiner, PublicationData
        m = MockMiner()
        self.assertEqual(m.vbkTip.previousBlock, "000000000000000000000000")
        self.assertEqual(m.vbkTip.height, 0)

        endorsed = m.mineVbkBlocks(100)
        self.assertEqual(endorsed.height, 100)
        m.endorseVbkBlock(endorsed, m.btcTip.getHash(), 10)

        p = PublicationData()
        p.identifier = 1337
        p.header = "0011223344"
        p.payoutInfo = "0014aaddff"
        payloads = m.endorseAltBlock(p, m.vbkTip.getHash())
        print(repr(payloads))
        self.assertEqual(len(payloads.vtbs), 10)
        self.assertEqual(m.vbkTip.height, 102)