Skip to content

Commit

Permalink
Merge pull request #2 from 0xEther/master
Browse files Browse the repository at this point in the history
Feat: Truffle tests to create DAI (MCD)
  • Loading branch information
ryanio committed Mar 10, 2020
2 parents 1600e80 + d3cac95 commit 60a4652
Show file tree
Hide file tree
Showing 10 changed files with 2,375 additions and 2,223 deletions.
File renamed without changes.
38 changes: 38 additions & 0 deletions DAI/test/dai.js
@@ -0,0 +1,38 @@
const {BN, ether, balance} = require("openzeppelin-test-helpers");
const {expect} = require("chai");
const {asyncForEach} = require("./utils");

// ABI
const daiABI = require("./abi/dai");

// userAddress must be unlocked using --unlock ADDRESS
// https://etherscan.io/token/0x6b175474e89094c44da98b954eedeac495271d0f#balances)
const userAddress = '0xdfbaf3e4c7496dad574a1b842bc85b402bdc298d';
// Dai
const daiAddress = '0x6b175474e89094c44da98b954eedeac495271d0f';
const daiContract = new web3.eth.Contract(daiABI, daiAddress);

contract("Truffle Mint Dai", async accounts => {
it("should send ether to the Dai address", async () => {
// Send 0.1 eth to userAddress to have gas to send an ERC20 tx.
// Uses ForceSend contract, otherwise just sending
// a normal tx will revert.
const amount = ether("0.01");
await web3.eth.sendTransaction({from: accounts[0], to: userAddress, value: amount})
const ethBalance = await balance.current(userAddress);
expect(new BN(ethBalance)).to.be.bignumber.least(new BN(ether("0.01")));
});

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 `transfer` method
await daiContract.methods
.transfer(account, '100000000000000000000')
.send({from: userAddress, gasLimit: 800000});
const daiBalance = await daiContract.methods.balanceOf(account).call();
expect(new BN(daiBalance)).to.be.bignumber.least(ether("100"));
});
});
});
File renamed without changes.
4 changes: 2 additions & 2 deletions truffle-config.js → DAI/truffle-config.js
Expand Up @@ -46,7 +46,7 @@ module.exports = {
//
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
port: 8546, // Standard Ethereum port (default: none)
network_id: "*" // Any network (default: none)
}

Expand Down Expand Up @@ -87,7 +87,7 @@ module.exports = {
// Configure your compilers
compilers: {
solc: {
// version: "0.5.1", // Fetch exact version from solc-bin (default: truffle's version)
version: "0.5.1", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
Expand Down
File renamed without changes.
325 changes: 325 additions & 0 deletions SAI/test/abi/erc20.js
@@ -0,0 +1,325 @@
module.exports = [
{
constant: true,
inputs: [],
name: "name",
outputs: [{ name: "", type: "bytes32" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [],
name: "stop",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{ name: "guy", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "approve",
outputs: [{ name: "", type: "bool" }],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [{ name: "owner_", type: "address" }],
name: "setOwner",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [],
name: "totalSupply",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [
{ name: "src", type: "address" },
{ name: "dst", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "transferFrom",
outputs: [{ name: "", type: "bool" }],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [],
name: "decimals",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [
{ name: "guy", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "mint",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [{ name: "wad", type: "uint256" }],
name: "burn",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [{ name: "name_", type: "bytes32" }],
name: "setName",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [{ name: "src", type: "address" }],
name: "balanceOf",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "stopped",
outputs: [{ name: "", type: "bool" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [{ name: "authority_", type: "address" }],
name: "setAuthority",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [],
name: "owner",
outputs: [{ name: "", type: "address" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [],
name: "symbol",
outputs: [{ name: "", type: "bytes32" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [
{ name: "guy", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "burn",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [{ name: "wad", type: "uint256" }],
name: "mint",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{ name: "dst", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "transfer",
outputs: [{ name: "", type: "bool" }],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{ name: "dst", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "push",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{ name: "src", type: "address" },
{ name: "dst", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "move",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [],
name: "start",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [],
name: "authority",
outputs: [{ name: "", type: "address" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [{ name: "guy", type: "address" }],
name: "approve",
outputs: [{ name: "", type: "bool" }],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [
{ name: "src", type: "address" },
{ name: "guy", type: "address" }
],
name: "allowance",
outputs: [{ name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [
{ name: "src", type: "address" },
{ name: "wad", type: "uint256" }
],
name: "pull",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
inputs: [{ name: "symbol_", type: "bytes32" }],
payable: false,
stateMutability: "nonpayable",
type: "constructor"
},
{
anonymous: false,
inputs: [
{ indexed: true, name: "guy", type: "address" },
{ indexed: false, name: "wad", type: "uint256" }
],
name: "Mint",
type: "event"
},
{
anonymous: false,
inputs: [
{ indexed: true, name: "guy", type: "address" },
{ indexed: false, name: "wad", type: "uint256" }
],
name: "Burn",
type: "event"
},
{
anonymous: false,
inputs: [{ indexed: true, name: "authority", type: "address" }],
name: "LogSetAuthority",
type: "event"
},
{
anonymous: false,
inputs: [{ indexed: true, name: "owner", type: "address" }],
name: "LogSetOwner",
type: "event"
},
{
anonymous: true,
inputs: [
{ indexed: true, name: "sig", type: "bytes4" },
{ indexed: true, name: "guy", type: "address" },
{ indexed: true, name: "foo", type: "bytes32" },
{ indexed: true, name: "bar", type: "bytes32" },
{ indexed: false, name: "wad", type: "uint256" },
{ indexed: false, name: "fax", type: "bytes" }
],
name: "LogNote",
type: "event"
},
{
anonymous: false,
inputs: [
{ indexed: true, name: "src", type: "address" },
{ indexed: true, name: "guy", type: "address" },
{ indexed: false, name: "wad", type: "uint256" }
],
name: "Approval",
type: "event"
},
{
anonymous: false,
inputs: [
{ indexed: true, name: "src", type: "address" },
{ indexed: true, name: "dst", type: "address" },
{ indexed: false, name: "wad", type: "uint256" }
],
name: "Transfer",
type: "event"
}
];

0 comments on commit 60a4652

Please sign in to comment.