Add bytes32 to bytes32 enumerable map (#3192)

* feat(enumerablemap): add bytes32 to bytes32 map

* chore(changelog): edit CHANGELOG

* feat(enumerable map): edit struct visibility
This commit is contained in:
Wias Liaw
2022-03-22 23:36:29 +08:00
committed by GitHub
parent c028c56965
commit b13bdb0249
8 changed files with 334 additions and 378 deletions

View File

@ -0,0 +1,58 @@
const { BN, constants } = require('@openzeppelin/test-helpers');
const AddressToUintMapMock = artifacts.require('AddressToUintMapMock');
const UintToAddressMapMock = artifacts.require('UintToAddressMapMock');
const Bytes32ToBytes32MapMock = artifacts.require('Bytes32ToBytes32MapMock');
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,
);
});
});