示例#1
0
文件: test_vm.py 项目: ccniuj/py-evm
def test_state_db(chain_without_block_validation):  # noqa: F811
    vm = chain_without_block_validation.get_vm()
    address = decode_hex('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0c')
    initial_state_root = vm.block.header.state_root

    with vm.state_db(read_only=True) as state_db:
        state_db.get_balance(address)
    assert vm.block.header.state_root == initial_state_root

    with vm.state_db() as state_db:
        state_db.set_balance(address, 10)
    assert vm.block.header.state_root != initial_state_root

    with pytest.raises(AssertionError):
        with vm.state_db(read_only=True) as state_db:
            state_db.set_balance(address, 0)
示例#2
0
def test_state_db(chain_without_block_validation):  # noqa: F811
    vm = chain_without_block_validation.get_vm()
    address = decode_hex('0xa94f5374fce5edbc8e2a8697c15331677e6ebf0c')
    initial_state_root = vm.block.header.state_root

    # test cannot write to state_db after context exits
    with vm.state_db() as state_db:
        pass

    with pytest.raises(TypeError):
        state_db.increment_nonce(address)

    with vm.state_db(read_only=True) as state_db:
        state_db.get_balance(address)
    assert vm.block.header.state_root == initial_state_root

    with vm.state_db() as state_db:
        state_db.set_balance(address, 10)
    assert vm.block.header.state_root != initial_state_root

    with vm.state_db(read_only=True) as state_db:
        with pytest.raises(TypeError):
            state_db.set_balance(address, 0)
示例#3
0
def state(chain_without_block_validation):
    return chain_without_block_validation.get_vm().state
示例#4
0
def state(chain_without_block_validation):
    return chain_without_block_validation.get_vm().state
示例#5
0
def state(chain_without_block_validation):
    state = chain_without_block_validation.get_vm().state
    with state.mutable_state_db() as state_db:
        state_db.set_balance(CANONICAL_ADDRESS_A, 1000)
    return state
def state(chain_without_block_validation):
    state = chain_without_block_validation.get_vm().state
    with state.state_db() as state_db:
        state_db.set_balance(CANONICAL_ADDRESS_A, 1000)
    return state