From 52203bcfe2437ab9dfde2340f012b88f4a34c297 Mon Sep 17 00:00:00 2001 From: apanizo Date: Thu, 31 May 2018 20:10:45 +0200 Subject: [PATCH] WA-238 Init contracts for test mode only used in travis --- .travis.yml | 5 +++-- package.json | 2 +- src/wallets/safeContracts.js | 24 ++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7f5b70c5..de4df85f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,15 +5,16 @@ os: - linux before_script: - yarn global add surge + - export NODE_ENV=testing after_success: - - yarn build-storybook - - yarn build - | if [ ${TRAVIS_BRANCH} = "master" ]; then export NODE_ENV=production; else export NODE_ENV=development; fi + - yarn build-storybook + - yarn build - cd build_webpack/ && cp index.html 200.html && cd .. - chmod ugo+x ./config/deploy/deploy.sh - ./config/deploy/deploy.sh diff --git a/package.json b/package.json index d7dd1cb6..3acd02cb 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "start": "node scripts/start.js", "build": "node scripts/build.js", "test": "run-with-testrpc -l 40000000 'node scripts/test.js --env=jsdom'", - "test-local": "node scripts/test.js --env=jsdom", + "test-local": "NODE_ENV=test && node scripts/test.js --env=jsdom", "precommit": "./precommit.sh", "flow": "flow", "storybook": "start-storybook -p 6006", diff --git a/src/wallets/safeContracts.js b/src/wallets/safeContracts.js index 997792a6..3b40d90c 100644 --- a/src/wallets/safeContracts.js +++ b/src/wallets/safeContracts.js @@ -2,6 +2,7 @@ import contract from 'truffle-contract' import { ensureOnce } from '~/utils/singleton' import { getWeb3 } from '~/wallets/getWeb3' +import { promisify } from '~/utils/promisify' import GnosisSafeSol from '#/GnosisSafeTeamEdition.json' import ProxyFactorySol from '#/ProxyFactory.json' import CreateAndAddModules from '#/CreateAndAddModules.json' @@ -62,7 +63,7 @@ const getCreateProxyFactoryContract = ensureOnce(createProxyFactoryContract) const getCreateAddExtensionContract = ensureOnce(createAddExtensionContract) export const getCreateDailyLimitExtensionContract = ensureOnce(createDailyLimitExtensionContract) -const createMasterCopies = async () => { +const instanciateMasterCopies = async () => { const web3 = getWeb3() // Create ProxyFactory Master Copy @@ -82,7 +83,26 @@ const createMasterCopies = async () => { dailyLimitMaster = await DailyLimitExtension.deployed() } -export const initContracts = ensureOnce(createMasterCopies) +// ONLY USED IN TEST ENVIRONMENT +const createMasterCopies = async () => { + const web3 = getWeb3() + const accounts = await promisify(cb => web3.eth.getAccounts(cb)) + const userAccount = accounts[0] + + const ProxyFactory = getCreateProxyFactoryContract(web3) + proxyFactoryMaster = await ProxyFactory.new({ from: userAccount, gas: '5000000' }) + + const CreateAndAddExtension = getCreateAddExtensionContract(web3) + createAndAddModuleMaster = await CreateAndAddExtension.new({ from: userAccount, gas: '5000000' }) + + const GnosisSafe = getGnosisSafeContract(web3) + safeMaster = await GnosisSafe.new([userAccount], 1, 0, 0, { from: userAccount, gas: '5000000' }) + + const DailyLimitExtension = getCreateDailyLimitExtensionContract(web3) + dailyLimitMaster = await DailyLimitExtension.new([], [], { from: userAccount, gas: '5000000' }) +} + +export const initContracts = ensureOnce(process.env.NODE_ENV === 'test' ? createMasterCopies : instanciateMasterCopies) const getSafeDataBasedOn = async (accounts, numConfirmations, dailyLimitInEth) => { const web3 = getWeb3()