diff --git a/.circleci/config.yml b/.circleci/config.yml index 43e2947822..54b86c86ee 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -47,7 +47,7 @@ jobs: - restore_cache: keys: - repo-{{ .Environment.CIRCLE_SHA1 }} - - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-dev-utils @0x/contracts-staking + - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-extensions @0x/contracts-asset-proxy @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-coordinator @0x/contracts-tests @0x/contracts-staking test-exchange-ganache-3.0: resource_class: medium+ docker: @@ -67,7 +67,7 @@ jobs: - restore_cache: keys: - repo-{{ .Environment.CIRCLE_SHA1 }} - - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-asset-proxy @0x/contracts-exchange-forwarder @0x/contracts-dev-utils @0x/contracts-staking @0x/contracts-coordinator + - run: yarn wsrun test:circleci @0x/contracts-multisig @0x/contracts-utils @0x/contracts-exchange-libs @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-asset-proxy @0x/contracts-exchange-forwarder @0x/contracts-tests @0x/contracts-staking @0x/contracts-coordinator # TODO(dorothy-zbornak): Re-enable after updating this package for 3.0. # - run: yarn wsrun test:circleci @0x/contracts-extensions test-publish: diff --git a/contracts/dev-utils/package.json b/contracts/dev-utils/package.json index 99ba92c705..659f18ce0b 100644 --- a/contracts/dev-utils/package.json +++ b/contracts/dev-utils/package.json @@ -6,30 +6,17 @@ }, "description": "0x protocol specific utility contracts", "main": "lib/src/index.js", - "directories": { - "test": "test" - }, "scripts": { "build": "yarn pre_build && tsc -b", + "test": "echo !!! Run tests in @0x/contracts-tests instead !!!", "build:ci": "yarn build", "pre_build": "run-s compile quantify_bytecode contracts:gen generate_contract_wrappers", - "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:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", - "test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha", - "run_mocha": "UNLIMITED_CONTRACT_SIZE=true mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", "compile": "sol-compiler", "watch": "sol-compiler -w", "clean": "shx rm -rf lib generated-artifacts generated-wrappers", "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", - "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", "contracts:gen": "contracts-gen", "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol", "quantify_bytecode": "echo EVM bytecode object lengths:;for i in ./generated-artifacts/*.json; do node -e \"console.log('$i\t' + (require('$i').compilerOutput.evm.bytecode.object.length - 2) / 2)\"; done", @@ -51,19 +38,9 @@ "devDependencies": { "@0x/abi-gen": "^4.3.0-beta.0", "@0x/contracts-gen": "^1.1.0-beta.0", - "@0x/contracts-test-utils": "^3.2.0-beta.0", - "@0x/dev-utils": "^2.4.0-beta.0", "@0x/sol-compiler": "^3.2.0-beta.0", "@0x/tslint-config": "^3.0.1", - "@types/lodash": "4.14.104", - "@types/mocha": "^5.2.7", "@types/node": "*", - "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", - "mocha": "^6.2.0", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "solhint": "^1.4.1", @@ -72,21 +49,15 @@ "typescript": "3.0.1" }, "dependencies": { + "@0x/assert": "^2.2.0-beta.0", "@0x/base-contract": "^5.5.0-beta.0", - "@0x/contracts-asset-proxy": "^2.3.0-beta.0", - "@0x/contracts-erc1155": "^1.2.0-beta.0", - "@0x/contracts-erc20": "^2.3.0-beta.0", - "@0x/contracts-erc721": "^2.2.0-beta.0", - "@0x/contracts-exchange": "^2.2.0-beta.0", - "@0x/contracts-exchange-libs": "^3.1.0-beta.0", - "@0x/contracts-utils": "^3.3.0-beta.0", - "@0x/order-utils": "^8.5.0-beta.0", + "@0x/contract-addresses": "^3.3.0-beta.0", + "@0x/json-schemas": "^4.1.0-beta.0", "@0x/types": "^2.5.0-beta.0", - "@0x/typescript-typings": "^4.4.0-beta.0", "@0x/utils": "^4.6.0-beta.0", "@0x/web3-wrapper": "^6.1.0-beta.0", "ethereum-types": "^2.2.0-beta.0", - "ethereumjs-util": "^5.1.1" + "ethers": "~4.0.4" }, "publishConfig": { "access": "public" diff --git a/contracts/tests/CHANGELOG.json b/contracts/tests/CHANGELOG.json new file mode 100644 index 0000000000..b4dd63c035 --- /dev/null +++ b/contracts/tests/CHANGELOG.json @@ -0,0 +1,11 @@ +[ + { + "version": "0.0.1", + "changes": [ + { + "note": "Created package", + "pr": 2261 + } + ] + } +] diff --git a/contracts/tests/README.md b/contracts/tests/README.md new file mode 100644 index 0000000000..f55bf39be6 --- /dev/null +++ b/contracts/tests/README.md @@ -0,0 +1,75 @@ +## Tests + +This package implements unit tests against 0x's smart contracts. Its primary purpose is to help avoid circular dependencies between the contract packages. + +## Contributing + +We strongly recommend that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository. + +For proposals regarding the 0x protocol's smart contract architecture, message format, or additional functionality, go to the [0x Improvement Proposals (ZEIPs)](https://github.com/0xProject/ZEIPs) repository and follow the contribution guidelines provided therein. + +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/contracts-tests yarn build +``` + +Or continuously rebuild on change: + +```bash +PKG=@0x/contracts-tests yarn watch +``` + +If imports are rebuilt in their source packages, they do not need to be rebuilt here. + +Example: + +``` +// contracts/tests/test/some-new/some_new_test.ts +import { SomeNewContract } from '@0x/contracts-some-new'; + +describe('should do its thing', () => { + const contractInstance = new SomeNewContract(); + expect(contractInstance.someTruthyFunction.callAsync()).to.be.true(); +}) +``` + +Run `yarn watch` from `contracts/some-new`, and then running `yarn test` from this package should test the new changes. + +### Clean + +```bash +yarn clean +``` + +Since the purpose of this package is to test other packages, make sure you are running `yarn clean` as necessary in the imported packages as well. + +### Lint + +```bash +yarn lint +``` + +### Run Tests + +```bash +yarn test +``` diff --git a/contracts/tests/compiler.json b/contracts/tests/compiler.json new file mode 100644 index 0000000000..6b74c612c2 --- /dev/null +++ b/contracts/tests/compiler.json @@ -0,0 +1,26 @@ +{ + "artifactsDir": "./generated-artifacts", + "contractsDir": "./contracts", + "useDockerisedSolc": false, + "isOfflineMode": false, + "compilerSettings": { + "evmVersion": "constantinople", + "optimizer": { + "enabled": true, + "runs": 1000000, + "details": { "yul": true, "deduplicate": true, "cse": true, "constantOptimizer": true } + }, + "outputSelection": { + "*": { + "*": [ + "abi", + "devdoc", + "evm.bytecode.object", + "evm.bytecode.sourceMap", + "evm.deployedBytecode.object", + "evm.deployedBytecode.sourceMap" + ] + } + } + } +} diff --git a/contracts/tests/package.json b/contracts/tests/package.json new file mode 100644 index 0000000000..061c3b5d13 --- /dev/null +++ b/contracts/tests/package.json @@ -0,0 +1,86 @@ +{ + "name": "@0x/contracts-tests", + "version": "0.0.1", + "engines": { + "node": ">=6.12" + }, + "description": "Unit tests for 0x contracts", + "main": "lib/src/index.js", + "directories": { + "test": "test" + }, + "scripts": { + "build": "tsc -b", + "build:ci": "yarn build", + "pre_build": "run-s compile contracts:gen generate_contract_wrappers", + "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:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", + "test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha", + "run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", + "compile": "sol-compiler", + "watch": "sol-compiler -w", + "clean": "shx rm -rf lib generated-artifacts generated-wrappers", + "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", + "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", + "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", + "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", + "contracts:gen": "contracts-gen", + "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol", + "compile:truffle": "truffle compile" + }, + "config": { + "abis": "./generated-artifacts/@().json", + "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." + }, + "repository": { + "type": "git", + "url": "https://github.com/0xProject/0x-monorepo.git" + }, + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/0xProject/0x-monorepo/issues" + }, + "homepage": "https://github.com/0xProject/0x-monorepo/contracts/tests/README.md", + "devDependencies": { + "@0x/abi-gen": "^4.3.0-beta.0", + "@0x/contracts-asset-proxy": "^2.3.0-beta.0", + "@0x/base-contract": "^5.5.0-beta.0", + "@0x/contracts-dev-utils": "^0.1.0-beta.0", + "@0x/contracts-erc1155": "^1.2.0-beta.0", + "@0x/contracts-erc20": "^2.3.0-beta.0", + "@0x/contracts-erc721": "^2.2.0-beta.0", + "@0x/contracts-exchange": "^2.2.0-beta.0", + "@0x/contracts-gen": "^1.1.0-beta.0", + "@0x/contracts-test-utils": "^3.2.0-beta.0", + "@0x/sol-compiler": "^3.2.0-beta.0", + "@0x/tslint-config": "^3.0.1", + "@0x/types": "^2.5.0-beta.0", + "@0x/typescript-typings": "^4.4.0-beta.0", + "@0x/utils": "^4.6.0-beta.0", + "@0x/web3-wrapper": "^6.1.0-beta.0", + "@types/mocha": "^5.2.7", + "@types/node": "*", + "chai": "^4.0.1", + "chai-as-promised": "^7.1.0", + "chai-bignumber": "^3.0.0", + "dirty-chai": "^2.0.1", + "ethereum-types": "^2.2.0-beta.0", + "make-promises-safe": "^1.1.0", + "mocha": "^6.2.0", + "npm-run-all": "^4.1.2", + "shx": "^0.2.2", + "solhint": "^1.4.1", + "truffle": "^5.0.32", + "tslint": "5.11.0", + "typescript": "3.0.1" + }, + "publishConfig": { + "access": "private" + } +} diff --git a/contracts/tests/src/artifacts.ts b/contracts/tests/src/artifacts.ts new file mode 100644 index 0000000000..ee78e80403 --- /dev/null +++ b/contracts/tests/src/artifacts.ts @@ -0,0 +1,8 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ +import { ContractArtifact } from 'ethereum-types'; + +export const artifacts = {}; diff --git a/contracts/tests/src/index.ts b/contracts/tests/src/index.ts new file mode 100644 index 0000000000..01206c99a9 --- /dev/null +++ b/contracts/tests/src/index.ts @@ -0,0 +1 @@ +export * from './artifacts'; diff --git a/contracts/tests/src/wrappers.ts b/contracts/tests/src/wrappers.ts new file mode 100644 index 0000000000..74ff63e906 --- /dev/null +++ b/contracts/tests/src/wrappers.ts @@ -0,0 +1,5 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ diff --git a/contracts/dev-utils/test/global_hooks.ts b/contracts/tests/test/dev-utils/global_hooks.ts similarity index 100% rename from contracts/dev-utils/test/global_hooks.ts rename to contracts/tests/test/dev-utils/global_hooks.ts diff --git a/contracts/dev-utils/test/lib_asset_data.ts b/contracts/tests/test/dev-utils/lib_asset_data.ts similarity index 99% rename from contracts/dev-utils/test/lib_asset_data.ts rename to contracts/tests/test/dev-utils/lib_asset_data.ts index 3707b34280..1b1d9b6dda 100644 --- a/contracts/dev-utils/test/lib_asset_data.ts +++ b/contracts/tests/test/dev-utils/lib_asset_data.ts @@ -25,7 +25,7 @@ import { AssetProxyId } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import * as ethUtil from 'ethereumjs-util'; -import { artifacts, LibAssetDataContract } from '../src'; +import { artifacts, LibAssetDataContract } from '@0x/contracts-dev-utils'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/dev-utils/test/lib_transaction_decoder.ts b/contracts/tests/test/dev-utils/lib_transaction_decoder.ts similarity index 98% rename from contracts/dev-utils/test/lib_transaction_decoder.ts rename to contracts/tests/test/dev-utils/lib_transaction_decoder.ts index 7c4ea38894..9fe5ee13d6 100644 --- a/contracts/dev-utils/test/lib_transaction_decoder.ts +++ b/contracts/tests/test/dev-utils/lib_transaction_decoder.ts @@ -4,7 +4,7 @@ import { BlockchainLifecycle } from '@0x/dev-utils'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; -import { artifacts, LibTransactionDecoderContract } from '../src'; +import { artifacts, LibTransactionDecoderContract } from '@0x/contracts-dev-utils'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/dev-utils/test/order_validation_utils.ts b/contracts/tests/test/dev-utils/order_validation_utils.ts similarity index 99% rename from contracts/dev-utils/test/order_validation_utils.ts rename to contracts/tests/test/dev-utils/order_validation_utils.ts index 8d4087fb75..e8d2c126fd 100644 --- a/contracts/dev-utils/test/order_validation_utils.ts +++ b/contracts/tests/test/dev-utils/order_validation_utils.ts @@ -24,7 +24,7 @@ import { OrderTransferResults, SignedOrder } from '@0x/types'; import { BigNumber, providerUtils } from '@0x/utils'; import * as chai from 'chai'; -import { artifacts, DevUtilsContract } from '../src'; +import { artifacts, DevUtilsContract } from '@0x/contracts-dev-utils'; chaiSetup.configure(); const expect = chai.expect; diff --git a/contracts/tests/tsconfig.json b/contracts/tests/tsconfig.json new file mode 100644 index 0000000000..6d6a1bf83b --- /dev/null +++ b/contracts/tests/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig", + "compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true }, + "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], + "exclude": ["./lib/**/*"] +} diff --git a/package.json b/package.json index 7eeed92f4f..d80b0ac141 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "lint:contracts": "wsrun lint -p ${npm_package_config_contractsPackages} -c --fast-exit --stages --exclude-missing" }, "config": { - "contractsPackages": "@0x/contracts-asset-proxy @0x/contracts-dev-utils @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-exchange-libs @0x/contracts-integrations @0x/contracts-multisig @0x/contracts-staking @0x/contracts-test-utils @0x/contracts-utils @0x/contracts-coordinator", + "contractsPackages": "@0x/contracts-asset-proxy @0x/contracts-dev-utils @0x/contracts-erc20 @0x/contracts-erc721 @0x/contracts-erc1155 @0x/contracts-exchange @0x/contracts-exchange-forwarder @0x/contracts-exchange-libs @0x/contracts-integrations @0x/contracts-multisig @0x/contracts-staking @0x/contracts-test-utils @0x/contracts-utils @0x/contracts-coordinator @0x/contracts-tests", "mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic", "packagesWithDocPages": "contract-wrappers 0x.js connect json-schemas subproviders web3-wrapper order-utils sol-compiler sol-coverage sol-profiler sol-trace ethereum-types asset-buyer asset-swapper migrations", "ignoreDependencyVersions": "@types/styled-components @types/node",