Ejemplo n.º 1
0
def test_add_longer_side_chain(db, alt_db):
    """"
    Local: L0, L1, L2
    Remote: R0, R1, R2, R3
    """
    k, v, k2, v2 = accounts()
    # Remote: mine three blocks
    chainR = Chain({v: {"balance": utils.denoms.ether * 1}}, difficulty=1)
    remote_blocks = []
    for i in range(3):
        tx = get_transaction(nonce=i)
        blk = mine_next_block(chainR, transactions=[tx])
        remote_blocks.append(blk)
    # Local: mine two blocks
    chainL = Chain({v: {"balance": utils.denoms.ether * 1}}, difficulty=1)
    tx0 = get_transaction(nonce=0)
    L1 = mine_next_block(chainL, transactions=[tx0])
    tx1 = get_transaction(nonce=1)
    L2 = mine_next_block(chainL, transactions=[tx1])

    # receive serialized remote blocks, newest first
    rlp_blocks = [rlp.encode(x) for x in remote_blocks]
    for rlp_block in rlp_blocks:
        block = rlp.decode(rlp_block, Block)
        chainL.add_block(block)

    assert chainL.head == remote_blocks[-1]
Ejemplo n.º 2
0
def test_add_side_chain(db, alt_db):
    """"
    Local: L0, L1, L2
    add
    Remote: R0, R1
    """
    k, v, k2, v2 = accounts()
    # Remote: mine one block
    chainR = Chain({v: {"balance": utils.denoms.ether * 1}}, difficulty=1)
    tx0 = get_transaction(nonce=0)
    R1 = mine_next_block(chainR, transactions=[tx0])
    assert tx0.hash in [x.hash for x in R1.transactions]

    # Local: mine two blocks
    chainL = Chain({v: {"balance": utils.denoms.ether * 1}}, difficulty=1)
    tx0 = get_transaction(nonce=0)
    L1 = mine_next_block(chainL, transactions=[tx0])
    tx1 = get_transaction(nonce=1)
    L2 = mine_next_block(chainL, transactions=[tx1])

    # receive serialized remote blocks, newest first
    rlp_blocks = [rlp.encode(R1)]
    for rlp_block in rlp_blocks:
        block = rlp.decode(rlp_block, Block)
        chainL.add_block(block)

    assert L2.hash in chainL
    assert chainL.head == L2