Skip to content

Commit

Permalink
Merge pull request #443 from equilibria-xyz/prateek/fix-update-extension
Browse files Browse the repository at this point in the history
Fix update extension
  • Loading branch information
prateekdefi authored Sep 23, 2024
2 parents b5fa427 + 2fdcd35 commit 01e6c3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/perennial/contracts/MarketFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ contract MarketFactory is IMarketFactory, Factory {
emit ParameterUpdated(newParameter);
}

/// @notice Updates the status of an operator for the caller
/// @param extension The operator to update to enable protocol-wide
/// @param newEnabled The new status of the operator
function updateExtension(address extension, bool newEnabled) external {
/// @notice Updates the status of an extension
/// @param extension The extension to update to enable protocol-wide
/// @param newEnabled The new status of the extension
function updateExtension(address extension, bool newEnabled) external onlyOwner {
extensions[extension] = newEnabled;
emit ExtensionUpdated(extension, newEnabled);
}
Expand Down
10 changes: 7 additions & 3 deletions packages/perennial/test/integration/core/happyPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ describe('Happy Path', () => {
const POSITION = parse6decimal('10')
const POSITION_B = parse6decimal('1')
const COLLATERAL = parse6decimal('1000')
const { user, userB, dsu, marketFactory } = instanceVars
const { owner, user, userB, dsu, marketFactory } = instanceVars

const market = await createMarket(instanceVars)

Expand All @@ -2014,9 +2014,13 @@ describe('Happy Path', () => {
.connect(user)
['update(address,uint256,uint256,uint256,int256,bool)'](user.address, POSITION, 0, 0, COLLATERAL, false)

// set user as extension for userB with signature
await marketFactory.connect(userB).updateExtension(user.address, true)
// try to update extension using incorrect owner
await expect(marketFactory.connect(userB).updateExtension(user.address, true))
.to.be.revertedWithCustomError(marketFactory, 'OwnableNotOwnerError')
.withArgs(userB.address)

// update extension with owner
await marketFactory.connect(owner).updateExtension(user.address, true)
// user opens long position for userB
await expect(
market
Expand Down
10 changes: 8 additions & 2 deletions packages/perennial/test/unit/marketfactory/MarketFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,18 +399,24 @@ describe('MarketFactory', () => {

describe('#updateExtension', async () => {
it('updates the operator status', async () => {
await expect(factory.connect(user).updateExtension(owner.address, true))
await expect(factory.connect(owner).updateExtension(owner.address, true))
.to.emit(factory, 'ExtensionUpdated')
.withArgs(owner.address, true)

expect(await factory.extensions(owner.address)).to.equal(true)

await expect(factory.connect(user).updateExtension(owner.address, false))
await expect(factory.connect(owner).updateExtension(owner.address, false))
.to.emit(factory, 'ExtensionUpdated')
.withArgs(owner.address, false)

expect(await factory.extensions(owner.address)).to.equal(false)
})

it('reverts if not owner', async () => {
await expect(factory.connect(user).updateExtension(user.address, true))
.to.be.revertedWithCustomError(factory, 'OwnableNotOwnerError')
.withArgs(user.address)
})
})

describe('#updateOperator', async () => {
Expand Down

0 comments on commit 01e6c3b

Please sign in to comment.