From 813523fe585c1b88e2ab89108fc8b39413687947 Mon Sep 17 00:00:00 2001 From: JhChoy Date: Tue, 22 Jan 2019 17:19:28 +0900 Subject: [PATCH] feat: #61 Allow to set private key --- CONFIGURATION-ko.md | 2 + CONFIGURATION.md | 2 + ...emonicToPrivateKey.js => getPrivateKey.js} | 5 ++ packages/vvisp-utils/src/index.js | 4 +- packages/vvisp-utils/test/deploy.test.js | 4 +- .../vvisp-utils/test/getPrivateKey.test.js | 71 +++++++++++++++++++ .../test/mnemonicToPrivateKey.test.js | 64 ----------------- .../test/privateKeyToAddress.test.js | 6 +- .../test/utils/filterPrivateKey.test.js | 4 +- packages/vvisp/bin/error.js | 4 +- packages/vvisp/scripts/deploy-contract.js | 4 +- .../vvisp/scripts/deploy-service/constants.js | 7 +- packages/vvisp/template/script.mustache | 4 +- packages/vvisp/test/bin/error.test.js | 45 +++++++++--- .../testContractApis/back/js/HaechiV1.js | 11 +-- .../test/scripts/abi-to-script/index.test.js | 4 +- .../test/scripts/deploy-contract.test.js | 13 +++- .../test/scripts/deploy-service/index.test.js | 4 +- packages/vvisp/test/scripts/init.test.js | 4 +- 19 files changed, 153 insertions(+), 109 deletions(-) rename packages/vvisp-utils/src/{mnemonicToPrivateKey.js => getPrivateKey.js} (84%) create mode 100644 packages/vvisp-utils/test/getPrivateKey.test.js delete mode 100644 packages/vvisp-utils/test/mnemonicToPrivateKey.test.js diff --git a/CONFIGURATION-ko.md b/CONFIGURATION-ko.md index 419d11e..dc68de7 100644 --- a/CONFIGURATION-ko.md +++ b/CONFIGURATION-ko.md @@ -19,6 +19,7 @@ vvisp는 `.env` file에 작성된 환경 변수들을 [`process.env`](https://no - `GAS_LIMIT`: 트랙잭션 발생시 설정하고자 하는 gas limit입니다. 기본값은 4600000입니다. - `SOLC_VERSION`: 사용하고자 하는 컴파일러 버전을 입력합니다. 특정 버전 입력시 네트워크와의 통신이 필요하며, 입력 값이 없을 경우 vvisp에 내장된 로컬 solc를 사용합니다. - `SOLC_OPTIMIZATION`: compile 최적화를 원하지 않는다면 false를 입력하십시오. 기본 값은 true입니다. +- `PRIVATE_KEY`: private key *주의: 이 옵션은 MNEMONIC 옵션을 덮어씁니다* ### Examples @@ -32,6 +33,7 @@ GAS_PRICE= 20000000000 // 20Gwei GAS_LIMIT= 5000000 // 500만 SOLC_VERSION= // 내장된 컴파일러를 사용합니다. SOLC_OPTIMIZATION= // 최적화를 사용합니다. +PRIVATE_KEY= // private key // private key // private key // private key ``` ## service.vvisp.json diff --git a/CONFIGURATION.md b/CONFIGURATION.md index f5c7e8a..c5435f9 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -19,6 +19,7 @@ We use [dotenv](/~https://github.com/motdotla/dotenv) that loads environment varia - `GAS_LIMIT`: The gas limit to pay for transactions. Default is 4600000. - `SOLC_VERSION`: The version of solc compiler version you want to use and it needs network communication. You can keep it empty to use local compiler in vvisp. - `SOLC_OPTIMIZATION`: If you don't want to optimize compile, set this false. Default is true. +- PRIVATE_KEY: private key for specific account. *IT OVERRIDES MNEMONIC OPTIONS!!!* ### Example @@ -32,6 +33,7 @@ GAS_PRICE= 20000000000 // 20Gwei GAS_LIMIT= 5000000 // 5 million SOLC_VERSION= // Use local compiler SOLC_OPTIMIZATION= // Use optimization +PRIVATE_KEY= // private key ``` diff --git a/packages/vvisp-utils/src/mnemonicToPrivateKey.js b/packages/vvisp-utils/src/getPrivateKey.js similarity index 84% rename from packages/vvisp-utils/src/mnemonicToPrivateKey.js rename to packages/vvisp-utils/src/getPrivateKey.js index 1b04cd6..6c24492 100644 --- a/packages/vvisp-utils/src/mnemonicToPrivateKey.js +++ b/packages/vvisp-utils/src/getPrivateKey.js @@ -1,4 +1,9 @@ module.exports = function(mnemonic, index) { + if (process.env.PRIVATE_KEY) { + if (process.env.PRIVATE_KEY.slice(0, 2) === '0x') + return process.env.PRIVATE_KEY.slice(2); + else return process.env.PRIVATE_KEY; + } if (!index) { index = 0; } diff --git a/packages/vvisp-utils/src/index.js b/packages/vvisp-utils/src/index.js index 7a46972..f2a3ce2 100644 --- a/packages/vvisp-utils/src/index.js +++ b/packages/vvisp-utils/src/index.js @@ -8,7 +8,7 @@ const getCompiledContracts = require('./getCompiledContracts'); const getCycle = require('./getCycle'); const getTxCount = require('./getTxCount'); const getWeb3 = require('./getWeb3'); -const mnemonicToPrivateKey = require('./mnemonicToPrivateKey'); +const getPrivateKey = require('./getPrivateKey'); const printOrSilent = require('./printOrSilent'); const privateKeyToAddress = require('./privateKeyToAddress'); const sendTx = require('./sendTx'); @@ -29,7 +29,7 @@ module.exports = { getCycle, getTxCount, getWeb3, - mnemonicToPrivateKey, + getPrivateKey, printOrSilent, privateKeyToAddress, sendTx, diff --git a/packages/vvisp-utils/test/deploy.test.js b/packages/vvisp-utils/test/deploy.test.js index f0a23fa..c685de5 100644 --- a/packages/vvisp-utils/test/deploy.test.js +++ b/packages/vvisp-utils/test/deploy.test.js @@ -7,7 +7,7 @@ const { deploy, getCompiledContracts, getWeb3, - mnemonicToPrivateKey, + getPrivateKey, privateKeyToAddress } = require('../src'); const web3 = getWeb3(); @@ -19,7 +19,7 @@ const ARRAY_INPUT_CONTRACT = path.join( '../contracts/DependencyD.sol' ); const NO_INPUT_CONTRACT = path.join(__dirname, '../contracts/SecondB.sol'); -const PRIV_KEY = mnemonicToPrivateKey(process.env.MNEMONIC); +const PRIV_KEY = getPrivateKey(process.env.MNEMONIC); const SENDER = privateKeyToAddress(PRIV_KEY); describe('# deploy test', function() { diff --git a/packages/vvisp-utils/test/getPrivateKey.test.js b/packages/vvisp-utils/test/getPrivateKey.test.js new file mode 100644 index 0000000..438cc58 --- /dev/null +++ b/packages/vvisp-utils/test/getPrivateKey.test.js @@ -0,0 +1,71 @@ +const chai = require('chai'); +const expect = chai.expect; +chai.should(); + +const { getPrivateKey } = require('../src'); + +const MNEMONIC = + 'away clutch still element short tooth spy hood army split stomach sail'; + +describe('# getPrivateKey test', function() { + describe('# input arguments', function() { + it('should reject when mnemonic is not string', function() { + expect(() => getPrivateKey(undefined)).to.throw(TypeError); + expect(() => getPrivateKey(null)).to.throw(TypeError); + expect(() => getPrivateKey(123)).to.throw(TypeError); + expect(() => getPrivateKey({ a: 1 })).to.throw(TypeError); + expect(() => getPrivateKey(['hello', 'there'])).to.throw(TypeError); + }); + it('should reject when length of mnemonic is not 12', function() { + const mnemonic11 = + 'away clutch still element short tooth spy hood army split stomach'; + const mnemonic13 = + 'away clutch still element short tooth spy hood army split stomach sail still'; + expect(() => getPrivateKey('')).to.throw(TypeError); + expect(() => getPrivateKey(mnemonic11)).to.throw(TypeError); + expect(() => getPrivateKey(mnemonic13)).to.throw(TypeError); + }); + it('should reject when index is not number except undefined and null', function() { + expect(() => getPrivateKey(MNEMONIC, '123')).to.throw(TypeError); + expect(() => getPrivateKey(MNEMONIC, { a: 1 })).to.throw(TypeError); + expect(() => getPrivateKey(MNEMONIC, ['hello', 'there'])).to.throw( + TypeError + ); + }); + it('should set 0 when index is undefined or null', function() { + const nullIndex = getPrivateKey(MNEMONIC, null); + const undefinedIndex = getPrivateKey(MNEMONIC, undefined); + const noIndex = getPrivateKey(MNEMONIC); + const normalIndex = getPrivateKey(MNEMONIC, 0); + nullIndex.should.equal(normalIndex); + undefinedIndex.should.equal(normalIndex); + noIndex.should.equal(normalIndex); + }); + }); + describe('# return value', function() { + it('should be a string', function() { + const result = getPrivateKey(MNEMONIC); + result.should.a('string'); + }); + it('should have 64 length', function() { + const result = getPrivateKey(MNEMONIC); + result.should.have.lengthOf(64); + }); + it('should be different when indexes are different', function() { + const result0 = getPrivateKey(MNEMONIC, 0); + const result1 = getPrivateKey(MNEMONIC, 1); + result0.should.not.equal(result1); + }); + }); + describe('private key enable', function() { + before(function() { + process.env.MNEMONIC = ''; + process.env.PRIVATE_KEY = + '9741fa712a6912b862c9043f8752ffae513cb01895985998c61620da5aaf2d2d'; + }); + it('should pass when private key given', function() { + const result = getPrivateKey(); + result.should.equal(process.env.PRIVATE_KEY); + }); + }); +}); diff --git a/packages/vvisp-utils/test/mnemonicToPrivateKey.test.js b/packages/vvisp-utils/test/mnemonicToPrivateKey.test.js deleted file mode 100644 index ddb7c07..0000000 --- a/packages/vvisp-utils/test/mnemonicToPrivateKey.test.js +++ /dev/null @@ -1,64 +0,0 @@ -const chai = require('chai'); -const expect = chai.expect; -chai.should(); - -const { mnemonicToPrivateKey } = require('../src'); - -const MNEMONIC = - 'away clutch still element short tooth spy hood army split stomach sail'; - -describe('# mnemonicToPrivateKey test', function() { - describe('# input arguments', function() { - it('should reject when mnemonic is not string', function() { - expect(() => mnemonicToPrivateKey(undefined)).to.throw(TypeError); - expect(() => mnemonicToPrivateKey(null)).to.throw(TypeError); - expect(() => mnemonicToPrivateKey(123)).to.throw(TypeError); - expect(() => mnemonicToPrivateKey({ a: 1 })).to.throw(TypeError); - expect(() => mnemonicToPrivateKey(['hello', 'there'])).to.throw( - TypeError - ); - }); - it('should reject when length of mnemonic is not 12', function() { - const mnemonic11 = - 'away clutch still element short tooth spy hood army split stomach'; - const mnemonic13 = - 'away clutch still element short tooth spy hood army split stomach sail still'; - expect(() => mnemonicToPrivateKey('')).to.throw(TypeError); - expect(() => mnemonicToPrivateKey(mnemonic11)).to.throw(TypeError); - expect(() => mnemonicToPrivateKey(mnemonic13)).to.throw(TypeError); - }); - it('should reject when index is not number except undefined and null', function() { - expect(() => mnemonicToPrivateKey(MNEMONIC, '123')).to.throw(TypeError); - expect(() => mnemonicToPrivateKey(MNEMONIC, { a: 1 })).to.throw( - TypeError - ); - expect(() => mnemonicToPrivateKey(MNEMONIC, ['hello', 'there'])).to.throw( - TypeError - ); - }); - it('should set 0 when index is undefined or null', function() { - const nullIndex = mnemonicToPrivateKey(MNEMONIC, null); - const undefinedIndex = mnemonicToPrivateKey(MNEMONIC, undefined); - const noIndex = mnemonicToPrivateKey(MNEMONIC); - const normalIndex = mnemonicToPrivateKey(MNEMONIC, 0); - nullIndex.should.equal(normalIndex); - undefinedIndex.should.equal(normalIndex); - noIndex.should.equal(normalIndex); - }); - }); - describe('# return value', function() { - it('should be a string', function() { - const result = mnemonicToPrivateKey(MNEMONIC); - result.should.a('string'); - }); - it('should have 64 length', function() { - const result = mnemonicToPrivateKey(MNEMONIC); - result.should.have.lengthOf(64); - }); - it('should be different when indexes are different', function() { - const result0 = mnemonicToPrivateKey(MNEMONIC, 0); - const result1 = mnemonicToPrivateKey(MNEMONIC, 1); - result0.should.not.equal(result1); - }); - }); -}); diff --git a/packages/vvisp-utils/test/privateKeyToAddress.test.js b/packages/vvisp-utils/test/privateKeyToAddress.test.js index fc6d359..72199b5 100644 --- a/packages/vvisp-utils/test/privateKeyToAddress.test.js +++ b/packages/vvisp-utils/test/privateKeyToAddress.test.js @@ -1,14 +1,14 @@ const chai = require('chai'); chai.should(); -const { privateKeyToAddress, mnemonicToPrivateKey } = require('../src'); +const { privateKeyToAddress, getPrivateKey } = require('../src'); const MNEMONIC = 'away clutch still element short tooth spy hood army split stomach sail'; describe('# privateKeyToAddress test', function() { before(function() { - this.privateKey = mnemonicToPrivateKey(MNEMONIC); + this.privateKey = getPrivateKey(MNEMONIC); }); describe('# return value', function() { it('should be a string type', function() { @@ -34,7 +34,7 @@ describe('# privateKeyToAddress test', function() { const MNEMONIC2 = 'away clutch still element short sail spy hood army split stomach sail'; const return1 = privateKeyToAddress(this.privateKey); - const return2 = privateKeyToAddress(mnemonicToPrivateKey(MNEMONIC2)); + const return2 = privateKeyToAddress(getPrivateKey(MNEMONIC2)); return1.should.not.equal(return2); }); }); diff --git a/packages/vvisp-utils/test/utils/filterPrivateKey.test.js b/packages/vvisp-utils/test/utils/filterPrivateKey.test.js index c0e111e..b85491f 100644 --- a/packages/vvisp-utils/test/utils/filterPrivateKey.test.js +++ b/packages/vvisp-utils/test/utils/filterPrivateKey.test.js @@ -3,12 +3,12 @@ const expect = chai.expect; chai.should(); require('dotenv').config(); -const { mnemonicToPrivateKey } = require('../../src'); +const { getPrivateKey } = require('../../src'); const filterPrivateKey = require('../../src/utils/filterPrivateKey'); describe('# privateKeyToAddress test', function() { before(function() { - this.privateKey = mnemonicToPrivateKey(process.env.MNEMONIC); + this.privateKey = getPrivateKey(process.env.MNEMONIC); }); describe('# input arguments', function() { it('should reject when private is wrong type', function() { diff --git a/packages/vvisp/bin/error.js b/packages/vvisp/bin/error.js index 421f0b6..5e113a9 100644 --- a/packages/vvisp/bin/error.js +++ b/packages/vvisp/bin/error.js @@ -56,8 +56,8 @@ function checkEnv() { } } - if (!process.env.MNEMONIC) { - throw new Error('You should set MNEMONIC in .env file'); + if (!process.env.MNEMONIC && !process.env.PRIVATE_KEY) { + throw new Error('You should set MNEMONIC or PRIVATE_KEY in .env file'); } } diff --git a/packages/vvisp/scripts/deploy-contract.js b/packages/vvisp/scripts/deploy-contract.js index aac7bfd..3725eb1 100755 --- a/packages/vvisp/scripts/deploy-contract.js +++ b/packages/vvisp/scripts/deploy-contract.js @@ -4,13 +4,13 @@ module.exports = async function(file, arguments, options) { const { compileAndDeploy, - mnemonicToPrivateKey, + getPrivateKey, getWeb3, printOrSilent } = require('@haechi-labs/vvisp-utils'); const web3 = getWeb3(); - const privateKey = mnemonicToPrivateKey( + const privateKey = getPrivateKey( process.env.MNEMONIC, process.env.PRIV_INDEX ); diff --git a/packages/vvisp/scripts/deploy-service/constants.js b/packages/vvisp/scripts/deploy-service/constants.js index 548bfbe..b69cfe5 100644 --- a/packages/vvisp/scripts/deploy-service/constants.js +++ b/packages/vvisp/scripts/deploy-service/constants.js @@ -1,6 +1,6 @@ module.exports = (function() { const path = require('path'); - const { getWeb3, mnemonicToPrivateKey } = require('@haechi-labs/vvisp-utils'); + const { getWeb3, getPrivateKey } = require('@haechi-labs/vvisp-utils'); const web3 = getWeb3(); return { @@ -19,10 +19,7 @@ module.exports = (function() { ? web3.utils.toHex(process.env.GAS_LIMIT) : undefined }, - PRIVATE_KEY: mnemonicToPrivateKey( - process.env.MNEMONIC, - process.env.PRIV_INDEX - ), + PRIVATE_KEY: getPrivateKey(process.env.MNEMONIC, process.env.PRIV_INDEX), // service contract property name VARIABLES: 'variables', diff --git a/packages/vvisp/template/script.mustache b/packages/vvisp/template/script.mustache index e661a8d..02243c0 100644 --- a/packages/vvisp/template/script.mustache +++ b/packages/vvisp/template/script.mustache @@ -1,9 +1,9 @@ const path = require('path'); -const { getWeb3, mnemonicToPrivateKey, sendTx } = require('@haechi-labs/vvisp-utils'); +const { getWeb3, getPrivateKey, sendTx } = require('@haechi-labs/vvisp-utils'); const web3 = getWeb3(); const fs = require('fs'); -const privateKey = mnemonicToPrivateKey(process.env.MNEMONIC, process.env.PRIV_INDEX); +const privateKey = getPrivateKey(process.env.MNEMONIC, process.env.PRIV_INDEX); const abi = fs.readFileSync(path.join(__dirname, '../abi/', '{{name}}.json'), {'encoding': 'utf8'}); diff --git a/packages/vvisp/test/bin/error.test.js b/packages/vvisp/test/bin/error.test.js index e98ac5a..dfdc739 100644 --- a/packages/vvisp/test/bin/error.test.js +++ b/packages/vvisp/test/bin/error.test.js @@ -14,6 +14,19 @@ const { NETWORKS, SERVICE_PATH, ENV_PATH } = constants; describe('# error test', function() { this.timeout(50000); + before(function() { + delete process.env.NETWORK; + delete process.env.URL; + delete process.env.PORT; + delete process.env.INFURA_API_KEY; + delete process.env.MNEMONIC; + delete process.env.PRIV_INDEX; + delete process.env.GAS_PRICE; + delete process.env.GAS_LIMIT; + delete process.env.SOLC_VERSION; + delete process.env.SOLC_OPTIMIZATION; + }); + after(function() { delete process.env.NETWORK; delete process.env.URL; @@ -30,7 +43,7 @@ describe('# error test', function() { describe('checkConfigExist()', function() { beforeEach(function() { - fs.remove(path.join(SERVICE_PATH)); + fs.removeSync(path.join(SERVICE_PATH)); }); it('should throw error when service.vvisp.json file does not exist', function() { @@ -42,7 +55,7 @@ describe('# error test', function() { it('should not throw error when service.vvisp.json exists', function() { fs.writeJsonSync(SERVICE_PATH, { serviceName: 'test' }); expect(() => checkConfigExist()).to.not.throw(); - fs.remove(path.join(SERVICE_PATH)); + fs.removeSync(path.join(SERVICE_PATH)); }); }); @@ -50,7 +63,6 @@ describe('# error test', function() { const tmpENV = path.join('./', 'tmp.env'); before(function() { - dotenv(); fs.moveSync(ENV_PATH, tmpENV, { overwrite: true }); }); @@ -67,6 +79,10 @@ describe('# error test', function() { fs.copyFileSync(tmpENV, ENV_PATH); }); + beforeEach(function() { + setMockEnv(); + }); + describe('NETWORK', function() { it('should throw error when NETWORK is not set', function() { delete process.env.NETWORK; @@ -99,15 +115,10 @@ describe('# error test', function() { }); describe('should throw error when INFURA_API_KEY is not set in other NETWORK', function() { - const INFURA_API_KEY = process.env.INFURA_API_KEY; - before(function() { + beforeEach(function() { delete process.env.INFURA_API_KEY; }); - after(function() { - process.env.INFURA_API_KEY = INFURA_API_KEY; - }); - it(NETWORKS.kovan, function() { process.env.NETWORK = NETWORKS.kovan; expect(() => checkEnv()).to.throw( @@ -182,10 +193,24 @@ describe('# error test', function() { it('should throw error when MNEMONIC is not set', function() { delete process.env.MNEMONIC; expect(() => checkEnv()).to.throw( - 'You should set MNEMONIC in .env file' + 'You should set MNEMONIC or PRIVATE_KEY in .env file' ); }); }); }); }); }); + +function setMockEnv() { + process.env.NETWORK = NETWORKS.local; + process.env.URL = 'sample/link'; + process.env.PORT = '8545'; + process.env.INFURA_API_KEY = 'samplekey'; + process.env.MNEMONIC = + 'piano garage flag neglect spare title drill basic strong aware enforce fury'; + process.env.PRIV_INDEX = '0'; + process.env.GAS_PRICE = '20000000000'; + process.env.GAS_LIMIT = '6000000'; + process.env.SOLC_VERSION = '0.4.24'; + process.env.SOLC_OPTIMIZATION = 'true'; +} diff --git a/packages/vvisp/test/dummy/testContractApis/back/js/HaechiV1.js b/packages/vvisp/test/dummy/testContractApis/back/js/HaechiV1.js index 89b1005..3fe5620 100644 --- a/packages/vvisp/test/dummy/testContractApis/back/js/HaechiV1.js +++ b/packages/vvisp/test/dummy/testContractApis/back/js/HaechiV1.js @@ -1,16 +1,9 @@ const path = require('path'); -const { - getWeb3, - mnemonicToPrivateKey, - sendTx -} = require('@haechi-labs/vvisp-utils'); +const { getWeb3, getPrivateKey, sendTx } = require('@haechi-labs/vvisp-utils'); const web3 = getWeb3(); const fs = require('fs'); -const privateKey = mnemonicToPrivateKey( - process.env.MNEMONIC, - process.env.PRIV_INDEX -); +const privateKey = getPrivateKey(process.env.MNEMONIC, process.env.PRIV_INDEX); const abi = fs.readFileSync(path.join(__dirname, '../abi/', 'HaechiV1.json'), { encoding: 'utf8' diff --git a/packages/vvisp/test/scripts/abi-to-script/index.test.js b/packages/vvisp/test/scripts/abi-to-script/index.test.js index ad79fcf..e86eb0d 100644 --- a/packages/vvisp/test/scripts/abi-to-script/index.test.js +++ b/packages/vvisp/test/scripts/abi-to-script/index.test.js @@ -11,7 +11,7 @@ const { compileAndDeploy, forIn, getWeb3, - mnemonicToPrivateKey, + getPrivateKey, privateKeyToAddress } = require('@haechi-labs/vvisp-utils'); const web3 = getWeb3(); @@ -23,7 +23,7 @@ const CONTRACT_PATH2 = path.join(`./contracts/test/${CONTRACT2}.sol`); const FILES = [CONTRACT_PATH1, CONTRACT_PATH2]; const ROOT = path.join('./contractApis'); -const PRIV_KEY = mnemonicToPrivateKey(process.env.MNEMONIC); +const PRIV_KEY = getPrivateKey(process.env.MNEMONIC); const SENDER = privateKeyToAddress(PRIV_KEY); describe('# abi-to-script process test', function() { diff --git a/packages/vvisp/test/scripts/deploy-contract.test.js b/packages/vvisp/test/scripts/deploy-contract.test.js index 047b0f4..c480613 100644 --- a/packages/vvisp/test/scripts/deploy-contract.test.js +++ b/packages/vvisp/test/scripts/deploy-contract.test.js @@ -1,6 +1,6 @@ const deployContract = require('../../scripts/deploy-contract'); const path = require('path'); - +require('dotenv').config(); describe('# deploy contract process test', function() { this.timeout(50000); const CONTRACT_PATH = path.join('./contracts', 'libs', 'Ownable.sol'); @@ -21,6 +21,17 @@ describe('# deploy contract process test', function() { .fulfilled; }); + it('should deploy one contract through private key', async () => { + process.env.PRIVATE_KEY = + '9741fa712a6912b862c9043f8752ffae513cb01895985998c61620da5aaf2d2d'; + process.env.MNEMONIC = ''; + await deployContract(CONTRACT_PATH, [], { silent: true }).should.be + .fulfilled; + process.env.PRIVATE_KEY = ''; + process.env.MNEMONIC = + 'piano garage flag neglect spare title drill basic strong aware enforce fury'; + }); + it('should deploy two contract', async () => { await deployContract(CONTRACT_PATH, [], { silent: true }).should.be .fulfilled; diff --git a/packages/vvisp/test/scripts/deploy-service/index.test.js b/packages/vvisp/test/scripts/deploy-service/index.test.js index ca75fa2..860f4a3 100644 --- a/packages/vvisp/test/scripts/deploy-service/index.test.js +++ b/packages/vvisp/test/scripts/deploy-service/index.test.js @@ -14,7 +14,7 @@ const { hasInitArgs } = require('../../../scripts/deploy-service/utils'); const { forIn, getWeb3, - mnemonicToPrivateKey, + getPrivateKey, privateKeyToAddress } = require('@haechi-labs/vvisp-utils'); const web3 = getWeb3(); @@ -22,7 +22,7 @@ const path = require('path'); const fs = require('fs-extra'); const Mitm = require('mitm'); -const SENDER = privateKeyToAddress(mnemonicToPrivateKey(process.env.MNEMONIC)); +const SENDER = privateKeyToAddress(getPrivateKey(process.env.MNEMONIC)); const SERVICE1 = path.join('./test/dummy/service1.json'); const SERVICE2 = path.join('./test/dummy/service2.json'); const STATE1 = path.join('./test/dummy/state1.json'); diff --git a/packages/vvisp/test/scripts/init.test.js b/packages/vvisp/test/scripts/init.test.js index 596bcc4..a8f0561 100644 --- a/packages/vvisp/test/scripts/init.test.js +++ b/packages/vvisp/test/scripts/init.test.js @@ -8,11 +8,13 @@ const fs = require('fs-extra'); describe('# init script test', function() { this.timeout(50000); const directoryName = 'a8feya73db'; + before(function() { fs.ensureDirSync(path.join('./', directoryName)); }); + after(function() { - fs.remove(path.join('./', directoryName)); + fs.removeSync(path.join('./', directoryName)); }); it('should disallow to initialize in non-empty directory', async function() {