This library provides a truffle framework friendly api that allows developers to use the "GodMode Ganache" within the javascript testing environment provided in the truffle framework. The library also pre-compiles GodMode contracts for popular defi projects such as MakerDao, Uniswap, and Compound. It provides an easy way to modify the state of the projects through a set of API.
Join our Discord to learn more.
npm install --save-dev @xgm/godmode
You will also need to install truffle so godmode can compile its contracts:
npm install -g truffle
When using this library, you need to run GodMode ganache as well.
To see a sample project that uses this library, see this repo:
In your javascript test file, import the library
const GM = require('@xgm/godmode');
Initialize it with the provider, which should be the GodMode Ganache (referenced above). The first argument indicates the network name -- use mainnet
if you want to use pre-compiled contracts.
let GODMODE = new GM('development', 'ws://localhost:8545');
await GODMODE.executeAs(
targetContract,
replacementContractArtifact,
'function_In_RC',
/* some arguments for the function */
{ from: Bob } // Transaction meta info
);
Variable explanation:
targetContract
is the deployed contract, for example:- the
hasOwnerShipContract
inhasOwnerShipContract = await HasOwnerShip.new({ from: Alice });
.
- the
replacementContractArtifact
is the contract artifact produced by truffle, for example:- the
HasOwnerShipInstrumented
inconst HasOwnerShipInstrumented = artifacts.require("HasOwnerShipInstrumented");
- the
function_In_RC
is the function that was defined in the replacementContractArtifact.
IMPORTANT: this only works on mainnet fork
When you install a protocol, all of the contracts for that protocol will be stored in your build/protocols
directory.
- Install all GM protocols
npx godmode install --all
- Install protocols from command line
npx godmode install --protocols Maker Compound
- Install protocols from package.json
"godmode": {
"protocols": [
"Maker",
"Compound"
]
}
npx godmode install
- Mint DAI to an address:
await GODMODE.mintDai(Bob, 10000);
- Enable Fee collection in UniswapV2:
await GODMODE.uniswapV2Factory_setFeeTo(Bob);
- Give the address cTokens:
await GODMODE.CToken_giveAddrTokens("0x6c8c6b02e7b2be14d4fa6022dfd6d75921d90e4e", Bob, 100);
Tests are written in mocha.
Test the core GM class with npm run test:core
.
Test GM contract interactions with npm run test:contracts
.
Fork this repo and create a descriptive PR.
GodMode is in alpha so releases may be frequent. Core devs should create releases after merging in new features by running
npm run dist && npm run release
This will ask you for the release version, then automatically create a release and publish it to npm.