diff options
author | Hsuan Lee <boczeratul@gmail.com> | 2019-03-06 17:46:50 +0800 |
---|---|---|
committer | Hsuan Lee <boczeratul@gmail.com> | 2019-03-06 17:46:50 +0800 |
commit | 35703539d0f2b4ddb3b11d0de8c9634af59ab71f (patch) | |
tree | ae3731221dbbb3a6fa40060a8d916cfd3f738289 /packages/metacoin/test | |
parent | 92a1fde5b1ecd81b07cdb5bf0c9c1cd3544799db (diff) | |
download | dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.gz dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.bz2 dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.lz dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.xz dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.tar.zst dexon-0x-contracts-35703539d0f2b4ddb3b11d0de8c9634af59ab71f.zip |
Deploy @dexon-foundation/0x.jsstable
Diffstat (limited to 'packages/metacoin/test')
-rw-r--r-- | packages/metacoin/test/global_hooks.ts | 15 | ||||
-rw-r--r-- | packages/metacoin/test/metacoin_test.ts | 120 | ||||
-rw-r--r-- | packages/metacoin/test/utils/chai_setup.ts | 13 | ||||
-rw-r--r-- | packages/metacoin/test/utils/config.ts | 12 | ||||
-rw-r--r-- | packages/metacoin/test/utils/coverage.ts | 21 | ||||
-rw-r--r-- | packages/metacoin/test/utils/profiler.ts | 27 | ||||
-rw-r--r-- | packages/metacoin/test/utils/web3_wrapper.ts | 76 |
7 files changed, 0 insertions, 284 deletions
diff --git a/packages/metacoin/test/global_hooks.ts b/packages/metacoin/test/global_hooks.ts deleted file mode 100644 index 437061b46..000000000 --- a/packages/metacoin/test/global_hooks.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { env, EnvVars } from '@0x/dev-utils'; - -import { coverage } from './utils/coverage'; -import { profiler } from './utils/profiler'; - -after('generate coverage || profiler report', async () => { - if (env.parseBoolean(EnvVars.SolidityCoverage)) { - const coverageSubprovider = coverage.getCoverageSubproviderSingleton(); - await coverageSubprovider.writeCoverageAsync(); - } - if (env.parseBoolean(EnvVars.SolidityProfiler)) { - const profilerSubprovider = profiler.getProfilerSubproviderSingleton(); - await profilerSubprovider.writeProfilerOutputAsync(); - } -}); diff --git a/packages/metacoin/test/metacoin_test.ts b/packages/metacoin/test/metacoin_test.ts deleted file mode 100644 index a8ba85814..000000000 --- a/packages/metacoin/test/metacoin_test.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { BlockchainLifecycle, devConstants } from '@0x/dev-utils'; -import { BigNumber } from '@0x/utils'; -import * as chai from 'chai'; -import { ContractArtifact, LogWithDecodedArgs } from 'ethereum-types'; - -import * as MetacoinArtifact from '../artifacts/Metacoin.json'; -import { MetacoinContract, MetacoinTransferEventArgs } from '../src/contract_wrappers/metacoin'; - -import { chaiSetup } from './utils/chai_setup'; -import { config } from './utils/config'; -// Comment out the next line enable profiling -// import { profiler } from './utils/profiler'; -import { provider, web3Wrapper } from './utils/web3_wrapper'; - -const artifact: ContractArtifact = MetacoinArtifact as any; - -chaiSetup.configure(); -const { expect } = chai; -const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); -// tslint:disable:no-unnecessary-type-assertion -describe('Metacoin', () => { - let metacoin: MetacoinContract; - const ownerAddress = devConstants.TESTRPC_FIRST_ADDRESS; - const INITIAL_BALANCE = new BigNumber(10000); - before(async () => { - metacoin = await MetacoinContract.deployFrom0xArtifactAsync(artifact, provider, config.txDefaults); - web3Wrapper.abiDecoder.addABI(metacoin.abi); - }); - beforeEach(async () => { - await blockchainLifecycle.startAsync(); - }); - afterEach(async () => { - await blockchainLifecycle.revertAsync(); - }); - describe('#constructor', () => { - it(`should initialy give ${INITIAL_BALANCE} tokens to the creator`, async () => { - const balance = await metacoin.balances.callAsync(ownerAddress); - expect(balance).to.be.bignumber.equal(INITIAL_BALANCE); - }); - }); - describe('#transfer', () => { - it(`should successfully transfer tokens (via transfer1)`, async () => { - const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; - const amount = INITIAL_BALANCE.div(2); - const oldBalance = await metacoin.balances.callAsync(ZERO_ADDRESS); - expect(oldBalance).to.be.bignumber.equal(0); - // profiler.start(); - const txHash = await metacoin.transfer1.sendTransactionAsync( - { - to: ZERO_ADDRESS, - amount, - }, - { from: devConstants.TESTRPC_FIRST_ADDRESS }, - ); - // profiler.stop(); - const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash); - const transferLogs = txReceipt.logs[0] as LogWithDecodedArgs<MetacoinTransferEventArgs>; - expect(transferLogs.args).to.be.deep.equal({ - _to: ZERO_ADDRESS, - _from: devConstants.TESTRPC_FIRST_ADDRESS, - _value: amount, - }); - const newBalance = await metacoin.balances.callAsync(ZERO_ADDRESS); - expect(newBalance).to.be.bignumber.equal(amount); - }); - - it(`should successfully transfer tokens (via transfer2)`, async () => { - const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; - const amount = INITIAL_BALANCE.div(2); - const oldBalance = await metacoin.balances.callAsync(ZERO_ADDRESS); - expect(oldBalance).to.be.bignumber.equal(0); - const callback = 59; - const txHash = await metacoin.transfer2.sendTransactionAsync( - { - to: ZERO_ADDRESS, - amount, - }, - callback, - { from: devConstants.TESTRPC_FIRST_ADDRESS }, - ); - const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash); - const transferLogs = txReceipt.logs[0] as LogWithDecodedArgs<MetacoinTransferEventArgs>; - expect(transferLogs.args).to.be.deep.equal({ - _to: ZERO_ADDRESS, - _from: devConstants.TESTRPC_FIRST_ADDRESS, - _value: amount, - }); - const newBalance = await metacoin.balances.callAsync(ZERO_ADDRESS); - expect(newBalance).to.be.bignumber.equal(amount); - }); - - it(`should successfully transfer tokens (via transfer3)`, async () => { - const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'; - const amount = INITIAL_BALANCE.div(2); - const oldBalance = await metacoin.balances.callAsync(ZERO_ADDRESS); - expect(oldBalance).to.be.bignumber.equal(0); - const callback = 59; - const txHash = await metacoin.transfer3.sendTransactionAsync( - { - transferData: { - to: ZERO_ADDRESS, - amount, - }, - callback, - }, - { from: devConstants.TESTRPC_FIRST_ADDRESS }, - ); - const txReceipt = await web3Wrapper.awaitTransactionSuccessAsync(txHash); - const transferLogs = txReceipt.logs[0] as LogWithDecodedArgs<MetacoinTransferEventArgs>; - expect(transferLogs.args).to.be.deep.equal({ - _to: ZERO_ADDRESS, - _from: devConstants.TESTRPC_FIRST_ADDRESS, - _value: amount, - }); - const newBalance = await metacoin.balances.callAsync(ZERO_ADDRESS); - expect(newBalance).to.be.bignumber.equal(amount); - }); - }); -}); -// tslint:enable:no-unnecessary-type-assertion diff --git a/packages/metacoin/test/utils/chai_setup.ts b/packages/metacoin/test/utils/chai_setup.ts deleted file mode 100644 index 1a8733093..000000000 --- a/packages/metacoin/test/utils/chai_setup.ts +++ /dev/null @@ -1,13 +0,0 @@ -import * as chai from 'chai'; -import chaiAsPromised = require('chai-as-promised'); -import ChaiBigNumber = require('chai-bignumber'); -import * as dirtyChai from 'dirty-chai'; - -export const chaiSetup = { - configure(): void { - chai.config.includeStack = true; - chai.use(ChaiBigNumber()); - chai.use(dirtyChai); - chai.use(chaiAsPromised); - }, -}; diff --git a/packages/metacoin/test/utils/config.ts b/packages/metacoin/test/utils/config.ts deleted file mode 100644 index 05f524d52..000000000 --- a/packages/metacoin/test/utils/config.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { devConstants } from '@0x/dev-utils'; - -export const config = { - networkId: 50, - artifactsDir: 'artifacts', - contractsDir: 'contracts', - ganacheLogFile: 'ganache.log', - txDefaults: { - from: devConstants.TESTRPC_FIRST_ADDRESS, - }, - mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic', -}; diff --git a/packages/metacoin/test/utils/coverage.ts b/packages/metacoin/test/utils/coverage.ts deleted file mode 100644 index 1a06d8c3c..000000000 --- a/packages/metacoin/test/utils/coverage.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { devConstants } from '@0x/dev-utils'; -import { CoverageSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-coverage'; -import * as _ from 'lodash'; - -import { config } from './config'; - -let coverageSubprovider: CoverageSubprovider; - -export const coverage = { - getCoverageSubproviderSingleton(): CoverageSubprovider { - if (_.isUndefined(coverageSubprovider)) { - coverageSubprovider = coverage._getCoverageSubprovider(); - } - return coverageSubprovider; - }, - _getCoverageSubprovider(): CoverageSubprovider { - const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS; - const zeroExArtifactsAdapter = new SolCompilerArtifactAdapter(config.artifactsDir, config.contractsDir); - return new CoverageSubprovider(zeroExArtifactsAdapter, defaultFromAddress); - }, -}; diff --git a/packages/metacoin/test/utils/profiler.ts b/packages/metacoin/test/utils/profiler.ts deleted file mode 100644 index 6e6fc309f..000000000 --- a/packages/metacoin/test/utils/profiler.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { devConstants } from '@0x/dev-utils'; -import { ProfilerSubprovider, SolCompilerArtifactAdapter } from '@0x/sol-profiler'; -import * as _ from 'lodash'; - -import { config } from './config'; - -let profilerSubprovider: ProfilerSubprovider; - -export const profiler = { - start(): void { - profiler.getProfilerSubproviderSingleton().start(); - }, - stop(): void { - profiler.getProfilerSubproviderSingleton().stop(); - }, - getProfilerSubproviderSingleton(): ProfilerSubprovider { - if (_.isUndefined(profilerSubprovider)) { - profilerSubprovider = profiler._getProfilerSubprovider(); - } - return profilerSubprovider; - }, - _getProfilerSubprovider(): ProfilerSubprovider { - const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS; - const zeroExArtifactsAdapter = new SolCompilerArtifactAdapter(config.artifactsDir, config.contractsDir); - return new ProfilerSubprovider(zeroExArtifactsAdapter, defaultFromAddress); - }, -}; diff --git a/packages/metacoin/test/utils/web3_wrapper.ts b/packages/metacoin/test/utils/web3_wrapper.ts deleted file mode 100644 index 258cf560f..000000000 --- a/packages/metacoin/test/utils/web3_wrapper.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { env, EnvVars } from '@0x/dev-utils'; -import { GanacheSubprovider, prependSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders'; -import { errorUtils, logUtils } from '@0x/utils'; -import { Web3Wrapper } from '@0x/web3-wrapper'; -import * as fs from 'fs'; - -import { config } from './config'; -import { coverage } from './coverage'; -import { profiler } from './profiler'; - -enum ProviderType { - Ganache = 'ganache', - Geth = 'geth', -} - -let testProvider: ProviderType; -switch (process.env.TEST_PROVIDER) { - case undefined: - testProvider = ProviderType.Ganache; - break; - case 'ganache': - testProvider = ProviderType.Ganache; - break; - case 'geth': - testProvider = ProviderType.Geth; - break; - default: - throw errorUtils.spawnSwitchErr('TEST_PROVIDER', process.env.TEST_PROVIDER); -} - -export const provider = new Web3ProviderEngine(); -if (testProvider === ProviderType.Ganache) { - provider.addProvider( - new GanacheSubprovider({ - logger: { - log: (arg: any) => { - fs.appendFileSync(config.ganacheLogFile, `${arg}\n`); - }, - }, - verbose: env.parseBoolean(EnvVars.SolidityCoverage), - networkId: config.networkId, - mnemonic: config.mnemonic, - }), - ); -} else { - provider.addProvider(new RPCSubprovider('http://localhost:8501')); -} -provider.start(); - -const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage); -const isProfilerEnabled = env.parseBoolean(EnvVars.SolidityProfiler); -if (isCoverageEnabled && isProfilerEnabled) { - throw new Error( - `Unfortunately for now you can't enable both coverage and profiler at the same time. They both use coverage.json file and there is no way to configure that.`, - ); -} -if (isCoverageEnabled) { - const coverageSubprovider = coverage.getCoverageSubproviderSingleton(); - prependSubprovider(provider, coverageSubprovider); -} -if (isProfilerEnabled) { - if (testProvider === ProviderType.Ganache) { - logUtils.warn( - "Gas costs in Ganache traces are incorrect and we don't recommend using it for profiling. Please switch to Geth. Check README for more details", - ); - process.exit(1); - } - const profilerSubprovider = profiler.getProfilerSubproviderSingleton(); - logUtils.log( - "By default profilerSubprovider is stopped so that you don't get noise from setup code. Don't forget to start it before the code you want to profile and stop it afterwards", - ); - profilerSubprovider.stop(); - prependSubprovider(provider, profilerSubprovider); -} - -export const web3Wrapper = new Web3Wrapper(provider); |