Commit 5f92adc2 by Nicolás Venturo Committed by Francisco Giordano

Migrate from truffle to test-environment (#2007)

* Sketch

* Migrate all tests to test-env

* Finish migration to test-env

* Add config

* Work on GSN tests

* Migrate to newer test-env version and loader syntax

* Add GSN setup

* Finish test-env migration

* Setup coverage using test-env

* Migrate to npm package

* Fix package.json

* Add compile step to CI

* Add comment on coverage setup

* Remove dependency on @truffle/contract

* Fix package-lock merge

* Fix linter errors

* Upgrade test-environment, depend locally on ganche-coverage

* Improve coverage script

* Improve sign.js API

* Move accounts destructuring to describe block

* Switch to prebuilt ethereumjs-vm package

* Upgrade test-enviroment version

* use workspace in circleci config

* remove unnecessary npx
parent ca6a5dc8
......@@ -8,14 +8,6 @@ aliases:
docker:
- image: circleci/node:10
- &npm_install_if_necessary
run:
name: Install npm dependencies
command: |
if [ ! -d node_modules ]; then
npm ci
fi
- &cache_key_node_modules
key: v1-node_modules-{{ checksum "package-lock.json" }}
......@@ -26,7 +18,19 @@ jobs:
- checkout
- restore_cache:
<<: *cache_key_node_modules
- *npm_install_if_necessary
- run:
name: Install npm dependencies and prepare
command: |
if [ ! -d node_modules ]; then
npm ci
else
npm run prepare
fi
- persist_to_workspace:
root: .
paths:
- node_modules
- build
- save_cache:
paths:
- node_modules
......@@ -36,9 +40,8 @@ jobs:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *cache_key_node_modules
- *npm_install_if_necessary
- attach_workspace:
at: .
- run:
name: Linter
command: npm run lint
......@@ -46,19 +49,18 @@ jobs:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *cache_key_node_modules
- *npm_install_if_necessary
- attach_workspace:
at: .
- run:
name: Unit tests
command: npm run test
coverage:
<<: *defaults
steps:
- checkout
- restore_cache:
<<: *cache_key_node_modules
- *npm_install_if_necessary
- attach_workspace:
at: .
- run:
name: Unit tests with coverage report
command: npm run coverage
......
......@@ -25,6 +25,7 @@
"strict": ["error", "global"],
// Code style
"array-bracket-spacing": ["off"],
"camelcase": ["error", {"properties": "always"}],
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": ["error", {"before": false, "after": true}],
......
......@@ -48,3 +48,6 @@ openzeppelin-docs
# only used to package @openzeppelin/contracts
contracts/build/
contracts/README.md
# temporary artifact from solidity-coverage
allFiredEvents
module.exports = {
norpc: true,
testCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle test --network coverage',
compileCommand: 'node --max-old-space-size=4096 ../node_modules/.bin/truffle compile --network coverage',
testCommand: 'npm test',
compileCommand: 'npm run compile',
skipFiles: [
'lifecycle/Migrations.sol',
'mocks'
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -11,7 +11,6 @@
],
"scripts": {
"compile": "scripts/compile.sh",
"console": "truffle console",
"coverage": "scripts/coverage.sh",
"docs": "scripts/docs.sh",
"prepare-docs": "scripts/prepare-docs.sh",
......@@ -23,7 +22,7 @@
"prepare": "node scripts/prepare.js",
"release": "scripts/release/release.sh",
"version": "scripts/release/version.sh",
"test": "scripts/test.sh"
"test": "mocha --exit --recursive test"
},
"repository": {
"type": "git",
......@@ -44,8 +43,10 @@
},
"homepage": "https://github.com/OpenZeppelin/openzeppelin-contracts",
"devDependencies": {
"@openzeppelin/cli": "^2.5.3",
"@openzeppelin/gsn-helpers": "^0.2.1",
"@openzeppelin/gsn-provider": "^0.1.9",
"@openzeppelin/test-environment": "^0.1.1",
"@openzeppelin/test-helpers": "^0.5.4",
"chai": "^4.2.0",
"concurrently": "^5.0.0",
......@@ -57,15 +58,15 @@
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"ethereumjs-util": "^6.2.0",
"ganache-cli": "^6.7.0",
"ganache-cli-coverage": "https://github.com/frangio/ganache-cli/releases/download/v6.4.1-coverage/ganache-cli-coverage-6.4.1.tgz",
"ganache-core-coverage": "https://github.com/OpenZeppelin/ganache-core-coverage/releases/download/2.5.3-coverage/ganache-core-coverage-2.5.3.tgz",
"http-server": "^0.11.1",
"lodash.startcase": "^4.4.0",
"micromatch": "^4.0.2",
"mocha": "^6.2.2",
"nodemon": "^2.0.1",
"solhint": "2.3.0",
"solidity-coverage": "github:rotcivegaf/solidity-coverage#5875f5b7bc74d447f3312c9c0e9fc7814b482477",
"solidity-docgen": "^0.3.13",
"truffle": "^5.0.44"
}
"solidity-docgen": "^0.3.13"
},
"dependencies": {}
}
......@@ -4,4 +4,4 @@ if [ "$SOLC_NIGHTLY" = true ]; then
docker pull ethereum/solc:nightly
fi
npx truffle compile
npx oz compile
......@@ -2,11 +2,23 @@
set -o errexit -o pipefail
# Executes cleanup function at script exit.
trap cleanup EXIT
cleanup() {
# Delete the symlink created to the allFiredEvents file solidity-coverage creates
rm -f allFiredEvents
}
log() {
echo "$*" >&2
}
SOLIDITY_COVERAGE=true scripts/test.sh || log "Test run failed"
# The allFiredEvents file is created inside coverageEnv, but solidity-coverage
# expects it to be at the top level. We create a symlink to fix this
ln -s coverageEnv/allFiredEvents allFiredEvents
OZ_TEST_ENV_COVERAGE=true npx solidity-coverage || log "Test run failed"
if [ "$CI" = true ]; then
curl -s https://codecov.io/bash | bash -s -- -C "$CIRCLE_SHA1"
......
#!/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
}
if [ "$SOLIDITY_COVERAGE" = true ]; then
ganache_port=8555
else
ganache_port=8545
fi
ganache_running() {
nc -z localhost "$ganache_port"
}
start_ganache() {
local accounts=(
# 10 accounts with balance 1M ether, needed for high-value tests.
--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"
# 3 accounts to be used for GSN matters.
--account="0x956b91cb2344d7863ea89e6945b753ca32f6d74bb97a59e59e04903ded14ad00,1000000000000000000000000"
--account="0x956b91cb2344d7863ea89e6945b753ca32f6d74bb97a59e59e04903ded14ad01,1000000000000000000000000"
--account="0x956b91cb2344d7863ea89e6945b753ca32f6d74bb97a59e59e04903ded14ad02,1000000000000000000000000"
)
if [ "$SOLIDITY_COVERAGE" = true ]; then
npx ganache-cli-coverage --emitFreeLogs true --allowUnlimitedContractSize true --gasLimit 0xfffffffffffff --port "$ganache_port" "${accounts[@]}" > /dev/null &
else
npx ganache-cli --gasLimit 0xfffffffffff --port "$ganache_port" "${accounts[@]}" > /dev/null &
fi
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!"
}
setup_relayhub() {
npx oz-gsn deploy-relay-hub \
--ethereumNodeURL "http://localhost:$ganache_port" \
--from "0xbb49ad04422f9fa6a217f3ed82261b942f6981f7"
}
if ganache_running; then
echo "Using existing ganache instance"
else
echo "Starting our own ganache instance"
start_ganache
fi
npx truffle version
setup_relayhub
if [ "$SOLIDITY_COVERAGE" = true ]; then
npx solidity-coverage
else
npx truffle test "$@"
fi
const { GSNDevProvider } = require('@openzeppelin/gsn-provider');
module.exports = {
accounts: {
ether: 1e6,
},
contracts: {
type: 'truffle',
},
setupProvider: (baseProvider) => {
const { accounts } = require('@openzeppelin/test-environment');
return new GSNDevProvider(baseProvider, {
txfee: 70,
useGSN: false,
ownerAddress: accounts[8],
relayerAddress: accounts[9],
});
},
};
const { contract } = require('@openzeppelin/test-environment');
const { BN, expectEvent } = require('@openzeppelin/test-helpers');
const ContextMock = artifacts.require('ContextMock');
const ContextMock = contract.fromArtifact('ContextMock');
function shouldBehaveLikeRegularContext (sender) {
describe('msgSender', function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
require('@openzeppelin/test-helpers');
const ContextMock = artifacts.require('ContextMock');
const ContextMockCaller = artifacts.require('ContextMockCaller');
const ContextMock = contract.fromArtifact('ContextMock');
const ContextMockCaller = contract.fromArtifact('ContextMockCaller');
const { shouldBehaveLikeRegularContext } = require('./Context.behavior');
contract('Context', function ([_, sender]) {
describe('Context', function () {
const [ sender ] = accounts;
beforeEach(async function () {
this.context = await ContextMock.new();
this.caller = await ContextMockCaller.new();
......
const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const { constants, expectEvent } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const gsn = require('@openzeppelin/gsn-helpers');
const { fixSignature } = require('../helpers/sign');
const { utils: { toBN } } = require('web3');
const ERC721GSNRecipientMock = artifacts.require('ERC721GSNRecipientMock');
const ERC721GSNRecipientMock = contract.fromArtifact('ERC721GSNRecipientMock');
describe('ERC721GSNRecipient (integration)', function () {
const [ signer, sender ] = accounts;
contract('ERC721GSNRecipient (integration)', function ([_, signer, sender]) {
const tokenId = '42';
beforeEach(async function () {
......
const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const { balance, BN, constants, ether, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
......@@ -5,12 +7,14 @@ const gsn = require('@openzeppelin/gsn-helpers');
const { expect } = require('chai');
const GSNRecipientMock = artifacts.require('GSNRecipientMock');
const ContextMockCaller = artifacts.require('ContextMockCaller');
const GSNRecipientMock = contract.fromArtifact('GSNRecipientMock');
const ContextMockCaller = contract.fromArtifact('ContextMockCaller');
const { shouldBehaveLikeRegularContext } = require('./Context.behavior');
contract('GSNRecipient', function ([_, payee, sender, newRelayHub]) {
describe('GSNRecipient', function () {
const [ payee, sender, newRelayHub ] = accounts;
beforeEach(async function () {
this.recipient = await GSNRecipientMock.new();
});
......
const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const { ether, expectEvent } = require('@openzeppelin/test-helpers');
const gsn = require('@openzeppelin/gsn-helpers');
const { expect } = require('chai');
const GSNRecipientERC20FeeMock = artifacts.require('GSNRecipientERC20FeeMock');
const ERC20Detailed = artifacts.require('ERC20Detailed');
const IRelayHub = artifacts.require('IRelayHub');
const GSNRecipientERC20FeeMock = contract.fromArtifact('GSNRecipientERC20FeeMock');
const ERC20Detailed = contract.fromArtifact('ERC20Detailed');
const IRelayHub = contract.fromArtifact('IRelayHub');
describe('GSNRecipientERC20Fee', function () {
const [ sender ] = accounts;
contract('GSNRecipientERC20Fee', function ([_, sender, other]) {
const name = 'FeeToken';
const symbol = 'FTKN';
......
const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const { expectEvent, expectRevert, constants } = require('@openzeppelin/test-helpers');
const gsn = require('@openzeppelin/gsn-helpers');
const { fixSignature } = require('../helpers/sign');
const { utils: { toBN } } = require('web3');
const { ZERO_ADDRESS } = constants;
const GSNRecipientSignatureMock = artifacts.require('GSNRecipientSignatureMock');
const GSNRecipientSignatureMock = contract.fromArtifact('GSNRecipientSignatureMock');
describe('GSNRecipientSignature', function () {
const [ signer, other ] = accounts;
contract('GSNRecipientSignature', function ([_, signer, other]) {
beforeEach(async function () {
this.recipient = await GSNRecipientSignatureMock.new(signer);
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { expectRevert, constants } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const RolesMock = artifacts.require('RolesMock');
const RolesMock = contract.fromArtifact('RolesMock');
describe('Roles', function () {
const [ authorized, otherAuthorized, other ] = accounts;
contract('Roles', function ([_, authorized, otherAuthorized, other]) {
beforeEach(async function () {
this.roles = await RolesMock.new();
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { shouldBehaveLikePublicRole } = require('../../behaviors/access/roles/PublicRole.behavior');
const CapperRoleMock = artifacts.require('CapperRoleMock');
const CapperRoleMock = contract.fromArtifact('CapperRoleMock');
describe('CapperRole', function () {
const [ capper, otherCapper, ...otherAccounts ] = accounts;
contract('CapperRole', function ([_, capper, otherCapper, ...otherAccounts]) {
beforeEach(async function () {
this.contract = await CapperRoleMock.new({ from: capper });
await this.contract.addCapper(otherCapper, { from: capper });
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { shouldBehaveLikePublicRole } = require('../../behaviors/access/roles/PublicRole.behavior');
const MinterRoleMock = artifacts.require('MinterRoleMock');
const MinterRoleMock = contract.fromArtifact('MinterRoleMock');
describe('MinterRole', function () {
const [ minter, otherMinter, ...otherAccounts ] = accounts;
contract('MinterRole', function ([_, minter, otherMinter, ...otherAccounts]) {
beforeEach(async function () {
this.contract = await MinterRoleMock.new({ from: minter });
await this.contract.addMinter(otherMinter, { from: minter });
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { shouldBehaveLikePublicRole } = require('../../behaviors/access/roles/PublicRole.behavior');
const PauserRoleMock = artifacts.require('PauserRoleMock');
const PauserRoleMock = contract.fromArtifact('PauserRoleMock');
describe('PauserRole', function () {
const [ pauser, otherPauser, ...otherAccounts ] = accounts;
contract('PauserRole', function ([_, pauser, otherPauser, ...otherAccounts]) {
beforeEach(async function () {
this.contract = await PauserRoleMock.new({ from: pauser });
await this.contract.addPauser(otherPauser, { from: pauser });
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { shouldBehaveLikePublicRole } = require('../../behaviors/access/roles/PublicRole.behavior');
const SignerRoleMock = artifacts.require('SignerRoleMock');
const SignerRoleMock = contract.fromArtifact('SignerRoleMock');
describe('SignerRole', function () {
const [ signer, otherSigner, ...otherAccounts ] = accounts;
contract('SignerRole', function ([_, signer, otherSigner, ...otherAccounts]) {
beforeEach(async function () {
this.contract = await SignerRoleMock.new({ from: signer });
await this.contract.addSigner(otherSigner, { from: signer });
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { shouldBehaveLikePublicRole } = require('../../behaviors/access/roles/PublicRole.behavior');
const WhitelistAdminRoleMock = artifacts.require('WhitelistAdminRoleMock');
const WhitelistAdminRoleMock = contract.fromArtifact('WhitelistAdminRoleMock');
describe('WhitelistAdminRole', function () {
const [ whitelistAdmin, otherWhitelistAdmin, ...otherAccounts ] = accounts;
contract('WhitelistAdminRole', function ([_, whitelistAdmin, otherWhitelistAdmin, ...otherAccounts]) {
beforeEach(async function () {
this.contract = await WhitelistAdminRoleMock.new({ from: whitelistAdmin });
await this.contract.addWhitelistAdmin(otherWhitelistAdmin, { from: whitelistAdmin });
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { shouldBehaveLikePublicRole } = require('../../behaviors/access/roles/PublicRole.behavior');
const WhitelistedRoleMock = artifacts.require('WhitelistedRoleMock');
const WhitelistedRoleMock = contract.fromArtifact('WhitelistedRoleMock');
describe('WhitelistedRole', function () {
const [ whitelisted, otherWhitelisted, whitelistAdmin, ...otherAccounts ] = accounts;
contract('WhitelistedRole', function ([_, whitelisted, otherWhitelisted, whitelistAdmin, ...otherAccounts]) {
beforeEach(async function () {
this.contract = await WhitelistedRoleMock.new({ from: whitelistAdmin });
await this.contract.addWhitelisted(whitelisted, { from: whitelistAdmin });
......
......@@ -76,8 +76,8 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [other], rolen
});
it(`emits a ${rolename}Added event`, async function () {
const { logs } = await this.contract[`add${rolename}`](other, { from });
expectEvent.inLogs(logs, `${rolename}Added`, { account: other });
const receipt = await this.contract[`add${rolename}`](other, { from });
expectEvent(receipt, `${rolename}Added`, { account: other });
});
it('reverts when adding role to an already assigned account', async function () {
......@@ -106,8 +106,8 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [other], rolen
});
it(`emits a ${rolename}Removed event`, async function () {
const { logs } = await this.contract[`remove${rolename}`](authorized, { from });
expectEvent.inLogs(logs, `${rolename}Removed`, { account: authorized });
const receipt = await this.contract[`remove${rolename}`](authorized, { from });
expectEvent(receipt, `${rolename}Removed`, { account: authorized });
});
it('reverts when removing from an unassigned account', async function () {
......@@ -131,8 +131,8 @@ function shouldBehaveLikePublicRole (authorized, otherAuthorized, [other], rolen
});
it(`emits a ${rolename}Removed event`, async function () {
const { logs } = await this.contract[`renounce${rolename}`]({ from: authorized });
expectEvent.inLogs(logs, `${rolename}Removed`, { account: authorized });
const receipt = await this.contract[`renounce${rolename}`]({ from: authorized });
expectEvent(receipt, `${rolename}Removed`, { account: authorized });
});
it('reverts when renouncing unassigned role', async function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { balance, BN, constants, ether, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const AllowanceCrowdsaleImpl = artifacts.require('AllowanceCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
const AllowanceCrowdsaleImpl = contract.fromArtifact('AllowanceCrowdsaleImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('AllowanceCrowdsale', function () {
const [ investor, wallet, purchaser, tokenWallet ] = accounts;
contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenWallet]) {
const rate = new BN('1');
const value = ether('0.42');
const expectedTokenAmount = rate.mul(value);
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, ether, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const CappedCrowdsaleImpl = artifacts.require('CappedCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
const CappedCrowdsaleImpl = contract.fromArtifact('CappedCrowdsaleImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('CappedCrowdsale', function () {
const [ wallet ] = accounts;
contract('CappedCrowdsale', function ([_, wallet]) {
const rate = new BN('1');
const cap = ether('100');
const lessThanCap = ether('60');
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { balance, BN, constants, ether, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const Crowdsale = artifacts.require('CrowdsaleMock');
const SimpleToken = artifacts.require('SimpleToken');
const Crowdsale = contract.fromArtifact('CrowdsaleMock');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('Crowdsale', function () {
const [ investor, wallet, purchaser ] = accounts;
contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BN(1);
const value = ether('42');
const tokenSupply = new BN('10').pow(new BN('22'));
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, expectEvent, expectRevert, time } = require('@openzeppelin/test-helpers');
const FinalizableCrowdsaleImpl = artifacts.require('FinalizableCrowdsaleImpl');
const ERC20 = artifacts.require('ERC20');
const FinalizableCrowdsaleImpl = contract.fromArtifact('FinalizableCrowdsaleImpl');
const ERC20 = contract.fromArtifact('ERC20');
describe('FinalizableCrowdsale', function () {
const [ wallet, other ] = accounts;
contract('FinalizableCrowdsale', function ([_, wallet, other]) {
const rate = new BN('1000');
before(async function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, ether, expectRevert, time } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const IncreasingPriceCrowdsaleImpl = artifacts.require('IncreasingPriceCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
const IncreasingPriceCrowdsaleImpl = contract.fromArtifact('IncreasingPriceCrowdsaleImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('IncreasingPriceCrowdsale', function () {
const [ investor, wallet, purchaser ] = accounts;
contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser]) {
const value = ether('1');
const tokenSupply = new BN('10').pow(new BN('22'));
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, ether, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const IndividuallyCappedCrowdsaleImpl = artifacts.require('IndividuallyCappedCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
const IndividuallyCappedCrowdsaleImpl = contract.fromArtifact('IndividuallyCappedCrowdsaleImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
const { shouldBehaveLikePublicRole } = require('../behaviors/access/roles/PublicRole.behavior');
contract('IndividuallyCappedCrowdsale', function (
[_, capper, otherCapper, wallet, alice, bob, charlie, other, ...otherAccounts]) {
describe('IndividuallyCappedCrowdsale', function () {
const [ capper, otherCapper, wallet, alice, bob, charlie, other, ...otherAccounts ] = accounts;
const rate = new BN(1);
const capAlice = ether('10');
const capBob = ether('2');
......
......@@ -2,7 +2,7 @@ const { balance, expectEvent } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate, value) {
function shouldBehaveLikeMintedCrowdsale ([ investor, wallet, purchaser ], rate, value) {
const expectedTokenAmount = rate.mul(value);
describe('as a minted crowdsale', function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, ether, expectRevert } = require('@openzeppelin/test-helpers');
const { shouldBehaveLikeMintedCrowdsale } = require('./MintedCrowdsale.behavior');
const { expect } = require('chai');
const MintedCrowdsaleImpl = artifacts.require('MintedCrowdsaleImpl');
const ERC20Mintable = artifacts.require('ERC20Mintable');
const ERC20 = artifacts.require('ERC20');
const MintedCrowdsaleImpl = contract.fromArtifact('MintedCrowdsaleImpl');
const ERC20Mintable = contract.fromArtifact('ERC20Mintable');
const ERC20 = contract.fromArtifact('ERC20');
describe('MintedCrowdsale', function () {
const [ deployer, investor, wallet, purchaser ] = accounts;
contract('MintedCrowdsale', function ([_, deployer, investor, wallet, purchaser]) {
const rate = new BN('1000');
const value = ether('5');
......@@ -24,7 +28,7 @@ contract('MintedCrowdsale', function ([_, deployer, investor, wallet, purchaser]
expect(await this.token.isMinter(this.crowdsale.address)).to.equal(true);
});
shouldBehaveLikeMintedCrowdsale([_, investor, wallet, purchaser], rate, value);
shouldBehaveLikeMintedCrowdsale([investor, wallet, purchaser], rate, value);
});
describe('using non-mintable token', function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, expectRevert } = require('@openzeppelin/test-helpers');
const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
const PausableCrowdsale = contract.fromArtifact('PausableCrowdsaleImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('PausableCrowdsale', function () {
const [ pauser, wallet, other ] = accounts;
contract('PausableCrowdsale', function ([_, pauser, wallet, other]) {
const rate = new BN(1);
const value = new BN(1);
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, ether, expectRevert, time } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const PostDeliveryCrowdsaleImpl = artifacts.require('PostDeliveryCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
const PostDeliveryCrowdsaleImpl = contract.fromArtifact('PostDeliveryCrowdsaleImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('PostDeliveryCrowdsale', function () {
const [ investor, wallet, purchaser ] = accounts;
contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BN(1);
const tokenSupply = new BN('10').pow(new BN('22'));
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { balance, BN, ether, expectRevert, time } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const RefundableCrowdsaleImpl = artifacts.require('RefundableCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
const RefundableCrowdsaleImpl = contract.fromArtifact('RefundableCrowdsaleImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('RefundableCrowdsale', function () {
const [ wallet, investor, other ] = accounts;
contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, other]) {
const rate = new BN(1);
const goal = ether('50');
const lessThanGoal = ether('45');
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, ether, expectRevert, time } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const RefundablePostDeliveryCrowdsaleImpl = artifacts.require('RefundablePostDeliveryCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
const RefundablePostDeliveryCrowdsaleImpl = contract.fromArtifact('RefundablePostDeliveryCrowdsaleImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('RefundablePostDeliveryCrowdsale', function () {
const [ investor, wallet, purchaser ] = accounts;
contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BN(1);
const tokenSupply = new BN('10').pow(new BN('22'));
const goal = ether('100');
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, ether, expectEvent, expectRevert, time } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const TimedCrowdsaleImpl = artifacts.require('TimedCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
const TimedCrowdsaleImpl = contract.fromArtifact('TimedCrowdsaleImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('TimedCrowdsale', function () {
const [ investor, wallet, purchaser ] = accounts;
contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BN(1);
const value = ether('42');
const tokenSupply = new BN('10').pow(new BN('22'));
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, ether, expectRevert } = require('@openzeppelin/test-helpers');
const WhitelistCrowdsale = artifacts.require('WhitelistCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
const WhitelistCrowdsale = contract.fromArtifact('WhitelistCrowdsaleImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('WhitelistCrowdsale', function () {
const [ wallet, whitelister, whitelisted, otherWhitelisted, other ] = accounts;
contract('WhitelistCrowdsale', function ([_, wallet, whitelister, whitelisted, otherWhitelisted, other]) {
const rate = new BN(1);
const value = ether('42');
const tokenSupply = new BN('10').pow(new BN('22'));
......
const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const { constants, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { toEthSignedMessageHash, fixSignature } = require('../helpers/sign');
const { expect } = require('chai');
const ECDSAMock = artifacts.require('ECDSAMock');
const ECDSAMock = contract.fromArtifact('ECDSAMock');
const TEST_MESSAGE = web3.utils.sha3('OpenZeppelin');
const WRONG_MESSAGE = web3.utils.sha3('Nope');
contract('ECDSA', function ([_, other]) {
describe('ECDSA', function () {
const [ other ] = accounts;
beforeEach(async function () {
this.ecdsa = await ECDSAMock.new();
});
......@@ -142,7 +146,7 @@ contract('ECDSA', function ([_, other]) {
context('toEthSignedMessage', function () {
it('should prefix hashes correctly', async function () {
(await this.ecdsa.toEthSignedMessageHash(TEST_MESSAGE)).should.equal(toEthSignedMessageHash(TEST_MESSAGE));
expect(await this.ecdsa.toEthSignedMessageHash(TEST_MESSAGE)).to.equal(toEthSignedMessageHash(TEST_MESSAGE));
expect(await this.ecdsa.toEthSignedMessageHash(TEST_MESSAGE)).to.equal(toEthSignedMessageHash(TEST_MESSAGE));
});
});
......
const { contract } = require('@openzeppelin/test-environment');
require('@openzeppelin/test-helpers');
const { MerkleTree } = require('../helpers/merkleTree.js');
......@@ -5,9 +7,9 @@ const { keccak256, bufferToHex } = require('ethereumjs-util');
const { expect } = require('chai');
const MerkleProofWrapper = artifacts.require('MerkleProofWrapper');
const MerkleProofWrapper = contract.fromArtifact('MerkleProofWrapper');
contract('MerkleProof', function () {
describe('MerkleProof', function () {
beforeEach(async function () {
this.merkleProof = await MerkleProofWrapper.new();
});
......
const { contract } = require('@openzeppelin/test-environment');
const { expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const CountersImpl = artifacts.require('CountersImpl');
const CountersImpl = contract.fromArtifact('CountersImpl');
contract('Counters', function () {
describe('Counters', function () {
beforeEach(async function () {
this.counter = await CountersImpl.new();
});
......
const { contract } = require('@openzeppelin/test-environment');
require('@openzeppelin/test-helpers');
const ERC20MetadataMock = artifacts.require('ERC20MetadataMock');
const ERC20MetadataMock = contract.fromArtifact('ERC20MetadataMock');
const { expect } = require('chai');
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, constants, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const ERC20Mock = artifacts.require('ERC20Mock');
const ERC20Mintable = artifacts.require('ERC20Mintable');
const ERC20Migrator = artifacts.require('ERC20Migrator');
const ERC20Mock = contract.fromArtifact('ERC20Mock');
const ERC20Mintable = contract.fromArtifact('ERC20Mintable');
const ERC20Migrator = contract.fromArtifact('ERC20Migrator');
describe('ERC20Migrator', function () {
const [ owner ] = accounts;
contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
const totalSupply = new BN('200');
it('reverts with a null legacy token address', async function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const ERC20SnapshotMock = artifacts.require('ERC20SnapshotMock');
const ERC20SnapshotMock = contract.fromArtifact('ERC20SnapshotMock');
const { expect } = require('chai');
contract('ERC20Snapshot', function ([_, initialHolder, recipient, other]) {
describe('ERC20Snapshot', function () {
const [ initialHolder, recipient, other ] = accounts;
const initialSupply = new BN(100);
beforeEach(async function () {
......
const { contract } = require('@openzeppelin/test-environment');
const { BN, constants, expectRevert } = require('@openzeppelin/test-helpers');
const { MAX_INT256, MIN_INT256 } = constants;
const { expect } = require('chai');
const SignedSafeMathMock = artifacts.require('SignedSafeMathMock');
const SignedSafeMathMock = contract.fromArtifact('SignedSafeMathMock');
contract('SignedSafeMath', function () {
describe('SignedSafeMath', function () {
beforeEach(async function () {
this.safeMath = await SignedSafeMathMock.new();
});
......
const { contract } = require('@openzeppelin/test-environment');
const { constants } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const StringsMock = artifacts.require('StringsMock');
const StringsMock = contract.fromArtifact('StringsMock');
contract('Strings', function () {
describe('Strings', function () {
beforeEach(async function () {
this.strings = await StringsMock.new();
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, constants, expectEvent, expectRevert, time } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const ERC20Mintable = artifacts.require('ERC20Mintable');
const TokenVesting = artifacts.require('TokenVesting');
const ERC20Mintable = contract.fromArtifact('ERC20Mintable');
const TokenVesting = contract.fromArtifact('TokenVesting');
describe('TokenVesting', function () {
const [ owner, beneficiary ] = accounts;
contract('TokenVesting', function ([_, owner, beneficiary]) {
const amount = new BN('1000');
beforeEach(async function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, balance, ether, expectRevert, time } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const SampleCrowdsale = artifacts.require('SampleCrowdsale');
const SampleCrowdsaleToken = artifacts.require('SampleCrowdsaleToken');
const SampleCrowdsale = contract.fromArtifact('SampleCrowdsale');
const SampleCrowdsaleToken = contract.fromArtifact('SampleCrowdsaleToken');
describe('SampleCrowdsale', function () {
const [ deployer, owner, wallet, investor ] = accounts;
contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
const RATE = new BN(10);
const GOAL = ether('10');
const CAP = ether('20');
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { constants, expectEvent } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const SimpleToken = artifacts.require('SimpleToken');
const SimpleToken = contract.fromArtifact('SimpleToken');
describe('SimpleToken', function () {
const [ creator ] = accounts;
contract('SimpleToken', function ([_, creator]) {
beforeEach(async function () {
this.token = await SimpleToken.new({ from: creator });
});
......
const REAL_SIGNATURE_SIZE = 2 * 65; // 65 bytes in hexadecimal string legnth
const PADDED_SIGNATURE_SIZE = 2 * 96; // 96 bytes in hexadecimal string length
const DUMMY_SIGNATURE = `0x${web3.utils.padLeft('', REAL_SIGNATURE_SIZE)}`;
const { web3 } = require('@openzeppelin/test-environment');
function toEthSignedMessageHash (messageHex) {
const messageBuffer = Buffer.from(messageHex.substring(2), 'hex');
......@@ -41,6 +38,10 @@ const getSignFor = (contract, signer) => (redeemer, methodName, methodArgs = [])
redeemer,
];
const REAL_SIGNATURE_SIZE = 2 * 65; // 65 bytes in hexadecimal string legnth
const PADDED_SIGNATURE_SIZE = 2 * 96; // 96 bytes in hexadecimal string length
const DUMMY_SIGNATURE = `0x${web3.utils.padLeft('', REAL_SIGNATURE_SIZE)}`;
// if we have a method, add it to the parts that we're signing
if (methodName) {
if (methodArgs.length > 0) {
......
const { contract } = require('@openzeppelin/test-environment');
const { expectRevert } = require('@openzeppelin/test-helpers');
const { shouldSupportInterfaces } = require('./SupportsInterface.behavior');
const ERC165Mock = artifacts.require('ERC165Mock');
const ERC165Mock = contract.fromArtifact('ERC165Mock');
contract('ERC165', function () {
describe('ERC165', function () {
beforeEach(async function () {
this.mock = await ERC165Mock.new();
});
......
const { contract } = require('@openzeppelin/test-environment');
require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const ERC165CheckerMock = artifacts.require('ERC165CheckerMock');
const ERC165NotSupported = artifacts.require('ERC165NotSupported');
const ERC165InterfacesSupported = artifacts.require('ERC165InterfacesSupported');
const ERC165CheckerMock = contract.fromArtifact('ERC165CheckerMock');
const ERC165NotSupported = contract.fromArtifact('ERC165NotSupported');
const ERC165InterfacesSupported = contract.fromArtifact('ERC165InterfacesSupported');
const DUMMY_ID = '0xdeadbeef';
const DUMMY_ID_2 = '0xcafebabe';
......@@ -13,7 +14,7 @@ const DUMMY_UNSUPPORTED_ID = '0xbaddcafe';
const DUMMY_UNSUPPORTED_ID_2 = '0xbaadcafe';
const DUMMY_ACCOUNT = '0x1111111111111111111111111111111111111111';
contract('ERC165Checker', function () {
describe('ERC165Checker', function () {
beforeEach(async function () {
this.mock = await ERC165CheckerMock.new();
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { expectRevert, singletons } = require('@openzeppelin/test-helpers');
const { bufferToHex, keccak256 } = require('ethereumjs-util');
const { expect } = require('chai');
const ERC1820ImplementerMock = artifacts.require('ERC1820ImplementerMock');
const ERC1820ImplementerMock = contract.fromArtifact('ERC1820ImplementerMock');
describe('ERC1820Implementer', function () {
const [ registryFunder, implementee, other ] = accounts;
contract('ERC1820Implementer', function ([_, registryFunder, implementee, other]) {
const ERC1820_ACCEPT_MAGIC = bufferToHex(keccak256('ERC1820_ACCEPT_MAGIC'));
beforeEach(async function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { shouldBehaveLikePublicRole } = require('../behaviors/access/roles/PublicRole.behavior');
const { expect } = require('chai');
const PausableMock = artifacts.require('PausableMock');
const PausableMock = contract.fromArtifact('PausableMock');
describe('Pausable', function () {
const [ pauser, otherPauser, other, ...otherAccounts ] = accounts;
contract('Pausable', function ([_, pauser, otherPauser, other, ...otherAccounts]) {
beforeEach(async function () {
this.pausable = await PausableMock.new({ from: pauser });
});
......
const { contract } = require('@openzeppelin/test-environment');
const { BN } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const MathMock = artifacts.require('MathMock');
const MathMock = contract.fromArtifact('MathMock');
contract('Math', function () {
describe('Math', function () {
const min = new BN('1234');
const max = new BN('5678');
......
const { contract } = require('@openzeppelin/test-environment');
const { BN, constants, expectRevert } = require('@openzeppelin/test-helpers');
const { MAX_UINT256 } = constants;
const { expect } = require('chai');
const SafeMathMock = artifacts.require('SafeMathMock');
const SafeMathMock = contract.fromArtifact('SafeMathMock');
contract('SafeMath', function () {
describe('SafeMath', function () {
beforeEach(async function () {
this.safeMath = await SafeMathMock.new();
});
......
......@@ -11,8 +11,8 @@ function shouldBehaveLikeOwnable (owner, [other]) {
it('changes owner after transfer', async function () {
expect(await this.ownable.isOwner({ from: other })).to.equal(false);
const { logs } = await this.ownable.transferOwnership(other, { from: owner });
expectEvent.inLogs(logs, 'OwnershipTransferred');
const receipt = await this.ownable.transferOwnership(other, { from: owner });
expectEvent(receipt, 'OwnershipTransferred');
expect(await this.ownable.owner()).to.equal(other);
expect(await this.ownable.isOwner({ from: other })).to.equal(true);
......@@ -33,8 +33,8 @@ function shouldBehaveLikeOwnable (owner, [other]) {
});
it('loses owner after renouncement', async function () {
const { logs } = await this.ownable.renounceOwnership({ from: owner });
expectEvent.inLogs(logs, 'OwnershipTransferred');
const receipt = await this.ownable.renounceOwnership({ from: owner });
expectEvent(receipt, 'OwnershipTransferred');
expect(await this.ownable.owner()).to.equal(ZERO_ADDRESS);
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
require('@openzeppelin/test-helpers');
const { shouldBehaveLikeOwnable } = require('./Ownable.behavior');
const Ownable = artifacts.require('OwnableMock');
const Ownable = contract.fromArtifact('OwnableMock');
describe('Ownable', function () {
const [ owner, ...otherAccounts ] = accounts;
contract('Ownable', function ([_, owner, ...otherAccounts]) {
beforeEach(async function () {
this.ownable = await Ownable.new({ from: owner });
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const SecondaryMock = artifacts.require('SecondaryMock');
const SecondaryMock = contract.fromArtifact('SecondaryMock');
describe('Secondary', function () {
const [ primary, newPrimary, other ] = accounts;
contract('Secondary', function ([_, primary, newPrimary, other]) {
beforeEach(async function () {
this.secondary = await SecondaryMock.new({ from: primary });
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { balance, constants, ether, expectEvent, send, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const PaymentSplitter = artifacts.require('PaymentSplitter');
const PaymentSplitter = contract.fromArtifact('PaymentSplitter');
describe('PaymentSplitter', function () {
const [ owner, payee1, payee2, payee3, nonpayee1, payer1 ] = accounts;
contract('PaymentSplitter', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) {
const amount = ether('1');
it('rejects an empty set of payees', async function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { balance, ether } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const PullPaymentMock = artifacts.require('PullPaymentMock');
const PullPaymentMock = contract.fromArtifact('PullPaymentMock');
describe('PullPayment', function () {
const [ payer, payee1, payee2 ] = accounts;
contract('PullPayment', function ([_, payer, payee1, payee2]) {
const amount = ether('17');
beforeEach(async function () {
......@@ -35,23 +39,23 @@ contract('PullPayment', function ([_, payer, payee1, payee2]) {
const balanceTracker = await balance.tracker(payee1);
await this.contract.callTransfer(payee1, amount, { from: payer });
(await this.contract.payments(payee1)).should.be.bignumber.equal(amount);
expect(await this.contract.payments(payee1)).to.be.bignumber.equal(amount);
await this.contract.withdrawPayments(payee1);
(await balanceTracker.delta()).should.be.bignumber.equal(amount);
(await this.contract.payments(payee1)).should.be.bignumber.equal('0');
expect(await balanceTracker.delta()).to.be.bignumber.equal(amount);
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('0');
});
it('can withdraw payment forwarding all gas', async function () {
const balanceTracker = await balance.tracker(payee1);
await this.contract.callTransfer(payee1, amount, { from: payer });
(await this.contract.payments(payee1)).should.be.bignumber.equal(amount);
expect(await this.contract.payments(payee1)).to.be.bignumber.equal(amount);
await this.contract.withdrawPaymentsWithGas(payee1);
(await balanceTracker.delta()).should.be.bignumber.equal(amount);
(await this.contract.payments(payee1)).should.be.bignumber.equal('0');
expect(await balanceTracker.delta()).to.be.bignumber.equal(amount);
expect(await this.contract.payments(payee1)).to.be.bignumber.equal('0');
});
});
const { accounts, contract } = require('@openzeppelin/test-environment');
const { ether, expectRevert } = require('@openzeppelin/test-helpers');
const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
const ConditionalEscrowMock = artifacts.require('ConditionalEscrowMock');
const ConditionalEscrowMock = contract.fromArtifact('ConditionalEscrowMock');
describe('ConditionalEscrow', function () {
const [ owner, payee, ...otherAccounts ] = accounts;
contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
beforeEach(async function () {
this.escrow = await ConditionalEscrowMock.new({ from: owner });
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
require('@openzeppelin/test-helpers');
const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
const Escrow = artifacts.require('Escrow');
const Escrow = contract.fromArtifact('Escrow');
describe('Escrow', function () {
const [ primary, ...otherAccounts ] = accounts;
contract('Escrow', function ([_, primary, ...otherAccounts]) {
beforeEach(async function () {
this.escrow = await Escrow.new({ from: primary });
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { balance, constants, ether, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const RefundEscrow = artifacts.require('RefundEscrow');
const RefundEscrow = contract.fromArtifact('RefundEscrow');
describe('RefundEscrow', function () {
const [ primary, beneficiary, refundee1, refundee2 ] = accounts;
contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee2]) {
const amount = ether('54');
const refundees = [refundee1, refundee2];
......
const { defaultSender, web3 } = require('@openzeppelin/test-environment');
const { deployRelayHub } = require('@openzeppelin/gsn-helpers');
before('deploy GSN RelayHub', async function () {
await deployRelayHub(web3, { from: defaultSender });
});
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { ZERO_ADDRESS } = constants;
......@@ -8,9 +10,11 @@ const {
shouldBehaveLikeERC20Approve,
} = require('./ERC20.behavior');
const ERC20Mock = artifacts.require('ERC20Mock');
const ERC20Mock = contract.fromArtifact('ERC20Mock');
describe('ERC20', function () {
const [ initialHolder, recipient, anotherAccount ] = accounts;
contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
const initialSupply = new BN(100);
beforeEach(async function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN } = require('@openzeppelin/test-helpers');
const { shouldBehaveLikeERC20Burnable } = require('./behaviors/ERC20Burnable.behavior');
const ERC20BurnableMock = artifacts.require('ERC20BurnableMock');
const ERC20BurnableMock = contract.fromArtifact('ERC20BurnableMock');
describe('ERC20Burnable', function () {
const [ owner, ...otherAccounts ] = accounts;
contract('ERC20Burnable', function ([_, owner, ...otherAccounts]) {
const initialBalance = new BN(1000);
beforeEach(async function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, ether, expectRevert } = require('@openzeppelin/test-helpers');
const { shouldBehaveLikeERC20Mintable } = require('./behaviors/ERC20Mintable.behavior');
const { shouldBehaveLikeERC20Capped } = require('./behaviors/ERC20Capped.behavior');
const ERC20Capped = artifacts.require('ERC20Capped');
const ERC20Capped = contract.fromArtifact('ERC20Capped');
describe('ERC20Capped', function () {
const [ minter, ...otherAccounts ] = accounts;
contract('ERC20Capped', function ([_, minter, ...otherAccounts]) {
const cap = ether('1000');
it('requires a non-zero cap', async function () {
......
const { contract } = require('@openzeppelin/test-environment');
const { BN } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const ERC20DetailedMock = artifacts.require('ERC20DetailedMock');
const ERC20DetailedMock = contract.fromArtifact('ERC20DetailedMock');
contract('ERC20Detailed', function () {
describe('ERC20Detailed', function () {
const _name = 'My Detailed ERC20';
const _symbol = 'MDT';
const _decimals = new BN(18);
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { shouldBehaveLikeERC20Mintable } = require('./behaviors/ERC20Mintable.behavior');
const ERC20MintableMock = artifacts.require('ERC20MintableMock');
const ERC20MintableMock = contract.fromArtifact('ERC20MintableMock');
const { shouldBehaveLikePublicRole } = require('../../behaviors/access/roles/PublicRole.behavior');
contract('ERC20Mintable', function ([_, minter, otherMinter, ...otherAccounts]) {
describe('ERC20Mintable', function () {
const [ minter, otherMinter, ...otherAccounts ] = accounts;
beforeEach(async function () {
this.token = await ERC20MintableMock.new({ from: minter });
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const ERC20PausableMock = artifacts.require('ERC20PausableMock');
const ERC20PausableMock = contract.fromArtifact('ERC20PausableMock');
const { shouldBehaveLikePublicRole } = require('../../behaviors/access/roles/PublicRole.behavior');
contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherAccount, ...otherAccounts]) {
describe('ERC20Pausable', function () {
const [ pauser, otherPauser, recipient, anotherAccount, ...otherAccounts ] = accounts;
const initialSupply = new BN(100);
beforeEach(async function () {
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { expectRevert } = require('@openzeppelin/test-helpers');
const ERC20ReturnFalseMock = artifacts.require('ERC20ReturnFalseMock');
const ERC20ReturnTrueMock = artifacts.require('ERC20ReturnTrueMock');
const ERC20NoReturnMock = artifacts.require('ERC20NoReturnMock');
const SafeERC20Wrapper = artifacts.require('SafeERC20Wrapper');
const ERC20ReturnFalseMock = contract.fromArtifact('ERC20ReturnFalseMock');
const ERC20ReturnTrueMock = contract.fromArtifact('ERC20ReturnTrueMock');
const ERC20NoReturnMock = contract.fromArtifact('ERC20NoReturnMock');
const SafeERC20Wrapper = contract.fromArtifact('SafeERC20Wrapper');
describe('SafeERC20', function () {
const [ hasNoCode ] = accounts;
contract('SafeERC20', function ([_, hasNoCode]) {
describe('with address that has no contract code', function () {
beforeEach(async function () {
this.wrapper = await SafeERC20Wrapper.new(hasNoCode);
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, expectRevert, time } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const ERC20Mintable = artifacts.require('ERC20Mintable');
const TokenTimelock = artifacts.require('TokenTimelock');
const ERC20Mintable = contract.fromArtifact('ERC20Mintable');
const TokenTimelock = contract.fromArtifact('TokenTimelock');
describe('TokenTimelock', function () {
const [ minter, beneficiary ] = accounts;
contract('TokenTimelock', function ([_, minter, beneficiary]) {
const amount = new BN(100);
context('with token', function () {
......
const { contract } = require('@openzeppelin/test-environment');
const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { ZERO_ADDRESS } = constants;
const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior');
const ERC721ReceiverMock = artifacts.require('ERC721ReceiverMock.sol');
const ERC721Mock = artifacts.require('ERC721Mock.sol');
const ERC721ReceiverMock = contract.fromArtifact('ERC721ReceiverMock');
const ERC721Mock = contract.fromArtifact('ERC721Mock');
function shouldBehaveLikeERC721 (
creator,
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
const ERC721Mock = artifacts.require('ERC721Mock.sol');
const ERC721Mock = contract.fromArtifact('ERC721Mock');
describe('ERC721', function () {
const [ creator, owner, other, ...otherAccounts ] = accounts;
contract('ERC721', function ([_, creator, owner, other, ...accounts]) {
beforeEach(async function () {
this.token = await ERC721Mock.new({ from: creator });
});
shouldBehaveLikeERC721(creator, creator, accounts);
shouldBehaveLikeERC721(creator, creator, otherAccounts);
describe('internal functions', function () {
const tokenId = new BN('5042');
......
const { accounts, contract } = require('@openzeppelin/test-environment');
require('@openzeppelin/test-helpers');
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
......@@ -5,15 +7,16 @@ const {
shouldBehaveLikeMintAndBurnERC721,
} = require('./ERC721MintBurn.behavior');
const ERC721BurnableImpl = artifacts.require('ERC721MintableBurnableImpl.sol');
const ERC721BurnableImpl = contract.fromArtifact('ERC721MintableBurnableImpl');
contract('ERC721Burnable', function ([_, creator, ...accounts]) {
describe('ERC721Burnable', function () {
const [ creator, ...otherAccounts ] = accounts;
const minter = creator;
beforeEach(async function () {
this.token = await ERC721BurnableImpl.new({ from: creator });
});
shouldBehaveLikeERC721(creator, minter, accounts);
shouldBehaveLikeMintAndBurnERC721(creator, minter, accounts);
shouldBehaveLikeERC721(creator, minter, otherAccounts);
shouldBehaveLikeMintAndBurnERC721(creator, minter, otherAccounts);
});
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior');
const ERC721FullMock = artifacts.require('ERC721FullMock.sol');
contract('ERC721Full', function ([
creator,
...accounts
]) {
const name = 'Non Fungible Token';
const symbol = 'NFT';
const firstTokenId = new BN(100);
const secondTokenId = new BN(200);
const thirdTokenId = new BN(300);
const nonExistentTokenId = new BN(999);
const ERC721FullMock = contract.fromArtifact('ERC721FullMock');
describe('ERC721Full', function () {
const [ creator, ...otherAccounts ] = accounts;
const minter = creator;
const [
owner,
newOwner,
other,
] = accounts;
] = otherAccounts;
const name = 'Non Fungible Token';
const symbol = 'NFT';
const firstTokenId = new BN(100);
const secondTokenId = new BN(200);
const thirdTokenId = new BN(300);
const nonExistentTokenId = new BN(999);
beforeEach(async function () {
this.token = await ERC721FullMock.new(name, symbol, { from: creator });
......@@ -245,7 +245,7 @@ contract('ERC721Full', function ([
});
});
shouldBehaveLikeERC721(creator, minter, accounts);
shouldBehaveLikeERC721(creator, minter, otherAccounts);
shouldSupportInterfaces([
'ERC165',
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { BN } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const ERC721Holder = artifacts.require('ERC721Holder.sol');
const ERC721Mintable = artifacts.require('ERC721MintableBurnableImpl.sol');
const ERC721Holder = contract.fromArtifact('ERC721Holder');
const ERC721Mintable = contract.fromArtifact('ERC721MintableBurnableImpl');
describe('ERC721Holder', function () {
const [ creator ] = accounts;
contract('ERC721Holder', function ([creator]) {
it('receives an ERC721 token', async function () {
const token = await ERC721Mintable.new({ from: creator });
const tokenId = new BN(1);
await token.mint(creator, tokenId, { from: creator });
const receiver = await ERC721Holder.new();
await token.approve(receiver.address, tokenId, { from: creator });
await token.safeTransferFrom(creator, receiver.address, tokenId);
await token.safeTransferFrom(creator, receiver.address, tokenId, { from: creator });
expect(await token.ownerOf(tokenId)).to.be.equal(receiver.address);
});
......
const { accounts, contract } = require('@openzeppelin/test-environment');
require('@openzeppelin/test-helpers');
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
const { shouldBehaveLikeMintAndBurnERC721 } = require('./ERC721MintBurn.behavior');
const ERC721MintableImpl = artifacts.require('ERC721MintableBurnableImpl.sol');
const ERC721MintableImpl = contract.fromArtifact('ERC721MintableBurnableImpl');
contract('ERC721Mintable', function ([_, creator, ...accounts]) {
describe('ERC721Mintable', function () {
const [ creator, ...otherAccounts ] = accounts;
const minter = creator;
beforeEach(async function () {
......@@ -13,6 +16,6 @@ contract('ERC721Mintable', function ([_, creator, ...accounts]) {
});
});
shouldBehaveLikeERC721(creator, minter, accounts);
shouldBehaveLikeMintAndBurnERC721(creator, minter, accounts);
shouldBehaveLikeERC721(creator, minter, otherAccounts);
shouldBehaveLikeMintAndBurnERC721(creator, minter, otherAccounts);
});
const { accounts, contract } = require('@openzeppelin/test-environment');
require('@openzeppelin/test-helpers');
const { shouldBehaveLikeERC721PausedToken } = require('./ERC721PausedToken.behavior');
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
const { shouldBehaveLikePublicRole } = require('../../behaviors/access/roles/PublicRole.behavior');
const ERC721PausableMock = artifacts.require('ERC721PausableMock.sol');
const ERC721PausableMock = contract.fromArtifact('ERC721PausableMock');
describe('ERC721Pausable', function () {
const [ creator, otherPauser, ...otherAccounts ] = accounts;
contract('ERC721Pausable', function ([
_,
creator,
otherPauser,
...accounts
]) {
beforeEach(async function () {
this.token = await ERC721PausableMock.new({ from: creator });
});
......@@ -21,7 +20,7 @@ contract('ERC721Pausable', function ([
await this.contract.addPauser(otherPauser, { from: creator });
});
shouldBehaveLikePublicRole(creator, otherPauser, accounts, 'pauser');
shouldBehaveLikePublicRole(creator, otherPauser, otherAccounts, 'pauser');
});
context('when token is paused', function () {
......@@ -29,11 +28,11 @@ contract('ERC721Pausable', function ([
await this.token.pause({ from: creator });
});
shouldBehaveLikeERC721PausedToken(creator, accounts);
shouldBehaveLikeERC721PausedToken(creator, otherAccounts);
});
context('when token is not paused yet', function () {
shouldBehaveLikeERC721(creator, creator, accounts);
shouldBehaveLikeERC721(creator, creator, otherAccounts);
});
context('when token is paused and then unpaused', function () {
......@@ -42,6 +41,6 @@ contract('ERC721Pausable', function ([
await this.token.unpause({ from: creator });
});
shouldBehaveLikeERC721(creator, creator, accounts);
shouldBehaveLikeERC721(creator, creator, otherAccounts);
});
});
const { contract, web3 } = require('@openzeppelin/test-environment');
const { BN, constants, expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { ZERO_ADDRESS } = constants;
const { expect } = require('chai');
const ERC777SenderRecipientMock = artifacts.require('ERC777SenderRecipientMock');
const ERC777SenderRecipientMock = contract.fromArtifact('ERC777SenderRecipientMock');
function shouldBehaveLikeERC777DirectSendBurn (holder, recipient, data) {
shouldBehaveLikeERC777DirectSend(holder, recipient, data);
......
const { accounts, contract, web3 } = require('@openzeppelin/test-environment');
const { BN, expectEvent, expectRevert, singletons } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
......@@ -15,12 +17,12 @@ const {
shouldBehaveLikeERC20,
} = require('../ERC20/ERC20.behavior');
const ERC777 = artifacts.require('ERC777Mock');
const ERC777SenderRecipientMock = artifacts.require('ERC777SenderRecipientMock');
const ERC777 = contract.fromArtifact('ERC777Mock');
const ERC777SenderRecipientMock = contract.fromArtifact('ERC777SenderRecipientMock');
describe('ERC777', function () {
const [ registryFunder, holder, defaultOperatorA, defaultOperatorB, newOperator, anyone ] = accounts;
contract('ERC777', function ([
_, registryFunder, holder, defaultOperatorA, defaultOperatorB, newOperator, anyone,
]) {
const initialSupply = new BN('10000');
const name = 'ERC777Test';
const symbol = '777T';
......
const { accounts, contract } = require('@openzeppelin/test-environment');
const { balance, constants, ether, expectRevert, send } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const AddressImpl = artifacts.require('AddressImpl');
const SimpleToken = artifacts.require('SimpleToken');
const EtherReceiver = artifacts.require('EtherReceiverMock');
const AddressImpl = contract.fromArtifact('AddressImpl');
const SimpleToken = contract.fromArtifact('SimpleToken');
const EtherReceiver = contract.fromArtifact('EtherReceiverMock');
describe('Address', function () {
const [ recipient, other ] = accounts;
contract('Address', function ([_, recipient, other]) {
const ALL_ONES_ADDRESS = '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF';
beforeEach(async function () {
......
const { contract } = require('@openzeppelin/test-environment');
require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const ArraysImpl = artifacts.require('ArraysImpl');
const ArraysImpl = contract.fromArtifact('ArraysImpl');
contract('Arrays', function () {
describe('Arrays', function () {
context('Even number of elements', function () {
const EVEN_ELEMENTS_ARRAY = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
......
const { contract } = require('@openzeppelin/test-environment');
const { expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const ReentrancyMock = artifacts.require('ReentrancyMock');
const ReentrancyAttack = artifacts.require('ReentrancyAttack');
const ReentrancyMock = contract.fromArtifact('ReentrancyMock');
const ReentrancyAttack = contract.fromArtifact('ReentrancyAttack');
contract('ReentrancyGuard', function () {
describe('ReentrancyGuard', function () {
beforeEach(async function () {
this.reentrancyMock = await ReentrancyMock.new();
expect(await this.reentrancyMock.counter()).to.be.bignumber.equal('0');
......
const { contract } = require('@openzeppelin/test-environment');
const { BN, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const SafeCastMock = artifacts.require('SafeCastMock');
const SafeCastMock = contract.fromArtifact('SafeCastMock');
contract('SafeCast', async () => {
describe('SafeCast', async () => {
beforeEach(async function () {
this.safeCast = await SafeCastMock.new();
});
......
require('chai/register-should');
const { GSNDevProvider } = require('@openzeppelin/gsn-provider');
const solcStable = {
version: '0.5.11',
};
const solcNightly = {
version: 'nightly',
docker: true,
};
const useSolcNightly = process.env.SOLC_NIGHTLY === 'true';
module.exports = {
networks: {
development: {
provider: new GSNDevProvider('http://localhost:8545', {
txfee: 70,
useGSN: false,
// The last two accounts defined in test.sh
ownerAddress: '0x26be9c03ca7f61ad3d716253ee1edcae22734698',
relayerAddress: '0xdc5fd04802ea70f6e27aec12d56716624c98e749',
}),
network_id: '*', // eslint-disable-line camelcase
},
coverage: {
provider: new GSNDevProvider('http://localhost:8555', {
txfee: 70,
useGSN: false,
// The last two accounts defined in test.sh
ownerAddress: '0x26be9c03ca7f61ad3d716253ee1edcae22734698',
relayerAddress: '0xdc5fd04802ea70f6e27aec12d56716624c98e749',
}),
gas: 0xfffffffffff,
gasPrice: 0x01,
network_id: '*', // eslint-disable-line camelcase
},
},
compilers: {
solc: useSolcNightly ? solcNightly : solcStable,
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment