From a2cbe60c7161d8dade690619ce8a9b2d1eaac28c Mon Sep 17 00:00:00 2001 From: "axxe.eth" Date: Wed, 22 Dec 2021 16:54:48 +0100 Subject: [PATCH] fix: removeOperator logic fix --- contracts/NestedFactory.sol | 15 +++++++++------ test/unit/NestedFactory.unit.ts | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/contracts/NestedFactory.sol b/contracts/NestedFactory.sol index 4268ed6a..57c70f42 100644 --- a/contracts/NestedFactory.sol +++ b/contracts/NestedFactory.sol @@ -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 diff --git a/test/unit/NestedFactory.unit.ts b/test/unit/NestedFactory.unit.ts index 739655dd..995a89bc 100644 --- a/test/unit/NestedFactory.unit.ts +++ b/test/unit/NestedFactory.unit.ts @@ -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"));