Unverified Commit 3e82db2f by Nicolás Venturo Committed by GitHub

Migration to truffle 5 (and web3 1.0 (and BN)) (#1601)

* Now compiling using truffle 5.

* Migrated some test files, missing BN scientific notation usage.

* Now using BN time values.

* Migrate ERC20 tests.

* Migrate all ERC20 tests.

* Migrate utils, payment and ownership tests.

* All tests save ERC721 migrated.

* Migrated ERC721 tests.

* Fix lint errors.

* Delete old test helpers.

* Fix remaining crowdsale tests.

* Fix signature bouncer tests.

* Update how constants is used.

* Compile script pre-removes the build dir.

* Fix SafeMath tests.

* Revert "Compile script pre-removes the build dir."

This reverts commit 247e7451135d33c056a126e9e5fd77a24348018d.

* Fix linter errors.

* Upgrade openzeppelin-test-helpers dependency.

* Update openzeppelin-test-helpers dependency.

* Define math constants globally.

* Remove unnecessary ether unit.

* Roll back reduced ether amounts in tests.

* Remove unnecessary toNumber conversions.

* Delete compile script.

* Fixed failing test.
parent 089f14aa
......@@ -37,6 +37,3 @@ build/
# truffle
.node-xmlhttprequest-*
# Temporary directory for 0.5.x compilation
solc-0.5
......@@ -106,33 +106,6 @@
"integrity": "sha1-kbR5JYinc4wl813W9jdSovh3YTU=",
"dev": true
},
"accepts": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz",
"integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=",
"dev": true,
"requires": {
"mime-types": "~2.1.18",
"negotiator": "0.6.1"
},
"dependencies": {
"mime-db": {
"version": "1.33.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz",
"integrity": "sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==",
"dev": true
},
"mime-types": {
"version": "2.1.18",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz",
"integrity": "sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==",
"dev": true,
"requires": {
"mime-db": "~1.33.0"
}
}
}
},
"acorn": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.1.tgz",
......@@ -215,6 +188,12 @@
"integrity": "sha512-haHyTW7Y9joE5MVs37P2lNYfU2RWBLfcRDD8OWldcdZm5TiCE91B5Xl1oWSwiDUSd4rlExpt2pu1fksYQjRBYQ==",
"dev": true
},
"app-module-path": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/app-module-path/-/app-module-path-2.2.0.tgz",
"integrity": "sha1-ZBqlXft9am8KgUHEucCqULbCTdU=",
"dev": true
},
"argparse": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
......@@ -251,12 +230,6 @@
"integrity": "sha1-7/UuN1gknTO+QCuLuOVkuytdQDE=",
"dev": true
},
"array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=",
"dev": true
},
"array-union": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz",
......@@ -320,12 +293,6 @@
"integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=",
"dev": true
},
"async-limiter": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.0.tgz",
"integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==",
"dev": true
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
......@@ -1611,50 +1578,6 @@
"integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==",
"dev": true
},
"body-parser": {
"version": "1.18.3",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz",
"integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=",
"dev": true,
"requires": {
"bytes": "3.0.0",
"content-type": "~1.0.4",
"debug": "2.6.9",
"depd": "~1.1.2",
"http-errors": "~1.6.3",
"iconv-lite": "0.4.23",
"on-finished": "~2.3.0",
"qs": "6.5.2",
"raw-body": "2.3.3",
"type-is": "~1.6.16"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"iconv-lite": {
"version": "0.4.23",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz",
"integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==",
"dev": true,
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
},
"qs": {
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==",
"dev": true
}
}
},
"brace-expansion": {
"version": "1.1.8",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
......@@ -1717,12 +1640,6 @@
"integrity": "sha512-c5mRlguI/Pe2dSZmpER62rSCu0ryKmWddzRYsuXc50U2/g8jMOulc31VZMa4mYx31U5xsmSOpDCgH88Vl9cDGQ==",
"dev": true
},
"buffer-to-arraybuffer": {
"version": "0.0.5",
"resolved": "https://registry.npmjs.org/buffer-to-arraybuffer/-/buffer-to-arraybuffer-0.0.5.tgz",
"integrity": "sha1-YGSkD6dutDxyOrqe+PbhIW0QURo=",
"dev": true
},
"buffer-xor": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz",
......@@ -1735,12 +1652,6 @@
"integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=",
"dev": true
},
"bytes": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz",
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=",
"dev": true
},
"cache-base": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/cache-base/-/cache-base-1.0.1.tgz",
......@@ -1847,10 +1758,10 @@
"type-detect": "^4.0.0"
}
},
"chai-bignumber": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/chai-bignumber/-/chai-bignumber-2.0.2.tgz",
"integrity": "sha512-BIdRNjRaoRj4bMsZLKbIZPMNKqmwnzNiyxqBYDSs6dFOCs9w8OHPuUE8e1bH60i1IhOzT0NjLtCD+lKEWB1KTQ==",
"chai-bn": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/chai-bn/-/chai-bn-0.1.0.tgz",
"integrity": "sha512-5HFepJrMEzJM/yz/bhLXAZP/jvHqtwKiTlqjv+kt8FsNGZ0eEh8zsmiVxVoVZI7ZRi8BqtJcSu5jzErHM6npaA==",
"dev": true
},
"chalk": {
......@@ -2154,36 +2065,12 @@
"integrity": "sha1-/ozxhP9mcLa67wGp1IYaXL7EEgo=",
"dev": true
},
"content-disposition": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz",
"integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=",
"dev": true
},
"content-type": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==",
"dev": true
},
"convert-source-map": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.5.1.tgz",
"integrity": "sha1-uCeAl7m8IpNl3lxiz1/K7YtVmeU=",
"dev": true
},
"cookie": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz",
"integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=",
"dev": true
},
"cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=",
"dev": true
},
"copy-descriptor": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz",
......@@ -2202,16 +2089,6 @@
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
"dev": true
},
"cors": {
"version": "2.8.4",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.4.tgz",
"integrity": "sha1-K9OB8usgECAQXNUOpZ2mMJBpRoY=",
"dev": true,
"requires": {
"object-assign": "^4",
"vary": "^1"
}
},
"coveralls": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/coveralls/-/coveralls-3.0.1.tgz",
......@@ -2449,18 +2326,6 @@
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
"dev": true
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=",
"dev": true
},
"destroy": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=",
"dev": true
},
"detect-conflict": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/detect-conflict/-/detect-conflict-1.0.1.tgz",
......@@ -2518,12 +2383,6 @@
"esutils": "^2.0.2"
}
},
"dom-walk": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.1.tgz",
"integrity": "sha1-ZyIm3HTI95mtNTB9+TaroRrNYBg=",
"dev": true
},
"drbg.js": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/drbg.js/-/drbg.js-1.0.1.tgz",
......@@ -2557,12 +2416,6 @@
"integrity": "sha512-gzao+mxnYDzIysXKMQi/+M1mjy/rjestjg6OPoYTtI+3Izp23oiGZitsl9lPDPiTGXbcSIk1iJWhliSaglxnUg==",
"dev": true
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=",
"dev": true
},
"elegant-spinner": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/elegant-spinner/-/elegant-spinner-1.0.1.tgz",
......@@ -2597,12 +2450,6 @@
"integrity": "sha1-TapNnbAPmBmIDHn6RXrlsJof04k=",
"dev": true
},
"encodeurl": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
"integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=",
"dev": true
},
"enhanced-resolve": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-4.1.0.tgz",
......@@ -2650,12 +2497,6 @@
"is-arrayish": "^0.2.1"
}
},
"escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=",
"dev": true
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
......@@ -3102,27 +2943,6 @@
"integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=",
"dev": true
},
"etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=",
"dev": true
},
"eth-lib": {
"version": "0.1.27",
"resolved": "https://registry.npmjs.org/eth-lib/-/eth-lib-0.1.27.tgz",
"integrity": "sha512-B8czsfkJYzn2UIEMwjc7Mbj+Cy72V+/OXH/tb44LV8jhrjizQJJ325xMOMyk3+ETa6r6oi0jsUY14+om8mQMWA==",
"dev": true,
"requires": {
"bn.js": "^4.11.6",
"elliptic": "^6.4.0",
"keccakjs": "^0.2.1",
"nano-json-stream-parser": "^0.1.2",
"servify": "^0.1.12",
"ws": "^3.0.0",
"xhr-request-promise": "^0.1.2"
}
},
"ethereumjs-testrpc-sc": {
"version": "6.1.2",
"resolved": "https://registry.npmjs.org/ethereumjs-testrpc-sc/-/ethereumjs-testrpc-sc-6.1.2.tgz",
......@@ -3191,24 +3011,6 @@
}
}
},
"ethjs-unit": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/ethjs-unit/-/ethjs-unit-0.1.6.tgz",
"integrity": "sha1-xmWSHkduh7ziqdWIpv4EBbLEFpk=",
"dev": true,
"requires": {
"bn.js": "4.11.6",
"number-to-bn": "1.7.0"
},
"dependencies": {
"bn.js": {
"version": "4.11.6",
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz",
"integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=",
"dev": true
}
}
},
"ethjs-util": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz",
......@@ -3277,129 +3079,6 @@
"homedir-polyfill": "^1.0.1"
}
},
"express": {
"version": "4.16.3",
"resolved": "https://registry.npmjs.org/express/-/express-4.16.3.tgz",
"integrity": "sha1-avilAjUNsyRuzEvs9rWjTSL37VM=",
"dev": true,
"requires": {
"accepts": "~1.3.5",
"array-flatten": "1.1.1",
"body-parser": "1.18.2",
"content-disposition": "0.5.2",
"content-type": "~1.0.4",
"cookie": "0.3.1",
"cookie-signature": "1.0.6",
"debug": "2.6.9",
"depd": "~1.1.2",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "1.1.1",
"fresh": "0.5.2",
"merge-descriptors": "1.0.1",
"methods": "~1.1.2",
"on-finished": "~2.3.0",
"parseurl": "~1.3.2",
"path-to-regexp": "0.1.7",
"proxy-addr": "~2.0.3",
"qs": "6.5.1",
"range-parser": "~1.2.0",
"safe-buffer": "5.1.1",
"send": "0.16.2",
"serve-static": "1.13.2",
"setprototypeof": "1.1.0",
"statuses": "~1.4.0",
"type-is": "~1.6.16",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
},
"dependencies": {
"body-parser": {
"version": "1.18.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz",
"integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=",
"dev": true,
"requires": {
"bytes": "3.0.0",
"content-type": "~1.0.4",
"debug": "2.6.9",
"depd": "~1.1.1",
"http-errors": "~1.6.2",
"iconv-lite": "0.4.19",
"on-finished": "~2.3.0",
"qs": "6.5.1",
"raw-body": "2.3.2",
"type-is": "~1.6.15"
}
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"iconv-lite": {
"version": "0.4.19",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz",
"integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==",
"dev": true
},
"qs": {
"version": "6.5.1",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz",
"integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==",
"dev": true
},
"raw-body": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz",
"integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=",
"dev": true,
"requires": {
"bytes": "3.0.0",
"http-errors": "1.6.2",
"iconv-lite": "0.4.19",
"unpipe": "1.0.0"
},
"dependencies": {
"depd": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz",
"integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=",
"dev": true
},
"http-errors": {
"version": "1.6.2",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz",
"integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=",
"dev": true,
"requires": {
"depd": "1.1.1",
"inherits": "2.0.3",
"setprototypeof": "1.0.3",
"statuses": ">= 1.3.1 < 2"
}
},
"setprototypeof": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz",
"integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=",
"dev": true
}
}
},
"statuses": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
"integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==",
"dev": true
}
}
},
"extend": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz",
......@@ -3879,38 +3558,6 @@
}
}
},
"finalhandler": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz",
"integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==",
"dev": true,
"requires": {
"debug": "2.6.9",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"on-finished": "~2.3.0",
"parseurl": "~1.3.2",
"statuses": "~1.4.0",
"unpipe": "~1.0.0"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"statuses": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
"integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==",
"dev": true
}
}
},
"find-up": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz",
......@@ -3948,15 +3595,6 @@
"integrity": "sha1-N4tRKNbQtVSosvFqTKPhq5ZJ8A4=",
"dev": true
},
"for-each": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.2.tgz",
"integrity": "sha1-LEBFC5NI6X8oEyJZO6lnBLmr1NQ=",
"dev": true,
"requires": {
"is-function": "~1.0.0"
}
},
"for-in": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
......@@ -3989,12 +3627,6 @@
"mime-types": "^2.1.12"
}
},
"forwarded": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=",
"dev": true
},
"fragment-cache": {
"version": "0.2.1",
"resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz",
......@@ -4004,12 +3636,6 @@
"map-cache": "^0.2.2"
}
},
"fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=",
"dev": true
},
"from2": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz",
......@@ -4250,16 +3876,6 @@
"integrity": "sha1-jFoUlNIGbFcMw7/kSWF1rMTVAqs=",
"dev": true
},
"global": {
"version": "4.3.2",
"resolved": "https://registry.npmjs.org/global/-/global-4.3.2.tgz",
"integrity": "sha1-52mJJopsdMOJCLEwWxD8DjlOnQ8=",
"dev": true,
"requires": {
"min-document": "^2.19.0",
"process": "~0.5.1"
}
},
"global-modules": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/global-modules/-/global-modules-1.0.0.tgz",
......@@ -4545,18 +4161,6 @@
"integrity": "sha512-5ai2iksyV8ZXmnZhHH4rWPoxxistEexSi5936zIQ1bnNTW5VnA85B6P/VpXiRM017IgRvb2kKo1a//y+0wSp3w==",
"dev": true
},
"http-errors": {
"version": "1.6.3",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz",
"integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=",
"dev": true,
"requires": {
"depd": "~1.1.2",
"inherits": "2.0.3",
"setprototypeof": "1.1.0",
"statuses": ">= 1.4.0 < 2"
}
},
"http-signature": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
......@@ -4768,12 +4372,6 @@
"integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=",
"dev": true
},
"ipaddr.js": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.6.0.tgz",
"integrity": "sha1-4/o1e3c9phnybpXwSdBVxyeW+Gs=",
"dev": true
},
"is-accessor-descriptor": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/is-accessor-descriptor/-/is-accessor-descriptor-0.1.6.tgz",
......@@ -4877,12 +4475,6 @@
"number-is-nan": "^1.0.0"
}
},
"is-function": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-function/-/is-function-1.0.1.tgz",
"integrity": "sha1-Es+5i2W1fdPRk6MSH19uL0N2ArU=",
"dev": true
},
"is-glob": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz",
......@@ -5708,12 +5300,6 @@
}
}
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=",
"dev": true
},
"mem": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz",
......@@ -5750,24 +5336,12 @@
"integrity": "sha1-htcJCzDORV1j+64S3aUaR93K+bI=",
"dev": true
},
"merge-descriptors": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
"integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=",
"dev": true
},
"merge2": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/merge2/-/merge2-1.2.2.tgz",
"integrity": "sha512-bgM8twH86rWni21thii6WCMQMRMmwqqdW3sGWi9IipnVAszdLXRjwDwAnyrVXo6DuP3AjRMMttZKUB48QWIFGg==",
"dev": true
},
"methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=",
"dev": true
},
"micromatch": {
"version": "2.3.11",
"resolved": "https://registry.npmjs.org/micromatch/-/micromatch-2.3.11.tgz",
......@@ -5789,12 +5363,6 @@
"regex-cache": "^0.4.2"
}
},
"mime": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz",
"integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==",
"dev": true
},
"mime-db": {
"version": "1.33.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz",
......@@ -5822,15 +5390,6 @@
"integrity": "sha1-3z02Uqc/3ta5sLJBRub9BSNTRY4=",
"dev": true
},
"min-document": {
"version": "2.19.0",
"resolved": "https://registry.npmjs.org/min-document/-/min-document-2.19.0.tgz",
"integrity": "sha1-e9KC4/WELtKVu3SM3Z8f+iyCRoU=",
"dev": true,
"requires": {
"dom-walk": "^0.1.0"
}
},
"minimalistic-assert": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.0.tgz",
......@@ -5962,12 +5521,6 @@
"integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==",
"dev": true
},
"nano-json-stream-parser": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/nano-json-stream-parser/-/nano-json-stream-parser-0.1.2.tgz",
"integrity": "sha1-DMj20OK2IrR5xA1JnEbWS3Vcb18=",
"dev": true
},
"nanomatch": {
"version": "1.2.13",
"resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz",
......@@ -6013,12 +5566,6 @@
"integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=",
"dev": true
},
"negotiator": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz",
"integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=",
"dev": true
},
"neo-async": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.5.0.tgz",
......@@ -6224,15 +5771,6 @@
}
}
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
"dev": true,
"requires": {
"ee-first": "1.1.1"
}
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
......@@ -6251,6 +5789,33 @@
"mimic-fn": "^1.0.0"
}
},
"openzeppelin-test-helpers": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/openzeppelin-test-helpers/-/openzeppelin-test-helpers-0.1.1.tgz",
"integrity": "sha512-mz6cJkCT90vjtrv9OXJggqn+zElSoF+/wk4u+GRg3JfrfafF+FvHTLBpoe5J8Lzs6O9xvy9PhFu5yEoj3OCypA==",
"dev": true,
"requires": {
"chai": "^4.2.0",
"chai-bn": "^0.1.0",
"ethjs-abi": "^0.2.1"
},
"dependencies": {
"chai": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz",
"integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==",
"dev": true,
"requires": {
"assertion-error": "^1.1.0",
"check-error": "^1.0.2",
"deep-eql": "^3.0.1",
"get-func-name": "^2.0.0",
"pathval": "^1.1.0",
"type-detect": "^4.0.5"
}
}
}
},
"optimist": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz",
......@@ -6437,16 +6002,6 @@
"is-glob": "^2.0.0"
}
},
"parse-headers": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/parse-headers/-/parse-headers-2.0.1.tgz",
"integrity": "sha1-aug6eqJanZtwCswoaYzR8e1+lTY=",
"dev": true,
"requires": {
"for-each": "^0.3.2",
"trim": "0.0.1"
}
},
"parse-json": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz",
......@@ -6462,12 +6017,6 @@
"integrity": "sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=",
"dev": true
},
"parseurl": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz",
"integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=",
"dev": true
},
"pascalcase": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/pascalcase/-/pascalcase-0.1.1.tgz",
......@@ -6513,12 +6062,6 @@
"integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=",
"dev": true
},
"path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=",
"dev": true
},
"path-type": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz",
......@@ -6696,12 +6239,6 @@
"integrity": "sha1-aM5eih7woju1cMwoU3tTMqumPvE=",
"dev": true
},
"process": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/process/-/process-0.5.2.tgz",
"integrity": "sha1-FjjYqONML0QKkduVq5rrZ3/Bhc8=",
"dev": true
},
"process-nextick-args": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
......@@ -6714,16 +6251,6 @@
"integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8=",
"dev": true
},
"proxy-addr": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.3.tgz",
"integrity": "sha512-jQTChiCJteusULxjBp8+jftSQE5Obdl3k4cnmLA6WXtK6XFuWRnvVL7aCiBqaLPM8c4ph0S4tKna8XvmIwEnXQ==",
"dev": true,
"requires": {
"forwarded": "~0.1.2",
"ipaddr.js": "1.6.0"
}
},
"pseudomap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz",
......@@ -6753,41 +6280,6 @@
"strict-uri-encode": "^1.0.0"
}
},
"randomhex": {
"version": "0.1.5",
"resolved": "https://registry.npmjs.org/randomhex/-/randomhex-0.1.5.tgz",
"integrity": "sha1-us7vmCMpCRQA8qKRLGzQLxCU9YU=",
"dev": true
},
"range-parser": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
"integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=",
"dev": true
},
"raw-body": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.3.tgz",
"integrity": "sha512-9esiElv1BrZoI3rCDuOuKCBRbuApGGaDPQfjSflGxdy4oyzqghxu6klEkkVIvBje+FF0BX9coEv8KqW6X/7njw==",
"dev": true,
"requires": {
"bytes": "3.0.0",
"http-errors": "1.6.3",
"iconv-lite": "0.4.23",
"unpipe": "1.0.0"
},
"dependencies": {
"iconv-lite": {
"version": "0.4.23",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz",
"integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==",
"dev": true,
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
}
}
},
"read-chunk": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/read-chunk/-/read-chunk-2.1.0.tgz",
......@@ -7020,9 +6512,9 @@
"dev": true
},
"require-from-string": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-1.2.1.tgz",
"integrity": "sha1-UpyczvJzgK3+yaL5ZbZJu+5jZBg=",
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
"dev": true
},
"require-main-filename": {
......@@ -7240,69 +6732,6 @@
"integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg==",
"dev": true
},
"send": {
"version": "0.16.2",
"resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz",
"integrity": "sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw==",
"dev": true,
"requires": {
"debug": "2.6.9",
"depd": "~1.1.2",
"destroy": "~1.0.4",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"fresh": "0.5.2",
"http-errors": "~1.6.2",
"mime": "1.4.1",
"ms": "2.0.0",
"on-finished": "~2.3.0",
"range-parser": "~1.2.0",
"statuses": "~1.4.0"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"statuses": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz",
"integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==",
"dev": true
}
}
},
"serve-static": {
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz",
"integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==",
"dev": true,
"requires": {
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"parseurl": "~1.3.2",
"send": "0.16.2"
}
},
"servify": {
"version": "0.1.12",
"resolved": "https://registry.npmjs.org/servify/-/servify-0.1.12.tgz",
"integrity": "sha512-/xE6GvsKKqyo1BAY+KxOWXcLpPsUUyji7Qg3bVD7hh1eRze5bR1uYiuDA/k3Gof1s9BTzQZEJK8sNcNGFIzeWw==",
"dev": true,
"requires": {
"body-parser": "^1.16.0",
"cors": "^2.8.1",
"express": "^4.14.0",
"request": "^2.79.0",
"xhr": "^2.3.3"
}
},
"set-blocking": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
......@@ -7332,12 +6761,6 @@
}
}
},
"setprototypeof": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz",
"integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==",
"dev": true
},
"sha.js": {
"version": "2.4.11",
"resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
......@@ -7389,12 +6812,6 @@
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
"dev": true
},
"simple-concat": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.0.tgz",
"integrity": "sha1-c0TLuLbib7J9ZrL8hvn21Zl1IcY=",
"dev": true
},
"slash": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-1.0.0.tgz",
......@@ -7539,38 +6956,126 @@
"dev": true
},
"solc": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/solc/-/solc-0.4.24.tgz",
"integrity": "sha512-2xd7Cf1HeVwrIb6Bu1cwY2/TaLRodrppCq3l7rhLimFQgmxptXhTC3+/wesVLpB09F1A2kZgvbMOgH7wvhFnBQ==",
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/solc/-/solc-0.5.0.tgz",
"integrity": "sha512-mdLHDl9WeYrN+FIKcMc9PlPfnA9DG9ur5QpCDKcv6VC4RINAsTF4EMuXMZMKoQTvZhtLyJIVH/BZ+KU830Z8Xg==",
"dev": true,
"requires": {
"fs-extra": "^0.30.0",
"keccak": "^1.0.2",
"memorystream": "^0.3.1",
"require-from-string": "^1.1.0",
"semver": "^5.3.0",
"yargs": "^4.7.1"
"require-from-string": "^2.0.0",
"semver": "^5.5.0",
"yargs": "^11.0.0"
},
"dependencies": {
"ansi-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=",
"dev": true
},
"camelcase": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz",
"integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=",
"dev": true
},
"cliui": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz",
"integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==",
"dev": true,
"requires": {
"string-width": "^2.1.1",
"strip-ansi": "^4.0.0",
"wrap-ansi": "^2.0.0"
}
},
"find-up": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz",
"integrity": "sha1-RdG35QbHF93UgndaK3eSCjwMV6c=",
"dev": true,
"requires": {
"locate-path": "^2.0.0"
}
},
"is-fullwidth-code-point": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
"dev": true
},
"os-locale": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-2.1.0.tgz",
"integrity": "sha512-3sslG3zJbEYcaC4YVAvDorjGxc7tv6KVATnLPZONiljsUncvihe9BQoVCEs0RZ1kmf4Hk9OBqlZfJZWI4GanKA==",
"dev": true,
"requires": {
"execa": "^0.7.0",
"lcid": "^1.0.0",
"mem": "^1.1.0"
}
},
"semver": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
"integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==",
"dev": true
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
"integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
"dev": true,
"requires": {
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^4.0.0"
}
},
"strip-ansi": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
"dev": true,
"requires": {
"ansi-regex": "^3.0.0"
}
},
"which-module": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz",
"integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=",
"dev": true
},
"yargs": {
"version": "4.8.1",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-4.8.1.tgz",
"integrity": "sha1-wMQpJMpKqmsObaFznfshZDn53cA=",
"version": "11.1.0",
"resolved": "http://registry.npmjs.org/yargs/-/yargs-11.1.0.tgz",
"integrity": "sha512-NwW69J42EsCSanF8kyn5upxvjp5ds+t3+udGBeTbFnERA+lF541DDpMawzo4z6W/QrzNM18D+BPMiOBibnFV5A==",
"dev": true,
"requires": {
"cliui": "^3.2.0",
"cliui": "^4.0.0",
"decamelize": "^1.1.1",
"find-up": "^2.1.0",
"get-caller-file": "^1.0.1",
"lodash.assign": "^4.0.3",
"os-locale": "^1.4.0",
"read-pkg-up": "^1.0.1",
"os-locale": "^2.0.0",
"require-directory": "^2.1.1",
"require-main-filename": "^1.0.1",
"set-blocking": "^2.0.0",
"string-width": "^1.0.1",
"which-module": "^1.0.0",
"window-size": "^0.2.0",
"string-width": "^2.0.0",
"which-module": "^2.0.0",
"y18n": "^3.2.1",
"yargs-parser": "^2.4.1"
"yargs-parser": "^9.0.2"
}
},
"yargs-parser": {
"version": "9.0.2",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-9.0.2.tgz",
"integrity": "sha1-nM9qQ0YP5O1Aqbto9I1DuKaMwHc=",
"dev": true,
"requires": {
"camelcase": "^4.1.0"
}
}
}
......@@ -8118,12 +7623,6 @@
}
}
},
"statuses": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=",
"dev": true
},
"strict-uri-encode": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz",
......@@ -8423,12 +7922,6 @@
"integrity": "sha512-DlX6dR0lOIRDFxI0mjL9IYg6OTncLm/Zt+JiBhE5OlFcAR8yc9S7FFXU9so0oda47frdM/JFsk7UjNt9vscKcg==",
"dev": true
},
"trim": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/trim/-/trim-0.0.1.tgz",
"integrity": "sha1-WFhUf2spB1fulczMZm+1AITEYN0=",
"dev": true
},
"trim-right": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/trim-right/-/trim-right-1.0.1.tgz",
......@@ -8436,14 +7929,15 @@
"dev": true
},
"truffle": {
"version": "4.1.13",
"resolved": "https://registry.npmjs.org/truffle/-/truffle-4.1.13.tgz",
"integrity": "sha1-vydYaYi0/4RWPt+/MrR5QUCKdq0=",
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/truffle/-/truffle-5.0.0.tgz",
"integrity": "sha512-la0TJu+E59Ut62i6cGY0sugeubglDqH5w49a7IrpxZ1nnsDqv6qWB3ibiyYiCp/jr+iI0bLtcr3DKkfQjVDd+g==",
"dev": true,
"requires": {
"app-module-path": "^2.2.0",
"mocha": "^4.1.0",
"original-require": "1.0.1",
"solc": "0.4.24"
"solc": "0.5.0"
}
},
"tslib": {
......@@ -8483,33 +7977,6 @@
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
"dev": true
},
"type-is": {
"version": "1.6.16",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz",
"integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==",
"dev": true,
"requires": {
"media-typer": "0.3.0",
"mime-types": "~2.1.18"
},
"dependencies": {
"mime-db": {
"version": "1.33.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz",
"integrity": "sha512-BHJ/EKruNIqJf/QahvxwQZXKygOQ256myeN/Ew+THcAa5q+PjyTTMMeNQC4DZw5AwfvelsUrA6B67NKMqXDbzQ==",
"dev": true
},
"mime-types": {
"version": "2.1.18",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.18.tgz",
"integrity": "sha512-lc/aahn+t4/SWV/qcmumYjymLsWfN3ELhpmVuUFjgsORruuZPVSwAQryq+HHGvO/SI2KVX26bx+En+zhM8g8hQ==",
"dev": true,
"requires": {
"mime-db": "~1.33.0"
}
}
}
},
"typedarray": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
......@@ -8535,12 +8002,6 @@
"dev": true,
"optional": true
},
"ultron": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",
"integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og==",
"dev": true
},
"underscore": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz",
......@@ -8582,12 +8043,6 @@
}
}
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=",
"dev": true
},
"unset-value": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unset-value/-/unset-value-1.0.0.tgz",
......@@ -8672,12 +8127,6 @@
"prepend-http": "^2.0.0"
}
},
"url-set-query": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/url-set-query/-/url-set-query-1.0.0.tgz",
"integrity": "sha1-AW6M/Xwg7gXK/neV6JK9BwL6ozk=",
"dev": true
},
"url-to-options": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/url-to-options/-/url-to-options-1.0.1.tgz",
......@@ -8713,12 +8162,6 @@
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=",
"dev": true
},
"utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=",
"dev": true
},
"uuid": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.0.tgz",
......@@ -8735,12 +8178,6 @@
"spdx-expression-parse": "~1.0.0"
}
},
"vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=",
"dev": true
},
"verror": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",
......@@ -8806,41 +8243,6 @@
"xmlhttprequest": "*"
}
},
"web3-utils": {
"version": "1.0.0-beta.34",
"resolved": "https://registry.npmjs.org/web3-utils/-/web3-utils-1.0.0-beta.34.tgz",
"integrity": "sha1-lBH8OarvOcpOBhafdiKX2f8CCXA=",
"dev": true,
"requires": {
"bn.js": "4.11.6",
"eth-lib": "0.1.27",
"ethjs-unit": "0.1.6",
"number-to-bn": "1.7.0",
"randomhex": "0.1.5",
"underscore": "1.8.3",
"utf8": "2.1.1"
},
"dependencies": {
"bn.js": {
"version": "4.11.6",
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz",
"integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=",
"dev": true
},
"underscore": {
"version": "1.8.3",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
"integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=",
"dev": true
},
"utf8": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/utf8/-/utf8-2.1.1.tgz",
"integrity": "sha1-LgHbAvfY0JRPdxBPFgnrDDBM92g=",
"dev": true
}
}
},
"webpack-addons": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/webpack-addons/-/webpack-addons-1.1.5.tgz",
......@@ -9577,66 +8979,6 @@
"slide": "^1.1.5"
}
},
"ws": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz",
"integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==",
"dev": true,
"requires": {
"async-limiter": "~1.0.0",
"safe-buffer": "~5.1.0",
"ultron": "~1.1.0"
}
},
"xhr": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/xhr/-/xhr-2.4.0.tgz",
"integrity": "sha1-4W5mpF+GmGHu76tBbV7/ci3ECZM=",
"dev": true,
"requires": {
"global": "~4.3.0",
"is-function": "^1.0.1",
"parse-headers": "^2.0.0",
"xtend": "^4.0.0"
}
},
"xhr-request": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/xhr-request/-/xhr-request-1.1.0.tgz",
"integrity": "sha512-Y7qzEaR3FDtL3fP30k9wO/e+FBnBByZeybKOhASsGP30NIkRAAkKD/sCnLvgEfAIEC1rcmK7YG8f4oEnIrrWzA==",
"dev": true,
"requires": {
"buffer-to-arraybuffer": "^0.0.5",
"object-assign": "^4.1.1",
"query-string": "^5.0.1",
"simple-get": "^2.7.0",
"timed-out": "^4.0.1",
"url-set-query": "^1.0.0",
"xhr": "^2.0.4"
},
"dependencies": {
"simple-get": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/simple-get/-/simple-get-2.8.1.tgz",
"integrity": "sha512-lSSHRSw3mQNUGPAYRqo7xy9dhKmxFXIjLjp4KHpf99GEH2VH7C3AM+Qfx6du6jhfUi6Vm7XnbEVEf7Wb6N8jRw==",
"dev": true,
"requires": {
"decompress-response": "^3.3.0",
"once": "^1.3.1",
"simple-concat": "^1.0.0"
}
}
}
},
"xhr-request-promise": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/xhr-request-promise/-/xhr-request-promise-0.1.2.tgz",
"integrity": "sha1-NDxE0e53JrhkgGloLQ+EDIO0Jh0=",
"dev": true,
"requires": {
"xhr-request": "^1.0.1"
}
},
"xhr2": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.4.tgz",
......
......@@ -9,7 +9,7 @@
],
"scripts": {
"build": "scripts/build.sh",
"compile": "scripts/compile.sh",
"compile": "truffle compile",
"console": "truffle console",
"coverage": "scripts/coverage.sh",
"lint": "npm run lint:js && npm run lint:sol",
......@@ -41,7 +41,6 @@
"homepage": "https://github.com/OpenZeppelin/zeppelin-solidity",
"devDependencies": {
"chai": "^4.1.2",
"chai-bignumber": "^2.0.2",
"coveralls": "^3.0.1",
"eslint": "^4.19.1",
"eslint-config-standard": "^10.2.1",
......@@ -53,11 +52,11 @@
"ethereumjs-util": "^6.0.0",
"ethjs-abi": "^0.2.1",
"ganache-cli": "6.1.8",
"openzeppelin-test-helpers": "^0.1.1",
"pify": "^4.0.1",
"solhint": "^1.5.0",
"solidity-coverage": "^0.5.4",
"truffle": "^4.1.13",
"web3-utils": "^1.0.0-beta.34"
"truffle": "^5.0.0"
},
"dependencies": {}
}
#!/usr/bin/env bash
# Configure to exit script as soon as a command fails.
set -o errexit
SOLC_05_DIR=solc-0.5
# Delete any previous build artifacts
rm -rf build/
# Create a subproject where 0.5.x compilation will take place
mkdir -p "$SOLC_05_DIR"
cd "$SOLC_05_DIR"
echo '{ "private": true }' > package.json
npm install --save-dev truffle@5.0.0
rm -rf contracts
ln --symbolic ../contracts contracts
# Delete any previous build artifacts
rm -rf build/
# Compile
echo "
module.exports = {
compilers: {
solc: {
version: \"0.5.0\",
},
},
};
" > truffle-config.js
npx truffle compile
# Modify the paths in the artifacts to make it look as if they were built in the root
sed --in-place --expression "s/\/$SOLC_05_DIR//g" build/contracts/*.json
# Copy them back into the root
cd ..
cp --recursive "$SOLC_05_DIR"/build build
const shouldFail = require('../helpers/shouldFail');
const { ZERO_ADDRESS } = require('../helpers/constants');
const { shouldFail, constants } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const RolesMock = artifacts.require('RolesMock');
require('./../helpers/setup');
contract('Roles', function ([_, authorized, otherAuthorized, anyone]) {
beforeEach(async function () {
this.roles = await RolesMock.new();
......
const shouldFail = require('../../helpers/shouldFail');
const { ZERO_ADDRESS } = require('../../helpers/constants');
const expectEvent = require('../../helpers/expectEvent');
require('../../helpers/setup');
const { shouldFail, constants, expectEvent } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function capitalize (str) {
return str.replace(/\b\w/g, l => l.toUpperCase());
......
const expectEvent = require('../helpers/expectEvent');
const { ether } = require('../helpers/ether');
const shouldFail = require('../helpers/shouldFail');
const { balanceDifference } = require('../helpers/balanceDifference');
const { ZERO_ADDRESS } = require('../helpers/constants');
const { BigNumber } = require('../helpers/setup');
const { balance, BN, constants, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const AllowanceCrowdsaleImpl = artifacts.require('AllowanceCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenWallet]) {
const rate = new BigNumber(1);
const value = ether(0.42);
const rate = new BN('1');
const value = ether('0.42');
const expectedTokenAmount = rate.mul(value);
const tokenAllowance = new BigNumber('1e22');
const tokenAllowance = new BN('10').pow(new BN('22'));
beforeEach(async function () {
this.token = await SimpleToken.new({ from: tokenWallet });
......@@ -52,7 +47,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
});
it('should forward funds to wallet', async function () {
(await balanceDifference(wallet, () =>
(await balance.difference(wallet, () =>
this.crowdsale.sendTransaction({ value, from: investor }))
).should.be.bignumber.equal(value);
});
......@@ -60,7 +55,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
describe('check remaining allowance', function () {
it('should report correct allowace left', async function () {
const remainingAllowance = tokenAllowance - expectedTokenAmount;
const remainingAllowance = tokenAllowance.sub(expectedTokenAmount);
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
(await this.crowdsale.remainingTokens()).should.be.bignumber.equal(remainingAllowance);
});
......@@ -68,7 +63,7 @@ contract('AllowanceCrowdsale', function ([_, investor, wallet, purchaser, tokenW
context('when the allowance is larger than the token amount', function () {
beforeEach(async function () {
const amount = await this.token.balanceOf(tokenWallet);
await this.token.approve(this.crowdsale.address, amount.plus(1), { from: tokenWallet });
await this.token.approve(this.crowdsale.address, amount.addn(1), { from: tokenWallet });
});
it('should report the amount instead of the allowance', async function () {
......
const { ether } = require('../helpers/ether');
const shouldFail = require('../helpers/shouldFail');
const { BigNumber } = require('../helpers/setup');
const { BN, ether, shouldFail } = require('openzeppelin-test-helpers');
const CappedCrowdsaleImpl = artifacts.require('CappedCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('CappedCrowdsale', function ([_, wallet]) {
const rate = new BigNumber(1);
const cap = ether(100);
const lessThanCap = ether(60);
const tokenSupply = new BigNumber('1e22');
const rate = new BN('1');
const cap = ether('100');
const lessThanCap = ether('60');
const tokenSupply = new BN('10').pow(new BN('22'));
beforeEach(async function () {
this.token = await SimpleToken.new();
......@@ -28,7 +25,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
describe('accepting payments', function () {
it('should accept payments within cap', async function () {
await this.crowdsale.send(cap.minus(lessThanCap));
await this.crowdsale.send(cap.sub(lessThanCap));
await this.crowdsale.send(lessThanCap);
});
......@@ -38,7 +35,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
});
it('should reject payments that exceed cap', async function () {
await shouldFail.reverting(this.crowdsale.send(cap.plus(1)));
await shouldFail.reverting(this.crowdsale.send(cap.addn(1)));
});
});
......@@ -49,7 +46,7 @@ contract('CappedCrowdsale', function ([_, wallet]) {
});
it('should not reach cap if sent just under cap', async function () {
await this.crowdsale.send(cap.minus(1));
await this.crowdsale.send(cap.subn(1));
(await this.crowdsale.capReached()).should.equal(false);
});
......
const expectEvent = require('../helpers/expectEvent');
const shouldFail = require('../helpers/shouldFail');
const { balanceDifference } = require('../helpers/balanceDifference');
const { ether } = require('../helpers/ether');
const { ZERO_ADDRESS } = require('../helpers/constants');
const { BigNumber } = require('../helpers/setup');
const { balance, BN, constants, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const Crowdsale = artifacts.require('CrowdsaleMock');
const SimpleToken = artifacts.require('SimpleToken');
contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BigNumber(1);
const value = ether(42);
const tokenSupply = new BigNumber('1e22');
const rate = new BN(1);
const value = ether('42');
const tokenSupply = new BN('10').pow(new BN('22'));
const expectedTokenAmount = rate.mul(value);
it('requires a non-null token', async function () {
......@@ -93,7 +88,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
});
it('should forward funds to wallet', async function () {
(await balanceDifference(wallet, () =>
(await balance.difference(wallet, () =>
this.crowdsale.sendTransaction({ value, from: investor }))
).should.be.bignumber.equal(value);
});
......@@ -116,7 +111,7 @@ contract('Crowdsale', function ([_, investor, wallet, purchaser]) {
});
it('should forward funds to wallet', async function () {
(await balanceDifference(wallet, () =>
(await balance.difference(wallet, () =>
this.crowdsale.buyTokens(investor, { value, from: purchaser }))
).should.be.bignumber.equal(value);
});
......
const expectEvent = require('../helpers/expectEvent');
const time = require('../helpers/time');
const shouldFail = require('../helpers/shouldFail');
const { BigNumber } = require('../helpers/setup');
const { BN, expectEvent, shouldFail, time } = require('openzeppelin-test-helpers');
const FinalizableCrowdsaleImpl = artifacts.require('FinalizableCrowdsaleImpl');
const ERC20 = artifacts.require('ERC20');
contract('FinalizableCrowdsale', function ([_, wallet, anyone]) {
const rate = new BigNumber(1000);
const rate = new BN('1000');
before(async function () {
// Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache
......@@ -16,9 +12,9 @@ contract('FinalizableCrowdsale', function ([_, wallet, anyone]) {
});
beforeEach(async function () {
this.openingTime = (await time.latest()) + time.duration.weeks(1);
this.closingTime = this.openingTime + time.duration.weeks(1);
this.afterClosingTime = this.closingTime + time.duration.seconds(1);
this.openingTime = (await time.latest()).add(time.duration.weeks(1));
this.closingTime = this.openingTime.add(time.duration.weeks(1));
this.afterClosingTime = this.closingTime.add(time.duration.seconds(1));
this.token = await ERC20.new();
this.crowdsale = await FinalizableCrowdsaleImpl.new(
......
const { ether } = require('../helpers/ether');
const time = require('../helpers/time');
const shouldFail = require('../helpers/shouldFail');
const { BigNumber } = require('../helpers/setup');
const { BN, ether, shouldFail, time } = require('openzeppelin-test-helpers');
const IncreasingPriceCrowdsaleImpl = artifacts.require('IncreasingPriceCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser]) {
const value = ether(1);
const tokenSupply = new BigNumber('1e22');
const value = ether('1');
const tokenSupply = new BN('10').pow(new BN('22'));
describe('rate during crowdsale should change at a fixed step every block', async function () {
const initialRate = new BigNumber(9166);
const finalRate = new BigNumber(5500);
const rateAtTime150 = new BigNumber(9166);
const rateAtTime300 = new BigNumber(9165);
const rateAtTime1500 = new BigNumber(9157);
const rateAtTime30 = new BigNumber(9166);
const rateAtTime150000 = new BigNumber(8257);
const rateAtTime450000 = new BigNumber(6439);
const initialRate = new BN('9166');
const finalRate = new BN('5500');
const rateAtTime150 = new BN('9166');
const rateAtTime300 = new BN('9165');
const rateAtTime1500 = new BN('9157');
const rateAtTime30 = new BN('9166');
const rateAtTime150000 = new BN('8257');
const rateAtTime450000 = new BN('6439');
beforeEach(async function () {
await time.advanceBlock();
this.startTime = (await time.latest()) + time.duration.weeks(1);
this.closingTime = this.startTime + time.duration.weeks(1);
this.afterClosingTime = this.closingTime + time.duration.seconds(1);
this.startTime = (await time.latest()).add(time.duration.weeks(1));
this.closingTime = this.startTime.add(time.duration.weeks(1));
this.afterClosingTime = this.closingTime.add(time.duration.seconds(1));
this.token = await SimpleToken.new();
});
it('reverts with a final rate larger than the initial rate', async function () {
await shouldFail.reverting(IncreasingPriceCrowdsaleImpl.new(
this.startTime, this.closingTime, wallet, this.token.address, initialRate, initialRate.plus(1)
this.startTime, this.closingTime, wallet, this.token.address, initialRate, initialRate.addn(1)
));
});
......@@ -65,12 +61,12 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser])
});
it('returns a rate of 0 before the crowdsale starts', async function () {
(await this.crowdsale.getCurrentRate()).should.be.bignumber.equal(0);
(await this.crowdsale.getCurrentRate()).should.be.bignumber.equal('0');
});
it('returns a rate of 0 after the crowdsale ends', async function () {
await time.increaseTo(this.afterClosingTime);
(await this.crowdsale.getCurrentRate()).should.be.bignumber.equal(0);
(await this.crowdsale.getCurrentRate()).should.be.bignumber.equal('0');
});
it('at start', async function () {
......@@ -80,37 +76,37 @@ contract('IncreasingPriceCrowdsale', function ([_, investor, wallet, purchaser])
});
it('at time 150', async function () {
await time.increaseTo(this.startTime + 150);
await time.increaseTo(this.startTime.addn(150));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150));
});
it('at time 300', async function () {
await time.increaseTo(this.startTime + 300);
await time.increaseTo(this.startTime.addn(300));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime300));
});
it('at time 1500', async function () {
await time.increaseTo(this.startTime + 1500);
await time.increaseTo(this.startTime.addn(1500));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime1500));
});
it('at time 30', async function () {
await time.increaseTo(this.startTime + 30);
await time.increaseTo(this.startTime.addn(30));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime30));
});
it('at time 150000', async function () {
await time.increaseTo(this.startTime + 150000);
await time.increaseTo(this.startTime.addn(150000));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime150000));
});
it('at time 450000', async function () {
await time.increaseTo(this.startTime + 450000);
await time.increaseTo(this.startTime.addn(450000));
await this.crowdsale.buyTokens(investor, { value, from: purchaser });
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value.mul(rateAtTime450000));
});
......
const { ether } = require('../helpers/ether');
const shouldFail = require('../helpers/shouldFail');
const { BigNumber } = require('../helpers/setup');
const { BN, ether, shouldFail } = require('openzeppelin-test-helpers');
const IndividuallyCappedCrowdsaleImpl = artifacts.require('IndividuallyCappedCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
......@@ -9,12 +6,12 @@ const { shouldBehaveLikePublicRole } = require('../access/roles/PublicRole.behav
contract('IndividuallyCappedCrowdsale', function (
[_, capper, otherCapper, wallet, alice, bob, charlie, anyone, ...otherAccounts]) {
const rate = new BigNumber(1);
const capAlice = ether(10);
const capBob = ether(2);
const lessThanCapAlice = ether(6);
const lessThanCapBoth = ether(1);
const tokenSupply = new BigNumber('1e22');
const rate = new BN(1);
const capAlice = ether('10');
const capBob = ether('2');
const lessThanCapAlice = ether('6');
const lessThanCapBoth = ether('1');
const tokenSupply = new BN('10').pow(new BN('22'));
beforeEach(async function () {
this.token = await SimpleToken.new();
......@@ -59,8 +56,8 @@ contract('IndividuallyCappedCrowdsale', function (
});
it('should reject payments that exceed cap', async function () {
await shouldFail.reverting(this.crowdsale.buyTokens(alice, { value: capAlice.plus(1) }));
await shouldFail.reverting(this.crowdsale.buyTokens(bob, { value: capBob.plus(1) }));
await shouldFail.reverting(this.crowdsale.buyTokens(alice, { value: capAlice.addn(1) }));
await shouldFail.reverting(this.crowdsale.buyTokens(bob, { value: capBob.addn(1) }));
});
it('should manage independent caps', async function () {
......
const expectEvent = require('../helpers/expectEvent');
const { balanceDifference } = require('../helpers/balanceDifference');
require('../helpers/setup');
const { balance, expectEvent } = require('openzeppelin-test-helpers');
function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate, value) {
const expectedTokenAmount = rate.mul(value);
......@@ -31,7 +28,7 @@ function shouldBehaveLikeMintedCrowdsale ([_, investor, wallet, purchaser], rate
});
it('should forward funds to wallet', async function () {
(await balanceDifference(wallet, () =>
(await balance.difference(wallet, () =>
this.crowdsale.sendTransaction({ value, from: investor }))
).should.be.bignumber.equal(value);
});
......
const { BN, ether, shouldFail } = require('openzeppelin-test-helpers');
const { shouldBehaveLikeMintedCrowdsale } = require('./MintedCrowdsale.behavior');
const { ether } = require('../helpers/ether');
const shouldFail = require('../helpers/shouldFail');
const { BigNumber } = require('../helpers/setup');
const MintedCrowdsaleImpl = artifacts.require('MintedCrowdsaleImpl');
const ERC20Mintable = artifacts.require('ERC20Mintable');
const ERC20 = artifacts.require('ERC20');
contract('MintedCrowdsale', function ([_, deployer, investor, wallet, purchaser]) {
const rate = new BigNumber(1000);
const value = ether(5);
const rate = new BN('1000');
const value = ether('5');
describe('using ERC20Mintable', function () {
beforeEach(async function () {
......
const shouldFail = require('../helpers/shouldFail');
const { BN, shouldFail } = require('openzeppelin-test-helpers');
const PausableCrowdsale = artifacts.require('PausableCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
require('../helpers/setup');
contract('PausableCrowdsale', function ([_, pauser, wallet, anyone]) {
const rate = 1;
const value = 1;
const rate = new BN(1);
const value = new BN(1);
beforeEach(async function () {
const from = pauser;
this.token = await SimpleToken.new({ from });
this.crowdsale = await PausableCrowdsale.new(rate, wallet, this.token.address, { from });
await this.token.transfer(this.crowdsale.address, 2 * value, { from });
await this.token.transfer(this.crowdsale.address, value.muln(2), { from });
});
it('purchases work', async function () {
......
const time = require('../helpers/time');
const shouldFail = require('../helpers/shouldFail');
const { ether } = require('../helpers/ether');
const { BigNumber } = require('../helpers/setup');
const { BN, ether, shouldFail, time } = require('openzeppelin-test-helpers');
const PostDeliveryCrowdsaleImpl = artifacts.require('PostDeliveryCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BigNumber(1);
const tokenSupply = new BigNumber('1e22');
const rate = new BN(1);
const tokenSupply = new BN('10').pow(new BN('22'));
before(async function () {
// Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache
......@@ -17,9 +13,9 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
});
beforeEach(async function () {
this.openingTime = (await time.latest()) + time.duration.weeks(1);
this.closingTime = this.openingTime + time.duration.weeks(1);
this.afterClosingTime = this.closingTime + time.duration.seconds(1);
this.openingTime = (await time.latest()).add(time.duration.weeks(1));
this.closingTime = this.openingTime.add(time.duration.weeks(1));
this.afterClosingTime = this.closingTime.add(time.duration.seconds(1));
this.token = await SimpleToken.new();
this.crowdsale = await PostDeliveryCrowdsaleImpl.new(
this.openingTime, this.closingTime, rate, wallet, this.token.address
......@@ -33,7 +29,7 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
});
context('with bought tokens', function () {
const value = ether(42);
const value = ether('42');
beforeEach(async function () {
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
......@@ -41,7 +37,7 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
it('does not immediately assign tokens to beneficiaries', async function () {
(await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal(value);
(await this.token.balanceOf(investor)).should.be.bignumber.equal(0);
(await this.token.balanceOf(investor)).should.be.bignumber.equal('0');
});
it('does not allow beneficiaries to withdraw tokens before crowdsale ends', async function () {
......@@ -55,7 +51,7 @@ contract('PostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
it('allows beneficiaries to withdraw tokens', async function () {
await this.crowdsale.withdrawTokens(investor);
(await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal(0);
(await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal('0');
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value);
});
......
const { ether } = require('../helpers/ether');
const { balanceDifference } = require('../helpers/balanceDifference');
const shouldFail = require('../helpers/shouldFail');
const time = require('../helpers/time');
const { ethGetBalance } = require('../helpers/web3');
const { BigNumber } = require('../helpers/setup');
const { balance, BN, ether, shouldFail, time } = require('openzeppelin-test-helpers');
const RefundableCrowdsaleImpl = artifacts.require('RefundableCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyone]) {
const rate = new BigNumber(1);
const goal = ether(50);
const lessThanGoal = ether(45);
const tokenSupply = new BigNumber('1e22');
const rate = new BN(1);
const goal = ether('50');
const lessThanGoal = ether('45');
const tokenSupply = new BN('10').pow(new BN('22'));
before(async function () {
// Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache
......@@ -21,10 +15,10 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon
});
beforeEach(async function () {
this.openingTime = (await time.latest()) + time.duration.weeks(1);
this.closingTime = this.openingTime + time.duration.weeks(1);
this.afterClosingTime = this.closingTime + time.duration.seconds(1);
this.preWalletBalance = await ethGetBalance(wallet);
this.openingTime = (await time.latest()).add(time.duration.weeks(1));
this.closingTime = this.openingTime.add(time.duration.weeks(1));
this.afterClosingTime = this.closingTime.add(time.duration.seconds(1));
this.preWalletBalance = await balance.current(wallet);
this.token = await SimpleToken.new();
});
......@@ -71,7 +65,7 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon
});
it('refunds', async function () {
(await balanceDifference(investor, () =>
(await balance.difference(investor, () =>
this.crowdsale.claimRefund(investor, { gasPrice: 0 }))
).should.be.bignumber.equal(lessThanGoal);
});
......@@ -94,8 +88,8 @@ contract('RefundableCrowdsale', function ([_, wallet, investor, purchaser, anyon
});
it('forwards funds to wallet', async function () {
const postWalletBalance = await ethGetBalance(wallet);
postWalletBalance.minus(this.preWalletBalance).should.be.bignumber.equal(goal);
const postWalletBalance = await balance.current(wallet);
postWalletBalance.sub(this.preWalletBalance).should.be.bignumber.equal(goal);
});
});
});
......
const time = require('../helpers/time');
const shouldFail = require('../helpers/shouldFail');
const { ether } = require('../helpers/ether');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
const { BN, ether, shouldFail, time } = require('openzeppelin-test-helpers');
const RefundablePostDeliveryCrowdsaleImpl = artifacts.require('RefundablePostDeliveryCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BigNumber(1);
const tokenSupply = new BigNumber('1e22');
const goal = ether(100);
const rate = new BN(1);
const tokenSupply = new BN('10').pow(new BN('22'));
const goal = ether('100');
before(async function () {
// Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache
......@@ -22,9 +14,9 @@ contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purc
});
beforeEach(async function () {
this.openingTime = (await time.latest()) + time.duration.weeks(1);
this.closingTime = this.openingTime + time.duration.weeks(1);
this.afterClosingTime = this.closingTime + time.duration.seconds(1);
this.openingTime = (await time.latest()).add(time.duration.weeks(1));
this.closingTime = this.openingTime.add(time.duration.weeks(1));
this.afterClosingTime = this.closingTime.add(time.duration.seconds(1));
this.token = await SimpleToken.new();
this.crowdsale = await RefundablePostDeliveryCrowdsaleImpl.new(
this.openingTime, this.closingTime, rate, wallet, this.token.address, goal
......@@ -38,7 +30,7 @@ contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purc
});
context('with bought tokens below the goal', function () {
const value = goal.sub(1);
const value = goal.subn(1);
beforeEach(async function () {
await this.crowdsale.buyTokens(investor, { value: value, from: purchaser });
......@@ -46,7 +38,7 @@ contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purc
it('does not immediately deliver tokens to beneficiaries', async function () {
(await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal(value);
(await this.token.balanceOf(investor)).should.be.bignumber.equal(0);
(await this.token.balanceOf(investor)).should.be.bignumber.equal('0');
});
it('does not allow beneficiaries to withdraw tokens before crowdsale ends', async function () {
......@@ -74,7 +66,7 @@ contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purc
it('does not immediately deliver tokens to beneficiaries', async function () {
(await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal(value);
(await this.token.balanceOf(investor)).should.be.bignumber.equal(0);
(await this.token.balanceOf(investor)).should.be.bignumber.equal('0');
});
it('does not allow beneficiaries to withdraw tokens before crowdsale ends', async function () {
......@@ -89,7 +81,7 @@ contract('RefundablePostDeliveryCrowdsale', function ([_, investor, wallet, purc
it('allows beneficiaries to withdraw tokens', async function () {
await this.crowdsale.withdrawTokens(investor);
(await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal(0);
(await this.crowdsale.balanceOf(investor)).should.be.bignumber.equal('0');
(await this.token.balanceOf(investor)).should.be.bignumber.equal(value);
});
......
const { ether } = require('../helpers/ether');
const shouldFail = require('../helpers/shouldFail');
const time = require('../helpers/time');
const { BigNumber } = require('../helpers/setup');
const { BN, ether, shouldFail, time } = require('openzeppelin-test-helpers');
const TimedCrowdsaleImpl = artifacts.require('TimedCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
const rate = new BigNumber(1);
const value = ether(42);
const tokenSupply = new BigNumber('1e22');
const rate = new BN(1);
const value = ether('42');
const tokenSupply = new BN('10').pow(new BN('22'));
before(async function () {
// Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache
......@@ -18,21 +14,21 @@ contract('TimedCrowdsale', function ([_, investor, wallet, purchaser]) {
});
beforeEach(async function () {
this.openingTime = (await time.latest()) + time.duration.weeks(1);
this.closingTime = this.openingTime + time.duration.weeks(1);
this.afterClosingTime = this.closingTime + time.duration.seconds(1);
this.openingTime = (await time.latest()).add(time.duration.weeks(1));
this.closingTime = this.openingTime.add(time.duration.weeks(1));
this.afterClosingTime = this.closingTime.add(time.duration.seconds(1));
this.token = await SimpleToken.new();
});
it('reverts if the opening time is in the past', async function () {
await shouldFail.reverting(TimedCrowdsaleImpl.new(
(await time.latest()) - time.duration.days(1), this.closingTime, rate, wallet, this.token.address
(await time.latest()).sub(time.duration.days(1)), this.closingTime, rate, wallet, this.token.address
));
});
it('reverts if the closing time is before the opening time', async function () {
await shouldFail.reverting(TimedCrowdsaleImpl.new(
this.openingTime, this.openingTime - time.duration.seconds(1), rate, wallet, this.token.address
this.openingTime, this.openingTime.sub(time.duration.seconds(1)), rate, wallet, this.token.address
));
});
......
require('../helpers/setup');
const { ether } = require('../helpers/ether');
const shouldFail = require('../helpers/shouldFail');
const BigNumber = web3.BigNumber;
const { BN, ether, shouldFail } = require('openzeppelin-test-helpers');
const WhitelistCrowdsale = artifacts.require('WhitelistCrowdsaleImpl');
const SimpleToken = artifacts.require('SimpleToken');
contract('WhitelistCrowdsale', function ([_, wallet, whitelister, whitelisted, otherWhitelisted, anyone]) {
const rate = 1;
const value = ether(42);
const tokenSupply = new BigNumber('1e22');
const rate = new BN(1);
const value = ether('42');
const tokenSupply = new BN('10').pow(new BN('22'));
beforeEach(async function () {
this.token = await SimpleToken.new({ from: whitelister });
......
const { shouldFail } = require('openzeppelin-test-helpers');
const { signMessage, toEthSignedMessageHash } = require('../helpers/sign');
const shouldFail = require('../helpers/shouldFail');
const ECDSAMock = artifacts.require('ECDSAMock');
require('../helpers/setup');
const TEST_MESSAGE = web3.sha3('OpenZeppelin');
const WRONG_MESSAGE = web3.sha3('Nope');
const TEST_MESSAGE = web3.utils.sha3('OpenZeppelin');
const WRONG_MESSAGE = web3.utils.sha3('Nope');
contract('ECDSA', function ([_, anyone]) {
beforeEach(async function () {
......@@ -16,7 +14,7 @@ contract('ECDSA', function ([_, anyone]) {
context('recover with valid signature', function () {
context('with v0 signature', function () {
// Signature generated outside ganache with method web3.eth.sign(signer, message)
const signer = '0x2cc1166f6212628a0deef2b33befb2187d35b86c';
const signer = '0x2cc1166f6212628A0deEf2B33BEFB2187D35b86c';
// eslint-disable-next-line max-len
const signatureWithoutVersion = '0x5d99b6f7f6d1f73d1a26497f2b1c89b24c0993913f86e9a2d02cd69887d9c94f3c880358579d811b21dd1b7fd9bb01c1d81d10e69f0384e675c32b39643be892';
......@@ -49,7 +47,7 @@ contract('ECDSA', function ([_, anyone]) {
});
context('with v1 signature', function () {
const signer = '0x1e318623ab09fe6de3c9b8672098464aeda9100e';
const signer = '0x1E318623aB09Fe6de3C9b8672098464Aeda9100E';
// eslint-disable-next-line max-len
const signatureWithoutVersion = '0x331fe75a821c982f9127538858900d87d3ec1f9f737338ad67cad133fa48feff48e6fa0c18abc62e42820f05943e47af3e9fbe306ce74d64094bdf1691ee53e0';
......@@ -85,7 +83,7 @@ contract('ECDSA', function ([_, anyone]) {
context('with correct signature', function () {
it('returns signer address', async function () {
// Create the signature
const signature = signMessage(anyone, TEST_MESSAGE);
const signature = await signMessage(anyone, TEST_MESSAGE);
// Recover the signer address from the generated message and signature.
(await this.ecdsa.recover(
......@@ -98,7 +96,7 @@ contract('ECDSA', function ([_, anyone]) {
context('with wrong signature', function () {
it('does not return signer address', async function () {
// Create the signature
const signature = signMessage(anyone, TEST_MESSAGE);
const signature = await signMessage(anyone, TEST_MESSAGE);
// Recover the signer address from the generated message and wrong signature.
(await this.ecdsa.recover(WRONG_MESSAGE, signature)).should.not.equal(anyone);
......@@ -111,7 +109,7 @@ contract('ECDSA', function ([_, anyone]) {
// @TODO - remove `skip` once we upgrade to solc^0.5
it.skip('reverts', async function () {
// Create the signature
const signature = signMessage(anyone, TEST_MESSAGE);
const signature = await signMessage(anyone, TEST_MESSAGE);
await shouldFail.reverting(
this.ecdsa.recover(TEST_MESSAGE.substring(2), signature)
);
......
require('openzeppelin-test-helpers');
const { MerkleTree } = require('../helpers/merkleTree.js');
const { keccak256, bufferToHex } = require('ethereumjs-util');
const MerkleProofWrapper = artifacts.require('MerkleProofWrapper');
require('../helpers/setup');
contract('MerkleProof', function () {
beforeEach(async function () {
this.merkleProof = await MerkleProofWrapper.new();
......
const { BN } = require('openzeppelin-test-helpers');
const CounterImpl = artifacts.require('CounterImpl');
require('../helpers/setup');
const EXPECTED = [1, 2, 3, 4];
const KEY1 = web3.sha3('key1');
const KEY2 = web3.sha3('key2');
const EXPECTED = [new BN(1), new BN(2), new BN(3), new BN(4)];
const KEY1 = web3.utils.sha3('key1');
const KEY2 = web3.utils.sha3('key2');
contract('Counter', function ([_, owner]) {
beforeEach(async function () {
......
const ERC20WithMetadataMock = artifacts.require('ERC20WithMetadataMock');
require('openzeppelin-test-helpers');
require('../../helpers/setup');
const ERC20WithMetadataMock = artifacts.require('ERC20WithMetadataMock');
const metadataURI = 'https://example.com';
......
const shouldFail = require('../helpers/shouldFail');
const { ZERO_ADDRESS } = require('../helpers/constants');
const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const ERC20Mock = artifacts.require('ERC20Mock');
const ERC20Mintable = artifacts.require('ERC20Mintable');
const ERC20Migrator = artifacts.require('ERC20Migrator');
require('../helpers/setup');
contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
const totalSupply = 200;
const totalSupply = new BN('200');
it('reverts with a null legacy token address', async function () {
await shouldFail.reverting(ERC20Migrator.new(ZERO_ADDRESS));
......@@ -81,7 +79,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
currentBurnedBalance.should.be.bignumber.equal(amount);
const currentLegacyTokenBalance = await this.legacyToken.balanceOf(owner);
currentLegacyTokenBalance.should.be.bignumber.equal(0);
currentLegacyTokenBalance.should.be.bignumber.equal('0');
});
it('updates the total supply', async function () {
......@@ -91,7 +89,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
});
describe('when the approved balance is lower than the owned balance', function () {
const amount = baseAmount - 1;
const amount = baseAmount.subn(1);
beforeEach('approving part of the balance to the new contract', async function () {
await this.legacyToken.approve(this.migrator.address, amount, { from: owner });
......@@ -106,7 +104,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
});
describe('migrate', function () {
const baseAmount = 50;
const baseAmount = new BN(50);
beforeEach('approving tokens to the new contract', async function () {
await this.legacyToken.approve(this.migrator.address, baseAmount, { from: owner });
......@@ -129,7 +127,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
currentBurnedBalance.should.be.bignumber.equal(amount);
const currentLegacyTokenBalance = await this.legacyToken.balanceOf(owner);
currentLegacyTokenBalance.should.be.bignumber.equal(totalSupply - amount);
currentLegacyTokenBalance.should.be.bignumber.equal(totalSupply.sub(amount));
});
it('updates the total supply', async function () {
......@@ -139,7 +137,7 @@ contract('ERC20Migrator', function ([_, owner, recipient, anotherAccount]) {
});
describe('when the given amount is higher than the one approved', function () {
const amount = baseAmount + 1;
const amount = baseAmount.addn(1);
it('reverts', async function () {
await shouldFail.reverting(this.migrator.migrate(owner, amount));
......
const shouldFail = require('../helpers/shouldFail');
const { shouldFail } = require('openzeppelin-test-helpers');
const { getSignFor } = require('../helpers/sign');
const { shouldBehaveLikePublicRole } = require('../access/roles/PublicRole.behavior');
const SignatureBouncerMock = artifacts.require('SignatureBouncerMock');
require('../helpers/setup');
const UINT_VALUE = 23;
const BYTES_VALUE = web3.toHex('test');
const BYTES_VALUE = web3.utils.toHex('test');
const INVALID_SIGNATURE = '0xabcd';
contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authorizedUser, ...otherAccounts]) {
......@@ -28,7 +26,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
describe('modifiers', function () {
context('plain signature', function () {
it('allows valid signature for sender', async function () {
await this.sigBouncer.onlyWithValidSignature(this.signFor(authorizedUser), { from: authorizedUser });
await this.sigBouncer.onlyWithValidSignature(await this.signFor(authorizedUser), { from: authorizedUser });
});
it('does not allow invalid signature for sender', async function () {
......@@ -39,13 +37,13 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
it('does not allow valid signature for other sender', async function () {
await shouldFail.reverting(
this.sigBouncer.onlyWithValidSignature(this.signFor(authorizedUser), { from: anyone })
this.sigBouncer.onlyWithValidSignature(await this.signFor(authorizedUser), { from: anyone })
);
});
it('does not allow valid signature for method for sender', async function () {
await shouldFail.reverting(
this.sigBouncer.onlyWithValidSignature(this.signFor(authorizedUser, 'onlyWithValidSignature'),
this.sigBouncer.onlyWithValidSignature(await this.signFor(authorizedUser, 'onlyWithValidSignature'),
{ from: authorizedUser })
);
});
......@@ -54,7 +52,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
context('method signature', function () {
it('allows valid signature with correct method for sender', async function () {
await this.sigBouncer.onlyWithValidSignatureAndMethod(
this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: authorizedUser }
await this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: authorizedUser }
);
});
......@@ -67,21 +65,21 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
it('does not allow valid signature with correct method for other sender', async function () {
await shouldFail.reverting(
this.sigBouncer.onlyWithValidSignatureAndMethod(
this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: anyone }
await this.signFor(authorizedUser, 'onlyWithValidSignatureAndMethod'), { from: anyone }
)
);
});
it('does not allow valid method signature with incorrect method for sender', async function () {
await shouldFail.reverting(
this.sigBouncer.onlyWithValidSignatureAndMethod(this.signFor(authorizedUser, 'theWrongMethod'),
this.sigBouncer.onlyWithValidSignatureAndMethod(await this.signFor(authorizedUser, 'theWrongMethod'),
{ from: authorizedUser })
);
});
it('does not allow valid non-method signature method for sender', async function () {
await shouldFail.reverting(
this.sigBouncer.onlyWithValidSignatureAndMethod(this.signFor(authorizedUser), { from: authorizedUser })
this.sigBouncer.onlyWithValidSignatureAndMethod(await this.signFor(authorizedUser), { from: authorizedUser })
);
});
});
......@@ -89,7 +87,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
context('method and data signature', function () {
it('allows valid signature with correct method and data for sender', async function () {
await this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE,
this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]), { from: authorizedUser }
await this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]), { from: authorizedUser }
);
});
......@@ -102,7 +100,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
it('does not allow valid signature with correct method and incorrect data for sender', async function () {
await shouldFail.reverting(
this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE + 10,
this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]),
await this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]),
{ from: authorizedUser }
)
);
......@@ -111,7 +109,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
it('does not allow valid signature with correct method and data for other sender', async function () {
await shouldFail.reverting(
this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE,
this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]),
await this.signFor(authorizedUser, 'onlyWithValidSignatureAndData', [UINT_VALUE]),
{ from: anyone }
)
);
......@@ -120,7 +118,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
it('does not allow valid non-method signature for sender', async function () {
await shouldFail.reverting(
this.sigBouncer.onlyWithValidSignatureAndData(UINT_VALUE,
this.signFor(authorizedUser), { from: authorizedUser }
await this.signFor(authorizedUser), { from: authorizedUser }
)
);
});
......@@ -136,7 +134,8 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
context('signature validation', function () {
context('plain signature', function () {
it('validates valid signature for valid user', async function () {
(await this.sigBouncer.checkValidSignature(authorizedUser, this.signFor(authorizedUser))).should.equal(true);
(await this.sigBouncer.checkValidSignature(authorizedUser, await this.signFor(authorizedUser)))
.should.equal(true);
});
it('does not validate invalid signature for valid user', async function () {
......@@ -144,11 +143,12 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
});
it('does not validate valid signature for anyone', async function () {
(await this.sigBouncer.checkValidSignature(anyone, this.signFor(authorizedUser))).should.equal(false);
(await this.sigBouncer.checkValidSignature(anyone, await this.signFor(authorizedUser))).should.equal(false);
});
it('does not validate valid signature for method for valid user', async function () {
(await this.sigBouncer.checkValidSignature(authorizedUser, this.signFor(authorizedUser, 'checkValidSignature'))
(await this.sigBouncer.checkValidSignature(
authorizedUser, await this.signFor(authorizedUser, 'checkValidSignature'))
).should.equal(false);
});
});
......@@ -156,7 +156,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
context('method signature', function () {
it('validates valid signature with correct method for valid user', async function () {
(await this.sigBouncer.checkValidSignatureAndMethod(authorizedUser,
this.signFor(authorizedUser, 'checkValidSignatureAndMethod'))
await this.signFor(authorizedUser, 'checkValidSignatureAndMethod'))
).should.equal(true);
});
......@@ -166,12 +166,12 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
it('does not validate valid signature with correct method for anyone', async function () {
(await this.sigBouncer.checkValidSignatureAndMethod(anyone,
this.signFor(authorizedUser, 'checkValidSignatureAndMethod'))
await this.signFor(authorizedUser, 'checkValidSignatureAndMethod'))
).should.equal(false);
});
it('does not validate valid non-method signature with correct method for valid user', async function () {
(await this.sigBouncer.checkValidSignatureAndMethod(authorizedUser, this.signFor(authorizedUser))
(await this.sigBouncer.checkValidSignatureAndMethod(authorizedUser, await this.signFor(authorizedUser))
).should.equal(false);
});
});
......@@ -179,7 +179,7 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
context('method and data signature', function () {
it('validates valid signature with correct method and data for valid user', async function () {
(await this.sigBouncer.checkValidSignatureAndData(authorizedUser, BYTES_VALUE, UINT_VALUE,
this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
await this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
).should.equal(true);
});
......@@ -191,21 +191,21 @@ contract('SignatureBouncer', function ([_, signer, otherSigner, anyone, authoriz
it('does not validate valid signature with correct method and incorrect data for valid user',
async function () {
(await this.sigBouncer.checkValidSignatureAndData(authorizedUser, BYTES_VALUE, UINT_VALUE + 10,
this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
await this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
).should.equal(false);
}
);
it('does not validate valid signature with correct method and data for anyone', async function () {
(await this.sigBouncer.checkValidSignatureAndData(anyone, BYTES_VALUE, UINT_VALUE,
this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
await this.signFor(authorizedUser, 'checkValidSignatureAndData', [authorizedUser, BYTES_VALUE, UINT_VALUE]))
).should.equal(false);
});
it('does not validate valid non-method-data signature with correct method and data for valid user',
async function () {
(await this.sigBouncer.checkValidSignatureAndData(authorizedUser, BYTES_VALUE, UINT_VALUE,
this.signFor(authorizedUser, 'checkValidSignatureAndData'))
await this.signFor(authorizedUser, 'checkValidSignatureAndData'))
).should.equal(false);
}
);
......
const shouldFail = require('../helpers/shouldFail');
const { MIN_INT256, MAX_INT256 } = require('../helpers/constants');
const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
const { MAX_INT256, MIN_INT256 } = constants;
const SignedSafeMathMock = artifacts.require('SignedSafeMathMock');
const { BigNumber } = require('../helpers/setup');
contract('SignedSafeMath', function () {
beforeEach(async function () {
this.safeMath = await SignedSafeMathMock.new();
......@@ -12,10 +10,10 @@ contract('SignedSafeMath', function () {
describe('add', function () {
it('adds correctly if it does not overflow and the result is positve', async function () {
const a = new BigNumber(1234);
const b = new BigNumber(5678);
const a = new BN('1234');
const b = new BN('5678');
(await this.safeMath.add(a, b)).should.be.bignumber.equal(a.plus(b));
(await this.safeMath.add(a, b)).should.be.bignumber.equal(a.add(b));
});
it('adds correctly if it does not overflow and the result is negative', async function () {
......@@ -23,19 +21,19 @@ contract('SignedSafeMath', function () {
const b = MIN_INT256;
const result = await this.safeMath.add(a, b);
result.should.be.bignumber.equal(a.plus(b));
result.should.be.bignumber.equal(a.add(b));
});
it('reverts on positive addition overflow', async function () {
const a = MAX_INT256;
const b = new BigNumber(1);
const b = new BN('1');
await shouldFail.reverting(this.safeMath.add(a, b));
});
it('reverts on negative addition overflow', async function () {
const a = MIN_INT256;
const b = new BigNumber(-1);
const b = new BN('-1');
await shouldFail.reverting(this.safeMath.add(a, b));
});
......@@ -43,31 +41,31 @@ contract('SignedSafeMath', function () {
describe('sub', function () {
it('subtracts correctly if it does not overflow and the result is positive', async function () {
const a = new BigNumber(5678);
const b = new BigNumber(1234);
const a = new BN('5678');
const b = new BN('1234');
const result = await this.safeMath.sub(a, b);
result.should.be.bignumber.equal(a.minus(b));
result.should.be.bignumber.equal(a.sub(b));
});
it('subtracts correctly if it does not overflow and the result is negative', async function () {
const a = new BigNumber(1234);
const b = new BigNumber(5678);
const a = new BN('1234');
const b = new BN('5678');
const result = await this.safeMath.sub(a, b);
result.should.be.bignumber.equal(a.minus(b));
result.should.be.bignumber.equal(a.sub(b));
});
it('reverts on positive subtraction overflow', async function () {
const a = MAX_INT256;
const b = new BigNumber(-1);
const b = new BN('-1');
await shouldFail.reverting(this.safeMath.sub(a, b));
});
it('reverts on negative subtraction overflow', async function () {
const a = MIN_INT256;
const b = new BigNumber(1);
const b = new BN('1');
await shouldFail.reverting(this.safeMath.sub(a, b));
});
......@@ -75,37 +73,37 @@ contract('SignedSafeMath', function () {
describe('mul', function () {
it('multiplies correctly', async function () {
const a = new BigNumber(5678);
const b = new BigNumber(-1234);
const a = new BN('5678');
const b = new BN('-1234');
const result = await this.safeMath.mul(a, b);
result.should.be.bignumber.equal(a.times(b));
result.should.be.bignumber.equal(a.mul(b));
});
it('handles a zero product correctly', async function () {
const a = new BigNumber(0);
const b = new BigNumber(5678);
const a = new BN('0');
const b = new BN('5678');
const result = await this.safeMath.mul(a, b);
result.should.be.bignumber.equal(a.times(b));
result.should.be.bignumber.equal(a.mul(b));
});
it('reverts on multiplication overflow, positive operands', async function () {
const a = MAX_INT256;
const b = new BigNumber(2);
const b = new BN('2');
await shouldFail.reverting(this.safeMath.mul(a, b));
});
it('reverts when minimum integer is multiplied by -1', async function () {
const a = MIN_INT256;
const b = new BigNumber(-1);
const b = new BN('-1');
await shouldFail.reverting(this.safeMath.mul(a, b));
});
it('reverts when -1 is multiplied by minimum integer', async function () {
const a = new BigNumber(-1);
const a = new BN('-1');
const b = MIN_INT256;
await shouldFail.reverting(this.safeMath.mul(a, b));
......@@ -114,23 +112,23 @@ contract('SignedSafeMath', function () {
describe('div', function () {
it('divides correctly', async function () {
const a = new BigNumber(-5678);
const b = new BigNumber(5678);
const a = new BN('-5678');
const b = new BN('5678');
const result = await this.safeMath.div(a, b);
result.should.be.bignumber.equal(a.div(b));
});
it('reverts on zero division', async function () {
const a = new BigNumber(-5678);
const b = new BigNumber(0);
const a = new BN('-5678');
const b = new BN('0');
await shouldFail.reverting(this.safeMath.div(a, b));
});
it('reverts on overflow, negative second', async function () {
const a = new BigNumber(MIN_INT256);
const b = new BigNumber(-1);
const a = new BN(MIN_INT256);
const b = new BN('-1');
await shouldFail.reverting(this.safeMath.div(a, b));
});
......
const shouldFail = require('../helpers/shouldFail');
const expectEvent = require('../helpers/expectEvent');
const time = require('../helpers/time');
const { ethGetBlock } = require('../helpers/web3');
const { ZERO_ADDRESS } = require('../helpers/constants');
const { BigNumber } = require('../helpers/setup');
const { BN, constants, expectEvent, shouldFail, time } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const ERC20Mintable = artifacts.require('ERC20Mintable');
const TokenVesting = artifacts.require('TokenVesting');
contract('TokenVesting', function ([_, owner, beneficiary]) {
const amount = new BigNumber(1000);
const amount = new BN('1000');
beforeEach(async function () {
// +1 minute so it starts after contract instantiation
this.start = (await time.latest()) + time.duration.minutes(1);
this.start = (await time.latest()).add(time.duration.minutes(1));
this.cliffDuration = time.duration.years(1);
this.duration = time.duration.years(2);
});
......@@ -23,7 +18,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
const cliffDuration = this.duration;
const duration = this.cliffDuration;
cliffDuration.should.be.gt(duration);
cliffDuration.should.be.bignumber.that.is.at.least(duration);
await shouldFail.reverting(
TokenVesting.new(beneficiary, this.start, cliffDuration, duration, true, { from: owner })
......@@ -46,7 +41,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
it('reverts if the end time is in the past', async function () {
const now = await time.latest();
this.start = now - this.duration - time.duration.minutes(1);
this.start = now.sub(this.duration).sub(time.duration.minutes(1));
await shouldFail.reverting(
TokenVesting.new(beneficiary, this.start, this.cliffDuration, this.duration, true, { from: owner })
);
......@@ -63,7 +58,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
it('can get state', async function () {
(await this.vesting.beneficiary()).should.be.equal(beneficiary);
(await this.vesting.cliff()).should.be.bignumber.equal(this.start + this.cliffDuration);
(await this.vesting.cliff()).should.be.bignumber.equal(this.start.add(this.cliffDuration));
(await this.vesting.start()).should.be.bignumber.equal(this.start);
(await this.vesting.duration()).should.be.bignumber.equal(this.duration);
(await this.vesting.revocable()).should.be.equal(true);
......@@ -74,7 +69,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});
it('can be released after cliff', async function () {
await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(1));
await time.increaseTo(this.start.add(this.cliffDuration).add(time.duration.weeks(1)));
const { logs } = await this.vesting.release(this.token.address);
expectEvent.inLogs(logs, 'TokensReleased', {
token: this.token.address,
......@@ -83,34 +78,33 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});
it('should release proper amount after cliff', async function () {
await time.increaseTo(this.start + this.cliffDuration);
await time.increaseTo(this.start.add(this.cliffDuration));
const { receipt } = await this.vesting.release(this.token.address);
const block = await ethGetBlock(receipt.blockNumber);
const releaseTime = block.timestamp;
await this.vesting.release(this.token.address);
const releaseTime = await time.latest();
const releasedAmount = amount.mul(releaseTime - this.start).div(this.duration).floor();
const releasedAmount = amount.mul(releaseTime.sub(this.start)).div(this.duration);
(await this.token.balanceOf(beneficiary)).should.bignumber.equal(releasedAmount);
(await this.vesting.released(this.token.address)).should.bignumber.equal(releasedAmount);
});
it('should linearly release tokens during vesting period', async function () {
const vestingPeriod = this.duration - this.cliffDuration;
const vestingPeriod = this.duration.sub(this.cliffDuration);
const checkpoints = 4;
for (let i = 1; i <= checkpoints; i++) {
const now = this.start + this.cliffDuration + i * (vestingPeriod / checkpoints);
const now = this.start.add(this.cliffDuration).add((vestingPeriod.muln(i).divn(checkpoints)));
await time.increaseTo(now);
await this.vesting.release(this.token.address);
const expectedVesting = amount.mul(now - this.start).div(this.duration).floor();
const expectedVesting = amount.mul(now.sub(this.start)).div(this.duration);
(await this.token.balanceOf(beneficiary)).should.bignumber.equal(expectedVesting);
(await this.vesting.released(this.token.address)).should.bignumber.equal(expectedVesting);
}
});
it('should have released all after end', async function () {
await time.increaseTo(this.start + this.duration);
await time.increaseTo(this.start.add(this.duration));
await this.vesting.release(this.token.address);
(await this.token.balanceOf(beneficiary)).should.bignumber.equal(amount);
(await this.vesting.released(this.token.address)).should.bignumber.equal(amount);
......@@ -131,7 +125,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});
it('should return the non-vested tokens when revoked by owner', async function () {
await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
await time.increaseTo(this.start.add(this.cliffDuration).add(time.duration.weeks(12)));
const vested = vestedAmount(amount, await time.latest(), this.start, this.cliffDuration, this.duration);
......@@ -141,7 +135,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});
it('should keep the vested tokens when revoked by owner', async function () {
await time.increaseTo(this.start + this.cliffDuration + time.duration.weeks(12));
await time.increaseTo(this.start.add(this.cliffDuration).add(time.duration.weeks(12)));
const vestedPre = vestedAmount(amount, await time.latest(), this.start, this.cliffDuration, this.duration);
......@@ -158,7 +152,7 @@ contract('TokenVesting', function ([_, owner, beneficiary]) {
});
function vestedAmount (total, now, start, cliffDuration, duration) {
return (now < start + cliffDuration) ? 0 : Math.round(total * (now - start) / duration);
return (now.lt(start.add(cliffDuration))) ? new BN(0) : total.mul((now.sub(start))).div(duration);
}
});
});
const { ether } = require('../helpers/ether');
const shouldFail = require('../helpers/shouldFail');
const time = require('../helpers/time');
const { balanceDifference } = require('../helpers/balanceDifference');
const { should, BigNumber } = require('../helpers/setup');
const { BN, balance, ether, should, shouldFail, time } = require('openzeppelin-test-helpers');
const SampleCrowdsale = artifacts.require('SampleCrowdsale');
const SampleCrowdsaleToken = artifacts.require('SampleCrowdsaleToken');
contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
const RATE = new BigNumber(10);
const GOAL = ether(10);
const CAP = ether(20);
const RATE = new BN(10);
const GOAL = ether('10');
const CAP = ether('20');
before(async function () {
// Advance to the next block to correctly read time in the solidity "now" function interpreted by ganache
......@@ -19,9 +14,9 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
});
beforeEach(async function () {
this.openingTime = (await time.latest()) + time.duration.weeks(1);
this.closingTime = this.openingTime + time.duration.weeks(1);
this.afterClosingTime = this.closingTime + time.duration.seconds(1);
this.openingTime = (await time.latest()).add(time.duration.weeks(1));
this.closingTime = this.openingTime.add(time.duration.weeks(1));
this.afterClosingTime = this.closingTime.add(time.duration.seconds(1));
this.token = await SampleCrowdsaleToken.new({ from: deployer });
this.crowdsale = await SampleCrowdsale.new(
......@@ -46,12 +41,12 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
});
it('should not accept payments before start', async function () {
await shouldFail.reverting(this.crowdsale.send(ether(1)));
await shouldFail.reverting(this.crowdsale.buyTokens(investor, { from: investor, value: ether(1) }));
await shouldFail.reverting(this.crowdsale.send(ether('1')));
await shouldFail.reverting(this.crowdsale.buyTokens(investor, { from: investor, value: ether('1') }));
});
it('should accept payments during the sale', async function () {
const investmentAmount = ether(1);
const investmentAmount = ether('1');
const expectedTokenAmount = RATE.mul(investmentAmount);
await time.increaseTo(this.openingTime);
......@@ -63,8 +58,8 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
it('should reject payments after end', async function () {
await time.increaseTo(this.afterClosingTime);
await shouldFail.reverting(this.crowdsale.send(ether(1)));
await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: ether(1), from: investor }));
await shouldFail.reverting(this.crowdsale.send(ether('1')));
await shouldFail.reverting(this.crowdsale.buyTokens(investor, { value: ether('1'), from: investor }));
});
it('should reject payments over cap', async function () {
......@@ -77,26 +72,26 @@ contract('SampleCrowdsale', function ([_, deployer, owner, wallet, investor]) {
await time.increaseTo(this.openingTime);
await this.crowdsale.send(GOAL);
(await balanceDifference(wallet, async () => {
(await balance.difference(wallet, async () => {
await time.increaseTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: owner });
})).should.be.bignumber.equal(GOAL);
});
it('should allow refunds if the goal is not reached', async function () {
(await balanceDifference(investor, async () => {
(await balance.difference(investor, async () => {
await time.increaseTo(this.openingTime);
await this.crowdsale.sendTransaction({ value: ether(1), from: investor, gasPrice: 0 });
await this.crowdsale.sendTransaction({ value: ether('1'), from: investor, gasPrice: 0 });
await time.increaseTo(this.afterClosingTime);
await this.crowdsale.finalize({ from: owner });
await this.crowdsale.claimRefund(investor, { gasPrice: 0 });
})).should.be.bignumber.equal(0);
})).should.be.bignumber.equal('0');
});
describe('when goal > cap', function () {
// goal > cap
const HIGH_GOAL = ether(30);
const HIGH_GOAL = ether('30');
it('creation reverts', async function () {
await shouldFail.reverting(SampleCrowdsale.new(
......
const expectEvent = require('../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../helpers/constants');
const SimpleToken = artifacts.require('SimpleToken');
const { constants, expectEvent } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
require('../helpers/setup');
const SimpleToken = artifacts.require('SimpleToken');
contract('SimpleToken', function ([_, creator]) {
beforeEach(async function () {
......@@ -18,7 +17,7 @@ contract('SimpleToken', function ([_, creator]) {
});
it('has 18 decimals', async function () {
(await this.token.decimals()).should.be.bignumber.equal(18);
(await this.token.decimals()).should.be.bignumber.equal('18');
});
it('assigns the initial total supply to the creator', async function () {
......
const { ethGetBalance } = require('./web3');
async function balanceDifference (account, promiseFunc) {
const balanceBefore = await ethGetBalance(account);
await promiseFunc();
const balanceAfter = await ethGetBalance(account);
return balanceAfter.minus(balanceBefore);
}
module.exports = {
balanceDifference,
};
const BigNumber = web3.BigNumber;
module.exports = {
ZERO_ADDRESS: '0x0000000000000000000000000000000000000000',
MAX_UINT256: new BigNumber(2).pow(256).minus(1),
MAX_INT256: new BigNumber(2).pow(255).minus(1),
MIN_INT256: new BigNumber(2).pow(255).times(-1),
};
function ether (n) {
return new web3.BigNumber(web3.toWei(n, 'ether'));
}
module.exports = {
ether,
};
const { should, BigNumber } = require('./setup');
const SolidityEvent = require('web3/lib/web3/event.js');
const { ethGetTransactionReceipt } = require('./web3');
function inLogs (logs, eventName, eventArgs = {}) {
const event = logs.find(function (e) {
if (e.event === eventName) {
for (const [k, v] of Object.entries(eventArgs)) {
contains(e.args, k, v);
}
return true;
}
});
should.exist(event);
return event;
}
async function inConstruction (contract, eventName, eventArgs = {}) {
return inTransaction(contract.transactionHash, contract.constructor, eventName, eventArgs);
}
async function inTransaction (txHash, emitter, eventName, eventArgs = {}) {
const receipt = await ethGetTransactionReceipt(txHash);
const logs = decodeLogs(receipt.logs, emitter.events);
return inLogs(logs, eventName, eventArgs);
}
function contains (args, key, value) {
if (isBigNumber(args[key])) {
args[key].should.be.bignumber.equal(value);
} else {
args[key].should.be.equal(value);
}
}
function isBigNumber (object) {
return object.isBigNumber ||
object instanceof BigNumber ||
(object.constructor && object.constructor.name === 'BigNumber');
}
function decodeLogs (logs, events) {
return Array.prototype.concat(...logs.map(log =>
log.topics.filter(topic => topic in events).map(topic => {
const event = new SolidityEvent(null, events[topic], 0);
return event.decode(log);
})
));
}
module.exports = {
inLogs,
inConstruction,
inTransaction,
};
const { soliditySha3 } = require('web3-utils');
const INTERFACE_ID_LENGTH = 4;
function makeInterfaceId (interfaces = []) {
const interfaceIdBuffer = interfaces
.map(methodSignature => soliditySha3(methodSignature)) // keccak256
.map(h =>
Buffer
.from(h.substring(2), 'hex')
.slice(0, 4) // bytes4()
)
.reduce((memo, bytes) => {
for (let i = 0; i < INTERFACE_ID_LENGTH; i++) {
memo[i] = memo[i] ^ bytes[i]; // xor
}
return memo;
}, Buffer.alloc(INTERFACE_ID_LENGTH));
return `0x${interfaceIdBuffer.toString('hex')}`;
}
module.exports = {
makeInterfaceId,
};
const ethjsABI = require('ethjs-abi');
const { ethSendTransaction } = require('./web3');
function findMethod (abi, name, args) {
for (let i = 0; i < abi.length; i++) {
const methodArgs = abi[i].inputs.map(input => input.type).join(',');
if ((abi[i].name === name) && (methodArgs === args)) {
return abi[i];
}
}
}
async function transaction (target, name, argsTypes, argsValues, opts) {
const abiMethod = findMethod(target.abi, name, argsTypes);
const encodedData = ethjsABI.encodeMethod(abiMethod, argsValues);
return target.sendTransaction(Object.assign({ data: encodedData }, opts));
}
function ether (from, to, value) {
return ethSendTransaction({ from, to, value, gasPrice: 0 });
}
module.exports = {
ether,
transaction,
};
const chai = require('chai');
const BigNumber = web3.BigNumber;
const should = chai.use(require('chai-bignumber')(BigNumber)).should();
module.exports = {
BigNumber,
should,
};
const { should } = require('./setup');
async function shouldFailWithMessage (promise, message) {
try {
await promise;
} catch (error) {
if (message) {
error.message.should.include(message, `Wrong failure type, expected '${message}'`);
}
return;
}
should.fail('Expected failure not received');
}
async function reverting (promise) {
await shouldFailWithMessage(promise, 'revert');
}
async function throwing (promise) {
await shouldFailWithMessage(promise, 'invalid opcode');
}
async function outOfGas (promise) {
await shouldFailWithMessage(promise, 'out of gas');
}
async function shouldFail (promise) {
await shouldFailWithMessage(promise);
}
shouldFail.reverting = reverting;
shouldFail.throwing = throwing;
shouldFail.outOfGas = outOfGas;
module.exports = shouldFail;
const { sha3, soliditySha3 } = require('web3-utils');
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.padLeft('', REAL_SIGNATURE_SIZE)}`;
const DUMMY_SIGNATURE = `0x${web3.utils.padLeft('', REAL_SIGNATURE_SIZE)}`;
// messageHex = '0xdeadbeef'
function toEthSignedMessageHash (messageHex) {
const messageBuffer = Buffer.from(messageHex.substring(2), 'hex');
const prefix = Buffer.from(`\u0019Ethereum Signed Message:\n${messageBuffer.length}`);
return sha3(Buffer.concat([prefix, messageBuffer]));
return web3.utils.sha3(Buffer.concat([prefix, messageBuffer]));
}
// signs message in node (ganache auto-applies "Ethereum Signed Message" prefix)
// messageHex = '0xdeadbeef'
const signMessage = (signer, messageHex = '0x') => {
return web3.eth.sign(signer, messageHex); // actually personal_sign
};
// @TODO - remove this when we migrate to web3-1.0.0
const transformToFullName = function (json) {
if (json.name.indexOf('(') !== -1) {
return json.name;
}
const typeName = json.inputs.map(function (i) { return i.type; }).join();
return json.name + '(' + typeName + ')';
return web3.eth.sign(messageHex, signer);
};
/**
* Create a signer between a contract and a signer for a voucher of method, args, and redeemer
* Note that `method` is the web3 method, not the truffle-contract method
* Well truffle is terrible, but luckily (?) so is web3 < 1.0, so we get to make our own method id
* fetcher because the method on the contract isn't actually the SolidityFunction object ಠ_ಠ
* @param contract TruffleContract
* @param signer address
* @param redeemer address
......@@ -49,21 +33,17 @@ const getSignFor = (contract, signer) => (redeemer, methodName, methodArgs = [])
if (methodName) {
if (methodArgs.length > 0) {
parts.push(
contract.contract[methodName].getData(...methodArgs.concat([DUMMY_SIGNATURE])).slice(
0,
-1 * PADDED_SIGNATURE_SIZE
)
contract.contract.methods[methodName](...methodArgs.concat([DUMMY_SIGNATURE])).encodeABI()
.slice(0, -1 * PADDED_SIGNATURE_SIZE)
);
} else {
const abi = contract.abi.find(abi => abi.name === methodName);
const name = transformToFullName(abi);
const signature = sha3(name).slice(0, 10);
parts.push(signature);
parts.push(abi.signature);
}
}
// return the signature of the "Ethereum Signed Message" hash of the hash of `parts`
const messageHex = soliditySha3(...parts);
const messageHex = web3.utils.soliditySha3(...parts);
return signMessage(signer, messageHex);
};
......
const { balanceDifference } = require('../balanceDifference');
const send = require('../send');
const { ether } = require('../ether');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
contract('balanceDifference', function ([sender, receiver]) {
it('returns balance increments', async function () {
(await balanceDifference(receiver, () =>
send.ether(sender, receiver, ether(1)))
).should.be.bignumber.equal(ether(1));
});
it('returns balance decrements', async function () {
(await balanceDifference(sender, () =>
send.ether(sender, receiver, ether(1)))
).should.be.bignumber.equal(ether(-1));
});
});
const { ether } = require('../ether');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
describe('ether', function () {
it('returns a BigNumber', function () {
ether(1, 'ether').should.be.bignumber.equal(new BigNumber(1000000000000000000));
});
it('works with negative amounts', function () {
ether(-1, 'ether').should.be.bignumber.equal(new BigNumber(-1000000000000000000));
});
});
const expectEvent = require('../expectEvent');
const shouldFail = require('../shouldFail');
const EventEmitter = artifacts.require('EventEmitter');
const IndirectEventEmitter = artifacts.require('IndirectEventEmitter');
const { should, BigNumber } = require('../../helpers/setup');
describe('expectEvent', function () {
beforeEach(async function () {
this.constructionValues = {
uint: 42,
boolean: true,
string: 'OpenZeppelin',
};
this.emitter = await EventEmitter.new(
this.constructionValues.uint,
this.constructionValues.boolean,
this.constructionValues.string
);
});
describe('inConstructor', function () {
context('short uint value', function () {
it('accepts emitted events with correct number', async function () {
await expectEvent.inConstruction(this.emitter, 'ShortUint',
{ value: this.constructionValues.uint }
);
});
it('throws if an incorrect value is passed', async function () {
await shouldFail(expectEvent.inConstruction(this.emitter, 'ShortUint', { value: 23 }));
});
});
context('boolean value', function () {
it('accepts emitted events with correct value', async function () {
await expectEvent.inConstruction(this.emitter, 'Boolean', { value: this.constructionValues.boolean });
});
it('throws if an incorrect value is passed', async function () {
await shouldFail(expectEvent.inConstruction(this.emitter, 'Boolean',
{ value: !this.constructionValues.boolean }
));
});
});
context('string value', function () {
it('accepts emitted events with correct string', async function () {
await expectEvent.inConstruction(this.emitter, 'String', { value: this.constructionValues.string });
});
it('throws if an incorrect string is passed', async function () {
await shouldFail(expectEvent.inConstruction(this.emitter, 'String', { value: 'ClosedZeppelin' }));
});
});
it('throws if an unemitted event is requested', async function () {
await shouldFail(expectEvent.inConstruction(this.emitter, 'UnemittedEvent'));
});
});
describe('inLogs', function () {
describe('with no arguments', function () {
beforeEach(async function () {
({ logs: this.logs } = await this.emitter.emitArgumentless());
});
it('accepts emitted events', function () {
expectEvent.inLogs(this.logs, 'Argumentless');
});
it('throws if an unemitted event is requested', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent'));
});
});
describe('with single argument', function () {
context('short uint value', function () {
beforeEach(async function () {
this.value = 42;
({ logs: this.logs } = await this.emitter.emitShortUint(this.value));
});
it('accepts emitted events with correct JavaScript number', function () {
expectEvent.inLogs(this.logs, 'ShortUint', { value: this.value });
});
it('accepts emitted events with correct BigNumber', function () {
expectEvent.inLogs(this.logs, 'ShortUint', { value: new BigNumber(this.value) });
});
it('throws if an unemitted event is requested', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value }));
});
it('throws if an incorrect value is passed', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'ShortUint', { value: 23 }));
});
});
context('short int value', function () {
beforeEach(async function () {
this.value = -42;
({ logs: this.logs } = await this.emitter.emitShortInt(this.value));
});
it('accepts emitted events with correct JavaScript number', function () {
expectEvent.inLogs(this.logs, 'ShortInt', { value: this.value });
});
it('accepts emitted events with correct BigNumber', function () {
expectEvent.inLogs(this.logs, 'ShortInt', { value: new BigNumber(this.value) });
});
it('throws if an unemitted event is requested', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value }));
});
it('throws if an incorrect value is passed', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'ShortInt', { value: -23 }));
});
});
context('long uint value', function () {
beforeEach(async function () {
this.bigNumValue = new BigNumber('123456789012345678901234567890');
({ logs: this.logs } = await this.emitter.emitLongUint(this.bigNumValue));
});
it('accepts emitted events with correct BigNumber', function () {
expectEvent.inLogs(this.logs, 'LongUint', { value: this.bigNumValue });
});
it('throws if an unemitted event is requested', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.bigNumValue }));
});
it('throws if an incorrect value is passed', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'LongUint', { value: 2300 }));
});
});
context('long int value', function () {
beforeEach(async function () {
this.bigNumValue = new BigNumber('-123456789012345678901234567890');
({ logs: this.logs } = await this.emitter.emitLongInt(this.bigNumValue));
});
it('accepts emitted events with correct BigNumber', function () {
expectEvent.inLogs(this.logs, 'LongInt', { value: this.bigNumValue });
});
it('throws if an unemitted event is requested', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.bigNumValue }));
});
it('throws if an incorrect value is passed', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'LongInt', { value: -2300 }));
});
});
context('address value', function () {
beforeEach(async function () {
this.value = '0x811412068e9fbf25dc300a29e5e316f7122b282c';
({ logs: this.logs } = await this.emitter.emitAddress(this.value));
});
it('accepts emitted events with correct address', function () {
expectEvent.inLogs(this.logs, 'Address', { value: this.value });
});
it('throws if an unemitted event is requested', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value }));
});
it('throws if an incorrect value is passed', function () {
should.Throw(() =>
expectEvent.inLogs(this.logs, 'Address', { value: '0x21d04e022e0b52b5d5bcf90b7f1aabf406be002d' })
);
});
});
context('boolean value', function () {
beforeEach(async function () {
this.value = true;
({ logs: this.logs } = await this.emitter.emitBoolean(this.value));
});
it('accepts emitted events with correct address', function () {
expectEvent.inLogs(this.logs, 'Boolean', { value: this.value });
});
it('throws if an unemitted event is requested', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value }));
});
it('throws if an incorrect value is passed', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'Boolean', { value: false }));
});
});
context('string value', function () {
beforeEach(async function () {
this.value = 'OpenZeppelin';
({ logs: this.logs } = await this.emitter.emitString(this.value));
});
it('accepts emitted events with correct string', function () {
expectEvent.inLogs(this.logs, 'String', { value: this.value });
});
it('throws if an unemitted event is requested', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.value }));
});
it('throws if an incorrect value is passed', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'String', { value: 'ClosedZeppelin' }));
});
});
});
describe('with multiple arguments', function () {
beforeEach(async function () {
this.uintValue = new BigNumber('123456789012345678901234567890');
this.booleanValue = true;
this.stringValue = 'OpenZeppelin';
({ logs: this.logs } =
await this.emitter.emitLongUintBooleanString(this.uintValue, this.booleanValue, this.stringValue));
});
it('accepts correct values', function () {
expectEvent.inLogs(this.logs, 'LongUintBooleanString', {
uintValue: this.uintValue, booleanValue: this.booleanValue, stringValue: this.stringValue,
});
});
it('throws with correct values assigned to wrong arguments', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', {
uintValue: this.booleanValue, booleanValue: this.uintValue, stringValue: this.stringValue,
}));
});
it('throws when any of the values is incorrect', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', {
uintValue: 23, booleanValue: this.booleanValue, stringValue: this.stringValue,
}));
should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', {
uintValue: this.uintValue, booleanValue: false, stringValue: this.stringValue,
}));
should.Throw(() => expectEvent.inLogs(this.logs, 'LongUintBooleanString', {
uintValue: this.uintValue, booleanValue: this.booleanValue, stringValue: 'ClosedZeppelin',
}));
});
});
describe('with multiple events', function () {
beforeEach(async function () {
this.uintValue = 42;
this.booleanValue = true;
({ logs: this.logs } = await this.emitter.emitLongUintAndBoolean(this.uintValue, this.booleanValue));
});
it('accepts all emitted events with correct values', function () {
expectEvent.inLogs(this.logs, 'LongUint', { value: this.uintValue });
expectEvent.inLogs(this.logs, 'Boolean', { value: this.booleanValue });
});
it('throws if an unemitted event is requested', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'UnemittedEvent', { value: this.uintValue }));
});
it('throws if incorrect values are passed', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'LongUint', { value: 23 }));
should.Throw(() => expectEvent.inLogs(this.logs, 'Boolean', { value: false }));
});
});
describe('with events emitted by an indirectly called contract', function () {
beforeEach(async function () {
this.secondEmitter = await IndirectEventEmitter.new();
this.value = 'OpenZeppelin';
({ logs: this.logs } = await this.emitter.emitStringAndEmitIndirectly(this.value, this.secondEmitter.address));
});
it('accepts events emitted by the directly called contract', function () {
expectEvent.inLogs(this.logs, 'String', { value: this.value });
});
it('throws when passing events emitted by the indirectly called contract', function () {
should.Throw(() => expectEvent.inLogs(this.logs, 'IndirectString', { value: this.value }));
});
});
});
describe('inTransaction', function () {
describe('when emitting from called contract and indirect calls', function () {
context('string value', function () {
beforeEach(async function () {
this.secondEmitter = await IndirectEventEmitter.new();
this.value = 'OpenZeppelin';
const receipt = await this.emitter.emitStringAndEmitIndirectly(this.value, this.secondEmitter.address);
this.txHash = receipt.tx;
});
context('with directly called contract', function () {
it('accepts emitted events with correct string', async function () {
await expectEvent.inTransaction(this.txHash, EventEmitter, 'String', { value: this.value });
});
it('throws if an unemitted event is requested', async function () {
await shouldFail(expectEvent.inTransaction(this.txHash, EventEmitter, 'UnemittedEvent',
{ value: this.value }
));
});
it('throws if an incorrect string is passed', async function () {
await shouldFail(expectEvent.inTransaction(this.txHash, EventEmitter, 'String',
{ value: 'ClosedZeppelin' }
));
});
it('throws if an event emitted from other contract is passed', async function () {
await shouldFail(expectEvent.inTransaction(this.txHash, EventEmitter, 'IndirectString',
{ value: this.value }
));
});
it('throws if an incorrect emitter is passed', async function () {
await shouldFail(expectEvent.inTransaction(this.txHash, IndirectEventEmitter, 'String',
{ value: this.value }
));
});
});
context('with indirectly called contract', function () {
it('accepts events emitted from other contracts', async function () {
await expectEvent.inTransaction(this.txHash, IndirectEventEmitter, 'IndirectString',
{ value: this.value }
);
});
it('throws if an unemitted event is requested', async function () {
await shouldFail(expectEvent.inTransaction(this.txHash, IndirectEventEmitter, 'UnemittedEvent',
{ value: this.value }
));
});
it('throws if an incorrect string is passed', async function () {
await shouldFail(expectEvent.inTransaction(this.txHash, IndirectEventEmitter, 'IndirectString',
{ value: 'ClosedZeppelin' }
));
});
it('throws if an event emitted from other contract is passed', async function () {
await shouldFail(expectEvent.inTransaction(this.txHash, IndirectEventEmitter, 'String',
{ value: this.value }
));
});
it('throws if an incorrect emitter is passed', async function () {
await shouldFail(expectEvent.inTransaction(this.txHash, EventEmitter, 'IndirectString',
{ value: this.value }
));
});
});
});
});
});
});
const { makeInterfaceId } = require('../makeInterfaceId');
const OwnableInterfaceId = artifacts.require('OwnableInterfaceId');
require('chai')
.should();
describe('makeInterfaceId', function () {
it('calculates the EIP165 interface id from function signatures', async function () {
const calculator = await OwnableInterfaceId.new();
const ownableId = await calculator.getInterfaceId();
makeInterfaceId([
'owner()',
'isOwner()',
'renounceOwnership()',
'transferOwnership(address)',
]).should.equal(ownableId);
});
});
const send = require('../send');
const shouldFail = require('../shouldFail');
const expectEvent = require('../expectEvent');
const { ether } = require('../ether');
const { ethGetBalance } = require('../web3');
const Acknowledger = artifacts.require('Acknowledger');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
contract('send', function ([sender, receiver]) {
describe('ether', function () {
it('sends ether with no gas cost', async function () {
const value = ether(1);
const initialSenderBalance = await ethGetBalance(sender);
const initialReceiverBalance = await ethGetBalance(receiver);
await send.ether(sender, receiver, value);
const finalSenderBalance = await ethGetBalance(sender);
const finalReceiverBalance = await ethGetBalance(receiver);
finalSenderBalance.sub(initialSenderBalance).should.be.bignumber.equal(-value);
finalReceiverBalance.sub(initialReceiverBalance).should.be.bignumber.equal(value);
});
it('throws if the sender balance is insufficient', async function () {
const value = (await ethGetBalance(sender)).plus(1);
await shouldFail(send.ether(sender, receiver, value));
});
});
describe('transaction', function () {
beforeEach(async function () {
this.acknowledger = await Acknowledger.new();
});
it('calls a function from its signature ', async function () {
const { logs } = await send.transaction(this.acknowledger, 'foo', 'uint256', [3]);
expectEvent.inLogs(logs, 'AcknowledgeFoo', { a: 3 });
});
it('calls overloaded functions with less arguments', async function () {
const { logs } = await send.transaction(this.acknowledger, 'bar', 'uint256', [3]);
expectEvent.inLogs(logs, 'AcknowledgeBarSingle', { a: 3 });
});
it('calls overloaded functions with more arguments', async function () {
const { logs } = await send.transaction(this.acknowledger, 'bar', 'uint256,uint256', [3, 5]);
expectEvent.inLogs(logs, 'AcknowledgeBarDouble', { a: 3, b: 5 });
});
it('throws if the number of arguments does not match', async function () {
await shouldFail(send.transaction(this.acknowledger, 'foo', 'uint256, uint256', [3, 5]));
});
it('throws if the method does not exist', async function () {
await shouldFail(send.transaction(this.acknowledger, 'baz', 'uint256', [3]));
});
it('throws if there is a mismatch in the number of types and values', async function () {
await shouldFail(send.transaction(this.acknowledger, 'foo', 'uint256', [3, 3]));
});
});
});
const shouldFail = require('../shouldFail');
const BigNumber = web3.BigNumber;
const should = require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
const Failer = artifacts.require('Failer');
async function assertFailure (promise) {
try {
await promise;
} catch (error) {
return;
}
should.fail();
}
describe('shouldFail', function () {
beforeEach(async function () {
this.failer = await Failer.new();
});
describe('shouldFail', function () {
it('rejects if no failure occurs', async function () {
await assertFailure(shouldFail(this.failer.dontFail()));
});
it('accepts a revert', async function () {
await shouldFail(this.failer.failWithRevert());
});
it('accepts a throw', async function () {
await shouldFail(this.failer.failWithThrow());
});
it('accepts an out of gas', async function () {
await shouldFail(this.failer.failWithOutOfGas({ gas: 2000000 }));
});
});
describe('reverting', function () {
it('rejects if no failure occurs', async function () {
await assertFailure(shouldFail.reverting(this.failer.dontFail()));
});
it('accepts a revert', async function () {
await shouldFail.reverting(this.failer.failWithRevert());
});
it('rejects a throw', async function () {
await assertFailure(shouldFail.reverting(this.failer.failWithThrow()));
});
it('rejects an outOfGas', async function () {
await assertFailure(shouldFail.reverting(this.failer.failWithOutOfGas({ gas: 2000000 })));
});
});
describe('throwing', function () {
it('rejects if no failure occurs', async function () {
await assertFailure(shouldFail.throwing(this.failer.dontFail()));
});
it('accepts a throw', async function () {
await shouldFail.throwing(this.failer.failWithThrow());
});
it('rejects a throw', async function () {
await assertFailure(shouldFail.throwing(this.failer.failWithRevert()));
});
it('rejects an outOfGas', async function () {
await assertFailure(shouldFail.throwing(this.failer.failWithOutOfGas({ gas: 2000000 })));
});
});
describe('outOfGas', function () {
it('rejects if no failure occurs', async function () {
await assertFailure(shouldFail.outOfGas(this.failer.dontFail()));
});
it('accepts an out of gas', async function () {
await shouldFail.outOfGas(this.failer.failWithOutOfGas({ gas: 2000000 }));
});
it('rejects a revert', async function () {
await assertFailure(shouldFail.outOfGas(this.failer.failWithRevert()));
});
it('rejects a throw', async function () {
await assertFailure(shouldFail.outOfGas(this.failer.failWithThrow()));
});
});
});
const time = require('../time');
const shouldFail = require('../shouldFail');
const BigNumber = web3.BigNumber;
require('chai')
.use(require('chai-bignumber')(BigNumber))
.should();
describe('time', function () {
const TOLERANCE_SECONDS = 1;
describe('duration', function () {
it('converts seconds to seconds', function () {
time.duration.seconds(1).should.equal(1);
});
it('converts minutes to seconds', function () {
time.duration.minutes(1).should.equal(60);
});
it('converts hours to seconds', function () {
time.duration.hours(1).should.equal(60 * 60);
});
it('converts days to seconds', function () {
time.duration.days(1).should.equal(60 * 60 * 24);
});
it('converts weeks to seconds', function () {
time.duration.weeks(1).should.equal(60 * 60 * 24 * 7);
});
it('converts years to seconds', function () {
time.duration.years(1).should.equal(60 * 60 * 24 * 365);
});
});
describe('advanceBlock', function () {
it('increases the block number by one', async function () {
const startingBlock = web3.eth.blockNumber;
await time.advanceBlock();
web3.eth.blockNumber.should.be.bignumber.equal(startingBlock + 1);
});
});
context('with starting time', function () {
beforeEach(async function () {
await time.advanceBlock();
this.start = await time.latest();
});
describe('increase', function () {
it('increases time by a duration', async function () {
await time.increase(time.duration.hours(1));
const end = this.start + time.duration.hours(1);
(await time.latest()).should.be.closeTo(end, TOLERANCE_SECONDS);
});
it('throws with negative durations', async function () {
await shouldFail(time.increase(-1));
});
});
describe('increaseTo', function () {
it('increases time to a time in the future', async function () {
const end = this.start + time.duration.hours(1);
await time.increaseTo(end);
(await time.latest()).should.be.closeTo(end, TOLERANCE_SECONDS);
});
it('throws with a time in the past', async function () {
await shouldFail(time.increaseTo(this.start - 30));
});
});
});
});
const { ethGetBlock } = require('./web3');
const pify = require('pify');
function advanceBlock () {
return pify(web3.currentProvider.sendAsync)({
jsonrpc: '2.0',
method: 'evm_mine',
});
}
// Returns the time of the last mined block in seconds
async function latest () {
const block = await ethGetBlock('latest');
return block.timestamp;
}
// Increases ganache time by the passed duration in seconds
async function increase (duration) {
if (duration < 0) throw Error(`Cannot increase time by a negative amount (${duration})`);
await pify(web3.currentProvider.sendAsync)({
jsonrpc: '2.0',
method: 'evm_increaseTime',
params: [duration],
});
await advanceBlock();
}
/**
* Beware that due to the need of calling two separate ganache methods and rpc calls overhead
* it's hard to increase time precisely to a target point so design your test to tolerate
* small fluctuations from time to time.
*
* @param target time in seconds
*/
async function increaseTo (target) {
const now = (await latest());
if (target < now) throw Error(`Cannot increase current time (${now}) to a moment in the past (${target})`);
const diff = target - now;
return increase(diff);
}
const duration = {
seconds: function (val) { return val; },
minutes: function (val) { return val * this.seconds(60); },
hours: function (val) { return val * this.minutes(60); },
days: function (val) { return val * this.hours(24); },
weeks: function (val) { return val * this.days(7); },
years: function (val) { return val * this.days(365); },
};
module.exports = {
advanceBlock,
latest,
increase,
increaseTo,
duration,
};
const pify = require('pify');
const ethAsync = pify(web3.eth);
module.exports = {
ethGetBalance: ethAsync.getBalance,
ethGetBlock: ethAsync.getBlock,
ethGetTransactionReceipt: ethAsync.getTransactionReceipt,
ethSendTransaction: ethAsync.sendTransaction,
};
const { shouldFail } = require('openzeppelin-test-helpers');
const { shouldSupportInterfaces } = require('./SupportsInterface.behavior');
const shouldFail = require('../helpers/shouldFail');
const ERC165Mock = artifacts.require('ERC165Mock');
require('chai')
.should();
contract('ERC165', function () {
beforeEach(async function () {
this.mock = await ERC165Mock.new();
});
it('does not allow 0xffffffff', async function () {
await shouldFail.reverting(
this.mock.registerInterface(0xffffffff)
);
await shouldFail.reverting(this.mock.registerInterface('0xffffffff'));
});
shouldSupportInterfaces([
......
require('openzeppelin-test-helpers');
const ERC165CheckerMock = artifacts.require('ERC165CheckerMock');
const ERC165NotSupported = artifacts.require('ERC165NotSupported');
const ERC165InterfacesSupported = artifacts.require('ERC165InterfacesSupported');
......@@ -9,8 +11,6 @@ const DUMMY_UNSUPPORTED_ID = '0xbaddcafe';
const DUMMY_UNSUPPORTED_ID_2 = '0xbaadcafe';
const DUMMY_ACCOUNT = '0x1111111111111111111111111111111111111111';
require('../helpers/setup');
contract('ERC165Checker', function () {
beforeEach(async function () {
this.mock = await ERC165CheckerMock.new();
......
const { makeInterfaceId } = require('../helpers/makeInterfaceId');
const { makeInterfaceId } = require('openzeppelin-test-helpers');
const INTERFACE_IDS = {
ERC165: makeInterfaceId([
......
const shouldFail = require('../helpers/shouldFail');
const expectEvent = require('../helpers/expectEvent');
const PausableMock = artifacts.require('PausableMock');
const { expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { shouldBehaveLikePublicRole } = require('../access/roles/PublicRole.behavior');
require('../helpers/setup');
const PausableMock = artifacts.require('PausableMock');
contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts]) {
beforeEach(async function () {
......@@ -26,10 +23,10 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts
});
it('can perform normal process in non-pause', async function () {
(await this.pausable.count()).should.be.bignumber.equal(0);
(await this.pausable.count()).should.be.bignumber.equal('0');
await this.pausable.normalProcess({ from: anyone });
(await this.pausable.count()).should.be.bignumber.equal(1);
(await this.pausable.count()).should.be.bignumber.equal('1');
});
it('cannot take drastic measure in non-pause', async function () {
......@@ -89,9 +86,9 @@ contract('Pausable', function ([_, pauser, otherPauser, anyone, ...otherAccounts
});
it('should resume allowing normal process', async function () {
(await this.pausable.count()).should.be.bignumber.equal(0);
(await this.pausable.count()).should.be.bignumber.equal('0');
await this.pausable.normalProcess({ from: anyone });
(await this.pausable.count()).should.be.bignumber.equal(1);
(await this.pausable.count()).should.be.bignumber.equal('1');
});
it('should prevent drastic measure', async function () {
......
const MathMock = artifacts.require('MathMock');
const { BN } = require('openzeppelin-test-helpers');
const { BigNumber } = require('../helpers/setup');
const MathMock = artifacts.require('MathMock');
contract('Math', function () {
const min = 1234;
const max = 5678;
const min = new BN('1234');
const max = new BN('5678');
beforeEach(async function () {
this.math = await MathMock.new();
......@@ -32,24 +32,24 @@ contract('Math', function () {
describe('average', function () {
function bnAverage (a, b) {
return a.plus(b).div(2).truncated();
return a.add(b).divn(2);
}
it('is correctly calculated with two odd numbers', async function () {
const a = new BigNumber(57417);
const b = new BigNumber(95431);
const a = new BN('57417');
const b = new BN('95431');
(await this.math.average(a, b)).should.be.bignumber.equal(bnAverage(a, b));
});
it('is correctly calculated with two even numbers', async function () {
const a = new BigNumber(42304);
const b = new BigNumber(84346);
const a = new BN('42304');
const b = new BN('84346');
(await this.math.average(a, b)).should.be.bignumber.equal(bnAverage(a, b));
});
it('is correctly calculated with one even and one odd number', async function () {
const a = new BigNumber(57417);
const b = new BigNumber(84346);
const a = new BN('57417');
const b = new BN('84346');
(await this.math.average(a, b)).should.be.bignumber.equal(bnAverage(a, b));
});
});
......
const shouldFail = require('../helpers/shouldFail');
const { MAX_UINT256 } = require('../helpers/constants');
const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
const { MAX_UINT256 } = constants;
const SafeMathMock = artifacts.require('SafeMathMock');
const { BigNumber } = require('../helpers/setup');
contract('SafeMath', function () {
beforeEach(async function () {
this.safeMath = await SafeMathMock.new();
......@@ -12,15 +10,15 @@ contract('SafeMath', function () {
describe('add', function () {
it('adds correctly', async function () {
const a = new BigNumber(5678);
const b = new BigNumber(1234);
const a = new BN('5678');
const b = new BN('1234');
(await this.safeMath.add(a, b)).should.be.bignumber.equal(a.plus(b));
(await this.safeMath.add(a, b)).should.be.bignumber.equal(a.add(b));
});
it('reverts on addition overflow', async function () {
const a = MAX_UINT256;
const b = new BigNumber(1);
const b = new BN('1');
await shouldFail.reverting(this.safeMath.add(a, b));
});
......@@ -28,15 +26,15 @@ contract('SafeMath', function () {
describe('sub', function () {
it('subtracts correctly', async function () {
const a = new BigNumber(5678);
const b = new BigNumber(1234);
const a = new BN('5678');
const b = new BN('1234');
(await this.safeMath.sub(a, b)).should.be.bignumber.equal(a.minus(b));
(await this.safeMath.sub(a, b)).should.be.bignumber.equal(a.sub(b));
});
it('reverts if subtraction result would be negative', async function () {
const a = new BigNumber(1234);
const b = new BigNumber(5678);
const a = new BN('1234');
const b = new BN('5678');
await shouldFail.reverting(this.safeMath.sub(a, b));
});
......@@ -44,29 +42,29 @@ contract('SafeMath', function () {
describe('mul', function () {
it('multiplies correctly', async function () {
const a = new BigNumber(1234);
const b = new BigNumber(5678);
const a = new BN('1234');
const b = new BN('5678');
(await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.times(b));
(await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.mul(b));
});
it('handles a zero product correctly (first number as zero)', async function () {
const a = new BigNumber(0);
const b = new BigNumber(5678);
const a = new BN('0');
const b = new BN('5678');
(await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.times(b));
(await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.mul(b));
});
it('handles a zero product correctly (second number as zero)', async function () {
const a = new BigNumber(5678);
const b = new BigNumber(0);
const a = new BN('5678');
const b = new BN('0');
(await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.times(b));
(await this.safeMath.mul(a, b)).should.be.bignumber.equal(a.mul(b));
});
it('reverts on multiplication overflow', async function () {
const a = MAX_UINT256;
const b = new BigNumber(2);
const b = new BN('2');
await shouldFail.reverting(this.safeMath.mul(a, b));
});
......@@ -74,29 +72,29 @@ contract('SafeMath', function () {
describe('div', function () {
it('divides correctly', async function () {
const a = new BigNumber(5678);
const b = new BigNumber(5678);
const a = new BN('5678');
const b = new BN('5678');
(await this.safeMath.div(a, b)).should.be.bignumber.equal(a.div(b));
});
it('divides zero correctly', async function () {
const a = new BigNumber(0);
const b = new BigNumber(5678);
const a = new BN('0');
const b = new BN('5678');
(await this.safeMath.div(a, b)).should.be.bignumber.equal(0);
(await this.safeMath.div(a, b)).should.be.bignumber.equal('0');
});
it('returns complete number result on non-even division', async function () {
const a = new BigNumber(7000);
const b = new BigNumber(5678);
const a = new BN('7000');
const b = new BN('5678');
(await this.safeMath.div(a, b)).should.be.bignumber.equal(1);
(await this.safeMath.div(a, b)).should.be.bignumber.equal('1');
});
it('reverts on zero division', async function () {
const a = new BigNumber(5678);
const b = new BigNumber(0);
const a = new BN('5678');
const b = new BN('0');
await shouldFail.reverting(this.safeMath.div(a, b));
});
......@@ -105,37 +103,37 @@ contract('SafeMath', function () {
describe('mod', function () {
describe('modulos correctly', async function () {
it('when the dividend is smaller than the divisor', async function () {
const a = new BigNumber(284);
const b = new BigNumber(5678);
const a = new BN('284');
const b = new BN('5678');
(await this.safeMath.mod(a, b)).should.be.bignumber.equal(a.mod(b));
});
it('when the dividend is equal to the divisor', async function () {
const a = new BigNumber(5678);
const b = new BigNumber(5678);
const a = new BN('5678');
const b = new BN('5678');
(await this.safeMath.mod(a, b)).should.be.bignumber.equal(a.mod(b));
});
it('when the dividend is larger than the divisor', async function () {
const a = new BigNumber(7000);
const b = new BigNumber(5678);
const a = new BN('7000');
const b = new BN('5678');
(await this.safeMath.mod(a, b)).should.be.bignumber.equal(a.mod(b));
});
it('when the dividend is a multiple of the divisor', async function () {
const a = new BigNumber(17034); // 17034 == 5678 * 3
const b = new BigNumber(5678);
const a = new BN('17034'); // 17034 == 5678 * 3
const b = new BN('5678');
(await this.safeMath.mod(a, b)).should.be.bignumber.equal(a.mod(b));
});
});
it('reverts with a 0 divisor', async function () {
const a = new BigNumber(5678);
const b = new BigNumber(0);
const a = new BN('5678');
const b = new BN('0');
await shouldFail.reverting(this.safeMath.mod(a, b));
});
......
const shouldFail = require('../helpers/shouldFail');
const expectEvent = require('../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../helpers/constants');
require('./../helpers/setup');
const { constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeOwnable (owner, [anyone]) {
describe('as an ownable', function () {
......@@ -23,7 +21,7 @@ function shouldBehaveLikeOwnable (owner, [anyone]) {
});
it('should guard ownership against stuck state', async function () {
await shouldFail.reverting(this.ownable.transferOwnership(null, { from: owner }));
await shouldFail.reverting(this.ownable.transferOwnership(ZERO_ADDRESS, { from: owner }));
});
it('loses owner after renouncement', async function () {
......
require('openzeppelin-test-helpers');
const { shouldBehaveLikeOwnable } = require('./Ownable.behavior');
const Ownable = artifacts.require('OwnableMock');
......
const shouldFail = require('../helpers/shouldFail');
const expectEvent = require('../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../helpers/constants');
const { constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const SecondaryMock = artifacts.require('SecondaryMock');
require('../helpers/setup');
contract('Secondary', function ([_, primary, newPrimary, anyone]) {
beforeEach(async function () {
this.secondary = await SecondaryMock.new({ from: primary });
......
const { ethGetBalance } = require('../helpers/web3');
const expectEvent = require('../helpers/expectEvent');
const send = require('./../helpers/send');
const { ether } = require('../helpers/ether');
const { ZERO_ADDRESS } = require('./../helpers/constants');
const { balance, constants, ether, expectEvent, send, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
require('../helpers/setup');
const shouldFail = require('../helpers/shouldFail');
const PaymentSplitter = artifacts.require('PaymentSplitter');
contract('PaymentSplitter', function ([_, owner, payee1, payee2, payee3, nonpayee1, payer1]) {
const amount = ether(1.0);
const amount = ether('1');
it('rejects an empty set of payees', async function () {
await shouldFail.reverting(PaymentSplitter.new([], []));
......@@ -45,28 +39,28 @@ contract('PaymentSplitter', function ([_, owner, payee1, payee2, payee3, nonpaye
});
it('should have total shares', async function () {
(await this.contract.totalShares()).should.be.bignumber.equal(20 + 10 + 70);
(await this.contract.totalShares()).should.be.bignumber.equal('100');
});
it('should have payees', async function () {
await Promise.all(this.payees.map(async (payee, index) => {
(await this.contract.payee(index)).should.be.equal(payee);
(await this.contract.released(payee)).should.be.bignumber.equal(0);
(await this.contract.released(payee)).should.be.bignumber.equal('0');
}));
});
it('should accept payments', async function () {
await send.ether(owner, this.contract.address, amount);
(await ethGetBalance(this.contract.address)).should.be.bignumber.equal(amount);
(await balance.current(this.contract.address)).should.be.bignumber.equal(amount);
});
it('should store shares if address is payee', async function () {
(await this.contract.shares(payee1)).should.be.bignumber.not.equal(0);
(await this.contract.shares(payee1)).should.be.bignumber.not.equal('0');
});
it('should not store shares if address is not payee', async function () {
(await this.contract.shares(nonpayee1)).should.be.bignumber.equal(0);
(await this.contract.shares(nonpayee1)).should.be.bignumber.equal('0');
});
it('should throw if no funds to claim', async function () {
......@@ -82,30 +76,31 @@ contract('PaymentSplitter', function ([_, owner, payee1, payee2, payee3, nonpaye
await send.ether(payer1, this.contract.address, amount);
// receive funds
const initBalance = await ethGetBalance(this.contract.address);
const initBalance = await balance.current(this.contract.address);
initBalance.should.be.bignumber.equal(amount);
// distribute to payees
const initAmount1 = await ethGetBalance(payee1);
const { logs: logs1 } = await this.contract.release(payee1);
const profit1 = (await ethGetBalance(payee1)).sub(initAmount1);
profit1.sub(web3.toWei(0.20, 'ether')).abs().should.be.bignumber.lt(1e16);
const initAmount1 = await balance.current(payee1);
const { logs: logs1 } = await this.contract.release(payee1, { gasPrice: 0 });
const profit1 = (await balance.current(payee1)).sub(initAmount1);
profit1.should.be.bignumber.equal(ether('0.20', 'ether'));
expectEvent.inLogs(logs1, 'PaymentReleased', { to: payee1, amount: profit1 });
const initAmount2 = await ethGetBalance(payee2);
const { logs: logs2 } = await this.contract.release(payee2);
const profit2 = (await ethGetBalance(payee2)).sub(initAmount2);
profit2.sub(web3.toWei(0.10, 'ether')).abs().should.be.bignumber.lt(1e16);
const initAmount2 = await balance.current(payee2);
const { logs: logs2 } = await this.contract.release(payee2, { gasPrice: 0 });
const profit2 = (await balance.current(payee2)).sub(initAmount2);
profit2.should.be.bignumber.equal(ether('0.10', 'ether'));
expectEvent.inLogs(logs2, 'PaymentReleased', { to: payee2, amount: profit2 });
const initAmount3 = await ethGetBalance(payee3);
const { logs: logs3 } = await this.contract.release(payee3);
const profit3 = (await ethGetBalance(payee3)).sub(initAmount3);
profit3.sub(web3.toWei(0.70, 'ether')).abs().should.be.bignumber.lt(1e16);
const initAmount3 = await balance.current(payee3);
const { logs: logs3 } = await this.contract.release(payee3, { gasPrice: 0 });
const profit3 = (await balance.current(payee3)).sub(initAmount3);
profit3.should.be.bignumber.equal(ether('0.70', 'ether'));
expectEvent.inLogs(logs3, 'PaymentReleased', { to: payee3, amount: profit3 });
// end balance should be zero
(await ethGetBalance(this.contract.address)).should.be.bignumber.equal(0);
(await balance.current(this.contract.address)).should.be.bignumber.equal('0');
// check correct funds released accounting
(await this.contract.totalReleased()).should.be.bignumber.equal(initBalance);
......
const { balanceDifference } = require('../helpers/balanceDifference');
const { ether } = require('../helpers/ether');
require('../helpers/setup');
const { balance, ether } = require('openzeppelin-test-helpers');
const PullPaymentMock = artifacts.require('PullPaymentMock');
contract('PullPayment', function ([_, payer, payee1, payee2]) {
const amount = ether(17.0);
const amount = ether('17');
beforeEach(async function () {
this.contract = await PullPaymentMock.new({ value: amount });
......@@ -14,32 +11,32 @@ contract('PullPayment', function ([_, payer, payee1, payee2]) {
it('can record an async payment correctly', async function () {
await this.contract.callTransfer(payee1, 100, { from: payer });
(await this.contract.payments(payee1)).should.be.bignumber.equal(100);
(await this.contract.payments(payee1)).should.be.bignumber.equal('100');
});
it('can add multiple balances on one account', async function () {
await this.contract.callTransfer(payee1, 200, { from: payer });
await this.contract.callTransfer(payee1, 300, { from: payer });
(await this.contract.payments(payee1)).should.be.bignumber.equal(500);
(await this.contract.payments(payee1)).should.be.bignumber.equal('500');
});
it('can add balances on multiple accounts', async function () {
await this.contract.callTransfer(payee1, 200, { from: payer });
await this.contract.callTransfer(payee2, 300, { from: payer });
(await this.contract.payments(payee1)).should.be.bignumber.equal(200);
(await this.contract.payments(payee1)).should.be.bignumber.equal('200');
(await this.contract.payments(payee2)).should.be.bignumber.equal(300);
(await this.contract.payments(payee2)).should.be.bignumber.equal('300');
});
it('can withdraw payment', async function () {
(await balanceDifference(payee1, async () => {
(await balance.difference(payee1, async () => {
await this.contract.callTransfer(payee1, amount, { from: payer });
(await this.contract.payments(payee1)).should.be.bignumber.equal(amount);
await this.contract.withdrawPayments(payee1);
})).should.be.bignumber.equal(amount);
(await this.contract.payments(payee1)).should.be.bignumber.equal(0);
(await this.contract.payments(payee1)).should.be.bignumber.equal('0');
});
});
const { ether, shouldFail } = require('openzeppelin-test-helpers');
const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
const shouldFail = require('../../helpers/shouldFail');
const { ether } = require('../../helpers/ether');
require('../../helpers/setup');
const ConditionalEscrowMock = artifacts.require('ConditionalEscrowMock');
contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
......@@ -21,7 +17,7 @@ contract('ConditionalEscrow', function ([_, owner, payee, ...otherAccounts]) {
});
context('when withdrawal is disallowed', function () {
const amount = ether(23.0);
const amount = ether('23');
beforeEach(async function () {
await this.escrow.setAllowed(payee, false);
......
const expectEvent = require('../../helpers/expectEvent');
const shouldFail = require('../../helpers/shouldFail');
const { ethGetBalance } = require('../../helpers/web3');
const { balanceDifference } = require('../../helpers/balanceDifference');
const { ether } = require('../../helpers/ether');
require('../../helpers/setup');
const { balance, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
const amount = ether(42.0);
const amount = ether('42');
describe('as an escrow', function () {
describe('deposits', function () {
it('can accept a single deposit', async function () {
await this.escrow.deposit(payee1, { from: primary, value: amount });
(await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(amount);
(await balance.current(this.escrow.address)).should.be.bignumber.equal(amount);
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount);
});
......@@ -37,34 +31,34 @@ function shouldBehaveLikeEscrow (primary, [payee1, payee2]) {
it('can add multiple deposits on a single account', async function () {
await this.escrow.deposit(payee1, { from: primary, value: amount });
await this.escrow.deposit(payee1, { from: primary, value: amount * 2 });
await this.escrow.deposit(payee1, { from: primary, value: amount.muln(2) });
(await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(amount * 3);
(await balance.current(this.escrow.address)).should.be.bignumber.equal(amount.muln(3));
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount * 3);
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount.muln(3));
});
it('can track deposits to multiple accounts', async function () {
await this.escrow.deposit(payee1, { from: primary, value: amount });
await this.escrow.deposit(payee2, { from: primary, value: amount * 2 });
await this.escrow.deposit(payee2, { from: primary, value: amount.muln(2) });
(await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(amount * 3);
(await balance.current(this.escrow.address)).should.be.bignumber.equal(amount.muln(3));
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(amount);
(await this.escrow.depositsOf(payee2)).should.be.bignumber.equal(amount * 2);
(await this.escrow.depositsOf(payee2)).should.be.bignumber.equal(amount.muln(2));
});
});
describe('withdrawals', async function () {
it('can withdraw payments', async function () {
(await balanceDifference(payee1, async () => {
(await balance.difference(payee1, async () => {
await this.escrow.deposit(payee1, { from: primary, value: amount });
await this.escrow.withdraw(payee1, { from: primary });
})).should.be.bignumber.equal(amount);
(await ethGetBalance(this.escrow.address)).should.be.bignumber.equal(0);
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal(0);
(await balance.current(this.escrow.address)).should.be.bignumber.equal('0');
(await this.escrow.depositsOf(payee1)).should.be.bignumber.equal('0');
});
it('can do an empty withdrawal', async function () {
......
require('openzeppelin-test-helpers');
const { shouldBehaveLikeEscrow } = require('./Escrow.behavior');
const Escrow = artifacts.require('Escrow');
......
const shouldFail = require('../../helpers/shouldFail');
const expectEvent = require('../../helpers/expectEvent');
const { balanceDifference } = require('../../helpers/balanceDifference');
const { ether } = require('../../helpers/ether');
const { ZERO_ADDRESS } = require('../../helpers/constants');
require('../../helpers/setup');
const { balance, constants, ether, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const RefundEscrow = artifacts.require('RefundEscrow');
contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee2]) {
const amount = ether(54.0);
const amount = ether('54');
const refundees = [refundee1, refundee2];
it('requires a non-null beneficiary', async function () {
......@@ -26,7 +21,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
context('active state', function () {
it('has beneficiary and state', async function () {
(await this.escrow.beneficiary()).should.be.equal(beneficiary);
(await this.escrow.state()).should.be.bignumber.equal(0);
(await this.escrow.state()).should.be.bignumber.equal('0');
});
it('accepts deposits', async function () {
......@@ -69,9 +64,9 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
});
it('allows beneficiary withdrawal', async function () {
(await balanceDifference(beneficiary, () =>
(await balance.difference(beneficiary, () =>
this.escrow.beneficiaryWithdraw()
)).should.be.bignumber.equal(amount * refundees.length);
)).should.be.bignumber.equal(amount.muln(refundees.length));
});
it('prevents entering the refund state', async function () {
......@@ -103,7 +98,7 @@ contract('RefundEscrow', function ([_, primary, beneficiary, refundee1, refundee
it('refunds refundees', async function () {
for (const refundee of [refundee1, refundee2]) {
(await balanceDifference(refundee, () =>
(await balance.difference(refundee, () =>
this.escrow.withdraw(refundee, { from: primary }))
).should.be.bignumber.equal(amount);
}
......
const shouldFail = require('../../helpers/shouldFail');
const expectEvent = require('../../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../../helpers/constants');
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const ERC20Mock = artifacts.require('ERC20Mock');
const { BigNumber } = require('../../helpers/setup');
contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
contract('ERC20', function ([_, initialHolder, recipient, anotherAccount]) {
const initialSupply = new BN(100);
beforeEach(async function () {
this.token = await ERC20Mock.new(owner, 100);
this.token = await ERC20Mock.new(initialHolder, initialSupply);
});
describe('total supply', function () {
it('returns the total amount of tokens', async function () {
(await this.token.totalSupply()).should.be.bignumber.equal(100);
(await this.token.totalSupply()).should.be.bignumber.equal(initialSupply);
});
});
describe('balanceOf', function () {
describe('when the requested account has no tokens', function () {
it('returns zero', async function () {
(await this.token.balanceOf(anotherAccount)).should.be.bignumber.equal(0);
(await this.token.balanceOf(anotherAccount)).should.be.bignumber.equal('0');
});
});
describe('when the requested account has some tokens', function () {
it('returns the total amount of tokens', async function () {
(await this.token.balanceOf(owner)).should.be.bignumber.equal(100);
(await this.token.balanceOf(initialHolder)).should.be.bignumber.equal(initialSupply);
});
});
});
......@@ -36,29 +34,29 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
const to = recipient;
describe('when the sender does not have enough balance', function () {
const amount = 101;
const amount = initialSupply.addn(1);
it('reverts', async function () {
await shouldFail.reverting(this.token.transfer(to, amount, { from: owner }));
await shouldFail.reverting(this.token.transfer(to, amount, { from: initialHolder }));
});
});
describe('when the sender has enough balance', function () {
const amount = 100;
const amount = initialSupply;
it('transfers the requested amount', async function () {
await this.token.transfer(to, amount, { from: owner });
await this.token.transfer(to, amount, { from: initialHolder });
(await this.token.balanceOf(owner)).should.be.bignumber.equal(0);
(await this.token.balanceOf(initialHolder)).should.be.bignumber.equal('0');
(await this.token.balanceOf(to)).should.be.bignumber.equal(amount);
});
it('emits a transfer event', async function () {
const { logs } = await this.token.transfer(to, amount, { from: owner });
const { logs } = await this.token.transfer(to, amount, { from: initialHolder });
expectEvent.inLogs(logs, 'Transfer', {
from: owner,
from: initialHolder,
to: to,
value: amount,
});
......@@ -70,7 +68,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
const to = ZERO_ADDRESS;
it('reverts', async function () {
await shouldFail.reverting(this.token.transfer(to, 100, { from: owner }));
await shouldFail.reverting(this.token.transfer(to, initialSupply, { from: initialHolder }));
});
});
});
......@@ -80,13 +78,13 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
const spender = recipient;
describe('when the sender has enough balance', function () {
const amount = 100;
const amount = initialSupply;
it('emits an approval event', async function () {
const { logs } = await this.token.approve(spender, amount, { from: owner });
const { logs } = await this.token.approve(spender, amount, { from: initialHolder });
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
owner: initialHolder,
spender: spender,
value: amount,
});
......@@ -94,33 +92,33 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
describe('when there was no approved amount before', function () {
it('approves the requested amount', async function () {
await this.token.approve(spender, amount, { from: owner });
await this.token.approve(spender, amount, { from: initialHolder });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
});
});
describe('when the spender had an approved amount', function () {
beforeEach(async function () {
await this.token.approve(spender, 1, { from: owner });
await this.token.approve(spender, new BN(1), { from: initialHolder });
});
it('approves the requested amount and replaces the previous one', async function () {
await this.token.approve(spender, amount, { from: owner });
await this.token.approve(spender, amount, { from: initialHolder });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
});
});
});
describe('when the sender does not have enough balance', function () {
const amount = 101;
const amount = initialSupply.addn(1);
it('emits an approval event', async function () {
const { logs } = await this.token.approve(spender, amount, { from: owner });
const { logs } = await this.token.approve(spender, amount, { from: initialHolder });
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
owner: initialHolder,
spender: spender,
value: amount,
});
......@@ -128,32 +126,32 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
describe('when there was no approved amount before', function () {
it('approves the requested amount', async function () {
await this.token.approve(spender, amount, { from: owner });
await this.token.approve(spender, amount, { from: initialHolder });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
});
});
describe('when the spender had an approved amount', function () {
beforeEach(async function () {
await this.token.approve(spender, 1, { from: owner });
await this.token.approve(spender, new BN(1), { from: initialHolder });
});
it('approves the requested amount and replaces the previous one', async function () {
await this.token.approve(spender, amount, { from: owner });
await this.token.approve(spender, amount, { from: initialHolder });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
});
});
});
});
describe('when the spender is the zero address', function () {
const amount = 100;
const amount = initialSupply;
const spender = ZERO_ADDRESS;
it('reverts', async function () {
await shouldFail.reverting(this.token.approve(spender, amount, { from: owner }));
await shouldFail.reverting(this.token.approve(spender, amount, { from: initialHolder }));
});
});
});
......@@ -166,89 +164,89 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
describe('when the spender has enough approved balance', function () {
beforeEach(async function () {
await this.token.approve(spender, 100, { from: owner });
await this.token.approve(spender, initialSupply, { from: initialHolder });
});
describe('when the owner has enough balance', function () {
const amount = 100;
describe('when the initial holder has enough balance', function () {
const amount = initialSupply;
it('transfers the requested amount', async function () {
await this.token.transferFrom(owner, to, amount, { from: spender });
await this.token.transferFrom(initialHolder, to, amount, { from: spender });
(await this.token.balanceOf(owner)).should.be.bignumber.equal(0);
(await this.token.balanceOf(initialHolder)).should.be.bignumber.equal('0');
(await this.token.balanceOf(to)).should.be.bignumber.equal(amount);
});
it('decreases the spender allowance', async function () {
await this.token.transferFrom(owner, to, amount, { from: spender });
await this.token.transferFrom(initialHolder, to, amount, { from: spender });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(0);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal('0');
});
it('emits a transfer event', async function () {
const { logs } = await this.token.transferFrom(owner, to, amount, { from: spender });
const { logs } = await this.token.transferFrom(initialHolder, to, amount, { from: spender });
expectEvent.inLogs(logs, 'Transfer', {
from: owner,
from: initialHolder,
to: to,
value: amount,
});
});
it('emits an approval event', async function () {
const { logs } = await this.token.transferFrom(owner, to, amount, { from: spender });
const { logs } = await this.token.transferFrom(initialHolder, to, amount, { from: spender });
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
owner: initialHolder,
spender: spender,
value: await this.token.allowance(owner, spender),
value: await this.token.allowance(initialHolder, spender),
});
});
});
describe('when the owner does not have enough balance', function () {
const amount = 101;
describe('when the initial holder does not have enough balance', function () {
const amount = initialSupply.addn(1);
it('reverts', async function () {
await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender }));
await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
});
});
});
describe('when the spender does not have enough approved balance', function () {
beforeEach(async function () {
await this.token.approve(spender, 99, { from: owner });
await this.token.approve(spender, initialSupply.subn(1), { from: initialHolder });
});
describe('when the owner has enough balance', function () {
const amount = 100;
describe('when the initial holder has enough balance', function () {
const amount = initialSupply;
it('reverts', async function () {
await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender }));
await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
});
});
describe('when the owner does not have enough balance', function () {
const amount = 101;
describe('when the initial holder does not have enough balance', function () {
const amount = initialSupply.addn(1);
it('reverts', async function () {
await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender }));
await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
});
});
});
});
describe('when the recipient is the zero address', function () {
const amount = 100;
const amount = initialSupply;
const to = ZERO_ADDRESS;
beforeEach(async function () {
await this.token.approve(spender, amount, { from: owner });
await this.token.approve(spender, amount, { from: initialHolder });
});
it('reverts', async function () {
await shouldFail.reverting(this.token.transferFrom(owner, to, amount, { from: spender }));
await shouldFail.reverting(this.token.transferFrom(initialHolder, to, amount, { from: spender }));
});
});
});
......@@ -260,7 +258,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
function shouldDecreaseApproval (amount) {
describe('when there was no approved amount before', function () {
it('reverts', async function () {
await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: owner }));
await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: initialHolder }));
});
});
......@@ -268,71 +266,73 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
const approvedAmount = amount;
beforeEach(async function () {
({ logs: this.logs } = await this.token.approve(spender, approvedAmount, { from: owner }));
({ logs: this.logs } = await this.token.approve(spender, approvedAmount, { from: initialHolder }));
});
it('emits an approval event', async function () {
const { logs } = await this.token.decreaseAllowance(spender, approvedAmount, { from: owner });
const { logs } = await this.token.decreaseAllowance(spender, approvedAmount, { from: initialHolder });
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
owner: initialHolder,
spender: spender,
value: 0,
value: new BN(0),
});
});
it('decreases the spender allowance subtracting the requested amount', async function () {
await this.token.decreaseAllowance(spender, approvedAmount - 1, { from: owner });
await this.token.decreaseAllowance(spender, approvedAmount.subn(1), { from: initialHolder });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(1);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal('1');
});
it('sets the allowance to zero when all allowance is removed', async function () {
await this.token.decreaseAllowance(spender, approvedAmount, { from: owner });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(0);
await this.token.decreaseAllowance(spender, approvedAmount, { from: initialHolder });
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal('0');
});
it('reverts when more than the full allowance is removed', async function () {
await shouldFail.reverting(this.token.decreaseAllowance(spender, approvedAmount + 1, { from: owner }));
await shouldFail.reverting(
this.token.decreaseAllowance(spender, approvedAmount.addn(1), { from: initialHolder })
);
});
});
}
describe('when the sender has enough balance', function () {
const amount = 100;
const amount = initialSupply;
shouldDecreaseApproval(amount);
});
describe('when the sender does not have enough balance', function () {
const amount = 101;
const amount = initialSupply.addn(1);
shouldDecreaseApproval(amount);
});
});
describe('when the spender is the zero address', function () {
const amount = 100;
const amount = initialSupply;
const spender = ZERO_ADDRESS;
it('reverts', async function () {
await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: owner }));
await shouldFail.reverting(this.token.decreaseAllowance(spender, amount, { from: initialHolder }));
});
});
});
describe('increase allowance', function () {
const amount = 100;
const amount = initialSupply;
describe('when the spender is not the zero address', function () {
const spender = recipient;
describe('when the sender has enough balance', function () {
it('emits an approval event', async function () {
const { logs } = await this.token.increaseAllowance(spender, amount, { from: owner });
const { logs } = await this.token.increaseAllowance(spender, amount, { from: initialHolder });
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
owner: initialHolder,
spender: spender,
value: amount,
});
......@@ -340,33 +340,33 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
describe('when there was no approved amount before', function () {
it('approves the requested amount', async function () {
await this.token.increaseAllowance(spender, amount, { from: owner });
await this.token.increaseAllowance(spender, amount, { from: initialHolder });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
});
});
describe('when the spender had an approved amount', function () {
beforeEach(async function () {
await this.token.approve(spender, 1, { from: owner });
await this.token.approve(spender, new BN(1), { from: initialHolder });
});
it('increases the spender allowance adding the requested amount', async function () {
await this.token.increaseAllowance(spender, amount, { from: owner });
await this.token.increaseAllowance(spender, amount, { from: initialHolder });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount + 1);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount.addn(1));
});
});
});
describe('when the sender does not have enough balance', function () {
const amount = 101;
const amount = initialSupply.addn(1);
it('emits an approval event', async function () {
const { logs } = await this.token.increaseAllowance(spender, amount, { from: owner });
const { logs } = await this.token.increaseAllowance(spender, amount, { from: initialHolder });
expectEvent.inLogs(logs, 'Approval', {
owner: owner,
owner: initialHolder,
spender: spender,
value: amount,
});
......@@ -374,21 +374,21 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
describe('when there was no approved amount before', function () {
it('approves the requested amount', async function () {
await this.token.increaseAllowance(spender, amount, { from: owner });
await this.token.increaseAllowance(spender, amount, { from: initialHolder });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount);
});
});
describe('when the spender had an approved amount', function () {
beforeEach(async function () {
await this.token.approve(spender, 1, { from: owner });
await this.token.approve(spender, new BN(1), { from: initialHolder });
});
it('increases the spender allowance adding the requested amount', async function () {
await this.token.increaseAllowance(spender, amount, { from: owner });
await this.token.increaseAllowance(spender, amount, { from: initialHolder });
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(amount + 1);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(amount.addn(1));
});
});
});
......@@ -398,14 +398,13 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
const spender = ZERO_ADDRESS;
it('reverts', async function () {
await shouldFail.reverting(this.token.increaseAllowance(spender, amount, { from: owner }));
await shouldFail.reverting(this.token.increaseAllowance(spender, amount, { from: initialHolder }));
});
});
});
describe('_mint', function () {
const initialSupply = new BigNumber(100);
const amount = new BigNumber(50);
const amount = new BN(50);
it('rejects a null account', async function () {
await shouldFail.reverting(this.token.mint(ZERO_ADDRESS, amount));
......@@ -418,7 +417,7 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
});
it('increments totalSupply', async function () {
const expectedSupply = initialSupply.plus(amount);
const expectedSupply = initialSupply.add(amount);
(await this.token.totalSupply()).should.be.bignumber.equal(expectedSupply);
});
......@@ -438,37 +437,35 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
});
describe('_burn', function () {
const initialSupply = new BigNumber(100);
it('rejects a null account', async function () {
await shouldFail.reverting(this.token.burn(ZERO_ADDRESS, 1));
await shouldFail.reverting(this.token.burn(ZERO_ADDRESS, new BN(1)));
});
describe('for a non null account', function () {
it('rejects burning more than balance', async function () {
await shouldFail.reverting(this.token.burn(owner, initialSupply.plus(1)));
await shouldFail.reverting(this.token.burn(initialHolder, initialSupply.addn(1)));
});
const describeBurn = function (description, amount) {
describe(description, function () {
beforeEach('burning', async function () {
const { logs } = await this.token.burn(owner, amount);
const { logs } = await this.token.burn(initialHolder, amount);
this.logs = logs;
});
it('decrements totalSupply', async function () {
const expectedSupply = initialSupply.minus(amount);
const expectedSupply = initialSupply.sub(amount);
(await this.token.totalSupply()).should.be.bignumber.equal(expectedSupply);
});
it('decrements owner balance', async function () {
const expectedBalance = initialSupply.minus(amount);
(await this.token.balanceOf(owner)).should.be.bignumber.equal(expectedBalance);
it('decrements initialHolder balance', async function () {
const expectedBalance = initialSupply.sub(amount);
(await this.token.balanceOf(initialHolder)).should.be.bignumber.equal(expectedBalance);
});
it('emits Transfer event', async function () {
const event = expectEvent.inLogs(this.logs, 'Transfer', {
from: owner,
from: initialHolder,
to: ZERO_ADDRESS,
});
......@@ -478,58 +475,57 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
};
describeBurn('for entire balance', initialSupply);
describeBurn('for less amount than balance', initialSupply.sub(1));
describeBurn('for less amount than balance', initialSupply.subn(1));
});
});
describe('_burnFrom', function () {
const initialSupply = new BigNumber(100);
const allowance = new BigNumber(70);
const allowance = new BN(70);
const spender = anotherAccount;
beforeEach('approving', async function () {
await this.token.approve(spender, allowance, { from: owner });
await this.token.approve(spender, allowance, { from: initialHolder });
});
it('rejects a null account', async function () {
await shouldFail.reverting(this.token.burnFrom(ZERO_ADDRESS, 1));
await shouldFail.reverting(this.token.burnFrom(ZERO_ADDRESS, new BN(1)));
});
describe('for a non null account', function () {
it('rejects burning more than allowance', async function () {
await shouldFail.reverting(this.token.burnFrom(owner, allowance.plus(1)));
await shouldFail.reverting(this.token.burnFrom(initialHolder, allowance.addn(1)));
});
it('rejects burning more than balance', async function () {
await shouldFail.reverting(this.token.burnFrom(owner, initialSupply.plus(1)));
await shouldFail.reverting(this.token.burnFrom(initialHolder, initialSupply.addn(1)));
});
const describeBurnFrom = function (description, amount) {
describe(description, function () {
beforeEach('burning', async function () {
const { logs } = await this.token.burnFrom(owner, amount, { from: spender });
const { logs } = await this.token.burnFrom(initialHolder, amount, { from: spender });
this.logs = logs;
});
it('decrements totalSupply', async function () {
const expectedSupply = initialSupply.minus(amount);
const expectedSupply = initialSupply.sub(amount);
(await this.token.totalSupply()).should.be.bignumber.equal(expectedSupply);
});
it('decrements owner balance', async function () {
const expectedBalance = initialSupply.minus(amount);
(await this.token.balanceOf(owner)).should.be.bignumber.equal(expectedBalance);
it('decrements initialHolder balance', async function () {
const expectedBalance = initialSupply.sub(amount);
(await this.token.balanceOf(initialHolder)).should.be.bignumber.equal(expectedBalance);
});
it('decrements spender allowance', async function () {
const expectedAllowance = allowance.minus(amount);
(await this.token.allowance(owner, spender)).should.be.bignumber.equal(expectedAllowance);
const expectedAllowance = allowance.sub(amount);
(await this.token.allowance(initialHolder, spender)).should.be.bignumber.equal(expectedAllowance);
});
it('emits a Transfer event', async function () {
const event = expectEvent.inLogs(this.logs, 'Transfer', {
from: owner,
from: initialHolder,
to: ZERO_ADDRESS,
});
......@@ -538,16 +534,16 @@ contract('ERC20', function ([_, owner, recipient, anotherAccount]) {
it('emits an Approval event', async function () {
expectEvent.inLogs(this.logs, 'Approval', {
owner: owner,
owner: initialHolder,
spender: spender,
value: await this.token.allowance(owner, spender),
value: await this.token.allowance(initialHolder, spender),
});
});
});
};
describeBurnFrom('for entire allowance', allowance);
describeBurnFrom('for less amount than allowance', allowance.sub(1));
describeBurnFrom('for less amount than allowance', allowance.subn(1));
});
});
});
const { BN } = require('openzeppelin-test-helpers');
const { shouldBehaveLikeERC20Burnable } = require('./behaviors/ERC20Burnable.behavior');
const ERC20BurnableMock = artifacts.require('ERC20BurnableMock');
contract('ERC20Burnable', function ([_, owner, ...otherAccounts]) {
const initialBalance = 1000;
const initialBalance = new BN(1000);
beforeEach(async function () {
this.token = await ERC20BurnableMock.new(owner, initialBalance, { from: owner });
......
const shouldFail = require('../../helpers/shouldFail');
const { ether } = require('../../helpers/ether');
const { BN, ether, shouldFail } = require('openzeppelin-test-helpers');
const { shouldBehaveLikeERC20Mintable } = require('./behaviors/ERC20Mintable.behavior');
const { shouldBehaveLikeERC20Capped } = require('./behaviors/ERC20Capped.behavior');
const ERC20Capped = artifacts.require('ERC20Capped');
contract('ERC20Capped', function ([_, minter, ...otherAccounts]) {
const cap = ether(1000);
const cap = ether('1000');
it('requires a non-zero cap', async function () {
await shouldFail.reverting(
ERC20Capped.new(0, { from: minter })
ERC20Capped.new(new BN(0), { from: minter })
);
});
......
require('../../helpers/setup');
const { BN } = require('openzeppelin-test-helpers');
const ERC20DetailedMock = artifacts.require('ERC20DetailedMock');
contract('ERC20Detailed', function () {
const _name = 'My Detailed ERC20';
const _symbol = 'MDT';
const _decimals = 18;
const _decimals = new BN(18);
beforeEach(async function () {
this.detailedERC20 = await ERC20DetailedMock.new(_name, _symbol, _decimals);
......
const expectEvent = require('../../helpers/expectEvent');
const shouldFail = require('../../helpers/shouldFail');
const { BN, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const ERC20PausableMock = artifacts.require('ERC20PausableMock');
const { shouldBehaveLikePublicRole } = require('../../access/roles/PublicRole.behavior');
contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherAccount, ...otherAccounts]) {
const initialSupply = new BN(100);
beforeEach(async function () {
this.token = await ERC20PausableMock.new(pauser, 100, { from: pauser });
this.token = await ERC20PausableMock.new(pauser, initialSupply, { from: pauser });
});
describe('pauser role', function () {
......@@ -114,132 +115,142 @@ contract('ERC20Pausable', function ([_, pauser, otherPauser, recipient, anotherA
describe('transfer', function () {
it('allows to transfer when unpaused', async function () {
await this.token.transfer(recipient, 100, { from: pauser });
await this.token.transfer(recipient, initialSupply, { from: pauser });
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(0);
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(100);
(await this.token.balanceOf(pauser)).should.be.bignumber.equal('0');
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(initialSupply);
});
it('allows to transfer when paused and then unpaused', async function () {
await this.token.pause({ from: pauser });
await this.token.unpause({ from: pauser });
await this.token.transfer(recipient, 100, { from: pauser });
await this.token.transfer(recipient, initialSupply, { from: pauser });
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(0);
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(100);
(await this.token.balanceOf(pauser)).should.be.bignumber.equal('0');
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(initialSupply);
});
it('reverts when trying to transfer when paused', async function () {
await this.token.pause({ from: pauser });
await shouldFail.reverting(this.token.transfer(recipient, 100, { from: pauser }));
await shouldFail.reverting(this.token.transfer(recipient, initialSupply, { from: pauser }));
});
});
describe('approve', function () {
const allowance = new BN(40);
it('allows to approve when unpaused', async function () {
await this.token.approve(anotherAccount, 40, { from: pauser });
await this.token.approve(anotherAccount, allowance, { from: pauser });
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(40);
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance);
});
it('allows to approve when paused and then unpaused', async function () {
await this.token.pause({ from: pauser });
await this.token.unpause({ from: pauser });
await this.token.approve(anotherAccount, 40, { from: pauser });
await this.token.approve(anotherAccount, allowance, { from: pauser });
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(40);
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance);
});
it('reverts when trying to approve when paused', async function () {
await this.token.pause({ from: pauser });
await shouldFail.reverting(this.token.approve(anotherAccount, 40, { from: pauser }));
await shouldFail.reverting(this.token.approve(anotherAccount, allowance, { from: pauser }));
});
});
describe('transfer from', function () {
const allowance = new BN(40);
beforeEach(async function () {
await this.token.approve(anotherAccount, 50, { from: pauser });
await this.token.approve(anotherAccount, allowance, { from: pauser });
});
it('allows to transfer from when unpaused', async function () {
await this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount });
await this.token.transferFrom(pauser, recipient, allowance, { from: anotherAccount });
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(60);
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(40);
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(allowance);
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(initialSupply.sub(allowance));
});
it('allows to transfer when paused and then unpaused', async function () {
await this.token.pause({ from: pauser });
await this.token.unpause({ from: pauser });
await this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount });
await this.token.transferFrom(pauser, recipient, allowance, { from: anotherAccount });
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(60);
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(40);
(await this.token.balanceOf(recipient)).should.be.bignumber.equal(allowance);
(await this.token.balanceOf(pauser)).should.be.bignumber.equal(initialSupply.sub(allowance));
});
it('reverts when trying to transfer from when paused', async function () {
await this.token.pause({ from: pauser });
await shouldFail.reverting(this.token.transferFrom(pauser, recipient, 40, { from: anotherAccount }));
await shouldFail.reverting(this.token.transferFrom(pauser, recipient, allowance, { from: anotherAccount }));
});
});
describe('decrease approval', function () {
const allowance = new BN(40);
const decrement = new BN(10);
beforeEach(async function () {
await this.token.approve(anotherAccount, 100, { from: pauser });
await this.token.approve(anotherAccount, allowance, { from: pauser });
});
it('allows to decrease approval when unpaused', async function () {
await this.token.decreaseAllowance(anotherAccount, 40, { from: pauser });
await this.token.decreaseAllowance(anotherAccount, decrement, { from: pauser });
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(60);
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.sub(decrement));
});
it('allows to decrease approval when paused and then unpaused', async function () {
await this.token.pause({ from: pauser });
await this.token.unpause({ from: pauser });
await this.token.decreaseAllowance(anotherAccount, 40, { from: pauser });
await this.token.decreaseAllowance(anotherAccount, decrement, { from: pauser });
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(60);
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.sub(decrement));
});
it('reverts when trying to transfer when paused', async function () {
await this.token.pause({ from: pauser });
await shouldFail.reverting(this.token.decreaseAllowance(anotherAccount, 40, { from: pauser }));
await shouldFail.reverting(this.token.decreaseAllowance(anotherAccount, decrement, { from: pauser }));
});
});
describe('increase approval', function () {
const allowance = new BN(40);
const increment = new BN(30);
beforeEach(async function () {
await this.token.approve(anotherAccount, 100, { from: pauser });
await this.token.approve(anotherAccount, allowance, { from: pauser });
});
it('allows to increase approval when unpaused', async function () {
await this.token.increaseAllowance(anotherAccount, 40, { from: pauser });
await this.token.increaseAllowance(anotherAccount, increment, { from: pauser });
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(140);
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.add(increment));
});
it('allows to increase approval when paused and then unpaused', async function () {
await this.token.pause({ from: pauser });
await this.token.unpause({ from: pauser });
await this.token.increaseAllowance(anotherAccount, 40, { from: pauser });
await this.token.increaseAllowance(anotherAccount, increment, { from: pauser });
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(140);
(await this.token.allowance(pauser, anotherAccount)).should.be.bignumber.equal(allowance.add(increment));
});
it('reverts when trying to increase approval when paused', async function () {
await this.token.pause({ from: pauser });
await shouldFail.reverting(this.token.increaseAllowance(anotherAccount, 40, { from: pauser }));
await shouldFail.reverting(this.token.increaseAllowance(anotherAccount, increment, { from: pauser }));
});
});
});
......
const shouldFail = require('../../helpers/shouldFail');
require('../../helpers/setup');
const { shouldFail } = require('openzeppelin-test-helpers');
const SafeERC20Helper = artifacts.require('SafeERC20Helper');
......
const shouldFail = require('../../helpers/shouldFail');
const time = require('../../helpers/time');
const { BigNumber } = require('../../helpers/setup');
const { BN, shouldFail, time } = require('openzeppelin-test-helpers');
const ERC20Mintable = artifacts.require('ERC20Mintable');
const TokenTimelock = artifacts.require('TokenTimelock');
contract('TokenTimelock', function ([_, minter, beneficiary]) {
const amount = new BigNumber(100);
const amount = new BN(100);
context('with token', function () {
beforeEach(async function () {
......@@ -15,7 +12,7 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) {
});
it('rejects a release time in the past', async function () {
const pastReleaseTime = (await time.latest()) - time.duration.years(1);
const pastReleaseTime = (await time.latest()).sub(time.duration.years(1));
await shouldFail.reverting(
TokenTimelock.new(this.token.address, beneficiary, pastReleaseTime)
);
......@@ -23,7 +20,7 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) {
context('once deployed', function () {
beforeEach(async function () {
this.releaseTime = (await time.latest()) + time.duration.years(1);
this.releaseTime = (await time.latest()).add(time.duration.years(1));
this.timelock = await TokenTimelock.new(this.token.address, beneficiary, this.releaseTime);
await this.token.mint(this.timelock.address, amount, { from: minter });
});
......@@ -39,24 +36,24 @@ contract('TokenTimelock', function ([_, minter, beneficiary]) {
});
it('cannot be released just before time limit', async function () {
await time.increaseTo(this.releaseTime - time.duration.seconds(3));
await time.increaseTo(this.releaseTime.sub(time.duration.seconds(3)));
await shouldFail.reverting(this.timelock.release());
});
it('can be released just after limit', async function () {
await time.increaseTo(this.releaseTime + time.duration.seconds(1));
await time.increaseTo(this.releaseTime.add(time.duration.seconds(1)));
await this.timelock.release();
(await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
});
it('can be released after time limit', async function () {
await time.increaseTo(this.releaseTime + time.duration.years(1));
await time.increaseTo(this.releaseTime.add(time.duration.years(1)));
await this.timelock.release();
(await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
});
it('cannot be released twice', async function () {
await time.increaseTo(this.releaseTime + time.duration.years(1));
await time.increaseTo(this.releaseTime.add(time.duration.years(1)));
await this.timelock.release();
await shouldFail.reverting(this.timelock.release());
(await this.token.balanceOf(beneficiary)).should.be.bignumber.equal(amount);
......
const shouldFail = require('../../../helpers/shouldFail');
const expectEvent = require('../../../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../../../helpers/constants');
require('../../../helpers/setup');
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
describe('burn', function () {
describe('when the given amount is not greater than balance of the sender', function () {
context('for a zero amount', function () {
shouldBurn(0);
shouldBurn(new BN(0));
});
context('for a non-zero amount', function () {
shouldBurn(100);
shouldBurn(new BN(100));
});
function shouldBurn (amount) {
......@@ -21,7 +18,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
});
it('burns the requested amount', async function () {
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance - amount);
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance.sub(amount));
});
it('emits a transfer event', async function () {
......@@ -35,7 +32,7 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
});
describe('when the given amount is greater than the balance of the sender', function () {
const amount = initialBalance + 1;
const amount = initialBalance.addn(1);
it('reverts', async function () {
await shouldFail.reverting(this.token.burn(amount, { from: owner }));
......@@ -46,15 +43,15 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
describe('burnFrom', function () {
describe('on success', function () {
context('for a zero amount', function () {
shouldBurnFrom(0);
shouldBurnFrom(new BN(0));
});
context('for a non-zero amount', function () {
shouldBurnFrom(100);
shouldBurnFrom(new BN(100));
});
function shouldBurnFrom (amount) {
const originalAllowance = amount * 3;
const originalAllowance = amount.muln(3);
beforeEach(async function () {
await this.token.approve(burner, originalAllowance, { from: owner });
......@@ -63,11 +60,11 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
});
it('burns the requested amount', async function () {
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance - amount);
(await this.token.balanceOf(owner)).should.be.bignumber.equal(initialBalance.sub(amount));
});
it('decrements allowance', async function () {
(await this.token.allowance(owner, burner)).should.be.bignumber.equal(originalAllowance - amount);
(await this.token.allowance(owner, burner)).should.be.bignumber.equal(originalAllowance.sub(amount));
});
it('emits a transfer event', async function () {
......@@ -81,7 +78,8 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
});
describe('when the given amount is greater than the balance of the sender', function () {
const amount = initialBalance + 1;
const amount = initialBalance.addn(1);
it('reverts', async function () {
await this.token.approve(burner, amount, { from: owner });
await shouldFail.reverting(this.token.burnFrom(owner, amount, { from: burner }));
......@@ -89,10 +87,11 @@ function shouldBehaveLikeERC20Burnable (owner, initialBalance, [burner]) {
});
describe('when the given amount is greater than the allowance', function () {
const amount = 100;
const allowance = new BN(100);
it('reverts', async function () {
await this.token.approve(burner, amount - 1, { from: owner });
await shouldFail.reverting(this.token.burnFrom(owner, amount, { from: burner }));
await this.token.approve(burner, allowance, { from: owner });
await shouldFail.reverting(this.token.burnFrom(owner, allowance.addn(1), { from: burner }));
});
});
});
......
const shouldFail = require('../../../helpers/shouldFail');
require('../../../helpers/setup');
const { shouldFail } = require('openzeppelin-test-helpers');
function shouldBehaveLikeERC20Capped (minter, [anyone], cap) {
describe('capped token', function () {
......@@ -11,13 +9,13 @@ function shouldBehaveLikeERC20Capped (minter, [anyone], cap) {
});
it('should mint when amount is less than cap', async function () {
await this.token.mint(anyone, cap.sub(1), { from });
(await this.token.totalSupply()).should.be.bignumber.equal(cap.sub(1));
await this.token.mint(anyone, cap.subn(1), { from });
(await this.token.totalSupply()).should.be.bignumber.equal(cap.subn(1));
});
it('should fail to mint if the ammount exceeds the cap', async function () {
await this.token.mint(anyone, cap.sub(1), { from });
await shouldFail.reverting(this.token.mint(anyone, 100, { from }));
it('should fail to mint if the amount exceeds the cap', async function () {
await this.token.mint(anyone, cap.subn(1), { from });
await shouldFail.reverting(this.token.mint(anyone, 2, { from }));
});
it('should fail to mint after cap is reached', async function () {
......
const shouldFail = require('../../../helpers/shouldFail');
const expectEvent = require('../../../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../../../helpers/constants');
require('../../../helpers/setup');
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeERC20Mintable (minter, [anyone]) {
describe('as a mintable token', function () {
describe('mint', function () {
const amount = 100;
const amount = new BN(100);
context('when the sender has minting permission', function () {
const from = minter;
context('for a zero amount', function () {
shouldMint(0);
shouldMint(new BN(0));
});
context('for a non-zero amount', function () {
......
const expectEvent = require('../../helpers/expectEvent');
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior');
const shouldFail = require('../../helpers/shouldFail');
const { ZERO_ADDRESS } = require('../../helpers/constants');
const send = require('../../helpers/send');
const ERC721ReceiverMock = artifacts.require('ERC721ReceiverMock.sol');
require('../../helpers/setup');
function shouldBehaveLikeERC721 (
creator,
minter,
[owner, approved, anotherApproved, operator, anyone]
) {
const firstTokenId = 1;
const secondTokenId = 2;
const unknownTokenId = 3;
const firstTokenId = new BN(1);
const secondTokenId = new BN(2);
const unknownTokenId = new BN(3);
const RECEIVER_MAGIC_VALUE = '0x150b7a02';
describe('like an ERC721', function () {
......@@ -27,19 +24,19 @@ function shouldBehaveLikeERC721 (
describe('balanceOf', function () {
context('when the given address owns some tokens', function () {
it('returns the amount of tokens owned by the given address', async function () {
(await this.token.balanceOf(owner)).should.be.bignumber.equal(2);
(await this.token.balanceOf(owner)).should.be.bignumber.equal('2');
});
});
context('when the given address does not own any tokens', function () {
it('returns 0', async function () {
(await this.token.balanceOf(anyone)).should.be.bignumber.equal(0);
(await this.token.balanceOf(anyone)).should.be.bignumber.equal('0');
});
});
context('when querying the zero address', function () {
it('throws', async function () {
await shouldFail.reverting(this.token.balanceOf(0));
await shouldFail.reverting(this.token.balanceOf(ZERO_ADDRESS));
});
});
});
......@@ -101,15 +98,15 @@ function shouldBehaveLikeERC721 (
}
it('adjusts owners balances', async function () {
(await this.token.balanceOf(owner)).should.be.bignumber.equal(1);
(await this.token.balanceOf(owner)).should.be.bignumber.equal('1');
});
it('adjusts owners tokens by index', async function () {
if (!this.token.tokenOfOwnerByIndex) return;
(await this.token.tokenOfOwnerByIndex(this.toWhom, 0)).toNumber().should.be.equal(tokenId);
(await this.token.tokenOfOwnerByIndex(this.toWhom, 0)).should.be.bignumber.equal(tokenId);
(await this.token.tokenOfOwnerByIndex(owner, 0)).toNumber().should.not.be.equal(tokenId);
(await this.token.tokenOfOwnerByIndex(owner, 0)).should.be.bignumber.not.equal(tokenId);
});
};
......@@ -165,7 +162,7 @@ function shouldBehaveLikeERC721 (
});
it('keeps the owner balance', async function () {
(await this.token.balanceOf(owner)).should.be.bignumber.equal(2);
(await this.token.balanceOf(owner)).should.be.bignumber.equal('2');
});
it('keeps same tokens by index', async function () {
......@@ -173,7 +170,9 @@ function shouldBehaveLikeERC721 (
const tokensListed = await Promise.all(
[0, 1].map(i => this.token.tokenOfOwnerByIndex(owner, i))
);
tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId, secondTokenId]);
tokensListed.map(t => t.toNumber()).should.have.members(
[firstTokenId.toNumber(), secondTokenId.toNumber()]
);
});
});
......@@ -200,7 +199,9 @@ function shouldBehaveLikeERC721 (
context('when the address to transfer the token to is the zero address', function () {
it('reverts', async function () {
await shouldFail.reverting(transferFunction.call(this, owner, ZERO_ADDRESS, tokenId, { from: owner }));
await shouldFail.reverting(
transferFunction.call(this, owner, ZERO_ADDRESS, tokenId, { from: owner })
);
});
});
};
......@@ -213,17 +214,11 @@ function shouldBehaveLikeERC721 (
describe('via safeTransferFrom', function () {
const safeTransferFromWithData = function (from, to, tokenId, opts) {
return send.transaction(
this.token,
'safeTransferFrom',
'address,address,uint256,bytes',
[from, to, tokenId, data],
opts
);
return this.token.methods['safeTransferFrom(address,address,uint256,bytes)'](from, to, tokenId, data, opts);
};
const safeTransferFromWithoutData = function (from, to, tokenId, opts) {
return this.token.safeTransferFrom(from, to, tokenId, opts);
return this.token.methods['safeTransferFrom(address,address,uint256)'](from, to, tokenId, opts);
};
const shouldTransferSafely = function (transferFun, data) {
......@@ -282,7 +277,7 @@ function shouldBehaveLikeERC721 (
});
describe('without data', function () {
shouldTransferSafely(safeTransferFromWithoutData, '0x');
shouldTransferSafely(safeTransferFromWithoutData, null);
});
describe('to a receiver contract returning unexpected value', function () {
......
require('../../helpers/setup');
const { ZERO_ADDRESS } = require('../../helpers/constants');
const expectEvent = require('../../helpers/expectEvent');
const send = require('../../helpers/send');
const shouldFail = require('../../helpers/shouldFail');
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
const ERC721Mock = artifacts.require('ERC721Mock.sol');
......@@ -15,7 +12,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
shouldBehaveLikeERC721(creator, creator, accounts);
describe('internal functions', function () {
const tokenId = 5042;
const tokenId = new BN('5042');
describe('_mint(address, uint256)', function () {
it('reverts with a null destination address', async function () {
......@@ -32,7 +29,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
});
it('creates the token', async function () {
(await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal(1);
(await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal('1');
(await this.token.ownerOf(tokenId)).should.equal(tokenOwner);
});
......@@ -44,7 +41,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
describe('_burn(address, uint256)', function () {
it('reverts when burning a non-existent token id', async function () {
await shouldFail.reverting(send.transaction(this.token, 'burn', 'address,uint256', [tokenOwner, tokenId]));
await shouldFail.reverting(this.token.methods['burn(address,uint256)'](tokenOwner, tokenId));
});
context('with minted token', function () {
......@@ -53,13 +50,12 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
});
it('reverts when the account is not the owner', async function () {
await shouldFail.reverting(send.transaction(this.token, 'burn', 'address,uint256', [anyone, tokenId]));
await shouldFail.reverting(this.token.methods['burn(address,uint256)'](anyone, tokenId));
});
context('with burnt token', function () {
beforeEach(async function () {
({ logs: this.logs } =
await send.transaction(this.token, 'burn', 'address,uint256', [tokenOwner, tokenId]));
({ logs: this.logs } = await this.token.methods['burn(address,uint256)'](tokenOwner, tokenId));
});
it('emits a Transfer event', function () {
......@@ -67,12 +63,12 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
});
it('deletes the token', async function () {
(await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal(0);
(await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal('0');
await shouldFail.reverting(this.token.ownerOf(tokenId));
});
it('reverts when burning a token id that has been deleted', async function () {
await shouldFail.reverting(send.transaction(this.token, 'burn', 'address,uint256', [tokenOwner, tokenId]));
await shouldFail.reverting(this.token.methods['burn(address,uint256)'](tokenOwner, tokenId));
});
});
});
......@@ -80,7 +76,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
describe('_burn(uint256)', function () {
it('reverts when burning a non-existent token id', async function () {
await shouldFail.reverting(send.transaction(this.token, 'burn', 'uint256', [tokenId]));
await shouldFail.reverting(this.token.methods['burn(uint256)'](tokenId));
});
context('with minted token', function () {
......@@ -90,7 +86,7 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
context('with burnt token', function () {
beforeEach(async function () {
({ logs: this.logs } = await send.transaction(this.token, 'burn', 'uint256', [tokenId]));
({ logs: this.logs } = await this.token.methods['burn(uint256)'](tokenId));
});
it('emits a Transfer event', function () {
......@@ -98,12 +94,12 @@ contract('ERC721', function ([_, creator, tokenOwner, anyone, ...accounts]) {
});
it('deletes the token', async function () {
(await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal(0);
(await this.token.balanceOf(tokenOwner)).should.be.bignumber.equal('0');
await shouldFail.reverting(this.token.ownerOf(tokenId));
});
it('reverts when burning a token id that has been deleted', async function () {
await shouldFail.reverting(send.transaction(this.token, 'burn', 'uint256', [tokenId]));
await shouldFail.reverting(this.token.methods['burn(uint256)'](tokenId));
});
});
});
......
require('openzeppelin-test-helpers');
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
const {
shouldBehaveLikeMintAndBurnERC721,
......@@ -5,8 +7,6 @@ const {
const ERC721BurnableImpl = artifacts.require('ERC721MintableBurnableImpl.sol');
require('../../helpers/setup');
contract('ERC721Burnable', function ([_, creator, ...accounts]) {
const minter = creator;
......
const shouldFail = require('../../helpers/shouldFail');
const { BN, shouldFail } = require('openzeppelin-test-helpers');
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
const { shouldSupportInterfaces } = require('../../introspection/SupportsInterface.behavior');
const ERC721FullMock = artifacts.require('ERC721FullMock.sol');
require('../../helpers/setup');
contract('ERC721Full', function ([
creator,
...accounts
]) {
const name = 'Non Fungible Token';
const symbol = 'NFT';
const firstTokenId = 100;
const secondTokenId = 200;
const thirdTokenId = 300;
const nonExistentTokenId = 999;
const firstTokenId = new BN(100);
const secondTokenId = new BN(200);
const thirdTokenId = new BN(300);
const nonExistentTokenId = new BN(999);
const minter = creator;
......@@ -41,11 +40,11 @@ contract('ERC721Full', function ([
});
it('adjusts owner tokens by index', async function () {
(await this.token.tokenOfOwnerByIndex(newOwner, 0)).toNumber().should.be.equal(thirdTokenId);
(await this.token.tokenOfOwnerByIndex(newOwner, 0)).should.be.bignumber.equal(thirdTokenId);
});
it('adjusts all tokens list', async function () {
(await this.token.tokenByIndex(2)).toNumber().should.be.equal(thirdTokenId);
(await this.token.tokenByIndex(2)).should.be.bignumber.equal(thirdTokenId);
});
});
......@@ -55,16 +54,16 @@ contract('ERC721Full', function ([
});
it('removes that token from the token list of the owner', async function () {
(await this.token.tokenOfOwnerByIndex(owner, 0)).toNumber().should.be.equal(secondTokenId);
(await this.token.tokenOfOwnerByIndex(owner, 0)).should.be.bignumber.equal(secondTokenId);
});
it('adjusts all tokens list', async function () {
(await this.token.tokenByIndex(0)).toNumber().should.be.equal(secondTokenId);
(await this.token.tokenByIndex(0)).should.be.bignumber.equal(secondTokenId);
});
it('burns all tokens', async function () {
await this.token.burn(secondTokenId, { from: owner });
(await this.token.totalSupply()).toNumber().should.be.equal(0);
(await this.token.totalSupply()).should.be.bignumber.equal('0');
await shouldFail.reverting(this.token.tokenByIndex(0));
});
});
......@@ -115,7 +114,7 @@ contract('ERC721Full', function ([
describe('totalSupply', function () {
it('returns total token supply', async function () {
(await this.token.totalSupply()).should.be.bignumber.equal(2);
(await this.token.totalSupply()).should.be.bignumber.equal('2');
});
});
......@@ -145,15 +144,15 @@ contract('ERC721Full', function ([
});
it('returns correct token IDs for target', async function () {
(await this.token.balanceOf(another)).toNumber().should.be.equal(2);
(await this.token.balanceOf(another)).should.be.bignumber.equal('2');
const tokensListed = await Promise.all(
[0, 1].map(i => this.token.tokenOfOwnerByIndex(another, i))
);
tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId, secondTokenId]);
tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId.toNumber(), secondTokenId.toNumber()]);
});
it('returns empty collection for original owner', async function () {
(await this.token.balanceOf(owner)).toNumber().should.be.equal(0);
(await this.token.balanceOf(owner)).should.be.bignumber.equal('0');
await shouldFail.reverting(this.token.tokenOfOwnerByIndex(owner, 0));
});
});
......@@ -164,7 +163,7 @@ contract('ERC721Full', function ([
const tokensListed = await Promise.all(
[0, 1].map(i => this.token.tokenByIndex(i))
);
tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId, secondTokenId]);
tokensListed.map(t => t.toNumber()).should.have.members([firstTokenId.toNumber(), secondTokenId.toNumber()]);
});
it('should revert if index is greater than supply', async function () {
......@@ -173,14 +172,14 @@ contract('ERC721Full', function ([
[firstTokenId, secondTokenId].forEach(function (tokenId) {
it(`should return all tokens after burning token ${tokenId} and minting new tokens`, async function () {
const newTokenId = 300;
const anotherNewTokenId = 400;
const newTokenId = new BN(300);
const anotherNewTokenId = new BN(400);
await this.token.burn(tokenId, { from: owner });
await this.token.mint(newOwner, newTokenId, { from: minter });
await this.token.mint(newOwner, anotherNewTokenId, { from: minter });
(await this.token.totalSupply()).toNumber().should.be.equal(3);
(await this.token.totalSupply()).should.be.bignumber.equal('3');
const tokensListed = await Promise.all(
[0, 1, 2].map(i => this.token.tokenByIndex(i))
......@@ -188,7 +187,7 @@ contract('ERC721Full', function ([
const expectedTokens = [firstTokenId, secondTokenId, newTokenId, anotherNewTokenId].filter(
x => (x !== tokenId)
);
tokensListed.map(t => t.toNumber()).should.have.members(expectedTokens);
tokensListed.map(t => t.toNumber()).should.have.members(expectedTokens.map(t => t.toNumber()));
});
});
});
......
const { BN } = require('openzeppelin-test-helpers');
const ERC721Holder = artifacts.require('ERC721Holder.sol');
const ERC721Mintable = artifacts.require('ERC721MintableBurnableImpl.sol');
require('../../helpers/setup');
contract('ERC721Holder', function ([creator]) {
it('receives an ERC721 token', async function () {
const token = await ERC721Mintable.new({ from: creator });
const tokenId = 1;
const tokenId = new BN(1);
await token.mint(creator, tokenId, { from: creator });
const receiver = await ERC721Holder.new();
......
const shouldFail = require('../../helpers/shouldFail');
const expectEvent = require('../../helpers/expectEvent');
const { ZERO_ADDRESS } = require('../../helpers/constants');
require('../../helpers/setup');
const { BN, constants, expectEvent, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeMintAndBurnERC721 (
creator,
minter,
[owner, newOwner, approved, anyone]
) {
const firstTokenId = 1;
const secondTokenId = 2;
const thirdTokenId = 3;
const unknownTokenId = 4;
const firstTokenId = new BN(1);
const secondTokenId = new BN(2);
const thirdTokenId = new BN(3);
const unknownTokenId = new BN(4);
const MOCK_URI = 'https://example.com';
describe('like a mintable and burnable ERC721', function () {
......@@ -34,7 +32,7 @@ function shouldBehaveLikeMintAndBurnERC721 (
});
it('increases the balance of its owner', async function () {
(await this.token.balanceOf(newOwner)).should.be.bignumber.equal(1);
(await this.token.balanceOf(newOwner)).should.be.bignumber.equal('1');
});
it('emits a transfer and minted event', async function () {
......@@ -79,7 +77,7 @@ function shouldBehaveLikeMintAndBurnERC721 (
it('burns the given token ID and adjusts the balance of the owner', async function () {
await shouldFail.reverting(this.token.ownerOf(tokenId));
(await this.token.balanceOf(owner)).should.be.bignumber.equal(1);
(await this.token.balanceOf(owner)).should.be.bignumber.equal('1');
});
it('emits a burn event', async function () {
......
require('openzeppelin-test-helpers');
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
const {
shouldBehaveLikeMintAndBurnERC721,
} = require('./ERC721MintBurn.behavior');
const { shouldBehaveLikeMintAndBurnERC721 } = require('./ERC721MintBurn.behavior');
const ERC721MintableImpl = artifacts.require('ERC721MintableBurnableImpl.sol');
require('../../helpers/setup');
contract('ERC721Mintable', function ([_, creator, ...accounts]) {
const minter = creator;
......
require('openzeppelin-test-helpers');
const { shouldBehaveLikeERC721PausedToken } = require('./ERC721PausedToken.behavior');
const { shouldBehaveLikeERC721 } = require('./ERC721.behavior');
const { shouldBehaveLikePublicRole } = require('../../access/roles/PublicRole.behavior');
const ERC721PausableMock = artifacts.require('ERC721PausableMock.sol');
require('../../helpers/setup');
contract('ERC721Pausable', function ([
_,
creator,
......
const shouldFail = require('../../helpers/shouldFail');
const send = require('../../helpers/send');
const { ZERO_ADDRESS } = require('../../helpers/constants');
require('../../helpers/setup');
const { BN, constants, shouldFail } = require('openzeppelin-test-helpers');
const { ZERO_ADDRESS } = constants;
function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
const firstTokenId = 1;
const mintedTokens = 1;
const firstTokenId = new BN(1);
const mintedTokens = new BN(1);
const mockData = '0x42';
describe('like a paused ERC721', function () {
......@@ -31,14 +28,8 @@ function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
});
it('reverts when trying to safeTransferFrom with data', async function () {
await shouldFail.reverting(
send.transaction(
this.token,
'safeTransferFrom',
'address,address,uint256,bytes',
[owner, recipient, firstTokenId, mockData],
{ from: owner }
)
await shouldFail.reverting(this.token.methods['safeTransferFrom(address,address,uint256,bytes)'](
owner, recipient, firstTokenId, mockData, { from: owner })
);
});
......@@ -65,15 +56,13 @@ function shouldBehaveLikeERC721PausedToken (owner, [recipient, operator]) {
describe('exists', function () {
it('should return token existance', async function () {
const result = await this.token.exists(firstTokenId);
result.should.eq(true);
(await this.token.exists(firstTokenId)).should.equal(true);
});
});
describe('isApprovedForAll', function () {
it('returns the approval of the operator', async function () {
const isApproved = await this.token.isApprovedForAll(owner, operator);
isApproved.should.eq(false);
(await this.token.isApprovedForAll(owner, operator)).should.equal(false);
});
});
});
......
require('openzeppelin-test-helpers');
const AddressImpl = artifacts.require('AddressImpl');
const SimpleToken = artifacts.require('SimpleToken');
require('../helpers/setup');
contract('Address', function ([_, anyone]) {
beforeEach(async function () {
this.mock = await AddressImpl.new();
......
const ArraysImpl = artifacts.require('ArraysImpl');
require('openzeppelin-test-helpers');
require('../helpers/setup');
const ArraysImpl = artifacts.require('ArraysImpl');
contract('Arrays', function () {
context('Even number of elements', function () {
......@@ -11,23 +11,23 @@ contract('Arrays', function () {
});
it('should return correct index for the basic case', async function () {
(await this.arrays.findUpperBound(16)).should.be.bignumber.equal(5);
(await this.arrays.findUpperBound(16)).should.be.bignumber.equal('5');
});
it('should return 0 for the first element', async function () {
(await this.arrays.findUpperBound(11)).should.be.bignumber.equal(0);
(await this.arrays.findUpperBound(11)).should.be.bignumber.equal('0');
});
it('should return index of the last element', async function () {
(await this.arrays.findUpperBound(20)).should.be.bignumber.equal(9);
(await this.arrays.findUpperBound(20)).should.be.bignumber.equal('9');
});
it('should return first index after last element if searched value is over the upper boundary', async function () {
(await this.arrays.findUpperBound(32)).should.be.bignumber.equal(10);
(await this.arrays.findUpperBound(32)).should.be.bignumber.equal('10');
});
it('should return 0 for the element under the lower boundary', async function () {
(await this.arrays.findUpperBound(2)).should.be.bignumber.equal(0);
(await this.arrays.findUpperBound(2)).should.be.bignumber.equal('0');
});
});
......@@ -39,23 +39,23 @@ contract('Arrays', function () {
});
it('should return correct index for the basic case', async function () {
(await this.arrays.findUpperBound(16)).should.be.bignumber.equal(5);
(await this.arrays.findUpperBound(16)).should.be.bignumber.equal('5');
});
it('should return 0 for the first element', async function () {
(await this.arrays.findUpperBound(11)).should.be.bignumber.equal(0);
(await this.arrays.findUpperBound(11)).should.be.bignumber.equal('0');
});
it('should return index of the last element', async function () {
(await this.arrays.findUpperBound(21)).should.be.bignumber.equal(10);
(await this.arrays.findUpperBound(21)).should.be.bignumber.equal('10');
});
it('should return first index after last element if searched value is over the upper boundary', async function () {
(await this.arrays.findUpperBound(32)).should.be.bignumber.equal(11);
(await this.arrays.findUpperBound(32)).should.be.bignumber.equal('11');
});
it('should return 0 for the element under the lower boundary', async function () {
(await this.arrays.findUpperBound(2)).should.be.bignumber.equal(0);
(await this.arrays.findUpperBound(2)).should.be.bignumber.equal('0');
});
});
......@@ -67,7 +67,7 @@ contract('Arrays', function () {
});
it('should return index of first element in next filled range', async function () {
(await this.arrays.findUpperBound(17)).should.be.bignumber.equal(5);
(await this.arrays.findUpperBound(17)).should.be.bignumber.equal('5');
});
});
......@@ -77,7 +77,7 @@ contract('Arrays', function () {
});
it('should always return 0 for empty array', async function () {
(await this.arrays.findUpperBound(10)).should.be.bignumber.equal(0);
(await this.arrays.findUpperBound(10)).should.be.bignumber.equal('0');
});
});
});
const shouldFail = require('../helpers/shouldFail');
const { shouldFail } = require('openzeppelin-test-helpers');
const ReentrancyMock = artifacts.require('ReentrancyMock');
const ReentrancyAttack = artifacts.require('ReentrancyAttack');
require('../helpers/setup');
contract('ReentrancyGuard', function () {
beforeEach(async function () {
this.reentrancyMock = await ReentrancyMock.new();
(await this.reentrancyMock.counter()).should.be.bignumber.equal(0);
(await this.reentrancyMock.counter()).should.be.bignumber.equal('0');
});
it('should not allow remote callback', async function () {
......
......@@ -13,4 +13,10 @@ module.exports = {
gasPrice: 0x01,
},
},
compilers: {
solc: {
version: '0.5.0',
},
},
};
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