How to mock MakerDao and DAI to create a Dev environment for building Defi products?

@Dennison_Bertram asked on Twitter:

You can use --fork in ganache-cli to fork from an Ethereum network (e.g. mainnet).

You can also use --unlock, and ganache-cli will unlock the accounts so that you can send transactions from those addresses, even if you don’t have the private key.

(Thanks @nventuro :pray:)

ganache-cli documentation: https://github.com/trufflesuite/ganache-cli

"fork" : string or object - Fork from another currently running Ethereum client at a given block. When a string , input should be the HTTP location and port of the other client, e.g. http://localhost:8545 . You can optionally specify the block to fork from using an @ sign: http://localhost:8545@1599200 . Can also be a Web3 Provider object, optionally used in conjunction with the fork_block_number option below.

-u or --unlock : Specify --unlock ... any number of times passing either an address or an account index to unlock specific accounts. When used in conjunction with --secure , --unlock will override the locked state of specified accounts.

$ ganache-cli --secure --unlock "0x1234..." --unlock "0xabcd..."

This feature can also be used to impersonate accounts and unlock addresses you wouldn’t otherwise have access to. When used with the --fork feature, you can use ganache-cli to make transactions as any address on the blockchain, which is very useful for testing and dynamic analysis.

2 Likes

Have you checked https://github.com/makerdao/testchain/blob/dai.js/README.md ?

1 Like

The ganache-cli fork functionality is useful. Either way, you can mint DAI on the test networks yourself:

var rinkebyDai = "0x5592EC0cfb4dbc12D3aB100b257153436a1f0FEa";
const daiAmount =  "10000000000000000000000";

module.exports = async function(deployer, network, accounts) {
  if (network == "rinkeby") {
    let dai = await IDai.at(rinkebyDai);
    await dai.allocateTo(accounts[0], daiAmount);
  }
}
3 Likes