Skip to content

Commit

Permalink
fix: removeOperator logic fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maximebrugel committed Dec 22, 2021
1 parent 809fdfd commit a2cbe60
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions contracts/NestedFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,16 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, Ownable, MixinOperato

/// @inheritdoc INestedFactory
function removeOperator(bytes32 operator) external override onlyOwner {
uint256 i = 0;
while (operators[i] != operator) {
i++;
uint256 operatorsLength = operators.length;
for (uint256 i = 0; i < operatorsLength; i++) {
if (operators[i] == operator) {
operators[i] = operators[operatorsLength - 1];
operators.pop();
emit OperatorRemoved(operator);
return;
}
}
require(i != 0, "NF: NON_EXISTENT_OPERATOR");
delete operators[i];
emit OperatorRemoved(operator);
revert("NF: NON_EXISTENT_OPERATOR");
}

/// @inheritdoc INestedFactory
Expand Down
2 changes: 1 addition & 1 deletion test/unit/NestedFactory.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ describe("NestedFactory", () => {
const operators = await context.nestedFactory.resolverAddressesRequired();

// Must have 2 operators ("ZeroEx" from Fixture and "test")
expect(operators.length).to.be.equal(3);
expect(operators.length).to.be.equal(2);
expect(operators[0]).to.be.equal(context.zeroExOperatorNameBytes32);
expect(operators[1]).to.be.equal(context.flatOperatorNameBytes32);
expect(operators[2]).to.not.be.equal(toBytes32("test"));
Expand Down

0 comments on commit a2cbe60

Please sign in to comment.