diff --git a/package.json b/package.json index 4bc98e33..638831f6 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ambrosus-node-contracts", "author": "Ambrosus", "description": "Smart contracts used in AMB-NET", - "version": "0.0.92", + "version": "0.0.93", "license": "MPL-2.0-no-copyleft-exception", "repository": "git@github.com:ambrosus/ambrosus-node-contracts.git", "main": "dist/index.js", diff --git a/src/utils/web3_tools.js b/src/utils/web3_tools.js index 403a5bdb..1e4db4f6 100644 --- a/src/utils/web3_tools.js +++ b/src/utils/web3_tools.js @@ -11,7 +11,6 @@ import Web3 from 'web3'; import config from '../../config/config'; export const DEFAULT_GAS = 6000000; -const DEFAULT_PORT = 8545; export const {utils} = new Web3(); @@ -19,83 +18,6 @@ function isValidRPCAddress(rpc) { return /^((?:https?)|(?:ws)):\/\//g.test(rpc); } -function isUsingGanache(rpc) { - return rpc === 'ganache'; -} - -function getDefaultGanacheOptions(secretKey) { - if (!secretKey) { - throw 'Secret key not defined'; - } - return { - wallet: { - defaultBalance: 1000000000, - accounts: [ - { - balance: '0x1ed09bead87c0378d8e6400000000', - secretKey - }, - ...Array(9).fill({balance: '0x1ed09bead87c0378d8e64000000000'}) - ] - }, - logging: { - logger: { - log: () => {} // don't do anything - } - }, - chain: { - hardfork: 'istanbul', - vmErrorsOnRPCResponse: false - } - }; -} - -export async function createGanacheServer(secretKey) { - const Ganache = require('ganache'); - const server = Ganache.server(getDefaultGanacheOptions(secretKey)); - await server.listen(DEFAULT_PORT); -} - -function createGanacheProvider(secretKey) { - // import in code with purpose:D - const Ganache = require('ganache'); - const memdown = require('memdown'); - return Ganache.provider({ - ...getDefaultGanacheOptions(secretKey), - db: memdown() - }); -} - -async function ganacheTopUpDefaultAccount(web3) { - const [firstGanacheMasterAccount] = await web3.eth.getAccounts(); - await web3.eth.sendTransaction({ - from: firstGanacheMasterAccount, - to: getDefaultAddress(web3), - value: web3.utils.toWei('10', 'ether'), - gas: DEFAULT_GAS - }); -} - -function augmentWithSnapshotMethods(web3) { - web3.eth.extend({ - methods: [ - { - name: 'makeSnapshot', - call: 'evm_snapshot', - params: 0, - inputFormatter: [], - outputFormatter: web3.utils.hexToNumberString - }, - { - name: 'restoreSnapshot', - call: 'evm_revert', - params: 1, - inputFormatter: [web3.utils.numberToHex] - } - ] - }); -} - function importPrivateKey(web3, conf) { try { const {nodePrivateKey} = conf; @@ -112,14 +34,7 @@ export async function createWeb3(conf = config) { const web3 = new Web3(); const rpc = conf.web3Rpc; - const account = importPrivateKey(web3, conf); - - if (isUsingGanache(rpc)) { - web3.setProvider(createGanacheProvider(account.privateKey)); - await ganacheTopUpDefaultAccount(web3); - augmentWithSnapshotMethods(web3); - return web3; - } + importPrivateKey(web3, conf); if (!isValidRPCAddress(rpc)) { throw new Error(`The config value for the Parity RPC server is invalid: ${rpc}`); diff --git a/test/actions/multisig_actions_integration.js b/test/actions/multisig_actions_integration.js index 5820a3b3..39c058ed 100644 --- a/test/actions/multisig_actions_integration.js +++ b/test/actions/multisig_actions_integration.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import {multisig} from '../../src/contract_jsons'; -import {createWeb3, deployContract, makeSnapshot, restoreSnapshot} from '../../src/utils/web3_tools'; +import {deployContract, makeSnapshot, restoreSnapshot} from '../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../utils/web3_tools'; import deploy from '../helpers/deploy'; import MultiplexerWrapper from '../../src/wrappers/multiplexer_wrapper'; import MultisigWrapper from '../../src/wrappers/multisig_wrapper'; @@ -53,7 +54,7 @@ describe('Multisig actions integration', () => { const onboardAsApollo = async (sender, value) => roles.methods.onboardAsApollo().send({from: sender, value}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [owner, otherOwner, otherAddress] = await web3.eth.getAccounts(); multisigContract = await deployContract(web3, multisig, [[owner, otherOwner], 2]); ({multiplexer, head, kycWhitelist, fees, validatorSet, blockRewards, apolloDepositStore, roles, rolesPrivilagesStore} = await deploy({ diff --git a/test/contracts/boilerplate/base.js b/test/contracts/boilerplate/base.js index fc15a615..ef6e4757 100644 --- a/test/contracts/boilerplate/base.js +++ b/test/contracts/boilerplate/base.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; -import {createWeb3, deployContract} from '../../../src/utils/web3_tools'; +import {deployContract} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import chaiEmitEvents from '../../helpers/chaiEmitEvents'; import observeBalanceChange from '../../helpers/web3BalanceObserver'; @@ -40,7 +41,7 @@ describe('Base Contract', () => { before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployer, catalogue, storageCatalogue, migrator, fundsMigrationTarget] = await web3.eth.getAccounts(); head = await deployContract(web3, HeadJson, [deployer], {from: deployer}); diff --git a/test/contracts/boilerplate/context.js b/test/contracts/boilerplate/context.js index cc3ff431..7ae022ed 100644 --- a/test/contracts/boilerplate/context.js +++ b/test/contracts/boilerplate/context.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; -import {createWeb3, deployContract} from '../../../src/utils/web3_tools'; +import {deployContract} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import ContextJson from '../../../src/contracts/Context.json'; chai.use(sinonChai); @@ -34,7 +35,7 @@ describe('Context Contract', () => { const versionTag = async (contract) => contract.methods.versionTag().call(); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployer, trustedAddress, catalogueAddress, storageCatalogueAddress, untrustedAddress] = await web3.eth.getAccounts(); }); diff --git a/test/contracts/boilerplate/head.js b/test/contracts/boilerplate/head.js index db402651..aad2a00f 100644 --- a/test/contracts/boilerplate/head.js +++ b/test/contracts/boilerplate/head.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; -import {createWeb3, deployContract} from '../../../src/utils/web3_tools'; +import {deployContract} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import HeadJson from '../../../src/contracts/Head.json'; chai.use(sinonChai); @@ -36,7 +37,7 @@ describe('Head Contract', () => { const transferOwnership = async (contract, sender, newOwner) => contract.methods.transferOwnership(newOwner).send({...standardOptions, from: sender}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployAddress, ownerAddress, nonOwnerAddress, otherAddress] = await web3.eth.getAccounts(); }); diff --git a/test/contracts/boilerplate/multiplexer.js b/test/contracts/boilerplate/multiplexer.js index 0279daec..a8324c78 100644 --- a/test/contracts/boilerplate/multiplexer.js +++ b/test/contracts/boilerplate/multiplexer.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import deploy from '../../helpers/deploy'; import {APOLLO, HERMES, APOLLO_DEPOSIT} from '../../../src/constants'; @@ -55,7 +56,7 @@ describe('Multiplexer', () => { const baseReward = '2000000000000000000'; before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [oldOwner, newOwner, otherAddress, superUser, apollo, developer, support] = await web3.eth.getAccounts(); ({head, multiplexer, kycWhitelist, fees, roles, validatorProxy, validatorSet, blockRewards, apolloDepositStore} = await deploy({ web3, diff --git a/test/contracts/configuration/fees.js b/test/contracts/configuration/fees.js index d7f7b0f3..c1062269 100644 --- a/test/contracts/configuration/fees.js +++ b/test/contracts/configuration/fees.js @@ -14,7 +14,8 @@ import deploy from '../../helpers/deploy'; import {DAY, TWO} from '../../helpers/consts'; import TimeMockJson from '../../../src/contracts/TimeMock.json'; import BN from 'bn.js'; -import {makeSnapshot, restoreSnapshot, createWeb3, utils} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; const {expect} = chai; @@ -55,7 +56,7 @@ describe('Fees Contract', () => { const developerFee = (fee) => fee.sub(nonDeveloperFee(fee)); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [from, other, developer, support] = await web3.eth.getAccounts(); ({fees, time} = await deploy({ web3, diff --git a/test/contracts/configuration/time.js b/test/contracts/configuration/time.js index 72a22df8..8c5eb3ce 100644 --- a/test/contracts/configuration/time.js +++ b/test/contracts/configuration/time.js @@ -11,7 +11,8 @@ import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; import deploy from '../../helpers/deploy'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; chai.use(sinonChai); chai.use(chaiAsPromised); @@ -33,7 +34,7 @@ describe('Time Contract', () => { const payoutPeriodOffset = (timestamp, senderAddress = validUser) => time.methods.payoutPeriodOffset(timestamp).call({from: senderAddress}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [validUser] = await web3.eth.getAccounts(); ({time} = await deploy({ web3, diff --git a/test/contracts/consensus/block_rewards.js b/test/contracts/consensus/block_rewards.js index 39b14d83..40b8bdba 100644 --- a/test/contracts/consensus/block_rewards.js +++ b/test/contracts/consensus/block_rewards.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, deployContract, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {deployContract, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import chaiEmitEvents from '../../helpers/chaiEmitEvents'; import BlockRewardsJson from '../../../src/contracts/BlockRewards.json'; @@ -56,7 +57,7 @@ describe('Block rewards contract', () => { let snapshotId; before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployer, owner, otherUser, superUser, newOwner] = await web3.eth.getAccounts(); exampleBeneficiaries = Array(3) .fill(null) diff --git a/test/contracts/consensus/constructor_ownable.js b/test/contracts/consensus/constructor_ownable.js index d7a499d4..1517aead 100644 --- a/test/contracts/consensus/constructor_ownable.js +++ b/test/contracts/consensus/constructor_ownable.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, deployContract, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {deployContract, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import chaiEmitEvents from '../../helpers/chaiEmitEvents'; import ConstructorOwnableJson from '../../../src/contracts/ConstructorOwnable.json'; @@ -35,7 +36,7 @@ describe('ConstructorOwnable base contract', () => { let snapshotId; before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployer, owner, otherUser, newOwner] = await web3.eth.getAccounts(); contract = await deploy(web3, deployer, owner); }); diff --git a/test/contracts/consensus/validator_set.js b/test/contracts/consensus/validator_set.js index 1077be9c..24b5b6a6 100644 --- a/test/contracts/consensus/validator_set.js +++ b/test/contracts/consensus/validator_set.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, deployContract, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {deployContract, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import chaiEmitEvents from '../../helpers/chaiEmitEvents'; import ValidatorSetJson from '../../../src/contracts/ValidatorSet.json'; @@ -41,7 +42,7 @@ describe('Validator set contract', () => { let additionalValidator; before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployer, owner, otherUser, superUser, newOwner] = await web3.eth.getAccounts(); exampleValidatorAddresses = Array(3) .fill(null) diff --git a/test/contracts/front/challenges.js b/test/contracts/front/challenges.js index fcd1beb7..d69d090e 100644 --- a/test/contracts/front/challenges.js +++ b/test/contracts/front/challenges.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; -import {createWeb3, deployContract, makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {deployContract, makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import chaiEmitEvents from '../../helpers/chaiEmitEvents'; import BN from 'bn.js'; import { @@ -126,7 +127,7 @@ describe('Challenges Contract', () => { // eslint-disable-next-line new-cap before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [context, challenger, uploader, atlases[0], atlases[1], atlases[2], atlases[3], atlases[4], shelterer, totalStranger] = await web3.eth.getAccounts(); ({challenges, challengesStore, bundleStore, fees, sheltering, kycWhitelist, atlasStakeStore, time, roles, challengesEventEmitter} = await deploy({ web3, diff --git a/test/contracts/front/kyc_whitelist.js b/test/contracts/front/kyc_whitelist.js index 5f7af71f..8a81b696 100644 --- a/test/contracts/front/kyc_whitelist.js +++ b/test/contracts/front/kyc_whitelist.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import deploy from '../../helpers/deploy'; import {APOLLO, ATLAS, HERMES, APOLLO_DEPOSIT, ATLAS1_STAKE, ATLAS2_STAKE, ATLAS3_STAKE} from '../../../src/constants'; import {ONE} from '../../helpers/consts'; @@ -42,7 +43,7 @@ describe('KYC Whitelist Contract', () => { const getRoleAssigned = async (address) => kycWhitelist.methods.getRoleAssigned(address).call(); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [from, other, totalStranger] = await web3.eth.getAccounts(); ({kycWhitelist} = await deploy({ web3, diff --git a/test/contracts/front/payouts.js b/test/contracts/front/payouts.js index 5add3d83..1705e4db 100644 --- a/test/contracts/front/payouts.js +++ b/test/contracts/front/payouts.js @@ -13,7 +13,8 @@ import sinonChai from 'sinon-chai'; import deploy from '../../helpers/deploy'; import TimeMockJson from '../../../src/contracts/TimeMock.json'; import observeBalanceChange from '../../helpers/web3BalanceObserver'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import {PAYOUT_PERIOD_UNIT} from '../../helpers/consts'; chai.use(sinonChai); @@ -46,7 +47,7 @@ describe('Payouts Contract', () => { const expectBalanceChange = async (account, amount, codeBlock) => expect((await observeBalanceChange(web3, account, codeBlock)).toString()).to.eq(amount); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [validUser, beneficiary, withdrawTarget, otherUser] = await web3.eth.getAccounts(); ({payoutsStore, payouts, time} = await deploy({ web3, diff --git a/test/contracts/front/roles.js b/test/contracts/front/roles.js index cecfbb89..5f038db3 100644 --- a/test/contracts/front/roles.js +++ b/test/contracts/front/roles.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import deploy from '../../helpers/deploy'; import {ONE} from '../../helpers/consts'; import { @@ -80,7 +81,7 @@ describe('Roles Contract', () => { let snapshotId; before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [owner, apollo, apolloStake, initialApollo, atlas1, atlas2, atlas3, atlasStake, hermes] = await web3.eth.getAccounts(); ({roles, kycWhitelist, atlasStakeStore, apolloDepositStore, validatorSet, blockRewards, rolesEventEmitter} = await deploy({ web3, diff --git a/test/contracts/front/sheltering_transfers.js b/test/contracts/front/sheltering_transfers.js index c6f6ab11..ccee4b21 100644 --- a/test/contracts/front/sheltering_transfers.js +++ b/test/contracts/front/sheltering_transfers.js @@ -18,7 +18,8 @@ import { ROUND_DURATION } from '../../../src/constants'; import deploy from '../../helpers/deploy'; -import {createWeb3, makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import chaiEmitEvents from '../../helpers/chaiEmitEvents'; import AtlasStakeStoreMockJson from '../../../src/contracts/AtlasStakeStoreMock.json'; import ChallengesStoreMockJson from '../../../src/contracts/ChallengesStoreMock.json'; @@ -85,7 +86,7 @@ describe('ShelteringTransfers Contract', () => { const timestampToPayoutPeriod = (timestamp) => Math.floor(timestamp / PAYOUT_PERIOD_UNIT); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployer, hermes, atlas, notSheltering, notStaking] = await web3.eth.getAccounts(); ({shelteringTransfers, atlasStakeStore, sheltering, rolesStore, time, payoutsStore, challenges, fees, transfersEventEmitter} = await deploy({ web3, diff --git a/test/contracts/front/upload.js b/test/contracts/front/upload.js index b3b5c980..45487d9c 100644 --- a/test/contracts/front/upload.js +++ b/test/contracts/front/upload.js @@ -16,7 +16,8 @@ import chaiEmitEvents from '../../helpers/chaiEmitEvents'; import deploy from '../../helpers/deploy'; import {ATLAS, HERMES} from '../../../src/constants'; import {SYSTEM_CHALLENGES_COUNT} from '../../helpers/consts'; -import {createWeb3, makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import {expectEventEmission} from '../../helpers/web3EventObserver'; import BN from 'bn.js'; @@ -57,7 +58,7 @@ describe('Upload Contract', () => { const setDeveloperUploadFee = (fee, from = hermes) => fees.methods.setDeveloperUploadFee(fee).send({from, gasPrice: '0'}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); ({uploads, fees, challengesEventEmitter, bundleStore, rolesStore, rewardsEventEmitter} = await deploy({ web3, contracts: { diff --git a/test/contracts/lib/dmp_algorithm.js b/test/contracts/lib/dmp_algorithm.js index 6a8967c2..299e9e12 100644 --- a/test/contracts/lib/dmp_algorithm.js +++ b/test/contracts/lib/dmp_algorithm.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; -import {createWeb3, deployContract, makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {deployContract, makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import DmpAlgorithmAdapterJson from '../../../src/contracts/DmpAlgorithmAdapter.json'; import BN from 'bn.js'; import {DMP_PRECISION} from '../../../src/constants'; @@ -31,7 +32,7 @@ describe('DMP algorithm library', () => { const selectingAtlasTier = async (dmpBaseHash, atlasCounts, atlasNum) => DmpAlgorithmAdapter.methods.selectingAtlasTier(dmpBaseHash, atlasCounts, atlasNum).call(); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); for (let ind = 0; ind < DMP_PRECISION * 5; ind++) { const hash = utils.keccak256(ind.toString()); resultsToInputs[web3.utils diff --git a/test/contracts/lib/safe_math_extensions.js b/test/contracts/lib/safe_math_extensions.js index a252d1b5..b3626801 100644 --- a/test/contracts/lib/safe_math_extensions.js +++ b/test/contracts/lib/safe_math_extensions.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; -import {createWeb3, deployContract, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {deployContract, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import SafeMathExtensionsAdapter from '../../../src/contracts/SafeMathExtensionsAdapter.json'; import BN from 'bn.js'; import {ONE} from '../../helpers/consts'; @@ -43,7 +44,7 @@ describe('SafeMathExtensions', () => { let snapshotId; before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); safeMathExtension = await deployContract(web3, SafeMathExtensionsAdapter); }); diff --git a/test/contracts/middleware/sheltering.js b/test/contracts/middleware/sheltering.js index c4e9f83f..27466a13 100644 --- a/test/contracts/middleware/sheltering.js +++ b/test/contracts/middleware/sheltering.js @@ -11,7 +11,8 @@ import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; import observeBalanceChange from '../../helpers/web3BalanceObserver'; -import {createWeb3, makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import deploy from '../../helpers/deploy'; import {ATLAS, HERMES} from '../../../src/constants'; import {STORAGE_PERIOD_UNIT, PAYOUT_PERIOD_UNIT} from '../../helpers/consts'; @@ -86,7 +87,7 @@ describe('Sheltering Contract', () => { const timestampToPayoutPeriod = (timestamp) => Math.floor(timestamp / PAYOUT_PERIOD_UNIT); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployer, hermes, atlas, atlas2, atlas3, other] = await web3.eth.getAccounts(); ({bundleStore, sheltering, atlasStakeStore, rolesStore, payoutsStore, time} = await deploy({ web3, diff --git a/test/contracts/middleware/validator_proxy.js b/test/contracts/middleware/validator_proxy.js index 8105455b..0056b71a 100644 --- a/test/contracts/middleware/validator_proxy.js +++ b/test/contracts/middleware/validator_proxy.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import chaiEmitEvents from '../../helpers/chaiEmitEvents'; import deploy from '../../helpers/deploy'; @@ -90,7 +91,7 @@ describe('ValidatorProxy', () => { let snapshotId; before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [owner, otherUser, newOwner] = await web3.eth.getAccounts(); initialValidators = [ web3.eth.accounts.create().address, diff --git a/test/contracts/pool/pool.js b/test/contracts/pool/pool.js index cbe4f2f2..9fe0fa14 100644 --- a/test/contracts/pool/pool.js +++ b/test/contracts/pool/pool.js @@ -11,7 +11,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import {expect, assert} from '../../helpers/chaiPreconf'; import deploy from '../../helpers/deploy'; -import {createWeb3, makeSnapshot, restoreSnapshot, deployContract, DEFAULT_GAS} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot, deployContract, DEFAULT_GAS} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import PoolToken from '../../../src/contracts/PoolToken.json'; import Pool from '../../../src/contracts/Pool.json'; import {ROLE_CODES, APOLLO_DEPOSIT} from '../../../src/constants'; @@ -60,7 +61,7 @@ describe('Pool Contract', function() { const apolloPoolMaxTotalStake = apolloPoolNodeStake.mul(toBN(100)); before(async function() { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); web3.eth.handleRevert = true; [owner, initialApollo, poolService, node1, node2, addr1, addr2] = await web3.eth.getAccounts(); diff --git a/test/contracts/pool/pool_token.js b/test/contracts/pool/pool_token.js index b35efb66..e14ceeb2 100644 --- a/test/contracts/pool/pool_token.js +++ b/test/contracts/pool/pool_token.js @@ -8,7 +8,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined */ import {expect, assert} from '../../helpers/chaiPreconf'; -import {createWeb3, makeSnapshot, restoreSnapshot, deployContract} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot, deployContract} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import PoolToken from '../../../src/contracts/PoolToken.json'; import {utils} from 'web3'; import {ZERO_ADDRESS} from '../../../src/constants'; @@ -33,7 +34,7 @@ describe('PoolToken Contract', () => { // const transferFrom = (_from, _to, _value, senderAddress = owner) => poolToken.methods.transferFrom(_from, _to, _value).send({from: senderAddress}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); web3.eth.handleRevert = true; [owner, addr1, addr2] = await web3.eth.getAccounts(); poolToken = await deployContract(web3, PoolToken); diff --git a/test/contracts/pool/pools_nodes_manager.js b/test/contracts/pool/pools_nodes_manager.js index b6a7d621..dca2b4a9 100644 --- a/test/contracts/pool/pools_nodes_manager.js +++ b/test/contracts/pool/pools_nodes_manager.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import {expect, assert} from '../../helpers/chaiPreconf'; import deploy from '../../helpers/deploy'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import {ROLE_CODES, ZERO_ADDRESS, APOLLO_DEPOSIT, ATLAS1_STAKE} from '../../../src/constants'; import {utils} from 'web3'; @@ -56,7 +57,7 @@ describe('PoolsNodesManager Contract', () => { const addNodeRequestResolved = (requestId, status, senderAddress = owner) => poolsNodesManager.methods.addNodeRequestResolved(requestId, status).send({from: senderAddress}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); web3.eth.handleRevert = true; [owner, initialApollo, pool, pool2, node, user] = await web3.eth.getAccounts(); diff --git a/test/contracts/storage/apollo_deposit_store.js b/test/contracts/storage/apollo_deposit_store.js index aea289da..886b81f4 100644 --- a/test/contracts/storage/apollo_deposit_store.js +++ b/test/contracts/storage/apollo_deposit_store.js @@ -11,7 +11,8 @@ import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; import deploy from '../../helpers/deploy'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import observeBalanceChange from '../../helpers/web3BalanceObserver'; chai.use(sinonChai); @@ -32,7 +33,7 @@ describe('Apollo Deposit Contract', () => { const isDepositing = (apollo = from) => apolloDepositStore.methods.isDepositing(apollo).call(); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [from, other] = await web3.eth.getAccounts(); ({apolloDepositStore} = await deploy({ web3, diff --git a/test/contracts/storage/atlas_stake_store.js b/test/contracts/storage/atlas_stake_store.js index 7309f7d4..3e91e624 100644 --- a/test/contracts/storage/atlas_stake_store.js +++ b/test/contracts/storage/atlas_stake_store.js @@ -13,7 +13,8 @@ import sinonChai from 'sinon-chai'; import deploy from '../../helpers/deploy'; import BN from 'bn.js'; import observeBalanceChange from '../../helpers/web3BalanceObserver'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; chai.use(sinonChai); chai.use(chaiAsPromised); @@ -50,7 +51,7 @@ describe('AtlasStakeStore Contract', () => { before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployer, shelterer, otherAddress, ...moreShelterers] = await web3.eth.getAccounts(); ({atlasStakeStore} = await deploy({ web3, diff --git a/test/contracts/storage/bundle_store.js b/test/contracts/storage/bundle_store.js index e66e0d34..b3f2298b 100644 --- a/test/contracts/storage/bundle_store.js +++ b/test/contracts/storage/bundle_store.js @@ -12,7 +12,8 @@ import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; import chaiEmitEvents from '../../helpers/chaiEmitEvents'; import deploy from '../../helpers/deploy'; -import {createWeb3, makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; chai.use(chaiEmitEvents); chai.use(sinonChai); @@ -47,7 +48,7 @@ describe('BundleStore Contract', () => { const removeShelterer = async (bundleId, shelterer, sender = deployer) => bundleStore.methods.removeShelterer(bundleId, shelterer).send({from: sender}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployer, targetUser, otherUser, ...otherUsers] = await web3.eth.getAccounts(); ({bundleStore} = await deploy({ web3, diff --git a/test/contracts/storage/challenges_store.js b/test/contracts/storage/challenges_store.js index 2f258699..b1fdf769 100644 --- a/test/contracts/storage/challenges_store.js +++ b/test/contracts/storage/challenges_store.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import deploy from '../../helpers/deploy'; import observeBalanceChange from '../../helpers/web3BalanceObserver'; import BN from 'bn.js'; @@ -49,7 +50,7 @@ describe('ChallengesStoreContract', () => { const getActiveChallengesOnBundleCount = (bundleId) => challengesStore.methods.getActiveChallengesOnBundleCount(bundleId).call(); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [deployer, shelterer, challenger, otherAddress] = await web3.eth.getAccounts(); ({challengesStore} = await deploy({ web3, diff --git a/test/contracts/storage/kyc_whitelist_store.js b/test/contracts/storage/kyc_whitelist_store.js index 5873d4b9..44078ee9 100644 --- a/test/contracts/storage/kyc_whitelist_store.js +++ b/test/contracts/storage/kyc_whitelist_store.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import deploy from '../../helpers/deploy'; import {APOLLO, ATLAS, APOLLO_DEPOSIT, ATLAS1_STAKE} from '../../../src/constants'; @@ -31,7 +32,7 @@ describe('KYC Whitelist Store Contract', () => { const set = async (address, role, deposit, sender) => kycWhitelistStore.methods.set(address, role, deposit).send({from: sender}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [whitelistOwner, applicant] = await web3.eth.getAccounts(); ({kycWhitelistStore} = await deploy({ web3, diff --git a/test/contracts/storage/payouts_store.js b/test/contracts/storage/payouts_store.js index 4b19de93..09dda00a 100644 --- a/test/contracts/storage/payouts_store.js +++ b/test/contracts/storage/payouts_store.js @@ -12,7 +12,8 @@ import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; import deploy from '../../helpers/deploy'; import observeBalanceChange from '../../helpers/web3BalanceObserver'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; chai.use(sinonChai); chai.use(chaiAsPromised); @@ -38,7 +39,7 @@ describe('PayoutsStore Contract', () => { const expectBalanceChange = async (account, amount, codeBlock) => expect((await observeBalanceChange(web3, account, codeBlock)).toString()).to.eq(amount); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [validUser, beneficiary, withdrawTarget, otherUser] = await web3.eth.getAccounts(); ({payoutsStore} = await deploy({ web3, diff --git a/test/contracts/storage/pool_events_emitter.js b/test/contracts/storage/pool_events_emitter.js index 35aca07e..1955c329 100644 --- a/test/contracts/storage/pool_events_emitter.js +++ b/test/contracts/storage/pool_events_emitter.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import {expect} from '../../helpers/chaiPreconf'; import deploy from '../../helpers/deploy'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import {ROLE_CODES} from '../../../src/constants'; describe('PoolEventsEmitter Contract', () => { @@ -28,7 +29,7 @@ describe('PoolEventsEmitter Contract', () => { const addNodeRequestResolved = (pool, id, status, senderAddress = owner) => poolEventsEmitter.methods.addNodeRequestResolved(pool, id, status).send({from: senderAddress}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); web3.eth.handleRevert = true; [owner, pool, user] = await web3.eth.getAccounts(); diff --git a/test/contracts/storage/pools_store.js b/test/contracts/storage/pools_store.js index 6c57fdc1..b76ac368 100644 --- a/test/contracts/storage/pools_store.js +++ b/test/contracts/storage/pools_store.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import {expect, assert} from '../../helpers/chaiPreconf'; import deploy from '../../helpers/deploy'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import {ZERO_ADDRESS} from '../../../src/constants'; describe('PoolsStore Contract', () => { @@ -29,7 +30,7 @@ describe('PoolsStore Contract', () => { const getPools = (from, to, senderAddress = owner) => poolsStore.methods.getPools(from, to).call({from: senderAddress}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); web3.eth.handleRevert = true; [owner, pool] = await web3.eth.getAccounts(); diff --git a/test/contracts/storage/roles_store.js b/test/contracts/storage/roles_store.js index edfe8f1c..5f17a57c 100644 --- a/test/contracts/storage/roles_store.js +++ b/test/contracts/storage/roles_store.js @@ -12,7 +12,8 @@ import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; import deploy from '../../helpers/deploy'; import {APOLLO, ATLAS, HERMES} from '../../../src/constants'; -import {createWeb3, makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; chai.use(sinonChai); chai.use(chaiAsPromised); @@ -35,7 +36,7 @@ describe('RolesStore Contract', () => { const getUrl = async (node) => rolesStore.methods.getUrl(node).call(); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [from, atlas, hermes, apollo, other] = await web3.eth.getAccounts(); ({rolesStore} = await deploy({ web3, diff --git a/test/contracts/storage/sheltering_transfers_store.js b/test/contracts/storage/sheltering_transfers_store.js index 39e010c3..8c818f21 100644 --- a/test/contracts/storage/sheltering_transfers_store.js +++ b/test/contracts/storage/sheltering_transfers_store.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {makeSnapshot, restoreSnapshot, utils} from '../../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../../utils/web3_tools'; import deploy from '../../helpers/deploy'; chai.use(chaiAsPromised); @@ -36,7 +37,7 @@ describe('ShelteringTransfersStore Contract', () => { shelteringTransfersStore.methods.getTransferId(donorId, bundleId).call(); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); [contextAddress, donorAddress, otherAddress] = await web3.eth.getAccounts(); ({shelteringTransfersStore} = await deploy({ web3, diff --git a/test/helpers/deploy.js b/test/helpers/deploy.js index c57477e4..0ffa67e8 100644 --- a/test/helpers/deploy.js +++ b/test/helpers/deploy.js @@ -10,10 +10,11 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import MockContextJson from '../../src/contracts/MockContext.json'; import Deployer from '../../src/deployer'; import contractJsons from '../../src/contract_jsons'; -import {createWeb3, getDefaultAddress} from '../../src/utils/web3_tools'; +import {getDefaultAddress} from '../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../utils/web3_tools'; const deploy = async (options = {}) => { - const web3 = options.web3 || await createWeb3(); + const web3 = options.web3 || await createWeb3Ganache(); const sender = options.sender || getDefaultAddress(web3); const skipDeployment = []; const alreadyDeployed = {}; diff --git a/test/utils/web3_tools.js b/test/utils/web3_tools.js new file mode 100644 index 00000000..857a6b1d --- /dev/null +++ b/test/utils/web3_tools.js @@ -0,0 +1,112 @@ +/* +Copyright: Ambrosus Inc. +Email: tech@ambrosus.io + +This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0. +*/ + +import Web3 from 'web3'; +import config from '../../config/config'; +import {DEFAULT_GAS, getDefaultAddress} from '../../src/utils/web3_tools'; + +export const {utils} = new Web3(); + +const DEFAULT_PORT = 8545; + +function getDefaultGanacheOptions(secretKey) { + if (!secretKey) { + throw 'Secret key not defined'; + } + return { + wallet: { + defaultBalance: 1000000000, + accounts: [ + { + balance: '0x1ed09bead87c0378d8e6400000000', + secretKey + }, + ...Array(9).fill({balance: '0x1ed09bead87c0378d8e64000000000'}) + ] + }, + logging: { + logger: { + log: () => {} // don't do anything + } + }, + chain: { + hardfork: 'istanbul', + vmErrorsOnRPCResponse: false + } + }; +} + +export async function createGanacheServer(secretKey) { + const Ganache = require('ganache'); + const server = Ganache.server(getDefaultGanacheOptions(secretKey)); + await server.listen(DEFAULT_PORT); +} + +function createGanacheProvider(secretKey) { + // import in code with purpose:D + const Ganache = require('ganache'); + const memdown = require('memdown'); + return Ganache.provider({ + ...getDefaultGanacheOptions(secretKey), + db: memdown() + }); +} + +async function ganacheTopUpDefaultAccount(web3) { + const [firstGanacheMasterAccount] = await web3.eth.getAccounts(); + await web3.eth.sendTransaction({ + from: firstGanacheMasterAccount, + to: getDefaultAddress(web3), + value: web3.utils.toWei('10', 'ether'), + gas: DEFAULT_GAS + }); +} + +function augmentWithSnapshotMethods(web3) { + web3.eth.extend({ + methods: [ + { + name: 'makeSnapshot', + call: 'evm_snapshot', + params: 0, + inputFormatter: [], + outputFormatter: web3.utils.hexToNumberString + }, + { + name: 'restoreSnapshot', + call: 'evm_revert', + params: 1, + inputFormatter: [web3.utils.numberToHex] + } + ] + }); +} + +function importPrivateKey(web3, conf) { + try { + const {nodePrivateKey} = conf; + const account = web3.eth.accounts.privateKeyToAccount(nodePrivateKey); + web3.eth.accounts.wallet.add(account); + web3.eth.defaultAccount = account.address; + return account; + } catch (err) { + throw new Error('A configuration value for web3 node private key is missing'); + } +} + +export async function createWeb3Ganache(conf = config) { + const web3 = new Web3(); + + const account = importPrivateKey(web3, conf); + + web3.setProvider(createGanacheProvider(account.privateKey)); + await ganacheTopUpDefaultAccount(web3); + augmentWithSnapshotMethods(web3); + return web3; +} diff --git a/test/wrappers/block_rewards_wrapper.js b/test/wrappers/block_rewards_wrapper.js index 8ce00fb9..6b2e3480 100644 --- a/test/wrappers/block_rewards_wrapper.js +++ b/test/wrappers/block_rewards_wrapper.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai, {expect} from 'chai'; import sinon from 'sinon'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, deployContract, getDefaultAddress} from '../../src/utils/web3_tools'; +import {deployContract, getDefaultAddress} from '../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../utils/web3_tools'; import contractJsons from '../../src/contract_jsons'; import BlockRewardsWrapper from '../../src/wrappers/block_rewards_wrapper'; @@ -26,7 +27,7 @@ describe('Block Rewards Wrapper', () => { const deploy = async (web3, sender) => deployContract(web3, contractJsons.blockRewards, [sender, baseReward, sender], {from: sender}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); ownerAddress = getDefaultAddress(web3); contract = await deploy(web3, ownerAddress); wrapper = new BlockRewardsWrapper(contract.options.address, web3); diff --git a/test/wrappers/blockchain_state_wrapper.js b/test/wrappers/blockchain_state_wrapper.js index 4615ba51..2b3fbdbe 100644 --- a/test/wrappers/blockchain_state_wrapper.js +++ b/test/wrappers/blockchain_state_wrapper.js @@ -6,7 +6,8 @@ This Source Code Form is subject to the terms of the Mozilla Public License, v. This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0. */ -import {createWeb3, deployContract} from '../../src/utils/web3_tools'; +import {deployContract} from '../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../utils/web3_tools'; import chai from 'chai'; import BlockchainStateWrapper from '../../src/wrappers/blockchain_state_wrapper'; import chaiAsPromised from 'chai-as-promised'; @@ -22,7 +23,7 @@ describe('BlockchainStateWrapper', () => { let wrapper; beforeEach(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); wrapper = new BlockchainStateWrapper(web3); }); diff --git a/test/wrappers/genesis_contract_wrapper.js b/test/wrappers/genesis_contract_wrapper.js index 2e2a8bfc..2b9c7623 100644 --- a/test/wrappers/genesis_contract_wrapper.js +++ b/test/wrappers/genesis_contract_wrapper.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai, {expect} from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, deployContract, getDefaultAddress} from '../../src/utils/web3_tools'; +import {deployContract, getDefaultAddress} from '../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../utils/web3_tools'; import ConstructorOwnableJson from '../../src/contracts/ConstructorOwnable.json'; import GenesisContractWrapper from '../../src/wrappers/genesis_contract_wrapper'; @@ -25,7 +26,7 @@ describe('Genesis Contract Wrapper', () => { const deploy = async (web3, sender) => deployContract(web3, ConstructorOwnableJson, [sender], {from: sender}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); ownerAddress = getDefaultAddress(web3); otherAddress = web3.eth.accounts.create().address; }); diff --git a/test/wrappers/head_wrapper.js b/test/wrappers/head_wrapper.js index 13d14e98..60868440 100644 --- a/test/wrappers/head_wrapper.js +++ b/test/wrappers/head_wrapper.js @@ -9,7 +9,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, deployContract, getDefaultAddress} from '../../src/utils/web3_tools'; +import {deployContract, getDefaultAddress} from '../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../utils/web3_tools'; import contractJsons from '../../src/contract_jsons'; import HeadWrapper from '../../src/wrappers/head_wrapper'; @@ -52,7 +53,7 @@ describe('Head Wrapper', () => { }; before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); ownerAddress = getDefaultAddress(web3); await deployCatalogue(); await deployStorageCatalogue(); diff --git a/test/wrappers/validator_set_wrapper.js b/test/wrappers/validator_set_wrapper.js index f87887bf..8fbc7859 100644 --- a/test/wrappers/validator_set_wrapper.js +++ b/test/wrappers/validator_set_wrapper.js @@ -10,7 +10,8 @@ This Source Code Form is “Incompatible With Secondary Licenses”, as defined import chai, {expect} from 'chai'; import sinon from 'sinon'; import chaiAsPromised from 'chai-as-promised'; -import {createWeb3, deployContract, getDefaultAddress} from '../../src/utils/web3_tools'; +import {deployContract, getDefaultAddress} from '../../src/utils/web3_tools'; +import {createWeb3Ganache} from '../utils/web3_tools'; import contractJsons from '../../src/contract_jsons'; import ValidatorSetWrapper from '../../src/wrappers/validator_set_wrapper'; @@ -28,7 +29,7 @@ describe('ValidatorSet Wrapper', () => { const deploy = async (web3, sender) => deployContract(web3, contractJsons.validatorSet, [sender, generateValidatorSet(3), sender], {from: sender}); before(async () => { - web3 = await createWeb3(); + web3 = await createWeb3Ganache(); ownerAddress = getDefaultAddress(web3); contract = await deploy(web3, ownerAddress); wrapper = new ValidatorSetWrapper(contract.options.address, web3, ownerAddress);