API improvements for EnumerableSet (#2151)

* Add revert reason to EnumerableSet.get.

* Rename EnumerableSet values to keys

* Rename get to at

* Add changelog entry

* Rename keys to values

* Add leading underscore to struct members
This commit is contained in:
Nicolás Venturo
2020-03-27 18:39:18 -03:00
committed by GitHub
parent 24c37c1f9e
commit 7415ebe8bc
5 changed files with 42 additions and 31 deletions

View File

@ -1,5 +1,5 @@
const { accounts, contract } = require('@openzeppelin/test-environment');
const { expectEvent } = require('@openzeppelin/test-helpers');
const { expectEvent, expectRevert } = require('@openzeppelin/test-helpers');
const { expect } = require('chai');
const EnumerableSetMock = contract.fromArtifact('EnumerableSetMock');
@ -21,7 +21,7 @@ describe('EnumerableSet', function () {
expect(await set.length()).to.bignumber.equal(members.length.toString());
expect(await Promise.all([...Array(members.length).keys()].map(index =>
set.get(index)
set.at(index)
))).to.have.same.members(members);
}
@ -55,6 +55,10 @@ describe('EnumerableSet', function () {
await expectMembersMatch(this.set, [accountA]);
});
it('reverts when retrieving non-existent elements', async function () {
await expectRevert(this.set.at(0), 'EnumerableSet: index out of bounds');
});
it('removes added values', async function () {
await this.set.add(accountA);