Skip to content

Commit

Permalink
fix: delete operator from cache (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximebrugel committed Feb 16, 2022
1 parent 2ab7934 commit d2e48a8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
3 changes: 3 additions & 0 deletions contracts/NestedFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ contract NestedFactory is INestedFactory, ReentrancyGuard, OwnableProxyDelegatio
if (operators[i] == operator) {
operators[i] = operators[operatorsLength - 1];
operators.pop();
if (operatorCache[operator].implementation != address(0)) {
delete operatorCache[operator]; // remove from cache
}
emit OperatorRemoved(operator);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/abstracts/MixinOperatorResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract contract MixinOperatorResolver {
OperatorResolver public immutable resolver;

/// @dev Cache operators map of the name and Operator struct (address/selector)
mapping(bytes32 => IOperatorResolver.Operator) private operatorCache;
mapping(bytes32 => IOperatorResolver.Operator) internal operatorCache;

constructor(address _resolver) {
resolver = OperatorResolver(_resolver);
Expand Down
54 changes: 54 additions & 0 deletions test/unit/NestedFactory.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ describe("NestedFactory", () => {
await context.nestedFactory.connect(context.masterDeployer).rebuildCache();
await context.nestedFactory.connect(context.masterDeployer).removeOperator(toBytes32("test"));


// Get the operators from the factory
let operators = await context.nestedFactory.resolverOperatorsRequired();

Expand Down Expand Up @@ -195,6 +196,59 @@ describe("NestedFactory", () => {
operators = await context.nestedFactory.resolverOperatorsRequired();
expect(operators[0]).to.be.equal(context.flatOperatorNameBytes32);
});

it("remove an operator without rebuilding", async () => {
const testAddress = Wallet.createRandom().address;
const operatorResolver = await context.operatorResolver.connect(context.masterDeployer);
// Add the operator named "test"
await importOperatorsWithSigner(
operatorResolver,
[
{
name: "test",
contract: testAddress,
signature: "function test()",
},
],
context.nestedFactory,
context.masterDeployer,
);

await context.nestedFactory.connect(context.masterDeployer).removeOperator(toBytes32("test"));

// Get the operators from the factory
let operators = await context.nestedFactory.resolverOperatorsRequired();

// Must have 2 operators ("ZeroEx" from Fixture and "Flat")
expect(operators.length).to.be.equal(2);
expect(operators[0]).to.be.equal(context.zeroExOperatorNameBytes32);
expect(operators[1]).to.be.equal(context.flatOperatorNameBytes32);

let orders: OrderStruct[] = [
buildOrderStruct(toBytes32("test"), context.mockUNI.address, [
["address", context.mockDAI.address],
["address", context.mockUNI.address],
[
"bytes",
ethers.utils.hexConcat([
dummyRouterSelector,
abiCoder.encode(
["address", "address", "uint"],
[context.mockDAI.address, context.mockUNI.address, appendDecimals(5)],
),
]),
],
]),
];

await expect(
context.nestedFactory
.connect(context.user1)
.create(0, [
{ inputToken: context.mockDAI.address, amount: appendDecimals(5), orders, fromReserve: false },
]),
).to.be.revertedWith("MOR: MISSING_OPERATOR: test");
});
});

describe("setFeeSplitter()", () => {
Expand Down

0 comments on commit d2e48a8

Please sign in to comment.