Last active
December 30, 2020 22:39
-
-
Save ryanio/25d82d6127a23e50b035bc1734f72996 to your computer and use it in GitHub Desktop.
Minting Dai in a Truffle Test Suite with Forked Mainnet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { BN, ether, balance } = require("openzeppelin-test-helpers"); | |
const { expect } = require("chai"); | |
const { asyncForEach } = require("./utils"); | |
// Artifacts | |
const ForceSend = artifacts.require("ForceSend"); | |
// ABI | |
const erc20ABI = require("./abi/erc20"); | |
// Dai | |
const daiAddress = "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359"; | |
const daiContract = new web3.eth.Contract(erc20ABI, daiAddress); | |
// Utils | |
const getDaiBalance = async account => { | |
return daiContract.methods.balanceOf(account).call(); | |
}; | |
contract("Truffle Mint Dai", async accounts => { | |
it("should send ether to the Dai contract", async () => { | |
// Send 1 eth to daiAddress to have gas to mint. | |
// Uses ForceSend contract, otherwise just sending | |
// a normal tx will revert. | |
const forceSend = await ForceSend.new(); | |
await forceSend.go(daiAddress, { value: ether("1") }); | |
const ethBalance = await balance.current(daiAddress); | |
expect(new BN(ethBalance)).to.be.bignumber.least(new BN(ether("1"))); | |
}); | |
it("should mint Dai for our first 5 generated accounts", async () => { | |
// Get 100 Dai for first 5 accounts | |
await asyncForEach(accounts.slice(0, 5), async account => { | |
// daiAddress is passed to ganache-cli with flag `--unlock` | |
// so we can use the `mint` method. | |
await daiContract.methods | |
.mint(account, ether("100").toString()) | |
.send({ from: daiAddress }); | |
const daiBalance = await getDaiBalance(account); | |
expect(new BN(daiBalance)).to.be.bignumber.least(ether("100")); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://github.com/ryanio/truffle-mint-dai