* Drafted Enumerable.sol. * Drafted test framework. * Tweaked the tests to follow oz structure. * Coded EnumerableSet. * Moved EnumerableSet to `utils`. * Fixed linting. * Improved comments. * Tweaked contract description. * Renamed struct to AddressSet. * Relaxed version pragma to 0.5.0 * Removed events. * Revert on useless operations. * Small comment. * Created AddressSet factory method. * Failed transactions return false. * Transactions now return false on failure. * Remove comments from mock * Rename mock functions * Adapt tests to code style, use test-helpers * Fix bug in remove, improve tests. * Add changelog entry * Add entry on Utils doc * Add optimization for removal of last slot * Update docs * Fix headings of utilities documentation Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
34 lines
842 B
Solidity
34 lines
842 B
Solidity
pragma solidity ^0.5.0;
|
|
|
|
import "../utils/EnumerableSet.sol";
|
|
|
|
contract EnumerableSetMock{
|
|
using EnumerableSet for EnumerableSet.AddressSet;
|
|
|
|
event TransactionResult(bool result);
|
|
|
|
EnumerableSet.AddressSet private set;
|
|
|
|
constructor() public {
|
|
set = EnumerableSet.newAddressSet();
|
|
}
|
|
|
|
function contains(address value) public view returns (bool) {
|
|
return EnumerableSet.contains(set, value);
|
|
}
|
|
|
|
function add(address value) public {
|
|
bool result = EnumerableSet.add(set, value);
|
|
emit TransactionResult(result);
|
|
}
|
|
|
|
function remove(address value) public {
|
|
bool result = EnumerableSet.remove(set, value);
|
|
emit TransactionResult(result);
|
|
}
|
|
|
|
function enumerate() public view returns (address[] memory) {
|
|
return EnumerableSet.enumerate(set);
|
|
}
|
|
}
|