/
EnumerableMap.test.js
72 lines (59 loc) · 1.95 KB
/
EnumerableMap.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const { BN, constants } = require('@openzeppelin/test-helpers');
const AddressToUintMapMock = artifacts.require('AddressToUintMapMock');
const UintToAddressMapMock = artifacts.require('UintToAddressMapMock');
const Bytes32ToBytes32MapMock = artifacts.require('Bytes32ToBytes32MapMock');
const UintToUintMapMock = artifacts.require('UintToUintMapMock');
const { shouldBehaveLikeMap } = require('./EnumerableMap.behavior');
contract('EnumerableMap', function (accounts) {
const [ accountA, accountB, accountC ] = accounts;
const keyA = new BN('7891');
const keyB = new BN('451');
const keyC = new BN('9592328');
const bytesA = '0xdeadbeef'.padEnd(66, '0');
const bytesB = '0x0123456789'.padEnd(66, '0');
const bytesC = '0x42424242'.padEnd(66, '0');
// AddressToUintMap
describe('AddressToUintMap', function () {
beforeEach(async function () {
this.map = await AddressToUintMapMock.new();
});
shouldBehaveLikeMap(
[accountA, accountB, accountC],
[keyA, keyB, keyC],
new BN('0'),
);
});
// UintToAddressMap
describe('UintToAddressMap', function () {
beforeEach(async function () {
this.map = await UintToAddressMapMock.new();
});
shouldBehaveLikeMap(
[keyA, keyB, keyC],
[accountA, accountB, accountC],
constants.ZERO_ADDRESS,
);
});
// Bytes32ToBytes32Map
describe('Bytes32ToBytes32Map', function () {
beforeEach(async function () {
this.map = await Bytes32ToBytes32MapMock.new();
});
shouldBehaveLikeMap(
[keyA, keyB, keyC].map(k => ('0x' + k.toString(16)).padEnd(66, '0')),
[bytesA, bytesB, bytesC],
constants.ZERO_BYTES32,
);
});
// UintToUintMap
describe('UintToUintMap', function () {
beforeEach(async function () {
this.map = await UintToUintMapMock.new();
});
shouldBehaveLikeMap(
[ keyA, keyB, keyC ],
[ keyA, keyB, keyC ].map(k => k.add(new BN('1332'))),
new BN('0'),
);
});
});