Use Prettier for JS files (#3913)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -3,46 +3,39 @@ const { expect } = require('chai');
|
||||
|
||||
const zip = require('lodash.zip');
|
||||
|
||||
function shouldBehaveLikeMap (
|
||||
keys,
|
||||
values,
|
||||
zeroValue,
|
||||
methods,
|
||||
events,
|
||||
) {
|
||||
const [ keyA, keyB, keyC ] = keys;
|
||||
const [ valueA, valueB, valueC ] = values;
|
||||
function shouldBehaveLikeMap(keys, values, zeroValue, methods, events) {
|
||||
const [keyA, keyB, keyC] = keys;
|
||||
const [valueA, valueB, valueC] = values;
|
||||
|
||||
async function expectMembersMatch (map, keys, values) {
|
||||
async function expectMembersMatch(map, keys, values) {
|
||||
expect(keys.length).to.equal(values.length);
|
||||
|
||||
await Promise.all(keys.map(async key =>
|
||||
expect(await methods.contains(map, key)).to.equal(true),
|
||||
));
|
||||
await Promise.all(keys.map(async key => expect(await methods.contains(map, key)).to.equal(true)));
|
||||
|
||||
expect(await methods.length(map)).to.bignumber.equal(keys.length.toString());
|
||||
|
||||
expect(
|
||||
(await Promise.all(keys.map(key => methods.get(map, key)))).map(k => k.toString()),
|
||||
).to.have.same.members(
|
||||
expect((await Promise.all(keys.map(key => methods.get(map, key)))).map(k => k.toString())).to.have.same.members(
|
||||
values.map(value => value.toString()),
|
||||
);
|
||||
|
||||
// To compare key-value pairs, we zip keys and values, and convert BNs to
|
||||
// strings to workaround Chai limitations when dealing with nested arrays
|
||||
expect(await Promise.all([...Array(keys.length).keys()].map(async (index) => {
|
||||
const entry = await methods.at(map, index);
|
||||
return [ entry[0].toString(), entry[1].toString() ];
|
||||
}))).to.have.same.deep.members(
|
||||
zip(keys.map(k => k.toString()), values.map(v => v.toString())),
|
||||
expect(
|
||||
await Promise.all(
|
||||
[...Array(keys.length).keys()].map(async index => {
|
||||
const entry = await methods.at(map, index);
|
||||
return [entry[0].toString(), entry[1].toString()];
|
||||
}),
|
||||
),
|
||||
).to.have.same.deep.members(
|
||||
zip(
|
||||
keys.map(k => k.toString()),
|
||||
values.map(v => v.toString()),
|
||||
),
|
||||
);
|
||||
|
||||
// This also checks that both arrays have the same length
|
||||
expect(
|
||||
(await methods.keys(map)).map(k => k.toString()),
|
||||
).to.have.same.members(
|
||||
keys.map(key => key.toString()),
|
||||
);
|
||||
expect((await methods.keys(map)).map(k => k.toString())).to.have.same.members(keys.map(key => key.toString()));
|
||||
}
|
||||
|
||||
it('starts empty', async function () {
|
||||
@ -154,29 +147,21 @@ function shouldBehaveLikeMap (
|
||||
|
||||
describe('get', function () {
|
||||
it('existing value', async function () {
|
||||
expect(
|
||||
await methods.get(this.map, keyA).then(r => r.toString()),
|
||||
).to.be.equal(valueA.toString());
|
||||
expect(await methods.get(this.map, keyA).then(r => r.toString())).to.be.equal(valueA.toString());
|
||||
});
|
||||
it('missing value', async function () {
|
||||
await expectRevert(
|
||||
methods.get(this.map, keyB),
|
||||
'EnumerableMap: nonexistent key',
|
||||
);
|
||||
await expectRevert(methods.get(this.map, keyB), 'EnumerableMap: nonexistent key');
|
||||
});
|
||||
});
|
||||
|
||||
describe('get with message', function () {
|
||||
it('existing value', async function () {
|
||||
expect(
|
||||
await methods.getWithMessage(this.map, keyA, 'custom error string').then(r => r.toString()),
|
||||
).to.be.equal(valueA.toString());
|
||||
expect(await methods.getWithMessage(this.map, keyA, 'custom error string').then(r => r.toString())).to.be.equal(
|
||||
valueA.toString(),
|
||||
);
|
||||
});
|
||||
it('missing value', async function () {
|
||||
await expectRevert(
|
||||
methods.getWithMessage(this.map, keyB, 'custom error string'),
|
||||
'custom error string',
|
||||
);
|
||||
await expectRevert(methods.getWithMessage(this.map, keyB, 'custom error string'), 'custom error string');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user