Skip to content

Utilities build on top of anvil foundry for txn testing

License

Notifications You must be signed in to change notification settings

Haupc/anvilutils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference Go Report Card Go Coverage Badge

anvil utils

anvil utils is a library that provides cheating functionality executed in anvil foundry for interacting with account, transaction especially erc20 and erc721 token

installation

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

cheat code:

  • 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

How to Use:

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()

About

Utilities build on top of anvil foundry for txn testing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages