This document will go through the steps needed to test using Foundry. Currently, we use Foundry in the following capacity.
- Create a private network with our internal version of Geth.
- Deploy a smart contract to the private network.
- Test the smart contract on the private network.
- Create a transaction on the private network.
The steps to create a new project are as follows.
cd foundry/projects
.- Create a directory that captures your project:
mkdir local-private-network; cd local-private-network
. - Create a new foundry project:
forge init stateful
. - Follow the foundry documentation for writing smart contract tests.
You can choose to have custom deployments for your workflow. However, it is recommended to utilize Docker.
Below, you can find existing projects and their descriptions.
The purpose of this project is as follows:
- Compile the geth from the local source.
- Build a docker container with
ipld-eth-db
and another container for thelocal-private-network
. - Run the compiled version of geth.
- Deploy a smart contract to the private blockchain.
- Trigger a transaction on the newly deployed smart contract.
If you want to test your local geth code, do the following:
- Update the
related-directory-mapping.sh
file with the path to your local repositories. - cd
projects/local-private-network
. ./wrapper.sh
- This script will do all the heavy lifting for you. Run the flag with -h to see all the options it provides. Example Run command:../wrapper.sh -e remote -d local-db -v remove -u abdul -n alabaster.lan.vdb.to -p "../../../related-directory-mapping.sh"
- Keep an eye out for the outputs from the docker container.
- Enter the docker container and do as you please.
You will also notice that there are multiple docker compose files.
docker-compose.yml
- This pulls a published container.docker-compose-local-db.yml
- This will build the database image from the local repository, allowing you to test any changes.docker-compose-local-db-prom.yml
- This will build the database image from the local repository, allowing you to test any changes, and also start prometheus.
- If you want to build
geth
remotely, talk to Shane to create a user onalabaster
, (or any other server you want really). - The command to deploy the smart contract is:
forge create --keystore $(cat ~/transaction_info/CURRENT_ETH_KEYSTORE_FILE) --rpc-url http://127.0.0.1:8545 --constructor-args 1 --password $(cat ${ETHDIR}/config/password) --legacy /root/stateful/src/Stateful.sol:Stateful
- The command to create a transaction (which will create a new block) is:
cast send --keystore $(cat ~/transaction_info/CURRENT_ETH_KEYSTORE_FILE) --rpc-url http://127.0.0.1:8545 --password $(cat $(cat ~/transaction_info/ETHDIR)) --legacy $(cat ~/transaction_info/STATEFUL_TEST_DEPLOYED_ADDRESS) "inc()"
- To manually send a transaction (which will trigger the mining of a new block), simply run the following script:
~/transaction_info/NEW_TRANSACTION
.- This script is only populated after the
start-private-network.sh
script has completed successfully.
- This script is only populated after the
- The
Dockerfile
compilescast
andforge
. - The
foundry/projects/local-private-network/deploy-local-network.sh
file does most heavy lifting. It spins up geth and triggers various events. - The
foundry/projects/local-private-network/start-private-network.sh
file triggersdeploy-local-network.sh
. This file runs all the tests. - The
geth
node will stay running even after the tests are terminated. - If you are building the database locally and make change to the schema, you will have to remove the volume:
docker-compose down -v local-private-network_vdb_db_eth_server
. - If you wish to use a local
genesis.json
file, do not add thealloc
orextra_data
block. The start up script will do it for you.