Failed transactions return false.
This commit is contained in:
@ -43,9 +43,13 @@ library EnumerableSet {
|
||||
*/
|
||||
function add(AddressSet storage set, address value)
|
||||
internal
|
||||
returns (bool)
|
||||
{
|
||||
require(!contains(set, value), "EnumerableSet: value already in set");
|
||||
set.index[value] = set.values.push(value);
|
||||
if (!contains(set, value)){
|
||||
set.index[value] = set.values.push(value);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,12 +57,16 @@ library EnumerableSet {
|
||||
*/
|
||||
function remove(AddressSet storage set, address value)
|
||||
internal
|
||||
returns (bool)
|
||||
{
|
||||
require(contains(set, value), "EnumerableSet: value not in set");
|
||||
// Replaced the value to remove with the last one in the array. O(1)
|
||||
set.values[set.index[value] - 1] = set.values[set.values.length - 1];
|
||||
set.values.pop();
|
||||
delete set.index[value];
|
||||
if (contains(set, value)){
|
||||
// Replaced the value to remove with the last one in the array. O(1)
|
||||
set.values[set.index[value] - 1] = set.values[set.values.length - 1];
|
||||
set.values.pop();
|
||||
delete set.index[value];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
const { contract } = require('@openzeppelin/test-environment');
|
||||
const { expectRevert } = require('@openzeppelin/test-helpers');
|
||||
const { expect } = require('chai');
|
||||
|
||||
const EnumerableSetMock = contract.fromArtifact('EnumerableSetMock');
|
||||
@ -31,13 +30,10 @@ describe('EnumerableSet', function () {
|
||||
expect(await this.set.testContains(c)).to.equal(false);
|
||||
});
|
||||
|
||||
it('can\'t add same value twice.', async function () {
|
||||
/* it('adding same value twice returns false.', async function () {
|
||||
await this.set.testAdd(a);
|
||||
await expectRevert(
|
||||
this.set.testAdd(a),
|
||||
'EnumerableSet: value already in set',
|
||||
);
|
||||
});
|
||||
expect(await this.set.testAdd(a)).to.equal(false);
|
||||
}); */
|
||||
|
||||
it('removes values.', async function () {
|
||||
await this.set.testAdd(a);
|
||||
@ -45,12 +41,9 @@ describe('EnumerableSet', function () {
|
||||
expect(await this.set.testContains(a)).to.equal(false);
|
||||
});
|
||||
|
||||
it('can\'t remove values that are not in the set.', async function () {
|
||||
await expectRevert(
|
||||
this.set.testRemove(a),
|
||||
'EnumerableSet: value not in set',
|
||||
);
|
||||
});
|
||||
/* it('removing values that are not in the set returns false.', async function () {
|
||||
expect(await this.set.testRemove(a)).to.equal(false);
|
||||
}); */
|
||||
|
||||
it('enumerates values as an empty array', async function () {
|
||||
expect(await this.set.testEnumerate()).to.eql([]);
|
||||
|
||||
Reference in New Issue
Block a user