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

Commit bc64f92

Browse files
committed
Update mapping tests to use Maps
1 parent 1eea6e2 commit bc64f92

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

packages/truffle-debugger/test/data/decoding.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,42 +53,27 @@ const mappingFixtures = [
5353
from: "uint256",
5454
to: "uint256"
5555
},
56-
value: {
57-
...Object.assign(
58-
{},
59-
...generateArray(5).map((value, idx) => ({ [idx]: value }))
60-
)
61-
}
56+
value: new Map(generateArray(5).map((value, idx) => [idx, value]))
6257
},
6358
{
6459
name: "numberedStrings",
6560
type: {
6661
from: "uint256",
6762
to: "string"
6863
},
69-
value: {
70-
...Object.assign(
71-
{},
72-
...generateArray(7).map((value, idx) => ({
73-
[value]: faker.lorem.slug(idx)
74-
}))
75-
)
76-
}
64+
value: new Map(
65+
generateArray(7).map((value, idx) => [value, faker.lorem.slug(idx)])
66+
)
7767
},
7868
{
7969
name: "stringsToStrings",
8070
type: {
8171
from: "string",
8272
to: "string"
8373
},
84-
value: {
85-
...Object.assign(
86-
{},
87-
...[0, 1, 2, 3, 4].map(idx => ({
88-
[faker.lorem.slug(idx)]: faker.lorem.slug(idx)
89-
}))
90-
)
91-
}
74+
value: new Map(
75+
[0, 1, 2, 3, 4].map(idx => [faker.lorem.slug(idx), faker.lorem.slug(idx)])
76+
)
9277
}
9378
];
9479

@@ -146,7 +131,7 @@ contract ${contractName} {
146131
function run() public {
147132
${fixtures
148133
.map(({ name, type: { from }, value }) =>
149-
Object.entries(value)
134+
Array.from(value.entries())
150135
.map(
151136
([k, v]) =>
152137
from === "string"

packages/truffle-debugger/test/data/helpers.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,19 @@ function generateTests(fixtures) {
3232
for (let { name, value: expected } of fixtures) {
3333
it(`correctly decodes ${name}`, async () => {
3434
const response = await this.decode(name);
35-
assert.deepEqual(response, expected);
35+
if (expected instanceof Map) {
36+
assert.instanceOf(response, Map);
37+
assert.sameDeepMembers(
38+
Array.from(response.keys()),
39+
Array.from(expected.keys())
40+
);
41+
for (let key of expected.keys()) {
42+
//no mappings in this test are nested so this will do fine
43+
assert.deepEqual(response[key], expected[key]);
44+
}
45+
} else {
46+
assert.deepEqual(response, expected);
47+
}
3648
});
3749
}
3850
}

0 commit comments

Comments
 (0)