anvil utils is a library that provides cheating functionality executed in anvil foundry for interacting with account, transaction especially erc20 and erc721 token
To use this library, you need to install anvil foundry first. (see this link)
TL;DR:
curl -L https://foundry.paradigm.xyz | bash
foundryup
Import:
import github.com/haupc/anvilutils
- Write Erc20 balance
- Write native balance
- Set Erc20 approval
- Set code for address
- Start impersonate an address
- Stop impersonate an address
- Impersonate a txn(require impersonate account)
- Impersonate and make only 1 txn
- Take Erc721 token from another account
- Set approve Erc721 token
You can run anvil separately or use forkCmd to run an anvil chain.
// if you want to fork on test code, you can use fork command
// otherwise, you can run anvil separately then call setup cheats
forkCmd, err := anvilutils.NewForkCommand(ForkOpts{})
if err != nil {
// do something with err
}
forkUrl, err := forkCmd.Start()
if err != nil {
// do something with err
}
// setup client for anvil node
client := client.NewClient(forkUrl)
cheat := anvilutils.NewCheat(client)
cheat.WriteErc20Balance(helper.DummyContract, helper.DummyAccount, big.NewInt(1234567890123))
// call api, do everything for testing
// do something with onchain data using client.GlobalClient
// to sop fork
forkCmd.Stop()