Files
openzeppelin-contracts/test/math/Math.test.js
Nicolás Venturo 5f92adc2e7 Migrate from truffle to test-environment (#2007)
* Sketch

* Migrate all tests to test-env

* Finish migration to test-env

* Add config

* Work on GSN tests

* Migrate to newer test-env version and loader syntax

* Add GSN setup

* Finish test-env migration

* Setup coverage using test-env

* Migrate to npm package

* Fix package.json

* Add compile step to CI

* Add comment on coverage setup

* Remove dependency on @truffle/contract

* Fix package-lock merge

* Fix linter errors

* Upgrade test-environment, depend locally on ganche-coverage

* Improve coverage script

* Improve sign.js API

* Move accounts destructuring to describe block

* Switch to prebuilt ethereumjs-vm package

* Upgrade test-enviroment version

* use workspace in circleci config

* remove unnecessary npx
2019-11-28 15:46:42 -03:00

60 lines
1.9 KiB
JavaScript

const { contract } = require('@openzeppelin/test-environment');
const { BN } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const MathMock = contract.fromArtifact('MathMock');
describe('Math', function () {
const min = new BN('1234');
const max = new BN('5678');
beforeEach(async function () {
this.math = await MathMock.new();
});
describe('max', function () {
it('is correctly detected in first argument position', async function () {
expect(await this.math.max(max, min)).to.be.bignumber.equal(max);
});
it('is correctly detected in second argument position', async function () {
expect(await this.math.max(min, max)).to.be.bignumber.equal(max);
});
});
describe('min', function () {
it('is correctly detected in first argument position', async function () {
expect(await this.math.min(min, max)).to.be.bignumber.equal(min);
});
it('is correctly detected in second argument position', async function () {
expect(await this.math.min(max, min)).to.be.bignumber.equal(min);
});
});
describe('average', function () {
function bnAverage (a, b) {
return a.add(b).divn(2);
}
it('is correctly calculated with two odd numbers', async function () {
const a = new BN('57417');
const b = new BN('95431');
expect(await this.math.average(a, b)).to.be.bignumber.equal(bnAverage(a, b));
});
it('is correctly calculated with two even numbers', async function () {
const a = new BN('42304');
const b = new BN('84346');
expect(await this.math.average(a, b)).to.be.bignumber.equal(bnAverage(a, b));
});
it('is correctly calculated with one even and one odd number', async function () {
const a = new BN('57417');
const b = new BN('84346');
expect(await this.math.average(a, b)).to.be.bignumber.equal(bnAverage(a, b));
});
});
});