vyperlang / titanoboa

a vyper interpreter
https://titanoboa.readthedocs.io
Other
251 stars 49 forks source link

Provide a higher-level API to manipulate forked-network state #204

Closed sajal closed 4 months ago

sajal commented 5 months ago

I would like a helper method to override account state, similar to hardhat_setStorageAt feature by hardhat. The use-case is when running in forking mode, I would like my tests to run thru various scenarios which is only possible by manipulating state of other contracts.

For now, I am able to do this by going lower-level and doing these against pyEVM directly. Here is an example where I set the balance of a given account to 5000 stETH

    abi_encoded = eth_abi.encode(['address', 'uint256'], [trader, 0])
    storage_slot = Web3.solidity_keccak(["bytes"], ["0x" + abi_encoded.hex()])

    boa.env.evm.vm.state.set_storage(
        boa.util.abi.Address(STETH).canonical_address,
        Web3.to_int(storage_slot),
        5000 * 10**18
    )