Files
openzeppelin-contracts/test/drafts/Counters.test.js
Balaji Pachai 3682c6575c Added message string for require() (#1704)
* Error handling in ERC20 and ERC721

* Added message string for require.

* Fixed solhint errors.

* Updated PR as per issue #1709

* changes as per #1709 and openzeppelin forum.

* Changes in require statement

* Changes in require statement

* build pipeline fix

* Changes as per @nventuro's comment.

* Update revert reason strings.

* Fianal update of revert reason strings.

* WIP: Updating reason strings in test cases

* WIP: Added changes to ERC20 and ERC721

* Fixes linting errors in *.tes.js files

* Achieved 100% code coverage

* Updated the test cases with shouldFail.reverting.withMessage()

* Fix package-lock.

* address review comments

* fix linter issues

* fix remaining revert reasons
2019-04-24 11:17:08 -03:00

59 lines
1.8 KiB
JavaScript

const { shouldFail } = require('openzeppelin-test-helpers');
const CountersImpl = artifacts.require('CountersImpl');
contract('Counters', function () {
beforeEach(async function () {
this.counter = await CountersImpl.new();
});
it('starts at zero', async function () {
(await this.counter.current()).should.be.bignumber.equal('0');
});
describe('increment', function () {
it('increments the current value by one', async function () {
await this.counter.increment();
(await this.counter.current()).should.be.bignumber.equal('1');
});
it('can be called multiple times', async function () {
await this.counter.increment();
await this.counter.increment();
await this.counter.increment();
(await this.counter.current()).should.be.bignumber.equal('3');
});
});
describe('decrement', function () {
beforeEach(async function () {
await this.counter.increment();
(await this.counter.current()).should.be.bignumber.equal('1');
});
it('decrements the current value by one', async function () {
await this.counter.decrement();
(await this.counter.current()).should.be.bignumber.equal('0');
});
it('reverts if the current value is 0', async function () {
await this.counter.decrement();
await shouldFail.reverting.withMessage(this.counter.decrement(), 'SafeMath: subtraction overflow');
});
it('can be called multiple times', async function () {
await this.counter.increment();
await this.counter.increment();
(await this.counter.current()).should.be.bignumber.equal('3');
await this.counter.decrement();
await this.counter.decrement();
await this.counter.decrement();
(await this.counter.current()).should.be.bignumber.equal('0');
});
});
});