Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #192 from grandizzy/generate_dai_script
Browse files Browse the repository at this point in the history
Add script to generate DAI for given testchain address
  • Loading branch information
levity authored Dec 10, 2019
2 parents e8ae55b + 612a456 commit fca5e17
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/test-helpers/scripts/generateDai.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// usage:
// > node_modules/.bin/babel-node packages/test-helpers/scripts/generateDai.js <address> <daiAmount>

import { isAddress } from 'web3-utils';
import { MDAI, ETH } from '@makerdao/dai-plugin-mcd/src/index';
import { mcdMaker } from '@makerdao/dai-plugin-mcd/test/helpers';

async function main() {
const maker = await mcdMaker();
const address = process.argv[process.argv.length - 2];
const amount = process.argv[process.argv.length - 1];
if (!isAddress(address)) {
console.log('Pass a valid address as the last argument.');
return;
}

maker.service('accounts').useAccountWithAddress(address);
console.log(`Generating ${amount} MDAI for ${address}`);
const cdpMgr = maker.service('mcd:cdpManager');

await cdpMgr.openLockAndDraw('ETH-A', ETH(1), MDAI(amount));

const dai = cdpMgr.get('token').getToken(MDAI);
const balance = await dai.balanceOf(address)
console.log(`Balance of ${address}: ${balance}`)

}

(async fn => {
try {
await fn();
process.exit();
} catch (err) {
console.error(err);
process.exit(1);
}
})(main);

0 comments on commit fca5e17

Please sign in to comment.