Use hardhat-exposed to reduce the need for mocks (#3666)

Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
Hadrien Croubois
2023-01-03 15:38:13 +01:00
committed by GitHub
parent a81b0d0b21
commit c1d9da4052
190 changed files with 2297 additions and 4311 deletions

View File

@ -3,11 +3,11 @@ const { MAX_INT256, MIN_INT256 } = constants;
const { expect } = require('chai');
const SignedSafeMathMock = artifacts.require('SignedSafeMathMock');
const SignedSafeMath = artifacts.require('$SignedSafeMath');
contract('SignedSafeMath', function () {
beforeEach(async function () {
this.safeMath = await SignedSafeMathMock.new();
this.safeMath = await SignedSafeMath.new();
});
async function testCommutative (fn, lhs, rhs, expected) {
@ -25,28 +25,28 @@ contract('SignedSafeMath', function () {
const a = new BN('1234');
const b = new BN('5678');
await testCommutative(this.safeMath.add, a, b, a.add(b));
await testCommutative(this.safeMath.$add, a, b, a.add(b));
});
it('adds correctly if it does not overflow and the result is negative', async function () {
const a = MAX_INT256;
const b = MIN_INT256;
await testCommutative(this.safeMath.add, a, b, a.add(b));
await testCommutative(this.safeMath.$add, a, b, a.add(b));
});
it('reverts on positive addition overflow', async function () {
const a = MAX_INT256;
const b = new BN('1');
await testFailsCommutative(this.safeMath.add, a, b);
await testFailsCommutative(this.safeMath.$add, a, b);
});
it('reverts on negative addition overflow', async function () {
const a = MIN_INT256;
const b = new BN('-1');
await testFailsCommutative(this.safeMath.add, a, b);
await testFailsCommutative(this.safeMath.$add, a, b);
});
});
@ -55,7 +55,7 @@ contract('SignedSafeMath', function () {
const a = new BN('5678');
const b = new BN('1234');
const result = await this.safeMath.sub(a, b);
const result = await this.safeMath.$sub(a, b);
expect(result).to.be.bignumber.equal(a.sub(b));
});
@ -63,7 +63,7 @@ contract('SignedSafeMath', function () {
const a = new BN('1234');
const b = new BN('5678');
const result = await this.safeMath.sub(a, b);
const result = await this.safeMath.$sub(a, b);
expect(result).to.be.bignumber.equal(a.sub(b));
});
@ -71,14 +71,14 @@ contract('SignedSafeMath', function () {
const a = MAX_INT256;
const b = new BN('-1');
await expectRevert.unspecified(this.safeMath.sub(a, b));
await expectRevert.unspecified(this.safeMath.$sub(a, b));
});
it('reverts on negative subtraction overflow', async function () {
const a = MIN_INT256;
const b = new BN('1');
await expectRevert.unspecified(this.safeMath.sub(a, b));
await expectRevert.unspecified(this.safeMath.$sub(a, b));
});
});
@ -87,28 +87,28 @@ contract('SignedSafeMath', function () {
const a = new BN('5678');
const b = new BN('-1234');
await testCommutative(this.safeMath.mul, a, b, a.mul(b));
await testCommutative(this.safeMath.$mul, a, b, a.mul(b));
});
it('multiplies by zero correctly', async function () {
const a = new BN('0');
const b = new BN('5678');
await testCommutative(this.safeMath.mul, a, b, '0');
await testCommutative(this.safeMath.$mul, a, b, '0');
});
it('reverts on multiplication overflow, positive operands', async function () {
const a = MAX_INT256;
const b = new BN('2');
await testFailsCommutative(this.safeMath.mul, a, b);
await testFailsCommutative(this.safeMath.$mul, a, b);
});
it('reverts when minimum integer is multiplied by -1', async function () {
const a = MIN_INT256;
const b = new BN('-1');
await testFailsCommutative(this.safeMath.mul, a, b);
await testFailsCommutative(this.safeMath.$mul, a, b);
});
});
@ -117,7 +117,7 @@ contract('SignedSafeMath', function () {
const a = new BN('-5678');
const b = new BN('5678');
const result = await this.safeMath.div(a, b);
const result = await this.safeMath.$div(a, b);
expect(result).to.be.bignumber.equal(a.div(b));
});
@ -125,28 +125,28 @@ contract('SignedSafeMath', function () {
const a = new BN('0');
const b = new BN('5678');
expect(await this.safeMath.div(a, b)).to.be.bignumber.equal('0');
expect(await this.safeMath.$div(a, b)).to.be.bignumber.equal('0');
});
it('returns complete number result on non-even division', async function () {
const a = new BN('7000');
const b = new BN('5678');
expect(await this.safeMath.div(a, b)).to.be.bignumber.equal('1');
expect(await this.safeMath.$div(a, b)).to.be.bignumber.equal('1');
});
it('reverts on division by zero', async function () {
const a = new BN('-5678');
const b = new BN('0');
await expectRevert.unspecified(this.safeMath.div(a, b));
await expectRevert.unspecified(this.safeMath.$div(a, b));
});
it('reverts on overflow, negative second', async function () {
const a = new BN(MIN_INT256);
const b = new BN('-1');
await expectRevert.unspecified(this.safeMath.div(a, b));
await expectRevert.unspecified(this.safeMath.$div(a, b));
});
});
});