Make tests style more uniform (#4812)

This commit is contained in:
Renan Souza
2024-01-02 13:31:33 -03:00
committed by GitHub
parent a72c9561b9
commit 04cb014144
18 changed files with 118 additions and 118 deletions

View File

@ -85,7 +85,7 @@ describe('Arrays', function () {
it(name, async function () {
// findUpperBound does not support duplicated
if (hasDuplicates(array)) this.skip();
expect(await this.mock.findUpperBound(input)).to.be.equal(lowerBound(array, input));
expect(await this.mock.findUpperBound(input)).to.equal(lowerBound(array, input));
});
}
});
@ -114,7 +114,7 @@ describe('Arrays', function () {
for (const [name, { elements }] of Object.entries(contractCases)) {
it(name, async function () {
for (const i in elements) {
expect(await this.contracts[name].unsafeAccess(i)).to.be.equal(elements[i]);
expect(await this.contracts[name].unsafeAccess(i)).to.equal(elements[i]);
}
});
}

View File

@ -27,16 +27,16 @@ describe('MerkleProof', function () {
const hash = merkleTree.leafHash(['A']);
const proof = merkleTree.getProof(['A']);
expect(await this.mock.$verify(proof, root, hash)).to.equal(true);
expect(await this.mock.$verifyCalldata(proof, root, hash)).to.equal(true);
expect(await this.mock.$verify(proof, root, hash)).to.be.true;
expect(await this.mock.$verifyCalldata(proof, root, hash)).to.be.true;
// For demonstration, it is also possible to create valid proofs for certain 64-byte values *not* in elements:
const noSuchLeaf = hashPair(
ethers.toBeArray(merkleTree.leafHash(['A'])),
ethers.toBeArray(merkleTree.leafHash(['B'])),
);
expect(await this.mock.$verify(proof.slice(1), root, noSuchLeaf)).to.equal(true);
expect(await this.mock.$verifyCalldata(proof.slice(1), root, noSuchLeaf)).to.equal(true);
expect(await this.mock.$verify(proof.slice(1), root, noSuchLeaf)).to.be.true;
expect(await this.mock.$verifyCalldata(proof.slice(1), root, noSuchLeaf)).to.be.true;
});
it('returns false for an invalid Merkle proof', async function () {
@ -47,8 +47,8 @@ describe('MerkleProof', function () {
const hash = correctMerkleTree.leafHash(['a']);
const proof = otherMerkleTree.getProof(['d']);
expect(await this.mock.$verify(proof, root, hash)).to.equal(false);
expect(await this.mock.$verifyCalldata(proof, root, hash)).to.equal(false);
expect(await this.mock.$verify(proof, root, hash)).to.be.false;
expect(await this.mock.$verifyCalldata(proof, root, hash)).to.be.false;
});
it('returns false for a Merkle proof of invalid length', async function () {
@ -59,8 +59,8 @@ describe('MerkleProof', function () {
const proof = merkleTree.getProof(['a']);
const badProof = proof.slice(0, proof.length - 5);
expect(await this.mock.$verify(badProof, root, leaf)).to.equal(false);
expect(await this.mock.$verifyCalldata(badProof, root, leaf)).to.equal(false);
expect(await this.mock.$verify(badProof, root, leaf)).to.be.false;
expect(await this.mock.$verifyCalldata(badProof, root, leaf)).to.be.false;
});
});
@ -72,8 +72,8 @@ describe('MerkleProof', function () {
const { proof, proofFlags, leaves } = merkleTree.getMultiProof(toElements('bdf'));
const hashes = leaves.map(e => merkleTree.leafHash(e));
expect(await this.mock.$multiProofVerify(proof, proofFlags, root, hashes)).to.equal(true);
expect(await this.mock.$multiProofVerifyCalldata(proof, proofFlags, root, hashes)).to.equal(true);
expect(await this.mock.$multiProofVerify(proof, proofFlags, root, hashes)).to.be.true;
expect(await this.mock.$multiProofVerifyCalldata(proof, proofFlags, root, hashes)).to.be.true;
});
it('returns false for an invalid Merkle multi proof', async function () {
@ -84,8 +84,8 @@ describe('MerkleProof', function () {
const { proof, proofFlags, leaves } = otherMerkleTree.getMultiProof(toElements('ghi'));
const hashes = leaves.map(e => merkleTree.leafHash(e));
expect(await this.mock.$multiProofVerify(proof, proofFlags, root, hashes)).to.equal(false);
expect(await this.mock.$multiProofVerifyCalldata(proof, proofFlags, root, hashes)).to.equal(false);
expect(await this.mock.$multiProofVerify(proof, proofFlags, root, hashes)).to.be.false;
expect(await this.mock.$multiProofVerifyCalldata(proof, proofFlags, root, hashes)).to.be.false;
});
it('revert with invalid multi proof #1', async function () {
@ -139,16 +139,16 @@ describe('MerkleProof', function () {
const { proof, proofFlags, leaves } = merkleTree.getMultiProof(toElements('a'));
const hashes = leaves.map(e => merkleTree.leafHash(e));
expect(await this.mock.$multiProofVerify(proof, proofFlags, root, hashes)).to.equal(true);
expect(await this.mock.$multiProofVerifyCalldata(proof, proofFlags, root, hashes)).to.equal(true);
expect(await this.mock.$multiProofVerify(proof, proofFlags, root, hashes)).to.be.true;
expect(await this.mock.$multiProofVerifyCalldata(proof, proofFlags, root, hashes)).to.be.true;
});
it('limit case: can prove empty leaves', async function () {
const merkleTree = StandardMerkleTree.of(toElements('abcd'), ['string']);
const root = merkleTree.root;
expect(await this.mock.$multiProofVerify([root], [], root, [])).to.equal(true);
expect(await this.mock.$multiProofVerifyCalldata([root], [], root, [])).to.equal(true);
expect(await this.mock.$multiProofVerify([root], [], root, [])).to.be.true;
expect(await this.mock.$multiProofVerifyCalldata([root], [], root, [])).to.be.true;
});
it('reverts processing manipulated proofs with a zero-value node at depth 1', async function () {

View File

@ -17,25 +17,25 @@ describe('BitMap', function () {
});
it('starts empty', async function () {
expect(await this.bitmap.$get(0, keyA)).to.equal(false);
expect(await this.bitmap.$get(0, keyB)).to.equal(false);
expect(await this.bitmap.$get(0, keyC)).to.equal(false);
expect(await this.bitmap.$get(0, keyA)).to.be.false;
expect(await this.bitmap.$get(0, keyB)).to.be.false;
expect(await this.bitmap.$get(0, keyC)).to.be.false;
});
describe('setTo', function () {
it('set a key to true', async function () {
await this.bitmap.$setTo(0, keyA, true);
expect(await this.bitmap.$get(0, keyA)).to.equal(true);
expect(await this.bitmap.$get(0, keyB)).to.equal(false);
expect(await this.bitmap.$get(0, keyC)).to.equal(false);
expect(await this.bitmap.$get(0, keyA)).to.be.true;
expect(await this.bitmap.$get(0, keyB)).to.be.false;
expect(await this.bitmap.$get(0, keyC)).to.be.false;
});
it('set a key to false', async function () {
await this.bitmap.$setTo(0, keyA, true);
await this.bitmap.$setTo(0, keyA, false);
expect(await this.bitmap.$get(0, keyA)).to.equal(false);
expect(await this.bitmap.$get(0, keyB)).to.equal(false);
expect(await this.bitmap.$get(0, keyC)).to.equal(false);
expect(await this.bitmap.$get(0, keyA)).to.be.false;
expect(await this.bitmap.$get(0, keyB)).to.be.false;
expect(await this.bitmap.$get(0, keyC)).to.be.false;
});
it('set several consecutive keys', async function () {
@ -46,39 +46,39 @@ describe('BitMap', function () {
await this.bitmap.$setTo(0, keyA + 4n, true);
await this.bitmap.$setTo(0, keyA + 2n, false);
await this.bitmap.$setTo(0, keyA + 4n, false);
expect(await this.bitmap.$get(0, keyA + 0n)).to.equal(true);
expect(await this.bitmap.$get(0, keyA + 1n)).to.equal(true);
expect(await this.bitmap.$get(0, keyA + 2n)).to.equal(false);
expect(await this.bitmap.$get(0, keyA + 3n)).to.equal(true);
expect(await this.bitmap.$get(0, keyA + 4n)).to.equal(false);
expect(await this.bitmap.$get(0, keyA + 0n)).to.be.true;
expect(await this.bitmap.$get(0, keyA + 1n)).to.be.true;
expect(await this.bitmap.$get(0, keyA + 2n)).to.be.false;
expect(await this.bitmap.$get(0, keyA + 3n)).to.be.true;
expect(await this.bitmap.$get(0, keyA + 4n)).to.be.false;
});
});
describe('set', function () {
it('adds a key', async function () {
await this.bitmap.$set(0, keyA);
expect(await this.bitmap.$get(0, keyA)).to.equal(true);
expect(await this.bitmap.$get(0, keyB)).to.equal(false);
expect(await this.bitmap.$get(0, keyC)).to.equal(false);
expect(await this.bitmap.$get(0, keyA)).to.be.true;
expect(await this.bitmap.$get(0, keyB)).to.be.false;
expect(await this.bitmap.$get(0, keyC)).to.be.false;
});
it('adds several keys', async function () {
await this.bitmap.$set(0, keyA);
await this.bitmap.$set(0, keyB);
expect(await this.bitmap.$get(0, keyA)).to.equal(true);
expect(await this.bitmap.$get(0, keyB)).to.equal(true);
expect(await this.bitmap.$get(0, keyC)).to.equal(false);
expect(await this.bitmap.$get(0, keyA)).to.be.true;
expect(await this.bitmap.$get(0, keyB)).to.be.true;
expect(await this.bitmap.$get(0, keyC)).to.be.false;
});
it('adds several consecutive keys', async function () {
await this.bitmap.$set(0, keyA + 0n);
await this.bitmap.$set(0, keyA + 1n);
await this.bitmap.$set(0, keyA + 3n);
expect(await this.bitmap.$get(0, keyA + 0n)).to.equal(true);
expect(await this.bitmap.$get(0, keyA + 1n)).to.equal(true);
expect(await this.bitmap.$get(0, keyA + 2n)).to.equal(false);
expect(await this.bitmap.$get(0, keyA + 3n)).to.equal(true);
expect(await this.bitmap.$get(0, keyA + 4n)).to.equal(false);
expect(await this.bitmap.$get(0, keyA + 0n)).to.be.true;
expect(await this.bitmap.$get(0, keyA + 1n)).to.be.true;
expect(await this.bitmap.$get(0, keyA + 2n)).to.be.false;
expect(await this.bitmap.$get(0, keyA + 3n)).to.be.true;
expect(await this.bitmap.$get(0, keyA + 4n)).to.be.false;
});
});
@ -87,9 +87,9 @@ describe('BitMap', function () {
await this.bitmap.$set(0, keyA);
await this.bitmap.$set(0, keyB);
await this.bitmap.$unset(0, keyA);
expect(await this.bitmap.$get(0, keyA)).to.equal(false);
expect(await this.bitmap.$get(0, keyB)).to.equal(true);
expect(await this.bitmap.$get(0, keyC)).to.equal(false);
expect(await this.bitmap.$get(0, keyA)).to.be.false;
expect(await this.bitmap.$get(0, keyB)).to.be.true;
expect(await this.bitmap.$get(0, keyC)).to.be.false;
});
it('removes consecutive added keys', async function () {
@ -97,11 +97,11 @@ describe('BitMap', function () {
await this.bitmap.$set(0, keyA + 1n);
await this.bitmap.$set(0, keyA + 3n);
await this.bitmap.$unset(0, keyA + 1n);
expect(await this.bitmap.$get(0, keyA + 0n)).to.equal(true);
expect(await this.bitmap.$get(0, keyA + 1n)).to.equal(false);
expect(await this.bitmap.$get(0, keyA + 2n)).to.equal(false);
expect(await this.bitmap.$get(0, keyA + 3n)).to.equal(true);
expect(await this.bitmap.$get(0, keyA + 4n)).to.equal(false);
expect(await this.bitmap.$get(0, keyA + 0n)).to.be.true;
expect(await this.bitmap.$get(0, keyA + 1n)).to.be.false;
expect(await this.bitmap.$get(0, keyA + 2n)).to.be.false;
expect(await this.bitmap.$get(0, keyA + 3n)).to.be.true;
expect(await this.bitmap.$get(0, keyA + 4n)).to.be.false;
});
it('adds and removes multiple keys', async function () {
@ -141,9 +141,9 @@ describe('BitMap', function () {
// [A, C]
expect(await this.bitmap.$get(0, keyA)).to.equal(true);
expect(await this.bitmap.$get(0, keyB)).to.equal(false);
expect(await this.bitmap.$get(0, keyC)).to.equal(true);
expect(await this.bitmap.$get(0, keyA)).to.be.true;
expect(await this.bitmap.$get(0, keyB)).to.be.false;
expect(await this.bitmap.$get(0, keyC)).to.be.true;
});
});
});

View File

@ -124,7 +124,7 @@ function shouldBehaveLikeMap() {
describe('get', function () {
it('existing value', async function () {
expect(await this.methods.get(this.keyA)).to.be.equal(this.valueA);
expect(await this.methods.get(this.keyA)).to.equal(this.valueA);
});
it('missing value', async function () {