Skip to content

Commit

Permalink
refactor linkForGas in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
infiloop2 committed Feb 16, 2024
1 parent 7b43985 commit 91398f6
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions contracts/test/v0.8/automation/AutomationRegistry2_2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,18 +516,18 @@ describe('AutomationRegistry2_2', () => {
.slice(10)
})

// This function is similar to registry's _calculatePaymentAmount
// It uses global fastGasWei, linkEth, and assumes isExecution = false (gasFee = fastGasWei*multiplier)
// rest of the parameters are the same
const linkForGas = (
upkeepGasSpent: BigNumber,
gasOverhead: BigNumber,
gasMultiplier: BigNumber,
premiumPPB: BigNumber,
flatFee: BigNumber,
l1CostWei?: BigNumber,
numUpkeepsBatch?: BigNumber,
l1CostWei?: BigNumber

Check failure on line 528 in contracts/test/v0.8/automation/AutomationRegistry2_2.test.ts

View workflow job for this annotation

GitHub Actions / Solidity Lint

Insert `,`
) => {
l1CostWei = l1CostWei === undefined ? BigNumber.from(0) : l1CostWei
numUpkeepsBatch =
numUpkeepsBatch === undefined ? BigNumber.from(1) : numUpkeepsBatch

const gasSpent = gasOverhead.add(BigNumber.from(upkeepGasSpent))
const base = gasWei
Expand All @@ -536,16 +536,14 @@ describe('AutomationRegistry2_2', () => {
.mul(linkDivisibility)
.div(linkEth)
const l1Fee = l1CostWei

Check failure on line 538 in contracts/test/v0.8/automation/AutomationRegistry2_2.test.ts

View workflow job for this annotation

GitHub Actions / Solidity Lint

Replace `⏎······.mul(linkDivisibility)⏎······` with `.mul(linkDivisibility)`
.mul(gasMultiplier)
.div(numUpkeepsBatch)
.mul(linkDivisibility)
.div(linkEth)
const gasPayment = base.add(l1Fee)

const premium = gasWei
.mul(gasMultiplier)
.mul(upkeepGasSpent)
.add(l1CostWei.mul(gasMultiplier).div(numUpkeepsBatch))
.add(l1CostWei)
.mul(linkDivisibility)
.div(linkEth)
.mul(premiumPPB)
Expand All @@ -554,15 +552,15 @@ describe('AutomationRegistry2_2', () => {

return {
total: gasPayment.add(premium),
gasPaymemnt: gasPayment,
gasPayment,
premium,
}
}

const verifyMaxPayment = async (
registry: IAutomationRegistry,
chainModule: IChainModule,
l1CostWei?: BigNumber,
maxl1CostWeWithoutMultiplier?: BigNumber,
) => {
type TestCase = {
name: string
Expand Down Expand Up @@ -611,7 +609,7 @@ describe('AutomationRegistry2_2', () => {
),
),
)
.add(chainModuleOverheads.chainModuleFixedOverhead) // 0
.add(chainModuleOverheads.chainModuleFixedOverhead)

const totalLogOverhead = registryLogOverhead
.add(registryPerSignerGasOverhead.mul(fPlusOne))
Expand Down Expand Up @@ -667,7 +665,7 @@ describe('AutomationRegistry2_2', () => {
BigNumber.from(test.multiplier),
BigNumber.from(test.premium),
BigNumber.from(test.flatFee),
l1CostWei,
maxl1CostWeWithoutMultiplier?.mul(BigNumber.from(test.multiplier)),
).total,
)

Expand All @@ -679,7 +677,7 @@ describe('AutomationRegistry2_2', () => {
BigNumber.from(test.multiplier),
BigNumber.from(test.premium),
BigNumber.from(test.flatFee),
l1CostWei,
maxl1CostWeWithoutMultiplier?.mul(BigNumber.from(test.multiplier)),
).total,
)
}
Expand Down Expand Up @@ -1586,7 +1584,7 @@ describe('AutomationRegistry2_2', () => {
gasCeilingMultiplier,
paymentPremiumPPB,
flatFeeMicroLink,
l1CostWeiArb.div(gasCeilingMultiplier), // Dividing by gasCeilingMultiplier as it gets multiplied later
l1CostWeiArb,
).total.toString(),
totalPayment.toString(),
)
Expand Down Expand Up @@ -2616,8 +2614,7 @@ describe('AutomationRegistry2_2', () => {
gasCeilingMultiplier,
paymentPremiumPPB,
flatFeeMicroLink,
l1CostWeiArb.div(gasCeilingMultiplier), // Dividing by gasCeilingMultiplier as it gets multiplied later
BigNumber.from(numUpkeeps),
l1CostWeiArb.div(BigNumber.from(numUpkeeps)),
).total.toString(),
totalPayment.toString(),
)
Expand Down Expand Up @@ -3298,13 +3295,12 @@ describe('AutomationRegistry2_2', () => {
})

describe('#getMaxPaymentForGas', () => {
let arbL1PriceinWei: BigNumber
let l1CostWeiArb: BigNumber
let l1CostWeiOpt: BigNumber
let maxl1CostWeiArbWithoutMultiplier : BigNumber

Check failure on line 3298 in contracts/test/v0.8/automation/AutomationRegistry2_2.test.ts

View workflow job for this annotation

GitHub Actions / Solidity Lint

Delete `·`
let maxl1CostWeiOptWithoutMultiplier : BigNumber

Check failure on line 3299 in contracts/test/v0.8/automation/AutomationRegistry2_2.test.ts

View workflow job for this annotation

GitHub Actions / Solidity Lint

Delete `·`

beforeEach(async () => {
arbL1PriceinWei = BigNumber.from(1000) // Same as MockArbGasInfo.sol
l1CostWeiArb = arbL1PriceinWei
let arbL1PriceinWei = BigNumber.from(1000) // Same as MockArbGasInfo.sol

Check warning on line 3302 in contracts/test/v0.8/automation/AutomationRegistry2_2.test.ts

View workflow job for this annotation

GitHub Actions / Solidity Lint

'arbL1PriceinWei' is never reassigned. Use 'const' instead
maxl1CostWeiArbWithoutMultiplier = arbL1PriceinWei
.mul(16)
.mul(
maxPerformDataSize
Expand All @@ -3315,19 +3311,19 @@ describe('AutomationRegistry2_2', () => {
),
),
)
l1CostWeiOpt = BigNumber.from(2000000) // Same as MockOVMGasPriceOracle.sol
maxl1CostWeiOptWithoutMultiplier = BigNumber.from(2000000) // Same as MockOVMGasPriceOracle.sol

Check failure on line 3314 in contracts/test/v0.8/automation/AutomationRegistry2_2.test.ts

View workflow job for this annotation

GitHub Actions / Solidity Lint

Delete `··`
})

itMaybe('calculates the max fee appropriately', async () => {
await verifyMaxPayment(registry, chainModuleBase)
})

itMaybe('calculates the max fee appropriately for Arbitrum', async () => {
await verifyMaxPayment(arbRegistry, arbitrumModule, l1CostWeiArb)
await verifyMaxPayment(arbRegistry, arbitrumModule, maxl1CostWeiArbWithoutMultiplier)

Check failure on line 3322 in contracts/test/v0.8/automation/AutomationRegistry2_2.test.ts

View workflow job for this annotation

GitHub Actions / Solidity Lint

Replace `arbRegistry,·arbitrumModule,·maxl1CostWeiArbWithoutMultiplier` with `⏎········arbRegistry,⏎········arbitrumModule,⏎········maxl1CostWeiArbWithoutMultiplier,⏎······`
})

itMaybe('calculates the max fee appropriately for Optimism', async () => {
await verifyMaxPayment(opRegistry, optimismModule, l1CostWeiOpt)
await verifyMaxPayment(opRegistry, optimismModule, maxl1CostWeiOptWithoutMultiplier)

Check failure on line 3326 in contracts/test/v0.8/automation/AutomationRegistry2_2.test.ts

View workflow job for this annotation

GitHub Actions / Solidity Lint

Replace `opRegistry,·optimismModule,·maxl1CostWeiOptWithoutMultiplier` with `⏎········opRegistry,⏎········optimismModule,⏎········maxl1CostWeiOptWithoutMultiplier,⏎······`
})

it('uses the fallback gas price if the feed has issues', async () => {
Expand Down

0 comments on commit 91398f6

Please sign in to comment.