Use hardhat-exposed to reduce the need for mocks (#3666)
Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
@ -2,62 +2,62 @@ const { expectRevert } = require('@openzeppelin/test-helpers');
|
||||
|
||||
const { expect } = require('chai');
|
||||
|
||||
const CountersImpl = artifacts.require('CountersImpl');
|
||||
const Counters = artifacts.require('$Counters');
|
||||
|
||||
contract('Counters', function () {
|
||||
beforeEach(async function () {
|
||||
this.counter = await CountersImpl.new();
|
||||
this.counter = await Counters.new();
|
||||
});
|
||||
|
||||
it('starts at zero', async function () {
|
||||
expect(await this.counter.current()).to.be.bignumber.equal('0');
|
||||
expect(await this.counter.$current(0)).to.be.bignumber.equal('0');
|
||||
});
|
||||
|
||||
describe('increment', function () {
|
||||
context('starting from 0', function () {
|
||||
it('increments the current value by one', async function () {
|
||||
await this.counter.increment();
|
||||
expect(await this.counter.current()).to.be.bignumber.equal('1');
|
||||
await this.counter.$increment(0);
|
||||
expect(await this.counter.$current(0)).to.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.$increment(0);
|
||||
await this.counter.$increment(0);
|
||||
await this.counter.$increment(0);
|
||||
|
||||
expect(await this.counter.current()).to.be.bignumber.equal('3');
|
||||
expect(await this.counter.$current(0)).to.be.bignumber.equal('3');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('decrement', function () {
|
||||
beforeEach(async function () {
|
||||
await this.counter.increment();
|
||||
expect(await this.counter.current()).to.be.bignumber.equal('1');
|
||||
await this.counter.$increment(0);
|
||||
expect(await this.counter.$current(0)).to.be.bignumber.equal('1');
|
||||
});
|
||||
context('starting from 1', function () {
|
||||
it('decrements the current value by one', async function () {
|
||||
await this.counter.decrement();
|
||||
expect(await this.counter.current()).to.be.bignumber.equal('0');
|
||||
await this.counter.$decrement(0);
|
||||
expect(await this.counter.$current(0)).to.be.bignumber.equal('0');
|
||||
});
|
||||
|
||||
it('reverts if the current value is 0', async function () {
|
||||
await this.counter.decrement();
|
||||
await expectRevert(this.counter.decrement(), 'Counter: decrement overflow');
|
||||
await this.counter.$decrement(0);
|
||||
await expectRevert(this.counter.$decrement(0), 'Counter: decrement overflow');
|
||||
});
|
||||
});
|
||||
context('after incremented to 3', function () {
|
||||
it('can be called multiple times', async function () {
|
||||
await this.counter.increment();
|
||||
await this.counter.increment();
|
||||
await this.counter.$increment(0);
|
||||
await this.counter.$increment(0);
|
||||
|
||||
expect(await this.counter.current()).to.be.bignumber.equal('3');
|
||||
expect(await this.counter.$current(0)).to.be.bignumber.equal('3');
|
||||
|
||||
await this.counter.decrement();
|
||||
await this.counter.decrement();
|
||||
await this.counter.decrement();
|
||||
await this.counter.$decrement(0);
|
||||
await this.counter.$decrement(0);
|
||||
await this.counter.$decrement(0);
|
||||
|
||||
expect(await this.counter.current()).to.be.bignumber.equal('0');
|
||||
expect(await this.counter.$current(0)).to.be.bignumber.equal('0');
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -65,19 +65,19 @@ contract('Counters', function () {
|
||||
describe('reset', function () {
|
||||
context('null counter', function () {
|
||||
it('does not throw', async function () {
|
||||
await this.counter.reset();
|
||||
expect(await this.counter.current()).to.be.bignumber.equal('0');
|
||||
await this.counter.$reset(0);
|
||||
expect(await this.counter.$current(0)).to.be.bignumber.equal('0');
|
||||
});
|
||||
});
|
||||
|
||||
context('non null counter', function () {
|
||||
beforeEach(async function () {
|
||||
await this.counter.increment();
|
||||
expect(await this.counter.current()).to.be.bignumber.equal('1');
|
||||
await this.counter.$increment(0);
|
||||
expect(await this.counter.$current(0)).to.be.bignumber.equal('1');
|
||||
});
|
||||
it('reset to 0', async function () {
|
||||
await this.counter.reset();
|
||||
expect(await this.counter.current()).to.be.bignumber.equal('0');
|
||||
await this.counter.$reset(0);
|
||||
expect(await this.counter.$current(0)).to.be.bignumber.equal('0');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user