diff options
author | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
---|---|---|
committer | Hsuan Lee <hsuan@cobinhood.com> | 2019-01-19 18:42:04 +0800 |
commit | 7ae38906926dc09bc10670c361af0d2bf0050426 (patch) | |
tree | 5fb10ae366b987db09e4ddb4bc3ba0f75404ad08 /packages/metacoin | |
parent | b5fd3c72a08aaa6957917d74c333387a16edf66b (diff) | |
download | dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.gz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.bz2 dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.lz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.xz dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.tar.zst dexon-sol-tools-7ae38906926dc09bc10670c361af0d2bf0050426.zip |
Update dependency packages
Diffstat (limited to 'packages/metacoin')
-rw-r--r-- | packages/metacoin/README.md | 97 | ||||
-rw-r--r-- | packages/metacoin/compiler.json | 15 | ||||
-rw-r--r-- | packages/metacoin/contracts/Metacoin.sol | 40 | ||||
-rw-r--r-- | packages/metacoin/coverage/.gitkeep | 0 | ||||
-rw-r--r-- | packages/metacoin/package.json | 64 | ||||
-rw-r--r-- | packages/metacoin/src/global.d.ts | 4 | ||||
-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 | ||||
-rw-r--r-- | packages/metacoin/tsconfig.json | 16 | ||||
-rw-r--r-- | packages/metacoin/tslint.json | 3 |
15 files changed, 0 insertions, 523 deletions
diff --git a/packages/metacoin/README.md b/packages/metacoin/README.md deleted file mode 100644 index 6f35dfc25..000000000 --- a/packages/metacoin/README.md +++ /dev/null @@ -1,97 +0,0 @@ -## @0x/metacoin - -This is an example project that demonstrates how the many Ethereum dev tools developed by 0x can be used in any Solidity/TS project. -It supports: - -- Compiling & testing smart contracts -- Generating typed contract wrappers -- Solidity coverage -- Solidity gas profiling -- Running tests against Ganache -- Running tests against our fork of Geth (it supports snapshotting & time travel) - -## Contributing - -We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository. - -Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. - -### Install dependencies - -If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: - -```bash -yarn config set workspaces-experimental true -``` - -Then install dependencies - -```bash -yarn install -``` - -### Build - -To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: - -```bash -PKG=@0x/metacoin yarn build -``` - -Or continuously rebuild on change: - -```bash -PKG=@0x/metacoin yarn watch -``` - -### Clean - -```bash -yarn clean -``` - -### Lint - -```bash -yarn lint -``` - -### Test providers - -By default tests run against an in-process Ganache instance. If you want to use Geth you'll need to [start a Geth dev node](https://github.com/0xProject/0x-monorepo/blob/v2-prototype/packages/devnet/README.md) first. - -```bash -cd ../devnet -docker build -t 0x-devnet . -docker run -it --rm -p 8501:8501 0x-devnet -``` - -This Geth version supports snapshots and time travel. Then - run your tests against it. - -``` -TEST_PROVIDER=geth yarn test -``` - -### Coverage - -```bash -yarn test:coverage -yarn coverage:report:html -``` - -### Profiling - -Please note that traces emitted by ganache have incorrect gas costs so we recommend using Geth for profiling. - -```bash -TEST_PROVIDER=geth yarn test:profile -``` - -You'll see a warning that you need to explicitly enable and disable the profiler before and after the block of code you want to profile. - -```typescript -import { profiler } from './utils/profiler'; -profiler.start(); -// Some solidity stuff -profiler.stop(); -``` diff --git a/packages/metacoin/compiler.json b/packages/metacoin/compiler.json deleted file mode 100644 index f5817e0c8..000000000 --- a/packages/metacoin/compiler.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "compilerSettings": { - "outputSelection": { - "*": { - "*": [ - "abi", - "evm.bytecode.object", - "evm.bytecode.sourceMap", - "evm.deployedBytecode.object", - "evm.deployedBytecode.sourceMap" - ] - } - } - } -} diff --git a/packages/metacoin/contracts/Metacoin.sol b/packages/metacoin/contracts/Metacoin.sol deleted file mode 100644 index dc67e6242..000000000 --- a/packages/metacoin/contracts/Metacoin.sol +++ /dev/null @@ -1,40 +0,0 @@ -pragma solidity ^0.4.24; -pragma experimental ABIEncoderV2; - -contract Metacoin { - mapping (address => uint) public balances; - - event Transfer(address indexed _from, address indexed _to, uint256 _value); - - struct TransferData { - address to; - uint256 amount; - } - - struct NestedTransferData { - TransferData transferData; - uint32 callback; - } - - constructor () public { - balances[msg.sender] = 10000; - } - - function transfer(TransferData transferData) public returns (bool success) { - if (balances[msg.sender] < transferData.amount) return false; - balances[msg.sender] -= transferData.amount; - balances[transferData.to] += transferData.amount; - emit Transfer(msg.sender, transferData.to, transferData.amount); - return true; - } - - function transfer(TransferData transferData, uint32 callback) public returns (int) { - transfer(transferData); - return callback; - } - - function transfer(NestedTransferData nestedTransferData) public returns (int) { - return transfer(nestedTransferData.transferData, nestedTransferData.callback); - } - -} diff --git a/packages/metacoin/coverage/.gitkeep b/packages/metacoin/coverage/.gitkeep deleted file mode 100644 index e69de29bb..000000000 --- a/packages/metacoin/coverage/.gitkeep +++ /dev/null diff --git a/packages/metacoin/package.json b/packages/metacoin/package.json deleted file mode 100644 index 3b082f075..000000000 --- a/packages/metacoin/package.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "name": "@0x/metacoin", - "version": "0.0.36", - "engines": { - "node": ">=6.12" - }, - "private": true, - "description": "Example solidity project using 0x dev tools", - "scripts": { - "lint": "tslint --format stylish --project . --exclude **/src/contract_wrappers/**/*", - "build": "yarn pre_build && tsc -b", - "build:ci": "yarn build", - "pre_build": "run-s compile generate_contract_wrappers copy_artifacts", - "clean": "shx rm -rf lib artifacts src/contract_wrappers", - "copy_artifacts": "copyfiles './artifacts/**/*' './contracts/**/*' ./lib", - "test": "yarn run_mocha", - "rebuild_and_test": "run-s build test", - "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", - "test:profile": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", - "run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js lib/test/global_hooks.js --bail --exit --timeout 10000", - "generate_contract_wrappers": "abi-gen --abis 'artifacts/Metacoin.json' --template ../../node_modules/@0x/abi-gen-templates/contract.handlebars --partials '../../node_modules/@0x/abi-gen-templates/partials/**/*.handlebars' --output src/contract_wrappers --backend ethers", - "coverage:report:text": "istanbul report text", - "coverage:report:html": "istanbul report html && open coverage/index.html", - "profiler:report:html": "istanbul report html && open coverage/index.html", - "coverage:report:lcov": "istanbul report lcov", - "test:circleci": "yarn test:coverage", - "compile": "sol-compiler compile" - }, - "author": "", - "license": "Apache-2.0", - "dependencies": { - "@0x/abi-gen": "^1.0.22", - "@0x/abi-gen-templates": "^1.0.2", - "@0x/base-contract": "^3.0.13", - "@0x/sol-coverage": "^1.0.3", - "@0x/sol-profiler": "^1.0.3", - "@0x/sol-trace": "^1.0.3", - "@0x/subproviders": "^2.1.11", - "@0x/tslint-config": "^2.0.2", - "@0x/types": "^1.5.2", - "@0x/typescript-typings": "^3.0.8", - "@0x/utils": "^3.0.1", - "@0x/web3-wrapper": "^3.2.4", - "@types/mocha": "^5.2.2", - "copyfiles": "^2.0.0", - "ethereum-types": "^1.1.6", - "ethers": "~4.0.4", - "lodash": "^4.17.5", - "run-s": "^0.0.0" - }, - "devDependencies": { - "@0x/dev-utils": "^1.0.24", - "@0x/sol-compiler": "^2.0.2", - "chai": "^4.0.1", - "chai-as-promised": "^7.1.0", - "chai-bignumber": "^3.0.0", - "dirty-chai": "^2.0.1", - "make-promises-safe": "^1.1.0", - "npm-run-all": "^4.1.2", - "shx": "^0.2.2", - "tslint": "5.11.0", - "typescript": "3.0.1" - } -} diff --git a/packages/metacoin/src/global.d.ts b/packages/metacoin/src/global.d.ts deleted file mode 100644 index 783b92913..000000000 --- a/packages/metacoin/src/global.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module '*.json' { - const value: any; - export default value; -} 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); diff --git a/packages/metacoin/tsconfig.json b/packages/metacoin/tsconfig.json deleted file mode 100644 index 163465cf5..000000000 --- a/packages/metacoin/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../../tsconfig", - "compilerOptions": { - "outDir": "lib", - "rootDir": ".", - "typeRoots": [ - "comment: for building within 0x-monorepo:", - "../../node_modules/@0x/typescript-typings/types", - "../../node_modules/@types", - "comment: for building in an isolated environment:", - "node_modules/@0x/typescript-typings/types", - "node_modules/@types" - ] - }, - "include": ["src/**/*", "test/**/*"] -} diff --git a/packages/metacoin/tslint.json b/packages/metacoin/tslint.json deleted file mode 100644 index dd9053357..000000000 --- a/packages/metacoin/tslint.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": ["@0x/tslint-config"] -} |