Example #1
0
    def make_partion(self):
        '''make the p2p network partion into 2 seperate ones.'''
        # record current block height
        ec, message = mvs_rpc.get_info()
        self.assertEqual(ec, 0, message)
        self.partion_height = message[0]

        ec, peers = mvs_rpc.getpeerinfo()
        for peer in peers:
            ec, message = mvs_rpc.ban_node(peer)
            self.assertEqual(ec, 0, message)
Example #2
0
def fork_test(  ):
    origin = "origin"
    popback = "popback"
    # backup check point
    _, (height, _) = mvs_rpc.get_info()
    data_base_script(origin)

    # run testcase
    run_testcase()

    # make this node partion with the others
    peers = mvs_rpc.getpeerinfo()[1]
    for peer in peers:
        mvs_rpc.ban_node(peer)
    try:
        # popblock
        ec, _ = mvs_rpc.pop_block(height + 1)
        assert (ec == 0)
        assert( mvs_rpc.get_info()[1][0] == height)

        # check database
        data_base_script(popback)

    finally:
        for peer in peers:
            mvs_rpc.add_node(peer)

    # check origin and popback
    f_origin = open('./tools/%s/result.txt' % origin)
    f_popback= open('./tools/%s/result.txt' % popback)
    while True:
        line1 = f_origin.readline()
        line2 = f_popback.readline()
        assert (line1 == line2)

        if not (line1 or line2):
            break

    f_origin.close()
    f_popback.close()
    print "fork test passed!"
Example #3
0
        def __mine__():
            result, (header_hash, seed_hash, boundary) = mvs_rpc.eth_get_work()
            assert (result == 0)
            result, (height, difficulty) = mvs_rpc.get_info()
            assert (result == 0)

            rounds = 100
            nonce = 0
            while True:
                bin_nonce, mixhash = mine(block_number=height+1, difficulty=difficulty, mining_hash=header_hash,
                                          rounds=rounds, start_nonce=nonce)
                if bin_nonce:
                    break
                nonce += rounds
            return bin_nonce, '0x' + common.toString(header_hash), '0x' + common.toString(mixhash)
Example #4
0
    def fork(self):
        try:
            ming_round = 6
            expect_hight = self.remote_ming(ming_round)

            ec, message = mvs_rpc.add_node(self.remote_ip + ':5251')
            self.assertEqual(ec, 0, message)
            import time
            new_height = 0

            # wait until the fork complete
            timeout = 300
            while new_height < expect_hight:  # self.partion_height + ming_round:
                time.sleep(1)
                ec, message = mvs_rpc.get_info()
                self.assertEqual(ec, 0, message)
                new_height = message[0]
                timeout -= 1
                self.assertGreater(timeout, 0, "wait fork timeout error!")
        except:
            print 'unable to connect remote url:' + self.remote_ip