aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-03-08 08:06:38 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:16 +0800
commit7b166837d3ded48874042347d356dc7e4e02f2c1 (patch)
tree01a112d68fa96408104feac985e8089702b09f81 /packages/contracts
parent3ff8a319c5460caaf9edc1bea68e807fe0611aaa (diff)
downloaddexon-sol-tools-7b166837d3ded48874042347d356dc7e4e02f2c1.tar
dexon-sol-tools-7b166837d3ded48874042347d356dc7e4e02f2c1.tar.gz
dexon-sol-tools-7b166837d3ded48874042347d356dc7e4e02f2c1.tar.bz2
dexon-sol-tools-7b166837d3ded48874042347d356dc7e4e02f2c1.tar.lz
dexon-sol-tools-7b166837d3ded48874042347d356dc7e4e02f2c1.tar.xz
dexon-sol-tools-7b166837d3ded48874042347d356dc7e4e02f2c1.tar.zst
dexon-sol-tools-7b166837d3ded48874042347d356dc7e4e02f2c1.zip
Add script for starting testrpc with preconfigured private keys
Diffstat (limited to 'packages/contracts')
-rw-r--r--packages/contracts/scripts/testrpc.ts43
-rw-r--r--packages/contracts/src/utils/constants.ts22
-rw-r--r--packages/contracts/src/utils/utils.ts7
3 files changed, 72 insertions, 0 deletions
diff --git a/packages/contracts/scripts/testrpc.ts b/packages/contracts/scripts/testrpc.ts
new file mode 100644
index 000000000..8379cc69c
--- /dev/null
+++ b/packages/contracts/scripts/testrpc.ts
@@ -0,0 +1,43 @@
+import * as testrpc from 'ganache-cli';
+import * as _ from 'lodash';
+
+import { constants } from '../src/utils/constants';
+import { utils } from '../src/utils/utils';
+
+const opts = {
+ accounts: constants.TESTRPC_ACCOUNTS,
+};
+
+const server = testrpc.server(opts);
+
+server.listen(constants.TESTRPC_PORT, (err: any, result: any) => {
+ if (err) {
+ utils.consoleLog(err);
+ return;
+ }
+
+ const state = result ? result : server.provider.manager.state;
+
+ utils.consoleLog('');
+ utils.consoleLog('Available Accounts');
+ utils.consoleLog('==================');
+
+ const accounts = state.accounts;
+ const addresses = _.keys(accounts);
+
+ _.forEach(addresses, (address, index) => {
+ const line = `(${index}) ${address}`;
+ utils.consoleLog(line);
+ });
+
+ utils.consoleLog('');
+ utils.consoleLog('Private Keys');
+ utils.consoleLog('==================');
+
+ _.forEach(addresses, (address, index) => {
+ utils.consoleLog(`(${index}) ${accounts[address].secretKey.toString('hex')}`);
+ });
+
+ utils.consoleLog('');
+ utils.consoleLog('Listening on localhost:' + constants.TESTRPC_PORT);
+});
diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts
index d1152e683..09dd65653 100644
--- a/packages/contracts/src/utils/constants.ts
+++ b/packages/contracts/src/utils/constants.ts
@@ -1,3 +1,5 @@
+import * as ethUtil from 'ethereumjs-util';
+
const DUMMY_TOKEN_NAME = '';
const DUMMY_TOKEN_SYMBOL = '';
const DUMMY_TOKEN_DECIMALS = 18;
@@ -11,4 +13,24 @@ export const constants = {
MAX_TOKEN_TRANSFERFROM_GAS: 80000,
MAX_TOKEN_APPROVE_GAS: 60000,
DUMMY_TOKEN_ARGS: [DUMMY_TOKEN_NAME, DUMMY_TOKEN_SYMBOL, DUMMY_TOKEN_DECIMALS, DUMMY_TOKEN_TOTAL_SUPPLY],
+ TESTRPC_PORT: 8545,
+ TESTRPC_INITIAL_BALANCE_HEX: parseInt('100000000000000000000', 16),
+ TESTRPC_ACCOUNTS: [
+ {
+ balance: this.TESTRPC_INITIAL_BALANCE_HEX,
+ secretKey: ethUtil.sha3('secret0'),
+ },
+ {
+ balance: this.TESTRPC_INITIAL_BALANCE_HEX,
+ secretKey: ethUtil.sha3('secret1'),
+ },
+ {
+ balance: this.TESTRPC_INITIAL_BALANCE_HEX,
+ secretKey: ethUtil.sha3('secret2'),
+ },
+ {
+ balance: this.TESTRPC_INITIAL_BALANCE_HEX,
+ secretKey: ethUtil.sha3('secret3'),
+ },
+ ],
};
diff --git a/packages/contracts/src/utils/utils.ts b/packages/contracts/src/utils/utils.ts
new file mode 100644
index 000000000..04ac36b54
--- /dev/null
+++ b/packages/contracts/src/utils/utils.ts
@@ -0,0 +1,7 @@
+export const utils = {
+ consoleLog(message: string): void {
+ /* tslint:disable */
+ console.log(message);
+ /* tslint:enable */
+ },
+};