Пример #1
0
def post_blocks(api, blocks_cnt, chain_data_file):
    premined_blocks = chain_downloader.load_from_file(chain_data_file)
    for i in range(1, blocks_cnt + 1):
        block = chain_downloader.get_block(premined_blocks, height=i)
        api.post_block(block)
        wait(lambda: api.get_top().height >= i,
             timeout_seconds=3,
             sleep_seconds=0.25)
Пример #2
0
def test_block_post_wrong_pow():
    """
    Test rejecting a block with wrong PoW 
    """
    api = common.external_api(node)
    top = api.get_top()
    ## ensure there is only genesis block
    assert_equals(top.height, 0)

    premined_blocks = chain_downloader.load_from_file(chain_data_file)
    block1 = chain_downloader.get_block(premined_blocks, height=1)
    block2 = chain_downloader.get_block(premined_blocks, height=2)

    # modify the pow of block1 to be invalid against the header
    block1.pow = block2.pow
    res = api.post_block(block1)
    time.sleep(1)
    top = api.get_top()
    assert_equals(top.height, 0)
Пример #3
0
def test_block_post():
    """
    Test case for posting a new block
    """
    api = common.external_api(node)
    top = api.get_top()
    ## ensure there is only genesis block
    assert_equals(top.height, 0)

    premined_blocks = chain_downloader.load_from_file(chain_data_file)
    block = chain_downloader.get_block(premined_blocks, height=1)
    res = api.post_block(block)
    time.sleep(1)
    top = api.get_top()
    assert_equals(top.height, 1)
    assert_equals(top.pow, str(block.pow))
    assert_equals(top.state_hash, block.state_hash)
    assert_equals(top.txs_hash, block.txs_hash)
    assert_equals(top.version, block.version)
Пример #4
0
def test_block_post_3():
    """
    Test case for posting 3 blocks
    """
    api = common.external_api(node)
    top = api.get_top()
    ## ensure there is only genesis block
    assert_equals(top.height, 0)

    premined_blocks = chain_downloader.load_from_file(chain_data_file)
    for i in range(1, 4):
        block = chain_downloader.get_block(premined_blocks, height=i)
        api.post_block(block)
        time.sleep(1)
        top = api.get_top()
        # ensure block is accepted
        assert_equals(top.height, i)
        assert_equals(top.pow, str(block.pow))
        assert_equals(top.state_hash, block.state_hash)
        assert_equals(top.txs_hash, block.txs_hash)
        assert_equals(top.version, block.version)