Skip to content

Commit

Permalink
makerfactory coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrizzle committed Jul 15, 2023
1 parent c7af8fb commit f6d2a93
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/perennial/contracts/MarketFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ contract MarketFactory is IMarketFactory, Factory {
}

function fund(IMarket market) external {
if (!instances(IInstance(address(market)))) revert FactoryNotInstanceError();
market.claimFee();
}
}
111 changes: 110 additions & 1 deletion packages/perennial/test/unit/marketfactory/MarketFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
IPayoffProvider,
IPayoffFactory,
IOracleFactory,
IMarket,
} from '../../../types/generated'
import { parse6decimal } from '../../../../common/testutil/types'
import { BigNumber, constants } from 'ethers'
Expand Down Expand Up @@ -318,6 +319,53 @@ describe('MarketFactory', () => {
'FactoryAlreadyRegisteredError',
)
})

it('reverts when not owner', async () => {
const marketDefinition = {
name: 'Squeeth',
symbol: 'SQTH',
token: dsu.address,
oracle: oracle.address,
payoff: payoffProvider.address,
}
const marketParameter = {
maintenance: parse6decimal('0.3'),
fundingFee: parse6decimal('0.1'),
interestFee: parse6decimal('0.1'),
takerFee: 0,
takerSkewFee: 0,
takerImpactFee: 0,
makerFee: 0,
makerImpactFee: 0,
positionFee: 0,
makerLimit: parse6decimal('1000'),
efficiencyLimit: parse6decimal('0.2'),
liquidationFee: parse6decimal('0.50'),
minLiquidationFee: parse6decimal('0'),
maxLiquidationFee: parse6decimal('1000'),
utilizationCurve: {
minRate: parse6decimal('0.10'),
maxRate: parse6decimal('0.10'),
targetRate: parse6decimal('0.10'),
targetUtilization: parse6decimal('1'),
},
pController: {
k: parse6decimal('40000'),
max: parse6decimal('1.20'),
},
minMaintenance: parse6decimal('100'),
staleAfter: 7200,
makerReceiveOnly: false,
}

oracleFactory.instances.whenCalledWith(oracle.address).returns(true)
payoffFactory.payoffs.whenCalledWith(payoffProvider.address).returns(true)

await expect(factory.connect(user).create(marketDefinition, marketParameter)).to.revertedWithCustomError(
factory,
'UOwnableNotOwnerError',
)
})
})

describe('#updateParameter', async () => {
Expand Down Expand Up @@ -370,5 +418,66 @@ describe('MarketFactory', () => {
})
})

//TODO (coveragehint): fund
describe('#fund', async () => {
let marketAddress: string
let fakeMarket: FakeContract<IMarket>

beforeEach(async () => {
const marketDefinition = {
name: 'Squeeth',
symbol: 'SQTH',
token: dsu.address,
oracle: oracle.address,
payoff: constants.AddressZero,
}
const marketParameter = {
maintenance: parse6decimal('0.3'),
fundingFee: parse6decimal('0.1'),
interestFee: parse6decimal('0.1'),
takerFee: 0,
takerSkewFee: 0,
takerImpactFee: 0,
makerFee: 0,
makerImpactFee: 0,
positionFee: 0,
makerLimit: parse6decimal('1000'),
efficiencyLimit: parse6decimal('0.2'),
liquidationFee: parse6decimal('0.50'),
minLiquidationFee: parse6decimal('0'),
maxLiquidationFee: parse6decimal('1000'),
utilizationCurve: {
minRate: parse6decimal('0.10'),
maxRate: parse6decimal('0.10'),
targetRate: parse6decimal('0.10'),
targetUtilization: parse6decimal('1'),
},
pController: {
k: parse6decimal('40000'),
max: parse6decimal('1.20'),
},
minMaintenance: parse6decimal('100'),
staleAfter: 7200,
makerReceiveOnly: false,
}

oracleFactory.instances.whenCalledWith(oracle.address).returns(true)

marketAddress = await factory.callStatic.create(marketDefinition, marketParameter)
await factory.connect(owner).create(marketDefinition, marketParameter)
fakeMarket = await smock.fake<IMarket>('IMarket', { address: marketAddress })
})

it('claims its fees', async () => {
await factory.connect(user).fund(marketAddress)

expect(fakeMarket.claimFee).to.have.been.called
})

it('reverts if not an instance', async () => {
await expect(factory.connect(user).fund(user.address)).to.be.revertedWithCustomError(
factory,
'FactoryNotInstanceError',
)
})
})
})

0 comments on commit f6d2a93

Please sign in to comment.