Use Prettier for JS files (#3913)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -36,7 +36,7 @@ contract('Math', function () {
|
||||
});
|
||||
|
||||
describe('average', function () {
|
||||
function bnAverage (a, b) {
|
||||
function bnAverage(a, b) {
|
||||
return a.add(b).divn(2);
|
||||
}
|
||||
|
||||
@ -101,40 +101,25 @@ contract('Math', function () {
|
||||
});
|
||||
|
||||
it('large values', async function () {
|
||||
expect(await this.math.$mulDiv(
|
||||
new BN('42'),
|
||||
MAX_UINT256_SUB1,
|
||||
MAX_UINT256,
|
||||
Rounding.Down,
|
||||
)).to.be.bignumber.equal(new BN('41'));
|
||||
expect(
|
||||
await this.math.$mulDiv(new BN('42'), MAX_UINT256_SUB1, MAX_UINT256, Rounding.Down),
|
||||
).to.be.bignumber.equal(new BN('41'));
|
||||
|
||||
expect(await this.math.$mulDiv(
|
||||
expect(await this.math.$mulDiv(new BN('17'), MAX_UINT256, MAX_UINT256, Rounding.Down)).to.be.bignumber.equal(
|
||||
new BN('17'),
|
||||
MAX_UINT256,
|
||||
MAX_UINT256,
|
||||
Rounding.Down,
|
||||
)).to.be.bignumber.equal(new BN('17'));
|
||||
);
|
||||
|
||||
expect(await this.math.$mulDiv(
|
||||
MAX_UINT256_SUB1,
|
||||
MAX_UINT256_SUB1,
|
||||
MAX_UINT256,
|
||||
Rounding.Down,
|
||||
)).to.be.bignumber.equal(MAX_UINT256_SUB2);
|
||||
expect(
|
||||
await this.math.$mulDiv(MAX_UINT256_SUB1, MAX_UINT256_SUB1, MAX_UINT256, Rounding.Down),
|
||||
).to.be.bignumber.equal(MAX_UINT256_SUB2);
|
||||
|
||||
expect(await this.math.$mulDiv(
|
||||
MAX_UINT256,
|
||||
MAX_UINT256_SUB1,
|
||||
MAX_UINT256,
|
||||
Rounding.Down,
|
||||
)).to.be.bignumber.equal(MAX_UINT256_SUB1);
|
||||
expect(
|
||||
await this.math.$mulDiv(MAX_UINT256, MAX_UINT256_SUB1, MAX_UINT256, Rounding.Down),
|
||||
).to.be.bignumber.equal(MAX_UINT256_SUB1);
|
||||
|
||||
expect(await this.math.$mulDiv(
|
||||
expect(await this.math.$mulDiv(MAX_UINT256, MAX_UINT256, MAX_UINT256, Rounding.Down)).to.be.bignumber.equal(
|
||||
MAX_UINT256,
|
||||
MAX_UINT256,
|
||||
MAX_UINT256,
|
||||
Rounding.Down,
|
||||
)).to.be.bignumber.equal(MAX_UINT256);
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -145,40 +130,25 @@ contract('Math', function () {
|
||||
});
|
||||
|
||||
it('large values', async function () {
|
||||
expect(await this.math.$mulDiv(
|
||||
expect(await this.math.$mulDiv(new BN('42'), MAX_UINT256_SUB1, MAX_UINT256, Rounding.Up)).to.be.bignumber.equal(
|
||||
new BN('42'),
|
||||
MAX_UINT256_SUB1,
|
||||
MAX_UINT256,
|
||||
Rounding.Up,
|
||||
)).to.be.bignumber.equal(new BN('42'));
|
||||
);
|
||||
|
||||
expect(await this.math.$mulDiv(
|
||||
expect(await this.math.$mulDiv(new BN('17'), MAX_UINT256, MAX_UINT256, Rounding.Up)).to.be.bignumber.equal(
|
||||
new BN('17'),
|
||||
MAX_UINT256,
|
||||
MAX_UINT256,
|
||||
Rounding.Up,
|
||||
)).to.be.bignumber.equal(new BN('17'));
|
||||
);
|
||||
|
||||
expect(await this.math.$mulDiv(
|
||||
MAX_UINT256_SUB1,
|
||||
MAX_UINT256_SUB1,
|
||||
MAX_UINT256,
|
||||
Rounding.Up,
|
||||
)).to.be.bignumber.equal(MAX_UINT256_SUB1);
|
||||
expect(
|
||||
await this.math.$mulDiv(MAX_UINT256_SUB1, MAX_UINT256_SUB1, MAX_UINT256, Rounding.Up),
|
||||
).to.be.bignumber.equal(MAX_UINT256_SUB1);
|
||||
|
||||
expect(await this.math.$mulDiv(
|
||||
MAX_UINT256,
|
||||
expect(await this.math.$mulDiv(MAX_UINT256, MAX_UINT256_SUB1, MAX_UINT256, Rounding.Up)).to.be.bignumber.equal(
|
||||
MAX_UINT256_SUB1,
|
||||
MAX_UINT256,
|
||||
Rounding.Up,
|
||||
)).to.be.bignumber.equal(MAX_UINT256_SUB1);
|
||||
);
|
||||
|
||||
expect(await this.math.$mulDiv(
|
||||
expect(await this.math.$mulDiv(MAX_UINT256, MAX_UINT256, MAX_UINT256, Rounding.Up)).to.be.bignumber.equal(
|
||||
MAX_UINT256,
|
||||
MAX_UINT256,
|
||||
MAX_UINT256,
|
||||
Rounding.Up,
|
||||
)).to.be.bignumber.equal(MAX_UINT256);
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -196,8 +166,9 @@ contract('Math', function () {
|
||||
expect(await this.math.$sqrt('1000001', Rounding.Down)).to.be.bignumber.equal('1000');
|
||||
expect(await this.math.$sqrt('1002000', Rounding.Down)).to.be.bignumber.equal('1000');
|
||||
expect(await this.math.$sqrt('1002001', Rounding.Down)).to.be.bignumber.equal('1001');
|
||||
expect(await this.math.$sqrt(MAX_UINT256, Rounding.Down))
|
||||
.to.be.bignumber.equal('340282366920938463463374607431768211455');
|
||||
expect(await this.math.$sqrt(MAX_UINT256, Rounding.Down)).to.be.bignumber.equal(
|
||||
'340282366920938463463374607431768211455',
|
||||
);
|
||||
});
|
||||
|
||||
it('rounds up', async function () {
|
||||
@ -212,8 +183,9 @@ contract('Math', function () {
|
||||
expect(await this.math.$sqrt('1000001', Rounding.Up)).to.be.bignumber.equal('1001');
|
||||
expect(await this.math.$sqrt('1002000', Rounding.Up)).to.be.bignumber.equal('1001');
|
||||
expect(await this.math.$sqrt('1002001', Rounding.Up)).to.be.bignumber.equal('1001');
|
||||
expect(await this.math.$sqrt(MAX_UINT256, Rounding.Up))
|
||||
.to.be.bignumber.equal('340282366920938463463374607431768211456');
|
||||
expect(await this.math.$sqrt(MAX_UINT256, Rounding.Up)).to.be.bignumber.equal(
|
||||
'340282366920938463463374607431768211456',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -231,8 +203,9 @@ contract('Math', function () {
|
||||
expect(await this.math.methods['$log2(uint256,uint8)']('7', Rounding.Down)).to.be.bignumber.equal('2');
|
||||
expect(await this.math.methods['$log2(uint256,uint8)']('8', Rounding.Down)).to.be.bignumber.equal('3');
|
||||
expect(await this.math.methods['$log2(uint256,uint8)']('9', Rounding.Down)).to.be.bignumber.equal('3');
|
||||
expect(await this.math.methods['$log2(uint256,uint8)'](MAX_UINT256, Rounding.Down))
|
||||
.to.be.bignumber.equal('255');
|
||||
expect(await this.math.methods['$log2(uint256,uint8)'](MAX_UINT256, Rounding.Down)).to.be.bignumber.equal(
|
||||
'255',
|
||||
);
|
||||
});
|
||||
|
||||
it('rounds up', async function () {
|
||||
@ -247,8 +220,7 @@ contract('Math', function () {
|
||||
expect(await this.math.methods['$log2(uint256,uint8)']('7', Rounding.Up)).to.be.bignumber.equal('3');
|
||||
expect(await this.math.methods['$log2(uint256,uint8)']('8', Rounding.Up)).to.be.bignumber.equal('3');
|
||||
expect(await this.math.methods['$log2(uint256,uint8)']('9', Rounding.Up)).to.be.bignumber.equal('4');
|
||||
expect(await this.math.methods['$log2(uint256,uint8)'](MAX_UINT256, Rounding.Up))
|
||||
.to.be.bignumber.equal('256');
|
||||
expect(await this.math.methods['$log2(uint256,uint8)'](MAX_UINT256, Rounding.Up)).to.be.bignumber.equal('256');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ contract('SafeCast', async function () {
|
||||
this.safeCast = await SafeCast.new();
|
||||
});
|
||||
|
||||
function testToUint (bits) {
|
||||
function testToUint(bits) {
|
||||
describe(`toUint${bits}`, () => {
|
||||
const maxValue = new BN('2').pow(new BN(bits)).subn(1);
|
||||
|
||||
@ -60,21 +60,15 @@ contract('SafeCast', async function () {
|
||||
});
|
||||
|
||||
it('reverts when casting -1', async function () {
|
||||
await expectRevert(
|
||||
this.safeCast.$toUint256(-1),
|
||||
'SafeCast: value must be positive',
|
||||
);
|
||||
await expectRevert(this.safeCast.$toUint256(-1), 'SafeCast: value must be positive');
|
||||
});
|
||||
|
||||
it(`reverts when casting INT256_MIN (${minInt256})`, async function () {
|
||||
await expectRevert(
|
||||
this.safeCast.$toUint256(minInt256),
|
||||
'SafeCast: value must be positive',
|
||||
);
|
||||
await expectRevert(this.safeCast.$toUint256(minInt256), 'SafeCast: value must be positive');
|
||||
});
|
||||
});
|
||||
|
||||
function testToInt (bits) {
|
||||
function testToInt(bits) {
|
||||
describe(`toInt${bits}`, () => {
|
||||
const minValue = new BN('-2').pow(new BN(bits - 1));
|
||||
const maxValue = new BN('2').pow(new BN(bits - 1)).subn(1);
|
||||
@ -148,17 +142,11 @@ contract('SafeCast', async function () {
|
||||
});
|
||||
|
||||
it(`reverts when casting INT256_MAX + 1 (${maxInt256.addn(1)})`, async function () {
|
||||
await expectRevert(
|
||||
this.safeCast.$toInt256(maxInt256.addn(1)),
|
||||
'SafeCast: value doesn\'t fit in an int256',
|
||||
);
|
||||
await expectRevert(this.safeCast.$toInt256(maxInt256.addn(1)), "SafeCast: value doesn't fit in an int256");
|
||||
});
|
||||
|
||||
it(`reverts when casting UINT256_MAX (${maxUint256})`, async function () {
|
||||
await expectRevert(
|
||||
this.safeCast.$toInt256(maxUint256),
|
||||
'SafeCast: value doesn\'t fit in an int256',
|
||||
);
|
||||
await expectRevert(this.safeCast.$toInt256(maxUint256), "SafeCast: value doesn't fit in an int256");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -6,7 +6,7 @@ const { expect } = require('chai');
|
||||
const SafeMath = artifacts.require('$SafeMath');
|
||||
const SafeMathMemoryCheck = artifacts.require('$SafeMathMemoryCheck');
|
||||
|
||||
function expectStruct (value, expected) {
|
||||
function expectStruct(value, expected) {
|
||||
for (const key in expected) {
|
||||
if (BN.isBN(value[key])) {
|
||||
expect(value[key]).to.be.bignumber.equal(expected[key]);
|
||||
@ -21,12 +21,12 @@ contract('SafeMath', function () {
|
||||
this.safeMath = await SafeMath.new();
|
||||
});
|
||||
|
||||
async function testCommutative (fn, lhs, rhs, expected, ...extra) {
|
||||
async function testCommutative(fn, lhs, rhs, expected, ...extra) {
|
||||
expect(await fn(lhs, rhs, ...extra)).to.be.bignumber.equal(expected);
|
||||
expect(await fn(rhs, lhs, ...extra)).to.be.bignumber.equal(expected);
|
||||
}
|
||||
|
||||
async function testFailsCommutative (fn, lhs, rhs, reason, ...extra) {
|
||||
async function testFailsCommutative(fn, lhs, rhs, reason, ...extra) {
|
||||
if (reason === undefined) {
|
||||
await expectRevert.unspecified(fn(lhs, rhs, ...extra));
|
||||
await expectRevert.unspecified(fn(rhs, lhs, ...extra));
|
||||
@ -36,7 +36,7 @@ contract('SafeMath', function () {
|
||||
}
|
||||
}
|
||||
|
||||
async function testCommutativeIterable (fn, lhs, rhs, expected, ...extra) {
|
||||
async function testCommutativeIterable(fn, lhs, rhs, expected, ...extra) {
|
||||
expectStruct(await fn(lhs, rhs, ...extra), expected);
|
||||
expectStruct(await fn(rhs, lhs, ...extra), expected);
|
||||
}
|
||||
@ -47,14 +47,14 @@ contract('SafeMath', function () {
|
||||
const a = new BN('5678');
|
||||
const b = new BN('1234');
|
||||
|
||||
testCommutativeIterable(this.safeMath.$tryAdd, a, b, [ true, a.add(b) ]);
|
||||
testCommutativeIterable(this.safeMath.$tryAdd, a, b, [true, a.add(b)]);
|
||||
});
|
||||
|
||||
it('reverts on addition overflow', async function () {
|
||||
const a = MAX_UINT256;
|
||||
const b = new BN('1');
|
||||
|
||||
testCommutativeIterable(this.safeMath.$tryAdd, a, b, [ false, '0' ]);
|
||||
testCommutativeIterable(this.safeMath.$tryAdd, a, b, [false, '0']);
|
||||
});
|
||||
});
|
||||
|
||||
@ -63,14 +63,14 @@ contract('SafeMath', function () {
|
||||
const a = new BN('5678');
|
||||
const b = new BN('1234');
|
||||
|
||||
expectStruct(await this.safeMath.$trySub(a, b), [ true, a.sub(b) ]);
|
||||
expectStruct(await this.safeMath.$trySub(a, b), [true, a.sub(b)]);
|
||||
});
|
||||
|
||||
it('reverts if subtraction result would be negative', async function () {
|
||||
const a = new BN('1234');
|
||||
const b = new BN('5678');
|
||||
|
||||
expectStruct(await this.safeMath.$trySub(a, b), [ false, '0' ]);
|
||||
expectStruct(await this.safeMath.$trySub(a, b), [false, '0']);
|
||||
});
|
||||
});
|
||||
|
||||
@ -79,21 +79,21 @@ contract('SafeMath', function () {
|
||||
const a = new BN('1234');
|
||||
const b = new BN('5678');
|
||||
|
||||
testCommutativeIterable(this.safeMath.$tryMul, a, b, [ true, a.mul(b) ]);
|
||||
testCommutativeIterable(this.safeMath.$tryMul, a, b, [true, a.mul(b)]);
|
||||
});
|
||||
|
||||
it('multiplies by zero correctly', async function () {
|
||||
const a = new BN('0');
|
||||
const b = new BN('5678');
|
||||
|
||||
testCommutativeIterable(this.safeMath.$tryMul, a, b, [ true, a.mul(b) ]);
|
||||
testCommutativeIterable(this.safeMath.$tryMul, a, b, [true, a.mul(b)]);
|
||||
});
|
||||
|
||||
it('reverts on multiplication overflow', async function () {
|
||||
const a = MAX_UINT256;
|
||||
const b = new BN('2');
|
||||
|
||||
testCommutativeIterable(this.safeMath.$tryMul, a, b, [ false, '0' ]);
|
||||
testCommutativeIterable(this.safeMath.$tryMul, a, b, [false, '0']);
|
||||
});
|
||||
});
|
||||
|
||||
@ -102,28 +102,28 @@ contract('SafeMath', function () {
|
||||
const a = new BN('5678');
|
||||
const b = new BN('5678');
|
||||
|
||||
expectStruct(await this.safeMath.$tryDiv(a, b), [ true, a.div(b) ]);
|
||||
expectStruct(await this.safeMath.$tryDiv(a, b), [true, a.div(b)]);
|
||||
});
|
||||
|
||||
it('divides zero correctly', async function () {
|
||||
const a = new BN('0');
|
||||
const b = new BN('5678');
|
||||
|
||||
expectStruct(await this.safeMath.$tryDiv(a, b), [ true, a.div(b) ]);
|
||||
expectStruct(await this.safeMath.$tryDiv(a, b), [true, a.div(b)]);
|
||||
});
|
||||
|
||||
it('returns complete number result on non-even division', async function () {
|
||||
const a = new BN('7000');
|
||||
const b = new BN('5678');
|
||||
|
||||
expectStruct(await this.safeMath.$tryDiv(a, b), [ true, a.div(b) ]);
|
||||
expectStruct(await this.safeMath.$tryDiv(a, b), [true, a.div(b)]);
|
||||
});
|
||||
|
||||
it('reverts on division by zero', async function () {
|
||||
const a = new BN('5678');
|
||||
const b = new BN('0');
|
||||
|
||||
expectStruct(await this.safeMath.$tryDiv(a, b), [ false, '0' ]);
|
||||
expectStruct(await this.safeMath.$tryDiv(a, b), [false, '0']);
|
||||
});
|
||||
});
|
||||
|
||||
@ -133,28 +133,28 @@ contract('SafeMath', function () {
|
||||
const a = new BN('284');
|
||||
const b = new BN('5678');
|
||||
|
||||
expectStruct(await this.safeMath.$tryMod(a, b), [ true, a.mod(b) ]);
|
||||
expectStruct(await this.safeMath.$tryMod(a, b), [true, a.mod(b)]);
|
||||
});
|
||||
|
||||
it('when the dividend is equal to the divisor', async function () {
|
||||
const a = new BN('5678');
|
||||
const b = new BN('5678');
|
||||
|
||||
expectStruct(await this.safeMath.$tryMod(a, b), [ true, a.mod(b) ]);
|
||||
expectStruct(await this.safeMath.$tryMod(a, b), [true, a.mod(b)]);
|
||||
});
|
||||
|
||||
it('when the dividend is larger than the divisor', async function () {
|
||||
const a = new BN('7000');
|
||||
const b = new BN('5678');
|
||||
|
||||
expectStruct(await this.safeMath.$tryMod(a, b), [ true, a.mod(b) ]);
|
||||
expectStruct(await this.safeMath.$tryMod(a, b), [true, a.mod(b)]);
|
||||
});
|
||||
|
||||
it('when the dividend is a multiple of the divisor', async function () {
|
||||
const a = new BN('17034'); // 17034 == 5678 * 3
|
||||
const b = new BN('5678');
|
||||
|
||||
expectStruct(await this.safeMath.$tryMod(a, b), [ true, a.mod(b) ]);
|
||||
expectStruct(await this.safeMath.$tryMod(a, b), [true, a.mod(b)]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -162,7 +162,7 @@ contract('SafeMath', function () {
|
||||
const a = new BN('5678');
|
||||
const b = new BN('0');
|
||||
|
||||
expectStruct(await this.safeMath.$tryMod(a, b), [ false, '0' ]);
|
||||
expectStruct(await this.safeMath.$tryMod(a, b), [false, '0']);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -299,8 +299,9 @@ contract('SafeMath', function () {
|
||||
const a = new BN('5678');
|
||||
const b = new BN('1234');
|
||||
|
||||
expect(await this.safeMath.methods['$sub(uint256,uint256,string)'](a, b, 'MyErrorMessage'))
|
||||
.to.be.bignumber.equal(a.sub(b));
|
||||
expect(
|
||||
await this.safeMath.methods['$sub(uint256,uint256,string)'](a, b, 'MyErrorMessage'),
|
||||
).to.be.bignumber.equal(a.sub(b));
|
||||
});
|
||||
|
||||
it('reverts if subtraction result would be negative', async function () {
|
||||
@ -319,24 +320,27 @@ contract('SafeMath', function () {
|
||||
const a = new BN('5678');
|
||||
const b = new BN('5678');
|
||||
|
||||
expect(await this.safeMath.methods['$div(uint256,uint256,string)'](a, b, 'MyErrorMessage'))
|
||||
.to.be.bignumber.equal(a.div(b));
|
||||
expect(
|
||||
await this.safeMath.methods['$div(uint256,uint256,string)'](a, b, 'MyErrorMessage'),
|
||||
).to.be.bignumber.equal(a.div(b));
|
||||
});
|
||||
|
||||
it('divides zero correctly', async function () {
|
||||
const a = new BN('0');
|
||||
const b = new BN('5678');
|
||||
|
||||
expect(await this.safeMath.methods['$div(uint256,uint256,string)'](a, b, 'MyErrorMessage'))
|
||||
.to.be.bignumber.equal('0');
|
||||
expect(
|
||||
await this.safeMath.methods['$div(uint256,uint256,string)'](a, b, 'MyErrorMessage'),
|
||||
).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.methods['$div(uint256,uint256,string)'](a, b, 'MyErrorMessage'))
|
||||
.to.be.bignumber.equal('1');
|
||||
expect(
|
||||
await this.safeMath.methods['$div(uint256,uint256,string)'](a, b, 'MyErrorMessage'),
|
||||
).to.be.bignumber.equal('1');
|
||||
});
|
||||
|
||||
it('reverts on division by zero', async function () {
|
||||
@ -356,32 +360,36 @@ contract('SafeMath', function () {
|
||||
const a = new BN('284');
|
||||
const b = new BN('5678');
|
||||
|
||||
expect(await this.safeMath.methods['$mod(uint256,uint256,string)'](a, b, 'MyErrorMessage'))
|
||||
.to.be.bignumber.equal(a.mod(b));
|
||||
expect(
|
||||
await this.safeMath.methods['$mod(uint256,uint256,string)'](a, b, 'MyErrorMessage'),
|
||||
).to.be.bignumber.equal(a.mod(b));
|
||||
});
|
||||
|
||||
it('when the dividend is equal to the divisor', async function () {
|
||||
const a = new BN('5678');
|
||||
const b = new BN('5678');
|
||||
|
||||
expect(await this.safeMath.methods['$mod(uint256,uint256,string)'](a, b, 'MyErrorMessage'))
|
||||
.to.be.bignumber.equal(a.mod(b));
|
||||
expect(
|
||||
await this.safeMath.methods['$mod(uint256,uint256,string)'](a, b, 'MyErrorMessage'),
|
||||
).to.be.bignumber.equal(a.mod(b));
|
||||
});
|
||||
|
||||
it('when the dividend is larger than the divisor', async function () {
|
||||
const a = new BN('7000');
|
||||
const b = new BN('5678');
|
||||
|
||||
expect(await this.safeMath.methods['$mod(uint256,uint256,string)'](a, b, 'MyErrorMessage'))
|
||||
.to.be.bignumber.equal(a.mod(b));
|
||||
expect(
|
||||
await this.safeMath.methods['$mod(uint256,uint256,string)'](a, b, 'MyErrorMessage'),
|
||||
).to.be.bignumber.equal(a.mod(b));
|
||||
});
|
||||
|
||||
it('when the dividend is a multiple of the divisor', async function () {
|
||||
const a = new BN('17034'); // 17034 == 5678 * 3
|
||||
const b = new BN('5678');
|
||||
|
||||
expect(await this.safeMath.methods['$mod(uint256,uint256,string)'](a, b, 'MyErrorMessage'))
|
||||
.to.be.bignumber.equal(a.mod(b));
|
||||
expect(
|
||||
await this.safeMath.methods['$mod(uint256,uint256,string)'](a, b, 'MyErrorMessage'),
|
||||
).to.be.bignumber.equal(a.mod(b));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ contract('SignedMath', function () {
|
||||
});
|
||||
|
||||
describe('average', function () {
|
||||
function bnAverage (a, b) {
|
||||
function bnAverage(a, b) {
|
||||
return a.add(b).divn(2);
|
||||
}
|
||||
|
||||
@ -68,8 +68,10 @@ contract('SignedMath', function () {
|
||||
|
||||
for (const x of valuesX) {
|
||||
for (const y of valuesY) {
|
||||
expect(await this.math.$average(x, y))
|
||||
.to.be.bignumber.equal(bnAverage(x, y), `Bad result for average(${x}, ${y})`);
|
||||
expect(await this.math.$average(x, y)).to.be.bignumber.equal(
|
||||
bnAverage(x, y),
|
||||
`Bad result for average(${x}, ${y})`,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -10,12 +10,12 @@ contract('SignedSafeMath', function () {
|
||||
this.safeMath = await SignedSafeMath.new();
|
||||
});
|
||||
|
||||
async function testCommutative (fn, lhs, rhs, expected) {
|
||||
async function testCommutative(fn, lhs, rhs, expected) {
|
||||
expect(await fn(lhs, rhs)).to.be.bignumber.equal(expected);
|
||||
expect(await fn(rhs, lhs)).to.be.bignumber.equal(expected);
|
||||
}
|
||||
|
||||
async function testFailsCommutative (fn, lhs, rhs) {
|
||||
async function testFailsCommutative(fn, lhs, rhs) {
|
||||
await expectRevert.unspecified(fn(lhs, rhs));
|
||||
await expectRevert.unspecified(fn(rhs, lhs));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user