From a285aa05d3fd83555b7747fb90e9266dcbb07fdd Mon Sep 17 00:00:00 2001 From: Vittorio Minacori Date: Mon, 23 Jan 2023 11:56:03 +0100 Subject: [PATCH] feat: update to use expect --- .editorconfig | 3 + .eslintignore | 3 - .eslintrc | 42 ++--- .gitignore | 9 +- .nvmrc | 2 +- .prettierrc | 5 +- .solcover.js | 4 +- README.md | 50 ++---- docs/.vuepress/config.js | 33 +++- hardhat.config.js | 13 +- package.json | 56 +++--- scripts/compile.sh | 7 - scripts/coverage.sh | 4 - scripts/test.sh | 59 ------- .../ERC1363PayableCrowdsale.behaviour.js | 163 ++++++++++-------- .../SupportsInterface.behavior.js | 12 +- test/payment/ERC1363Payable.behaviour.js | 27 ++- test/token/ERC1363/ERC1363.behaviour.js | 15 +- truffle-config.js | 11 +- 19 files changed, 208 insertions(+), 310 deletions(-) delete mode 100644 .eslintignore delete mode 100755 scripts/compile.sh delete mode 100755 scripts/coverage.sh delete mode 100755 scripts/test.sh diff --git a/.editorconfig b/.editorconfig index d8525be..f162e8d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,3 +16,6 @@ indent_size = 4 [*.js] indent_size = 2 + +[*.{adoc,md}] +max_line_length = 0 diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index b2311b3..0000000 --- a/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -coverage -cache -node_modules diff --git a/.eslintrc b/.eslintrc index b21c7bf..9c89e5a 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,30 +1,26 @@ { - "extends" : [ - "standard", - "plugin:promise/recommended", + "root": true, + "extends": [ + "eslint:recommended", + "prettier" ], "plugins": [ - "mocha-no-only", - "promise", + "mocha-no-only" ], "env": { - "browser" : true, - "node" : true, - "mocha" : true, - "jest" : true, + "es2022": true, + "browser": true, + "node": true, + "mocha": true }, - "globals" : { - "artifacts": false, - "contract": false, - "assert": false, - "web3": false, + "globals": { + "artifacts": "readonly", + "contract": "readonly", + "web3": "readonly", + "extendEnvironment": "readonly", + "expect": "readonly" }, "rules": { - - // Strict mode - "strict": ["error", "global"], - - // Code style "array-bracket-spacing": ["off"], "camelcase": ["error", {"properties": "always"}], "comma-dangle": ["error", "always-multiline"], @@ -51,12 +47,6 @@ "semi": ["error", "always"], "space-before-function-paren": ["error", "always"], - "mocha-no-only/mocha-no-only": ["error"], - - "promise/always-return": "off", - "promise/avoid-new": "off", - }, - "parserOptions": { - "ecmaVersion": 2018 + "mocha-no-only/mocha-no-only": ["error"] } } diff --git a/.gitignore b/.gitignore index 6b4f3a4..3c51704 100644 --- a/.gitignore +++ b/.gitignore @@ -12,9 +12,9 @@ pids scTopics # Coverage directory used by tools like istanbul -/coverage -/coverageEnv +coverage coverage.json +coverageEnv # temporary artifact from solidity-coverage allFiredEvents @@ -37,6 +37,9 @@ npm-debug.log # truffle build directory /build +# hardat-exposed +contracts-exposed + # Hardhat files /artifacts /cache @@ -54,5 +57,5 @@ package-lock.json .idea # vuepress -docs/.vuepress/dist/ +docs/.vuepress/dist docs/.vuepress/.env.json diff --git a/.nvmrc b/.nvmrc index b6a7d89..3c03207 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16 +18 diff --git a/.prettierrc b/.prettierrc index 923a710..e08e242 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,12 +1,13 @@ { + "printWidth": 120, "singleQuote": true, "trailingComma": "all", + "arrowParens": "avoid", "overrides": [ { "files": "*.sol", "options": { - "singleQuote": false, - "printWidth": 120 + "singleQuote": false } } ] diff --git a/.solcover.js b/.solcover.js index a56c042..cb597f9 100644 --- a/.solcover.js +++ b/.solcover.js @@ -2,7 +2,5 @@ module.exports = { norpc: true, testCommand: 'npm run hardhat:test', compileCommand: 'npm run hardhat:compile', - skipFiles: [ - 'mocks' - ], + skipFiles: ['mocks'], }; diff --git a/README.md b/README.md index 5859d08..a75dd4b 100644 --- a/README.md +++ b/README.md @@ -143,70 +143,50 @@ As example: an Implementation of a classic token Crowdsale, but paid with ERC136 npm install ``` -### Linter - -Use Solhint - -```bash -npm run lint:sol -``` - -Use ESLint - -```bash -npm run lint:js -``` - -Use Eslint and fix - -```bash -npm run lint:fix -``` - -### Usage (using Truffle) +### Usage (using Hardhat) -Open the Truffle console +Open the console ```bash -npm run truffle:console +npm run console ``` #### Compile ```bash -npm run truffle:compile +npm run compile ``` #### Test ```bash -npm run truffle:test +npm test ``` -### Usage (using Hardhat) - -Open the Hardhat console +#### Code Coverage ```bash -npm run hardhat:console +npm run coverage ``` -#### Compile +### Linter + +Check Solidity files ```bash -npm run hardhat:compile +npm run lint:sol ``` -#### Test +Check JS/TS files ```bash -npm run hardhat:test +npm run lint:js ``` -#### Code Coverage +Fix JS and Solidity files ```bash -npm run hardhat:coverage +npm run lint:fix ``` ## License diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index dbe2d4a..6f8141f 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -2,21 +2,40 @@ const vars = require('./.env.json'); module.exports = { title: 'An ERC-20 token that can be used for payments', - description: 'The ERC-1363 is an ERC-20 compatible token that can make a callback on the receiver contract to notify token transfers or token approvals', + description: + 'The ERC-1363 is an ERC-20 compatible token that can make a callback on the receiver contract to notify token transfers or token approvals', base: '/erc1363-payable-token/', plugins: [ - ['@vuepress/google-analytics', { - ga: vars.gaId, - }] + [ + '@vuepress/google-analytics', + { + ga: vars.gaId, + }, + ], ], head: [ ['link', { rel: 'icon', href: '/favicon.ico' }], ['meta', { property: 'og:type', content: 'website' }], ['meta', { property: 'og:url', content: 'https://vittominacori.github.io/erc1363-payable-token' }], - ['meta', { property: 'og:image', content: 'https://vittominacori.github.io/erc1363-payable-token/assets/images/erc1363-payable-token.jpg' }], // eslint-disable-line max-len + [ + 'meta', + { + property: 'og:image', + content: 'https://vittominacori.github.io/erc1363-payable-token/assets/images/erc1363-payable-token.jpg', + }, + ], ['meta', { property: 'twitter:card', content: 'summary_large_image' }], - ['meta', { property: 'twitter:image', content: 'https://vittominacori.github.io/erc1363-payable-token/assets/images/erc1363-payable-token.jpg' }], // eslint-disable-line max-len - ['meta', { property: 'twitter:title', content: 'ERC-1363 Payable Token | An ERC-20 token that can be used for payments' }], + [ + 'meta', + { + property: 'twitter:image', + content: 'https://vittominacori.github.io/erc1363-payable-token/assets/images/erc1363-payable-token.jpg', + }, + ], + [ + 'meta', + { property: 'twitter:title', content: 'ERC-1363 Payable Token | An ERC-20 token that can be used for payments' }, + ], ], themeConfig: { repo: 'vittominacori/erc1363-payable-token', diff --git a/hardhat.config.js b/hardhat.config.js index 7153e7b..78ce14e 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -1,17 +1,9 @@ -require('chai/register-should'); -require('@nomiclabs/hardhat-ganache'); require('@nomiclabs/hardhat-truffle5'); +require('hardhat-exposed'); require('solidity-coverage'); module.exports = { defaultNetwork: 'hardhat', - networks: { - coverage: { - url: 'http://127.0.0.1:8555', - gas: 0xfffffffffff, - gasPrice: 0x01, - }, - }, solidity: { version: '0.8.17', settings: { @@ -21,4 +13,7 @@ module.exports = { }, }, }, + exposed: { + exclude: [], + }, }; diff --git a/package.json b/package.json index 94bcaaa..1317824 100644 --- a/package.json +++ b/package.json @@ -1,34 +1,36 @@ { "name": "erc-payable-token", - "version": "4.8.0", + "version": "4.8.1", "description": "ERC-1363 Payable Token Implementation", "files": [ "contracts", "test" ], "scripts": { - "truffle:console": "truffle develop", - "truffle:compile": "scripts/compile.sh", - "truffle:test": "npm run truffle:compile && scripts/test.sh", + "truffle:console": "truffle console", + "truffle:compile": "truffle compile --all", + "truffle:test": "truffle test", "hardhat:console": "hardhat console", "hardhat:compile": "hardhat compile", "hardhat:test": "hardhat test", - "hardhat:coverage": "hardhat coverage --network coverage", + "hardhat:coverage": "env COVERAGE=true hardhat coverage", + "console": "npm run hardhat:console", + "compile": "npm run hardhat:compile", "test": "npm run hardhat:test", - "coverage": "scripts/coverage.sh", + "coverage": "npm run hardhat:coverage", "clean": "rm -rf coverage", "profile": "npm run clean && npm run coverage && open coverage/index.html", "lint": "npm run lint:js && npm run lint:sol", "lint:fix": "npm run lint:js:fix && npm run lint:sol:fix", - "lint:js": "eslint --ignore-path .gitignore .", - "lint:js:fix": "eslint --ignore-path .gitignore . --fix", - "lint:sol": "solhint 'contracts/**/*.sol' && prettier -c 'contracts/**/*.sol'", - "lint:sol:fix": "prettier --write \"contracts/**/*.sol\"", + "lint:js": "prettier --loglevel warn --ignore-path .gitignore '**/*.{js,ts}' --check && eslint --ignore-path .gitignore .", + "lint:js:fix": "prettier --loglevel warn --ignore-path .gitignore '**/*.{js,ts}' --write && eslint --ignore-path .gitignore . --fix", + "lint:sol": "prettier --loglevel warn --ignore-path .gitignore '{contracts,test}/**/*.sol' --check && solhint '{contracts,test}/**/*.sol'", + "lint:sol:fix": "prettier --loglevel warn --ignore-path .gitignore '{contracts,test}/**/*.sol' --write", "flat": "scripts/flat.sh", "analyze": "scripts/analyze.sh", - "docs:dev": "vuepress dev docs", - "docs:build": "vuepress build docs", - "docs:deploy": "vuepress build docs && sh docs/deploy/deploy.sh" + "docs:dev": "export NODE_OPTIONS=--openssl-legacy-provider && vuepress dev docs", + "docs:build": "export NODE_OPTIONS=--openssl-legacy-provider && vuepress build docs", + "docs:deploy": "export NODE_OPTIONS=--openssl-legacy-provider && vuepress build docs && sh docs/deploy/deploy.sh" }, "repository": { "type": "git", @@ -49,32 +51,26 @@ }, "homepage": "https://vittominacori.github.io/erc1363-payable-token", "dependencies": { - "@openzeppelin/contracts": "4.8.0" + "@openzeppelin/contracts": "4.8.1" }, "devDependencies": { - "@nomiclabs/hardhat-ganache": "^2.0.1", "@nomiclabs/hardhat-truffle5": "^2.0.7", "@nomiclabs/hardhat-web3": "^2.0.0", "@openzeppelin/test-helpers": "^0.5.16", - "@vuepress/plugin-google-analytics": "^1.9.7", - "chai": "4.3.4", - "eslint": "^7.32.0", - "eslint-config-standard": "^16.0.3", - "eslint-plugin-import": "^2.26.0", + "chai": "^4.3.7", + "eslint": "^8.32.0", + "eslint-config-prettier": "^8.6.0", "eslint-plugin-mocha-no-only": "^1.1.1", - "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^5.2.0", - "eslint-plugin-standard": "^5.0.0", - "ganache-cli": "^6.12.2", - "hardhat": "^2.12.2", - "prettier": "^2.7.1", - "prettier-plugin-solidity": "^1.0.0-rc.1", - "sol2uml": "^2.2.6", - "solhint": "^3.3.7", + "hardhat": "^2.12.6", + "hardhat-exposed": "^0.3.0", + "prettier": "^2.8.3", + "prettier-plugin-solidity": "^1.1.1", + "sol2uml": "^2.4.2", + "solhint": "^3.3.8", "solhint-plugin-prettier": "^0.0.5", "solidity-coverage": "^0.8.2", "surya": "^0.4.6", - "truffle": "^5.6.4", + "truffle": "^5.7.3", "vuepress": "^1.9.7" } } diff --git a/scripts/compile.sh b/scripts/compile.sh deleted file mode 100755 index e4e144b..0000000 --- a/scripts/compile.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env sh - -if [ "$SOLC_NIGHTLY" = true ]; then - docker pull ethereum/solc:nightly -fi - -npx truffle compile --all diff --git a/scripts/coverage.sh b/scripts/coverage.sh deleted file mode 100755 index 8a22d82..0000000 --- a/scripts/coverage.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -npm run hardhat:compile -npm run hardhat:coverage diff --git a/scripts/test.sh b/scripts/test.sh deleted file mode 100755 index b15b21b..0000000 --- a/scripts/test.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env bash - -# Exit script as soon as a command fails. -set -o errexit - -# Executes cleanup function at script exit. -trap cleanup EXIT - -cleanup() { - # Kill the ganache instance that we started (if we started one and if it's still running). - if [ -n "$ganache_pid" ] && ps -p $ganache_pid > /dev/null; then - kill -9 $ganache_pid - fi -} - -ganache_port=8545 - -ganache_running() { - nc -z localhost "$ganache_port" -} - -start_ganache() { - # We define 10 accounts with balance 1M ether, needed for high-value tests. - local accounts=( - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200,1000000000000000000000000" - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501201,1000000000000000000000000" - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501202,1000000000000000000000000" - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501203,1000000000000000000000000" - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501204,1000000000000000000000000" - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501205,1000000000000000000000000" - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501206,1000000000000000000000000" - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501207,1000000000000000000000000" - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501208,1000000000000000000000000" - --account="0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501209,1000000000000000000000000" - ) - - npx ganache-cli --gasLimit 0xfffffffffff --port "$ganache_port" "${accounts[@]}" > /dev/null & - - ganache_pid=$! - - echo "Waiting for ganache to launch on port "$ganache_port"..." - - while ! ganache_running; do - sleep 0.1 # wait for 1/10 of the second before check again - done - - echo "Ganache launched!" -} - -if ganache_running; then - echo "Using existing ganache instance" -else - echo "Starting our own ganache instance" - start_ganache -fi - -npx truffle version - -npx truffle test "$@" diff --git a/test/examples/ERC1363PayableCrowdsale.behaviour.js b/test/examples/ERC1363PayableCrowdsale.behaviour.js index c99ed10..c084dd9 100644 --- a/test/examples/ERC1363PayableCrowdsale.behaviour.js +++ b/test/examples/ERC1363PayableCrowdsale.behaviour.js @@ -1,9 +1,10 @@ const { BN, constants, expectRevert, expectEvent } = require('@openzeppelin/test-helpers'); +const { expect } = require('chai'); const { ZERO_ADDRESS } = constants; const Crowdsale = artifacts.require('ERC1363PayableCrowdsale'); -function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, operator]) { +function shouldBehaveLikeERC1363PayableCrowdsale ([deployer, wallet, beneficiary, operator]) { const rate = new BN(1); const value = new BN('1000000000000000000'); const tokenSupply = new BN('10000000000000000000000'); @@ -12,49 +13,53 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera it('requires a non-null ERC20 token', async function () { await expectRevert.unspecified( - Crowdsale.new(rate, wallet, ZERO_ADDRESS, this.erc1363Token.address), + Crowdsale.new(rate, wallet, ZERO_ADDRESS, this.erc1363Token.address, { from: deployer }), ); }); it('requires a non-zero rate', async function () { await expectRevert.unspecified( - Crowdsale.new(0, wallet, this.erc20Token.address, this.erc1363Token.address), + Crowdsale.new(0, wallet, this.erc20Token.address, this.erc1363Token.address, { from: deployer }), ); }); it('requires a non-null wallet', async function () { await expectRevert.unspecified( - Crowdsale.new(rate, ZERO_ADDRESS, this.erc20Token.address, this.erc1363Token.address), + Crowdsale.new(rate, ZERO_ADDRESS, this.erc20Token.address, this.erc1363Token.address, { from: deployer }), ); }); it('requires a non-null ERC1363 token', async function () { await expectRevert( - Crowdsale.new(rate, wallet, this.erc20Token.address, ZERO_ADDRESS), + Crowdsale.new(rate, wallet, this.erc20Token.address, ZERO_ADDRESS, { from: deployer }), 'ERC1363Payable: acceptedToken is zero address', ); }); it('requires a ERC1363 valid token', async function () { - await expectRevert.unspecified(Crowdsale.new(rate, wallet, this.erc20Token.address, this.erc20Token.address)); + await expectRevert.unspecified( + Crowdsale.new(rate, wallet, this.erc20Token.address, this.erc20Token.address, { from: deployer }), + ); }); context('once deployed', async function () { beforeEach(async function () { - this.crowdsale = await Crowdsale.new(rate, wallet, this.erc20Token.address, this.erc1363Token.address); + this.crowdsale = await Crowdsale.new(rate, wallet, this.erc20Token.address, this.erc1363Token.address, { + from: deployer, + }); await this.erc20Token.transfer(this.crowdsale.address, tokenSupply); }); it('has rate', async function () { - (await this.crowdsale.rate()).should.be.bignumber.equal(rate); + expect(await this.crowdsale.rate()).to.be.bignumber.equal(rate); }); it('has wallet', async function () { - (await this.crowdsale.wallet()).should.be.equal(wallet); + expect(await this.crowdsale.wallet()).to.equal(wallet); }); it('has token', async function () { - (await this.crowdsale.token()).should.be.equal(this.erc20Token.address); + expect(await this.crowdsale.token()).to.equal(this.erc20Token.address); }); describe('accepting payments', function () { @@ -65,7 +70,11 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera const transferFromAndCallWithData = function (from, to, value, opts) { return this.erc1363Token.methods['transferFromAndCall(address,address,uint256,bytes)']( - from, to, value, data, opts, + from, + to, + value, + data, + opts, ); }; @@ -75,15 +84,15 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera describe('with data', function () { it('should accept payments', async function () { - await transferFromAndCallWithData.call( - this, beneficiary, this.crowdsale.address, value, { from: operator }, - ); + await transferFromAndCallWithData.call(this, beneficiary, this.crowdsale.address, value, { + from: operator, + }); }); it('should log purchase', async function () { - const receipt = await transferFromAndCallWithData.call( - this, beneficiary, this.crowdsale.address, value, { from: operator }, - ); + const receipt = await transferFromAndCallWithData.call(this, beneficiary, this.crowdsale.address, value, { + from: operator, + }); await expectEvent.inTransaction(receipt.tx, Crowdsale, 'TokensPurchased', { operator: operator, @@ -94,29 +103,29 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera }); it('should assign tokens to sender', async function () { - await transferFromAndCallWithData.call( - this, beneficiary, this.crowdsale.address, value, { from: operator }, - ); - (await this.erc20Token.balanceOf(beneficiary)).should.be.bignumber.equal(expectedTokenAmount); + await transferFromAndCallWithData.call(this, beneficiary, this.crowdsale.address, value, { + from: operator, + }); + expect(await this.erc20Token.balanceOf(beneficiary)).to.be.bignumber.equal(expectedTokenAmount); }); it('should increase token raised', async function () { const pre = await this.crowdsale.tokenRaised(); - pre.should.be.bignumber.equal(new BN(0)); - await transferFromAndCallWithData.call( - this, beneficiary, this.crowdsale.address, value, { from: operator }, - ); + expect(pre).to.be.bignumber.equal(new BN(0)); + await transferFromAndCallWithData.call(this, beneficiary, this.crowdsale.address, value, { + from: operator, + }); const post = await this.crowdsale.tokenRaised(); - post.should.be.bignumber.equal(value); + expect(post).to.be.bignumber.equal(value); }); it('should forward funds to wallet', async function () { const pre = await this.erc1363Token.balanceOf(wallet); - await transferFromAndCallWithData.call( - this, beneficiary, this.crowdsale.address, value, { from: operator }, - ); + await transferFromAndCallWithData.call(this, beneficiary, this.crowdsale.address, value, { + from: operator, + }); const post = await this.erc1363Token.balanceOf(wallet); - post.sub(pre).should.be.bignumber.equal(value); + expect(post.sub(pre)).to.be.bignumber.equal(value); }); it('reverts on zero-valued payments', async function () { @@ -135,14 +144,18 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera describe('without data', function () { it('should accept payments', async function () { - await transferFromAndCallWithoutData.call( - this, beneficiary, this.crowdsale.address, value, { from: operator }, - ); + await transferFromAndCallWithoutData.call(this, beneficiary, this.crowdsale.address, value, { + from: operator, + }); }); it('should log purchase', async function () { const receipt = await transferFromAndCallWithoutData.call( - this, beneficiary, this.crowdsale.address, value, { from: operator }, + this, + beneficiary, + this.crowdsale.address, + value, + { from: operator }, ); await expectEvent.inTransaction(receipt.tx, Crowdsale, 'TokensPurchased', { @@ -154,29 +167,29 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera }); it('should assign tokens to sender', async function () { - await transferFromAndCallWithoutData.call( - this, beneficiary, this.crowdsale.address, value, { from: operator }, - ); - (await this.erc20Token.balanceOf(beneficiary)).should.be.bignumber.equal(expectedTokenAmount); + await transferFromAndCallWithoutData.call(this, beneficiary, this.crowdsale.address, value, { + from: operator, + }); + expect(await this.erc20Token.balanceOf(beneficiary)).to.be.bignumber.equal(expectedTokenAmount); }); it('should increase token raised', async function () { const pre = await this.crowdsale.tokenRaised(); - pre.should.be.bignumber.equal(new BN(0)); - await transferFromAndCallWithoutData.call( - this, beneficiary, this.crowdsale.address, value, { from: operator }, - ); + expect(pre).to.be.bignumber.equal(new BN(0)); + await transferFromAndCallWithoutData.call(this, beneficiary, this.crowdsale.address, value, { + from: operator, + }); const post = await this.crowdsale.tokenRaised(); - post.should.be.bignumber.equal(value); + expect(post).to.be.bignumber.equal(value); }); it('should forward funds to wallet', async function () { const pre = await this.erc1363Token.balanceOf(wallet); - await transferFromAndCallWithoutData.call( - this, beneficiary, this.crowdsale.address, value, { from: operator }, - ); + await transferFromAndCallWithoutData.call(this, beneficiary, this.crowdsale.address, value, { + from: operator, + }); const post = await this.erc1363Token.balanceOf(wallet); - post.sub(pre).should.be.bignumber.equal(value); + expect(post.sub(pre)).to.be.bignumber.equal(value); }); it('reverts on zero-valued payments', async function () { @@ -209,9 +222,9 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera }); it('should log purchase', async function () { - const receipt = await transferAndCallWithData.call( - this, this.crowdsale.address, value, { from: beneficiary }, - ); + const receipt = await transferAndCallWithData.call(this, this.crowdsale.address, value, { + from: beneficiary, + }); await expectEvent.inTransaction(receipt.tx, Crowdsale, 'TokensPurchased', { operator: beneficiary, @@ -223,22 +236,22 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera it('should assign tokens to sender', async function () { await transferAndCallWithData.call(this, this.crowdsale.address, value, { from: beneficiary }); - (await this.erc20Token.balanceOf(beneficiary)).should.be.bignumber.equal(expectedTokenAmount); + expect(await this.erc20Token.balanceOf(beneficiary)).to.be.bignumber.equal(expectedTokenAmount); }); it('should increase token raised', async function () { const pre = await this.crowdsale.tokenRaised(); - pre.should.be.bignumber.equal(new BN(0)); + expect(pre).to.be.bignumber.equal(new BN(0)); await transferAndCallWithData.call(this, this.crowdsale.address, value, { from: beneficiary }); const post = await this.crowdsale.tokenRaised(); - post.should.be.bignumber.equal(value); + expect(post).to.be.bignumber.equal(value); }); it('should forward funds to wallet', async function () { const pre = await this.erc1363Token.balanceOf(wallet); await transferAndCallWithData.call(this, this.crowdsale.address, value, { from: beneficiary }); const post = await this.erc1363Token.balanceOf(wallet); - post.sub(pre).should.be.bignumber.equal(value); + expect(post.sub(pre)).to.be.bignumber.equal(value); }); it('reverts on zero-valued payments', async function () { @@ -261,9 +274,9 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera }); it('should log purchase', async function () { - const receipt = await transferAndCallWithoutData.call( - this, this.crowdsale.address, value, { from: beneficiary }, - ); + const receipt = await transferAndCallWithoutData.call(this, this.crowdsale.address, value, { + from: beneficiary, + }); await expectEvent.inTransaction(receipt.tx, Crowdsale, 'TokensPurchased', { operator: beneficiary, @@ -275,22 +288,22 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera it('should assign tokens to sender', async function () { await transferAndCallWithoutData.call(this, this.crowdsale.address, value, { from: beneficiary }); - (await this.erc20Token.balanceOf(beneficiary)).should.be.bignumber.equal(expectedTokenAmount); + expect(await this.erc20Token.balanceOf(beneficiary)).to.be.bignumber.equal(expectedTokenAmount); }); it('should increase token raised', async function () { const pre = await this.crowdsale.tokenRaised(); - pre.should.be.bignumber.equal(new BN(0)); + expect(pre).to.be.bignumber.equal(new BN(0)); await transferAndCallWithoutData.call(this, this.crowdsale.address, value, { from: beneficiary }); const post = await this.crowdsale.tokenRaised(); - post.should.be.bignumber.equal(value); + expect(post).to.be.bignumber.equal(value); }); it('should forward funds to wallet', async function () { const pre = await this.erc1363Token.balanceOf(wallet); await transferAndCallWithoutData.call(this, this.crowdsale.address, value, { from: beneficiary }); const post = await this.erc1363Token.balanceOf(wallet); - post.sub(pre).should.be.bignumber.equal(value); + expect(post.sub(pre)).to.be.bignumber.equal(value); }); it('reverts on zero-valued payments', async function () { @@ -323,9 +336,9 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera }); it('should log purchase', async function () { - const receipt = await approveAndCallWithData.call( - this, this.crowdsale.address, value, { from: beneficiary }, - ); + const receipt = await approveAndCallWithData.call(this, this.crowdsale.address, value, { + from: beneficiary, + }); await expectEvent.inTransaction(receipt.tx, Crowdsale, 'TokensPurchased', { operator: beneficiary, @@ -337,22 +350,22 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera it('should assign tokens to sender', async function () { await approveAndCallWithData.call(this, this.crowdsale.address, value, { from: beneficiary }); - (await this.erc20Token.balanceOf(beneficiary)).should.be.bignumber.equal(expectedTokenAmount); + expect(await this.erc20Token.balanceOf(beneficiary)).to.be.bignumber.equal(expectedTokenAmount); }); it('should increase token raised', async function () { const pre = await this.crowdsale.tokenRaised(); - pre.should.be.bignumber.equal(new BN(0)); + expect(pre).to.be.bignumber.equal(new BN(0)); await approveAndCallWithData.call(this, this.crowdsale.address, value, { from: beneficiary }); const post = await this.crowdsale.tokenRaised(); - post.should.be.bignumber.equal(value); + expect(post).to.be.bignumber.equal(value); }); it('should forward funds to wallet', async function () { const pre = await this.erc1363Token.balanceOf(wallet); await approveAndCallWithData.call(this, this.crowdsale.address, value, { from: beneficiary }); const post = await this.erc1363Token.balanceOf(wallet); - post.sub(pre).should.be.bignumber.equal(value); + expect(post.sub(pre)).to.be.bignumber.equal(value); }); it('reverts on zero-valued payments', async function () { @@ -375,9 +388,9 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera }); it('should log purchase', async function () { - const receipt = await approveAndCallWithoutData.call( - this, this.crowdsale.address, value, { from: beneficiary }, - ); + const receipt = await approveAndCallWithoutData.call(this, this.crowdsale.address, value, { + from: beneficiary, + }); await expectEvent.inTransaction(receipt.tx, Crowdsale, 'TokensPurchased', { operator: beneficiary, @@ -389,22 +402,22 @@ function shouldBehaveLikeERC1363PayableCrowdsale ([_, wallet, beneficiary, opera it('should assign tokens to sender', async function () { await approveAndCallWithoutData.call(this, this.crowdsale.address, value, { from: beneficiary }); - (await this.erc20Token.balanceOf(beneficiary)).should.be.bignumber.equal(expectedTokenAmount); + expect(await this.erc20Token.balanceOf(beneficiary)).to.be.bignumber.equal(expectedTokenAmount); }); it('should increase token raised', async function () { const pre = await this.crowdsale.tokenRaised(); - pre.should.be.bignumber.equal(new BN(0)); + expect(pre).to.be.bignumber.equal(new BN(0)); await approveAndCallWithoutData.call(this, this.crowdsale.address, value, { from: beneficiary }); const post = await this.crowdsale.tokenRaised(); - post.should.be.bignumber.equal(value); + expect(post).to.be.bignumber.equal(value); }); it('should forward funds to wallet', async function () { const pre = await this.erc1363Token.balanceOf(wallet); await approveAndCallWithoutData.call(this, this.crowdsale.address, value, { from: beneficiary }); const post = await this.erc1363Token.balanceOf(wallet); - post.sub(pre).should.be.bignumber.equal(value); + expect(post.sub(pre)).to.be.bignumber.equal(value); }); it('reverts on zero-valued payments', async function () { diff --git a/test/introspection/SupportsInterface.behavior.js b/test/introspection/SupportsInterface.behavior.js index d0138cb..aa5766b 100644 --- a/test/introspection/SupportsInterface.behavior.js +++ b/test/introspection/SupportsInterface.behavior.js @@ -3,9 +3,7 @@ const { makeInterfaceId } = require('@openzeppelin/test-helpers'); const { expect } = require('chai'); const INTERFACES = { - ERC165: [ - 'supportsInterface(bytes4)', - ], + ERC165: ['supportsInterface(bytes4)'], ERC1363: [ 'transferAndCall(address,uint256)', 'transferAndCall(address,uint256,bytes)', @@ -14,12 +12,8 @@ const INTERFACES = { 'approveAndCall(address,uint256)', 'approveAndCall(address,uint256,bytes)', ], - ERC1363Receiver: [ - 'onTransferReceived(address,address,uint256,bytes)', - ], - ERC1363Spender: [ - 'onApprovalReceived(address,uint256,bytes)', - ], + ERC1363Receiver: ['onTransferReceived(address,address,uint256,bytes)'], + ERC1363Spender: ['onApprovalReceived(address,uint256,bytes)'], }; const INTERFACE_IDS = {}; diff --git a/test/payment/ERC1363Payable.behaviour.js b/test/payment/ERC1363Payable.behaviour.js index fc61450..ea20766 100644 --- a/test/payment/ERC1363Payable.behaviour.js +++ b/test/payment/ERC1363Payable.behaviour.js @@ -1,4 +1,5 @@ const { BN, constants, expectRevert, expectEvent } = require('@openzeppelin/test-helpers'); +const { expect } = require('chai'); const { shouldSupportInterfaces } = require('../introspection/SupportsInterface.behavior'); const { ZERO_ADDRESS } = constants; @@ -12,9 +13,7 @@ function shouldBehaveLikeERC1363Payable ([owner, spender], balance) { describe('creating a valid contract', function () { describe('if accepted token is the zero address', function () { it('reverts', async function () { - await expectRevert( - ERC1363Payable.new(ZERO_ADDRESS), - 'ERC1363Payable: acceptedToken is zero address'); + await expectRevert(ERC1363Payable.new(ZERO_ADDRESS), 'ERC1363Payable: acceptedToken is zero address'); }); }); @@ -36,9 +35,7 @@ function shouldBehaveLikeERC1363Payable ([owner, spender], balance) { }); const transferFromAndCallWithData = function (from, to, value, opts) { - return this.token.methods['transferFromAndCall(address,address,uint256,bytes)']( - from, to, value, data, opts, - ); + return this.token.methods['transferFromAndCall(address,address,uint256,bytes)'](from, to, value, data, opts); }; const transferFromAndCallWithoutData = function (from, to, value, opts) { @@ -60,10 +57,10 @@ function shouldBehaveLikeERC1363Payable ([owner, spender], balance) { it('should execute transferReceived', async function () { let transferNumber = await this.mock.transferNumber(); - transferNumber.should.be.bignumber.equal(new BN(0)); + expect(transferNumber).to.be.bignumber.equal(new BN(0)); await transferFun.call(this, owner, this.mock.address, value, { from: spender }); transferNumber = await this.mock.transferNumber(); - transferNumber.should.be.bignumber.equal(new BN(1)); + expect(transferNumber).to.be.bignumber.equal(new BN(1)); }); }); @@ -111,10 +108,10 @@ function shouldBehaveLikeERC1363Payable ([owner, spender], balance) { it('should execute transferReceived', async function () { let transferNumber = await this.mock.transferNumber(); - transferNumber.should.be.bignumber.equal(new BN(0)); + expect(transferNumber).to.be.bignumber.equal(new BN(0)); await transferFun.call(this, this.mock.address, value, { from: owner }); transferNumber = await this.mock.transferNumber(); - transferNumber.should.be.bignumber.equal(new BN(1)); + expect(transferNumber).to.be.bignumber.equal(new BN(1)); }); }); @@ -161,10 +158,10 @@ function shouldBehaveLikeERC1363Payable ([owner, spender], balance) { it('should execute approvalReceived', async function () { let approvalNumber = await this.mock.approvalNumber(); - approvalNumber.should.be.bignumber.equal(new BN(0)); + expect(approvalNumber).to.be.bignumber.equal(new BN(0)); await approveFun.call(this, this.mock.address, value, { from: owner }); approvalNumber = await this.mock.approvalNumber(); - approvalNumber.should.be.bignumber.equal(new BN(1)); + expect(approvalNumber).to.be.bignumber.equal(new BN(1)); }); }); @@ -188,11 +185,7 @@ function shouldBehaveLikeERC1363Payable ([owner, spender], balance) { }); }); - shouldSupportInterfaces([ - 'ERC165', - 'ERC1363Receiver', - 'ERC1363Spender', - ]); + shouldSupportInterfaces(['ERC165', 'ERC1363Receiver', 'ERC1363Spender']); } module.exports = { diff --git a/test/token/ERC1363/ERC1363.behaviour.js b/test/token/ERC1363/ERC1363.behaviour.js index 719d1d6..190d6ce 100644 --- a/test/token/ERC1363/ERC1363.behaviour.js +++ b/test/token/ERC1363/ERC1363.behaviour.js @@ -12,10 +12,7 @@ function shouldBehaveLikeERC1363 ([owner, spender, recipient], balance) { const RECEIVER_MAGIC_VALUE = '0x88a7ca5c'; const SPENDER_MAGIC_VALUE = '0x7b04a2d0'; - shouldSupportInterfaces([ - 'ERC165', - 'ERC1363', - ]); + shouldSupportInterfaces(['ERC165', 'ERC1363']); describe('via transferFromAndCall', function () { beforeEach(async function () { @@ -23,9 +20,7 @@ function shouldBehaveLikeERC1363 ([owner, spender, recipient], balance) { }); const transferFromAndCallWithData = function (from, to, value, opts) { - return this.token.methods['transferFromAndCall(address,address,uint256,bytes)']( - from, to, value, data, opts, - ); + return this.token.methods['transferFromAndCall(address,address,uint256,bytes)'](from, to, value, data, opts); }; const transferFromAndCallWithoutData = function (from, to, value, opts) { @@ -114,9 +109,9 @@ function shouldBehaveLikeERC1363 ([owner, spender, recipient], balance) { }); it('emits a transfer event', async function () { - const { logs } = await transferFromAndCallWithoutData.call( - this, sender, receiver, amount, { from: spender }, - ); + const { logs } = await transferFromAndCallWithoutData.call(this, sender, receiver, amount, { + from: spender, + }); expectEvent.inLogs(logs, 'Transfer', { from: sender, diff --git a/truffle-config.js b/truffle-config.js index a80f456..fe88213 100644 --- a/truffle-config.js +++ b/truffle-config.js @@ -1,5 +1,3 @@ -require('chai/register-should'); - const solcStable = { version: '0.8.17', settings: { @@ -10,13 +8,6 @@ const solcStable = { }, }; -const solcNightly = { - version: 'nightly', - docker: true, -}; - -const useSolcNightly = process.env.SOLC_NIGHTLY === 'true'; - module.exports = { networks: { development: { @@ -33,7 +24,7 @@ module.exports = { }, }, compilers: { - solc: useSolcNightly ? solcNightly : solcStable, + solc: solcStable, }, plugins: ['solidity-coverage'], };