-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
61 lines (49 loc) · 1.8 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const cp = require('child_process');
const process = require('process');
const fs = require('fs');
const hdkey = require('ethereumjs-wallet/hdkey');
const bip39 = require('bip39');
const TestRPC = require('ethereumjs-testrpc');
const ACCOUNTS = 100;
const ACCOUNTFUNDING = '0x33B2E3C9FD0804000000000'; // One billion Ether in Wei
const HDPATH = 'm/44\'/60\'/0\'/0/';
function generateAccounts(mnemonic, hdPathIndex, totalToGenerate, accumulatedAddrs) {
const hdwallet = hdkey.fromMasterSeed(bip39.mnemonicToSeed(mnemonic));
const node = hdwallet.derivePath(HDPATH + hdPathIndex.toString());
let wallet = node.getWallet();
const secretKey = wallet.getPrivateKeyString();
const address = wallet.getAddressString();
accumulatedAddrs.push({
secretKey,
address,
balance: ACCOUNTFUNDING,
});
const nextHDPathIndex = hdPathIndex + 1;
if (nextHDPathIndex === totalToGenerate) {
return accumulatedAddrs;
}
return generateAccounts(mnemonic, nextHDPathIndex, totalToGenerate, accumulatedAddrs);
}
// try {
// cp.execSync('npm run lint ./');
// } catch (err) {
// console.log(err.stdout.toString());
// process.exit(1);
// }
if (!fs.existsSync('secrets.json')) {
throw new Error('no secrets.json found.');
}
const secrets = JSON.parse(fs.readFileSync('secrets.json', 'utf8'));
const mnemonic = secrets.mnemonic;
const testRPCInput = { accounts: generateAccounts(mnemonic, 0, ACCOUNTS, []) };
TestRPC.server(testRPCInput).listen(8545);
const truffle = cp.spawn('truffle', ['test']);
truffle.stdout.on('data', (data) => {
process.stdout.write(data.toString());
});
truffle.stderr.on('data', (data) => {
process.stdout.write(data.toString());
});
truffle.on('exit', (code) => {
process.exit(code);
});