Remove metacoin example from monorepo

This commit is contained in:
fabioberger 2019-07-19 19:38:08 +02:00
parent 620c66fb4c
commit e39dce6159
16 changed files with 0 additions and 381 deletions

View File

@ -102,7 +102,6 @@ jobs:
- run: yarn wsrun test:circleci @0x/contract-wrappers
- run: yarn wsrun test:circleci @0x/dev-utils
- run: yarn wsrun test:circleci @0x/json-schemas
- run: yarn wsrun test:circleci @0x/metacoin
- run: yarn wsrun test:circleci @0x/order-utils
- run: yarn wsrun test:circleci @0x/order-watcher
- run: yarn wsrun test:circleci @0x/sol-compiler
@ -144,10 +143,6 @@ jobs:
key: coverage-json-schemas-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/packages/json-schemas/coverage/lcov.info
- save_cache:
key: coverage-metacoin-{{ .Environment.CIRCLE_SHA1 }}
paths:
- ~/repo/packages/metacoin/coverage/lcov.info
- save_cache:
key: coverage-order-utils-{{ .Environment.CIRCLE_SHA1 }}
paths:
@ -326,9 +321,6 @@ jobs:
- restore_cache:
keys:
- coverage-json-schemas-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-metacoin-{{ .Environment.CIRCLE_SHA1 }}
- restore_cache:
keys:
- coverage-order-utils-{{ .Environment.CIRCLE_SHA1 }}

View File

@ -30,7 +30,6 @@ contracts: ['contracts']
@0x/typescript-typings: ['packages/typescript-typings']
0x.js: ['packages/0x.js']
@0x/abi-gen-wrappers: ['packages/abi-gen-wrappers']
@0x/metacoin: ['packages/metacoin']
@0x/contract-artifacts: ['packages/contract-artifacts']
@0x/dev-utils: ['packages/dev-utils']
@0x/contract-wrappers: ['packages/contract-wrappers']

2
.gitignore vendored
View File

@ -96,7 +96,6 @@ contracts/extensions/generated-artifacts/
contracts/exchange-forwarder/generated-artifacts/
contracts/dev-utils/generated-artifacts/
packages/sol-tracing-utils/test/fixtures/artifacts/
packages/metacoin/artifacts/
python-packages/contract_artifacts/src/zero_ex/contract_artifacts/artifacts/
# generated contract wrappers
@ -114,7 +113,6 @@ contracts/erc1155/generated-wrappers/
contracts/extensions/generated-wrappers/
contracts/exchange-forwarder/generated-wrappers/
contracts/dev-utils/generated-wrappers/
packages/metacoin/src/contract_wrappers
# cli test output
packages/abi-gen/test-cli/output

View File

@ -27,8 +27,6 @@ lib
/packages/abi-gen/test-cli/output
/packages/json-schemas/schemas
/python-packages/json_schemas/src/zero_ex/json_schemas/schemas
/packages/metacoin/src/contract_wrappers
/packages/metacoin/artifacts
/packages/sra-spec/public/
/packages/dev-tools-pages/ts/**/data.json
package.json

View File

@ -20,7 +20,6 @@ packages/contract-artifacts/ @albrow
packages/dev-utils/ @LogvinovLeon @fabioberger
packages/devnet/ @albrow
packages/ethereum-types/ @LogvinovLeon
packages/metacoin/ @LogvinovLeon
packages/monorepo-scripts/ @fabioberger
packages/order-utils/ @fabioberger @LogvinovLeon
packages/python-contract-wrappers/ @feuGeneA

View File

@ -1,81 +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
```
### 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();
```

View File

@ -1,18 +0,0 @@
{
"artifactsDir": "artifacts",
"contractsDir": "contracts",
"compilerSettings": {
"outputSelection": {
"*": {
"*": [
"abi",
"devdoc",
"evm.bytecode.object",
"evm.bytecode.sourceMap",
"evm.deployedBytecode.object",
"evm.deployedBytecode.sourceMap"
]
}
}
}
}

View File

@ -1,43 +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;
}
/// @dev This is an example devdoc
/// @param transferData Transfer data to act on.
/// @return success True if successful, otherwise false
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);
}
}

View File

@ -1,67 +0,0 @@
{
"name": "@0x/metacoin",
"version": "0.0.54",
"engines": {
"node": ">=6.12"
},
"private": true,
"description": "Example solidity project using 0x dev tools",
"scripts": {
"lint": "tslint --format stylish --project . --exclude **/src/contract_wrappers/**/*",
"fix": "tslint --fix --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",
"watch": "sol-compiler -w"
},
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@0x/abi-gen": "^2.1.1",
"@0x/abi-gen-templates": "^2.2.1",
"@0x/base-contract": "^5.1.1",
"@0x/sol-coverage": "^3.0.6",
"@0x/sol-profiler": "^3.1.8",
"@0x/sol-trace": "^2.0.14",
"@0x/subproviders": "^4.1.1",
"@0x/tslint-config": "^3.0.1",
"@0x/types": "^2.4.0",
"@0x/typescript-typings": "^4.2.3",
"@0x/utils": "^4.4.0",
"@0x/web3-wrapper": "^6.0.7",
"@types/mocha": "^2.2.42",
"copyfiles": "^2.0.0",
"ethereum-types": "^2.1.3",
"ethers": "~4.0.4",
"lodash": "^4.17.11",
"run-s": "^0.0.0"
},
"devDependencies": {
"@0x/contracts-test-utils": "^3.1.10",
"@0x/dev-utils": "^2.2.4",
"@0x/sol-compiler": "^3.1.9",
"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"
}
}

View File

@ -1,4 +0,0 @@
declare module '*.json' {
const value: any;
export default value;
}

View File

@ -1,18 +0,0 @@
import { env, EnvVars } from '@0x/dev-utils';
import { coverage, profiler, provider } from '@0x/contracts-test-utils';
import { providerUtils } from '@0x/utils';
before('start web3 provider', () => {
providerUtils.startProviderEngine(provider);
});
after('generate coverage 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();
}
provider.stop();
});

View File

@ -1,116 +0,0 @@
import { chaiSetup, provider, txDefaults, web3Wrapper } from '@0x/contracts-test-utils';
// Uncomment the next line to enable profiling
// import { profiler } from '@0x/contracts-test-utils';
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';
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, 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);
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

View File

@ -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/**/*"]
}

View File

@ -1,3 +0,0 @@
{
"extends": ["@0x/tslint-config"]
}

View File

@ -46,7 +46,6 @@
{ "path": "./packages/ethereum-types" },
{ "path": "./packages/fill-scenarios" },
{ "path": "./packages/json-schemas" },
{ "path": "./packages/metacoin" },
{ "path": "./packages/migrations" },
{ "path": "./packages/monorepo-scripts" },
{ "path": "./packages/order-utils" },