Skip to content

Commit cc51e31

Browse files
committed
toArray function tests
1 parent d975595 commit cc51e31

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

contracts/data/EnumerableMapAddressToAddressMock.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ contract EnumerableMapAddressToAddressMock {
3232
function remove(address key) external returns (bool) {
3333
return map.remove(key);
3434
}
35+
36+
function toArray()
37+
external
38+
view
39+
returns (address[] memory keys, address[] memory values)
40+
{
41+
(keys, values) = map.toArray();
42+
}
3543
}

contracts/data/EnumerableMapUintToAddressMock.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ contract EnumerableMapUintToAddressMock {
3232
function remove(uint256 key) external returns (bool) {
3333
return map.remove(key);
3434
}
35+
36+
function toArray()
37+
external
38+
view
39+
returns (uint256[] memory keys, address[] memory values)
40+
{
41+
(keys, values) = map.toArray();
42+
}
3543
}

test/data/EnumerableMap.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,19 @@ describe('EnumerableMap', () => {
187187
.false;
188188
});
189189
});
190+
191+
describe('#toArray()', () => {
192+
it('returns arrays of keys and values in map', async () => {
193+
await instance['set(address,address)'](addressOne, addressFour);
194+
await instance['set(address,address)'](addressTwo, addressFive);
195+
await instance['set(address,address)'](addressThree, addressSix);
196+
197+
const [keys, values] = await instance.callStatic['toArray()']();
198+
199+
expect(keys).to.deep.equal([addressOne, addressTwo, addressThree]);
200+
expect(values).to.deep.equal([addressFour, addressFive, addressSix]);
201+
});
202+
});
190203
});
191204
});
192205

@@ -365,6 +378,19 @@ describe('EnumerableMap', () => {
365378
.false;
366379
});
367380
});
381+
382+
describe('#toArray()', () => {
383+
it('returns arrays of keys and values in map', async () => {
384+
await instance['set(uint256,address)'](uintOne, addressOne);
385+
await instance['set(uint256,address)'](uintTwo, addressTwo);
386+
await instance['set(uint256,address)'](uintThree, addressThree);
387+
388+
const [keys, values] = await instance.callStatic['toArray()']();
389+
390+
expect(keys).to.deep.equal([uintOne, uintTwo, uintThree]);
391+
expect(values).to.deep.equal([addressOne, addressTwo, addressThree]);
392+
});
393+
});
368394
});
369395
});
370396
});

0 commit comments

Comments
 (0)