Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Update mapping tests to use Maps
Browse files Browse the repository at this point in the history
  • Loading branch information
haltman-at committed Apr 9, 2019
1 parent 1eea6e2 commit bc64f92
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
31 changes: 8 additions & 23 deletions packages/truffle-debugger/test/data/decoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,27 @@ const mappingFixtures = [
from: "uint256",
to: "uint256"
},
value: {
...Object.assign(
{},
...generateArray(5).map((value, idx) => ({ [idx]: value }))
)
}
value: new Map(generateArray(5).map((value, idx) => [idx, value]))
},
{
name: "numberedStrings",
type: {
from: "uint256",
to: "string"
},
value: {
...Object.assign(
{},
...generateArray(7).map((value, idx) => ({
[value]: faker.lorem.slug(idx)
}))
)
}
value: new Map(
generateArray(7).map((value, idx) => [value, faker.lorem.slug(idx)])
)
},
{
name: "stringsToStrings",
type: {
from: "string",
to: "string"
},
value: {
...Object.assign(
{},
...[0, 1, 2, 3, 4].map(idx => ({
[faker.lorem.slug(idx)]: faker.lorem.slug(idx)
}))
)
}
value: new Map(
[0, 1, 2, 3, 4].map(idx => [faker.lorem.slug(idx), faker.lorem.slug(idx)])
)
}
];

Expand Down Expand Up @@ -146,7 +131,7 @@ contract ${contractName} {
function run() public {
${fixtures
.map(({ name, type: { from }, value }) =>
Object.entries(value)
Array.from(value.entries())
.map(
([k, v]) =>
from === "string"
Expand Down
14 changes: 13 additions & 1 deletion packages/truffle-debugger/test/data/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ function generateTests(fixtures) {
for (let { name, value: expected } of fixtures) {
it(`correctly decodes ${name}`, async () => {
const response = await this.decode(name);
assert.deepEqual(response, expected);
if (expected instanceof Map) {
assert.instanceOf(response, Map);
assert.sameDeepMembers(
Array.from(response.keys()),
Array.from(expected.keys())
);
for (let key of expected.keys()) {
//no mappings in this test are nested so this will do fine
assert.deepEqual(response[key], expected[key]);
}
} else {
assert.deepEqual(response, expected);
}
});
}
}
Expand Down

0 comments on commit bc64f92

Please sign in to comment.