Skip to content

Commit

Permalink
fix(og): L-02 - Emit event on syncing upgraded OOv3 (#4487)
Browse files Browse the repository at this point in the history
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
  • Loading branch information
Reinis-FRP committed Mar 22, 2023
1 parent 835a6ff commit f3ea7a6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
Expand Up @@ -61,6 +61,8 @@ contract OptimisticGovernor is OptimisticOracleV3CallbackRecipientInterface, Mod

event SetEscalationManager(address indexed escalationManager);

event OptimisticOracleChanged(address indexed newOptimisticOracleV3);

FinderInterface public immutable finder; // Finder used to discover other UMA ecosystem contracts.

IERC20 public collateral; // Collateral currency used to assert proposed transactions.
Expand Down Expand Up @@ -419,9 +421,11 @@ contract OptimisticGovernor is OptimisticOracleV3CallbackRecipientInterface, Mod
// Caches the address of the Optimistic Oracle V3 from the Finder.
function _sync() internal {
optimisticOracleV3 = OptimisticOracleV3Interface(
finder.getImplementationAddress(OracleInterfaces.OptimisticOracleV3)
);
address newOptimisticOracleV3 = finder.getImplementationAddress(OracleInterfaces.OptimisticOracleV3);
if (newOptimisticOracleV3 != address(optimisticOracleV3)) {
optimisticOracleV3 = OptimisticOracleV3Interface(newOptimisticOracleV3);
emit OptimisticOracleChanged(newOptimisticOracleV3);
}
}
// Checks if the address is a contract.
Expand Down
Expand Up @@ -1224,6 +1224,28 @@ describe("OptimisticGovernor", () => {
);
});

it("Can reset Escalation Manager to zero address", async function () {
// Deploy Full Policy Escalation Manager and set it as new Escalation Manager.
const newEscalationManager = await FullPolicyEscalationManager.new(optimisticOracleV3.options.address).send({
from: owner,
});
const setEscalationManagerData = optimisticOracleModule.methods
.setEscalationManager(newEscalationManager.options.address)
.encodeABI();
await avatar.methods
.exec(optimisticOracleModule.options.address, "0", setEscalationManagerData)
.send({ from: owner });

// Reset Escalation Manager to zero address.
const resetEscalationManagerData = optimisticOracleModule.methods.setEscalationManager(ZERO_ADDRESS).encodeABI();
await avatar.methods
.exec(optimisticOracleModule.options.address, "0", resetEscalationManagerData)
.send({ from: owner });

// Check that Escalation Manager is set to zero address.
assert.equal(await optimisticOracleModule.methods.escalationManager().call(), ZERO_ADDRESS);
});

it("Cannot process callback from Optimistic Oracle V3 with invalid assertionId", async function () {
// Create assertion directly with Optimistic Oracle V3 and pointing Optimistic Governor as the callback recipient.
await bondToken.methods.approve(optimisticOracleV3.options.address, bond).send({ from: proposer });
Expand Down Expand Up @@ -1267,25 +1289,37 @@ describe("OptimisticGovernor", () => {
);
});

it("Can reset Escalation Manager to zero address", async function () {
// Deploy Full Policy Escalation Manager and set it as new Escalation Manager.
const newEscalationManager = await FullPolicyEscalationManager.new(optimisticOracleV3.options.address).send({
from: owner,
});
const setEscalationManagerData = optimisticOracleModule.methods
.setEscalationManager(newEscalationManager.options.address)
.encodeABI();
await avatar.methods
.exec(optimisticOracleModule.options.address, "0", setEscalationManagerData)
it("Emits event on syncing new Optimistic Oracle V3", async function () {
// Upgrade the Optimistic Oracle V3.
const defaultCurrency = await TestnetERC20.new("Default Currency", "DC", 18).send({ from: owner });
const newOptimisticOracleV3 = await OptimisticOracleV3Test.new(
finder.options.address,
defaultCurrency.options.address,
liveness,
timer.options.address
).send({ from: owner });
await finder.methods
.changeImplementationAddress(utf8ToHex(interfaceName.OptimisticOracleV3), newOptimisticOracleV3.options.address)
.send({ from: owner });

// Reset Escalation Manager to zero address.
const resetEscalationManagerData = optimisticOracleModule.methods.setEscalationManager(ZERO_ADDRESS).encodeABI();
await avatar.methods
.exec(optimisticOracleModule.options.address, "0", resetEscalationManagerData)
// Cache the upgraded Optimistic Oracle V3 and check the event is emitted.
const receipt = await optimisticOracleModule.methods.sync().send({ from: disputer });
await assertEventEmitted(
receipt,
optimisticOracleModule,
"OptimisticOracleChanged",
(event) => event.newOptimisticOracleV3 == newOptimisticOracleV3.options.address
);

// Revert to the original Optimistic Oracle V3 for other tests.
await finder.methods
.changeImplementationAddress(utf8ToHex(interfaceName.OptimisticOracleV3), optimisticOracleV3.options.address)
.send({ from: owner });
});

// Check that Escalation Manager is set to zero address.
assert.equal(await optimisticOracleModule.methods.escalationManager().call(), ZERO_ADDRESS);
it("Does not emit event on syncing the same Optimistic Oracle V3", async function () {
// Sync the Optimistic Oracle V3 and check the event is not emitted.
const receipt = await optimisticOracleModule.methods.sync().send({ from: owner });
assert.equal(Object.keys(receipt.events).length, 0);
});
});

0 comments on commit f3ea7a6

Please sign in to comment.