Skip to main content
Version: 1.3.1

Getting Started

Dependencies

This guide is mainly geared towards Unix users. For Windows users I recommend using Windows Subsystem for Linux to run everything.

Getting started

The Simulation Modules use Poetry to manage dependencies. To get set up with all the required dependencies, run:

pip install poetry
poetry install

To run the program you can run the command:

poetry run python -m simulations --run-id local --yaml-file ./config/configuration.yaml

This command will initially throw an error because we don't have a State Machine ready to connect to. It is expected that the state machine is available over a RPC-JSON connection on address 0.0.0.0 and port 8545. On a UNIX native machine it's fairly easy to run Anvil (EVM) as follows:

anvil -f https://rpc-mainnet-ethereum.forbole.com?apikey=H4y9w5SrqhcbhpfspD4Om/vdSUsWr42XDlju8UfIZP4= --fork-block-number 16600000 --balance 99999999999 --no-storage-caching --no-mining --order fifo

Once you have this system running you can try to run the program again using the command above. You'll see that it will now connect to the State Machine and starts to send transactions for the Bancor project. The Bancor project is currently the testcase that has been defined in config/configuration.yaml.

Troubleshooting

A hard part of EVMs is the troubleshooting. EVMs by default don't give much info on why a call to a contract failed, expecially when custom error objects are used to throw exceptions.

So as you can imagine it's sometimes hard to figure out what is causing an error. There are limited options when it comes to getting more insight into the error. One big part is to use Hardhat instead of Anvil temporarily to run as the EVM. One caviat is that the project needs to have configuration available for Hardhat, you can easily verify this by seeing if there's a file called hardhat.config.ts in the main directory. Most projects use this for testing though so there's a big chance that it's there.

The way to do this is pretty precise, you need to run Hardhat in the directory where the contracts are stored for the project that you're running into issues for. So for example for Bancor you would need to download the contracts-v3 repo and run Hardhat in the Terminal from the contracts-v3 directory.

The command to run Hardhat is

hardhat node --fork https://rpc-mainnet-ethereum.forbole.com?apikey=H4y9w5SrqhcbhpfspD4Om/vdSUsWr42XDlju8UfIZP4= --fork-block-number 16100000 --no-deploy

When you then run the simulation stack against it with the above mentioned command you should get more precise error messages. (Please note that the simulation will be significantly slower due to the Hardhat being used).

Common Errors

  • Gas

Gas will be a common issue when it comes to EVM. Due to this being a simulation we have to take gas into account, so when you run into an error related to gas and not having enough ETH to pay for it the easiest solution is to send some ETH from one of the 10 main accounts that automatically get generated to the address you want to send a transaction from. There currently is a function that you can call that will automatically give someone some ETH to pay for gas fees you can find that function at simulations/statemachine/evm/anvil.py:61.

  • Impersonate account

Impersonation is necessary to skip the authentication layer of the EVM. It is necessary to ask the EVM to impersonate an account before you can send a transaction from it, otherwise you will get an error. There is also the option of automatically impersonating all accounts using the anvil_autoImpersonateAccount RPC command. This is already included in the project so you shouldn't have this issue, but if for some reason you run into this issue you can see if it's still set correctly at simulations/statemachine/evm/anvil.py:33.