Take control of Maker, UniSwap and Compound with GodMode.

Benjamin Stanley
GodMode
Published in
3 min readJun 8, 2021
GodMode is an open-source Ethereum tool

GodMode is a development toolset allowing users to assume control of third-party contracts and protocols in Ethereum testing environments. Developers can fork mainnet and access and invoke methods on any contract therein, especially those not ordinarily accessible to them, permitting a much more robust integration testing for any smart contract suites they are making.

If you’re developing smart contracts, they likely integrate in some way to existing third-party protocols. For example, your smart contracts may interact with UniSwap or Maker. These interactions create dependencies on the expected function of those external smart contracts. But what if your external dependency begins to behave in unexpected ways (or even disappears completely)? What will your smart contract layer do? GodMode makes modelling these kinds of events easy, letting you adapt the behaviour of your application accordingly.

Thankfully, you won’t need to learn much extra technology: GodMode is built on Truffle and extends the functionality of Ganache using its own custom CLI, the GodMode Ganache CLI.

This article is a walkthrough of the GodMode Sample Project, showing how GodMode can access methods on both Custom and External (i.e. Third-party) contracts.

Pre-Reqs

You’ll need to install Truffle, the GodMode Ganache CLI and create an Infura Mainnet endpoint in addition to the GodMode Sample Project.

  1. Run $ npm install -g truffle on your dev machine.
  2. Create an Infura endpoint on your account on Mainnet. Note the Project ID from the Settings tab.
  3. Clone the GodMode Ganache CLI to your dev machine.
  4. Clone the Godmode Sample Project to your dev machine.

Custom Contracts

The Custom Contract demonstration is a simple implementation that runs on any local Ganache, allow us to execute a privileged function (flipping a boolean on a contract). There are two parties: Alex and Beth. As the controller of the contract, Alex begins by having the exclusive right to flip the boolean. In GodMode, Beth can assume this power.

  1. At a terminal in your godmode-ganache-cli folder (cloned in step 3 above), run $ npm run start.This command sets up the GodMode Ganache testing blockchain, which we’ll use for executing our demonstration.
  2. Open another terminal in your godmode-sample-projects folder (cloned in step 4 above). Run $ npm install to get the dependencies.
  3. In the same terminal, run $ truffle test test/CustomContracts.test.js.

Your system will execute the tests, and your output should end with something like this:

Test output from CustomContracts.test.js

At the start, Alex can flip the boolean and Beth is explicitly prohibited from doing so. As we see in GodMode, now Beth can flip it, too. So, now we’ve seen the fundamental principle in action, we can move onto something more meaningful: manipulating external contracts.

External Contracts

Here we demonstrate leveraging GodMode in minting DAI using Maker, amending the fee collector address on UniSwap and distributing Compound CTokens to an address of our choosing.

  1. At a terminal in your godmode-ganache-cli folder (as cloned in step 3 of the Pre-Reqs section) run $ export INFURA_PROJECT_ID=<your-infura-project-id> subbing in the Infura Project ID you created earlier. This creates a local variable that GodMode Ganache CLI will use to spin up a mainnet fork using your Infura account.
  2. In the same terminal, run $ npm run start-fork.The mainnet fork will startup.
  3. Open a second terminal in your godmode-sample-projects folder, then run $ npm install.
  4. Then, in the same terminal, run $ npx godmode install. This will install GodMode’s library of external contracts, allowing you to take control of Maker, UniSwap and Compound.
  5. Finally, in the same terminal, run $ truffle test test/ExternalContracts.test.js.

Your output should look end with something like this:

Test output from ExternalContracts.test.js

As you can see, we’ve successfully executed methods on the three external protocols to which we ordinarily don’t have access.

--

--

Benjamin Stanley
GodMode
Writer for

Ethereum Smart Contract dude. Brit in Paris. Founder of SureVX and GodMode.