Example #1
0
def test_reward_uncles(db):
    """
    B0 B1 B2
    B0 Uncle

    We raise the block's coinbase account by Rb, the block reward,
    and also add uncle and nephew rewards
    """
    k, v, k2, v2 = accounts()
    chain = Chain({}, difficulty=1)
    blk0 = mine_on_chain(chain, coinbase=decode_hex('0' * 40))
    local_coinbase = decode_hex('1' * 40)
    uncle_coinbase = decode_hex('2' * 40)
    # Mine the uncle
    uncle = mine_on_chain(chain, blk0, coinbase=uncle_coinbase)
    assert chain.state.get_balance(
        uncle_coinbase) == 1 * chain.env.config['BLOCK_REWARD']
    # Mine the first block in the "intended main chain"
    blk1 = mine_on_chain(chain, blk0, coinbase=local_coinbase)
    # next block should reward uncles
    blk2 = mine_on_chain(chain, blk1, coinbase=local_coinbase)
    # print [x.hash for x in chain.get_chain()], [blk0.hash, uncle.hash,
    # blk1.hash, blk2.hash]
    assert blk1.hash in chain
    assert uncle.header.hash in [u.hash for u in blk2.uncles]
    assert chain.head == blk2
    assert chain.get_chain() == [blk0, blk1, blk2]
    assert chain.state.get_balance(local_coinbase) == \
        2 * chain.env.config['BLOCK_REWARD'] + \
        chain.env.config['NEPHEW_REWARD']
    assert chain.state.get_balance(
        uncle_coinbase) == chain.env.config['BLOCK_REWARD'] * 7 // 8
Example #2
0
def test_genesis_chain(db):
    k, v, k2, v2 = accounts()
    chain = Chain({v: {"balance": utils.denoms.ether * 1}}, difficulty=1)
    blk = mine_on_chain(chain)
    print('blook', blk)

    assert chain.has_block(blk.hash)
    assert blk.hash in chain
    assert chain.get_block(blk.hash) == blk
    assert chain.head == blk
    assert chain.get_children(blk) == []
    assert chain.get_chain() == [blk]
    assert chain.get_block_by_number(1)
    assert not chain.get_block_by_number(2)
    assert chain.get_block_by_number(1) == blk
Example #3
0
def test_simple_chain(db):
    k, v, k2, v2 = accounts()
    chain = Chain({v: {"balance": utils.denoms.ether * 1}}, difficulty=1)
    tx = get_transaction()
    blk2 = mine_next_block(chain, transactions=[tx])
    blk3 = mine_next_block(chain)

    assert blk2.hash in chain
    assert blk3.hash in chain
    assert chain.has_block(blk2.hash)
    assert chain.has_block(blk3.hash)
    assert chain.get_block(blk2.hash) == blk2
    assert chain.get_block(blk3.hash) == blk3
    assert chain.head == blk3
    assert chain.get_children(blk2) == [blk3]

    assert chain.get_chain() == [blk2, blk3]

    assert chain.get_block_by_number(1) == blk2
    assert chain.get_block_by_number(2) == blk3
    assert not chain.get_block_by_number(3)
    assert chain.get_tx_position(tx.hash) == (blk2.number, 0)