Files
openzeppelin-contracts/test/drafts/Counters.test.js
Nicolás Venturo 07603d5875 Remove unnecessary SafeMath call (#1610)
* Refactor Counter to support increment and decrement.

* Move Counter out of drafts.

* Refactor ERC721 to use Counter.

* Rollback Counter returning the current value in increment and decrement.

* Update test/drafts/Counter.test.js

Co-Authored-By: nventuro <nicolas.venturo@gmail.com>

* Improve Counter documentation.

* Move Counter.test to utils.

* Move back Counter to drafts.
2019-01-21 17:24:51 -03:00

59 lines
1.7 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(this.counter.decrement());
});
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');
});
});
});