Update docs
This commit is contained in:
29
test/utils/Base64.test.js
Normal file
29
test/utils/Base64.test.js
Normal file
@ -0,0 +1,29 @@
|
||||
const { expect } = require('chai');
|
||||
|
||||
const Base64Mock = artifacts.require('Base64Mock');
|
||||
|
||||
contract('Strings', function () {
|
||||
beforeEach(async function () {
|
||||
this.base64 = await Base64Mock.new();
|
||||
});
|
||||
|
||||
describe('from bytes - base64', function () {
|
||||
it('converts to base64 encoded string with double padding', async function () {
|
||||
const TEST_MESSAGE = 'test';
|
||||
const input = web3.utils.asciiToHex(TEST_MESSAGE);
|
||||
expect(await this.base64.encode(input)).to.equal('dGVzdA==');
|
||||
});
|
||||
|
||||
it('converts to base64 encoded string with single padding', async function () {
|
||||
const TEST_MESSAGE = 'test1';
|
||||
const input = web3.utils.asciiToHex(TEST_MESSAGE);
|
||||
expect(await this.base64.encode(input)).to.equal('dGVzdDE=');
|
||||
});
|
||||
|
||||
it('converts to base64 encoded string without padding', async function () {
|
||||
const TEST_MESSAGE = 'test12';
|
||||
const input = web3.utils.asciiToHex(TEST_MESSAGE);
|
||||
expect(await this.base64.encode(input)).to.equal('dGVzdDEy');
|
||||
});
|
||||
});
|
||||
});
|
||||
59
test/utils/Checkpoints.test.js
Normal file
59
test/utils/Checkpoints.test.js
Normal file
@ -0,0 +1,59 @@
|
||||
const { expectRevert, time } = require('@openzeppelin/test-helpers');
|
||||
|
||||
const { expect } = require('chai');
|
||||
|
||||
const CheckpointsImpl = artifacts.require('CheckpointsImpl');
|
||||
|
||||
contract('Checkpoints', function (accounts) {
|
||||
beforeEach(async function () {
|
||||
this.checkpoint = await CheckpointsImpl.new();
|
||||
});
|
||||
|
||||
describe('without checkpoints', function () {
|
||||
it('returns zero as latest value', async function () {
|
||||
expect(await this.checkpoint.latest()).to.be.bignumber.equal('0');
|
||||
});
|
||||
|
||||
it('returns zero as past value', async function () {
|
||||
await time.advanceBlock();
|
||||
expect(await this.checkpoint.getAtBlock(await web3.eth.getBlockNumber() - 1)).to.be.bignumber.equal('0');
|
||||
});
|
||||
});
|
||||
|
||||
describe('with checkpoints', function () {
|
||||
beforeEach('pushing checkpoints', async function () {
|
||||
this.tx1 = await this.checkpoint.push(1);
|
||||
this.tx2 = await this.checkpoint.push(2);
|
||||
await time.advanceBlock();
|
||||
this.tx3 = await this.checkpoint.push(3);
|
||||
await time.advanceBlock();
|
||||
await time.advanceBlock();
|
||||
});
|
||||
|
||||
it('returns latest value', async function () {
|
||||
expect(await this.checkpoint.latest()).to.be.bignumber.equal('3');
|
||||
});
|
||||
|
||||
it('returns past values', async function () {
|
||||
expect(await this.checkpoint.getAtBlock(this.tx1.receipt.blockNumber - 1)).to.be.bignumber.equal('0');
|
||||
expect(await this.checkpoint.getAtBlock(this.tx1.receipt.blockNumber)).to.be.bignumber.equal('1');
|
||||
expect(await this.checkpoint.getAtBlock(this.tx2.receipt.blockNumber)).to.be.bignumber.equal('2');
|
||||
// Block with no new checkpoints
|
||||
expect(await this.checkpoint.getAtBlock(this.tx2.receipt.blockNumber + 1)).to.be.bignumber.equal('2');
|
||||
expect(await this.checkpoint.getAtBlock(this.tx3.receipt.blockNumber)).to.be.bignumber.equal('3');
|
||||
expect(await this.checkpoint.getAtBlock(this.tx3.receipt.blockNumber + 1)).to.be.bignumber.equal('3');
|
||||
});
|
||||
|
||||
it('reverts if block number >= current block', async function () {
|
||||
await expectRevert(
|
||||
this.checkpoint.getAtBlock(await web3.eth.getBlockNumber()),
|
||||
'Checkpoints: block not yet mined',
|
||||
);
|
||||
|
||||
await expectRevert(
|
||||
this.checkpoint.getAtBlock(await web3.eth.getBlockNumber() + 1),
|
||||
'Checkpoints: block not yet mined',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -74,6 +74,9 @@ const INTERFACES = {
|
||||
'proposalEta(uint256)',
|
||||
'queue(address[],uint256[],bytes[],bytes32)',
|
||||
],
|
||||
ERC2981: [
|
||||
'royaltyInfo(uint256,uint256)',
|
||||
],
|
||||
};
|
||||
|
||||
const INTERFACE_IDS = {};
|
||||
|
||||
93
test/utils/math/SignedMath.test.js
Normal file
93
test/utils/math/SignedMath.test.js
Normal file
@ -0,0 +1,93 @@
|
||||
const { BN, constants } = require('@openzeppelin/test-helpers');
|
||||
const { expect } = require('chai');
|
||||
const { MIN_INT256, MAX_INT256 } = constants;
|
||||
|
||||
const SignedMathMock = artifacts.require('SignedMathMock');
|
||||
|
||||
contract('SignedMath', function (accounts) {
|
||||
const min = new BN('-1234');
|
||||
const max = new BN('5678');
|
||||
|
||||
beforeEach(async function () {
|
||||
this.math = await SignedMathMock.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 various input', async function () {
|
||||
const valuesX = [
|
||||
new BN('0'),
|
||||
new BN('3'),
|
||||
new BN('-3'),
|
||||
new BN('4'),
|
||||
new BN('-4'),
|
||||
new BN('57417'),
|
||||
new BN('-57417'),
|
||||
new BN('42304'),
|
||||
new BN('-42304'),
|
||||
MIN_INT256,
|
||||
MAX_INT256,
|
||||
];
|
||||
|
||||
const valuesY = [
|
||||
new BN('0'),
|
||||
new BN('5'),
|
||||
new BN('-5'),
|
||||
new BN('2'),
|
||||
new BN('-2'),
|
||||
new BN('57417'),
|
||||
new BN('-57417'),
|
||||
new BN('42304'),
|
||||
new BN('-42304'),
|
||||
MIN_INT256,
|
||||
MAX_INT256,
|
||||
];
|
||||
|
||||
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})`);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('abs', function () {
|
||||
for (const n of [
|
||||
MIN_INT256,
|
||||
MIN_INT256.addn(1),
|
||||
new BN('-1'),
|
||||
new BN('0'),
|
||||
new BN('1'),
|
||||
MAX_INT256.subn(1),
|
||||
MAX_INT256,
|
||||
]) {
|
||||
it(`correctly computes the absolute value of ${n}`, async function () {
|
||||
expect(await this.math.abs(n)).to.be.bignumber.equal(n.abs());
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user