Skip to content

Commit

Permalink
withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixFan1992 committed Aug 2, 2024
1 parent 8bc27dc commit 49c8926
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2738,3 +2738,33 @@ contract SetPayees is SetUp {
assertEq(PAYEES[1], payee);
}
}

contract GetActiveUpkeepIDs is SetUp {
function test_RevertsWhen_IndexOutOfRange() external {
vm.expectRevert(Registry.IndexOutOfRange.selector);
registry.getActiveUpkeepIDs(5, 0);

vm.expectRevert(Registry.IndexOutOfRange.selector);
registry.getActiveUpkeepIDs(6, 0);
}

function test_ReturnsAllUpkeeps_WhenMaxCountIsZero() external {
uint256[] memory uids = registry.getActiveUpkeepIDs(0, 0);
assertEq(5, uids.length);

uids = registry.getActiveUpkeepIDs(2, 0);
assertEq(3, uids.length);
}

function test_ReturnsAllRemainingUpkeeps_WhenMaxCountIsTooLarge() external {
uint256[] memory uids = registry.getActiveUpkeepIDs(2, 20);
assertEq(3, uids.length);
}

function test_ReturnsUpkeeps_BoundByMaxCount() external {
uint256[] memory uids = registry.getActiveUpkeepIDs(1, 2);
assertEq(2, uids.length);
assertEq(uids[0], linkUpkeepID2);
assertEq(uids[1], usdUpkeepID18);
}
}
153 changes: 0 additions & 153 deletions contracts/test/v0.8/automation/AutomationRegistry2_3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3106,44 +3106,6 @@ describe('AutomationRegistry2_3', () => {
await getTransmitTx(registry, keeper1, [upkeepId2])
})

it('reverts if called on a non existing ID', async () => {
await evmRevertCustomError(
registry
.connect(admin)
.withdrawFunds(upkeepId.add(1), await payee1.getAddress()),
registry,
'OnlyCallableByAdmin',
)
})

it('reverts if called by anyone but the admin', async () => {
await evmRevertCustomError(
registry
.connect(owner)
.withdrawFunds(upkeepId, await payee1.getAddress()),
registry,
'OnlyCallableByAdmin',
)
})

it('reverts if called on an uncanceled upkeep', async () => {
await evmRevertCustomError(
registry
.connect(admin)
.withdrawFunds(upkeepId, await payee1.getAddress()),
registry,
'UpkeepNotCanceled',
)
})

it('reverts if called with the 0 address', async () => {
await evmRevertCustomError(
registry.connect(admin).withdrawFunds(upkeepId, zeroAddress),
registry,
'InvalidRecipient',
)
})

describe('after the registration is paused, then cancelled', () => {
it('allows the admin to withdraw', async () => {
const balance = await registry.getBalance(upkeepId)
Expand Down Expand Up @@ -3513,46 +3475,6 @@ describe('AutomationRegistry2_3', () => {
})
})

describe('#getActiveUpkeepIDs', () => {
it('reverts if startIndex is out of bounds ', async () => {
await evmRevertCustomError(
registry.getActiveUpkeepIDs(numUpkeeps, 0),
registry,
'IndexOutOfRange',
)
await evmRevertCustomError(
registry.getActiveUpkeepIDs(numUpkeeps + 1, 0),
registry,
'IndexOutOfRange',
)
})

it('returns upkeep IDs bounded by maxCount', async () => {
let upkeepIds = await registry.getActiveUpkeepIDs(0, 1)
assert(upkeepIds.length == 1)
assert(upkeepIds[0].eq(upkeepId))
upkeepIds = await registry.getActiveUpkeepIDs(1, 3)
assert(upkeepIds.length == 3)
expect(upkeepIds).to.deep.equal([
afUpkeepId,
logUpkeepId,
streamsLookupUpkeepId,
])
})

it('returns as many ids as possible if maxCount > num available', async () => {
const upkeepIds = await registry.getActiveUpkeepIDs(1, numUpkeeps + 100)
assert(upkeepIds.length == numUpkeeps - 1)
})

it('returns all upkeep IDs if maxCount is 0', async () => {
let upkeepIds = await registry.getActiveUpkeepIDs(0, 0)
assert(upkeepIds.length == numUpkeeps)
upkeepIds = await registry.getActiveUpkeepIDs(2, 0)
assert(upkeepIds.length == numUpkeeps - 2)
})
})

describe('#getMaxPaymentForGas', () => {
let maxl1CostWeiArbWithoutMultiplier: BigNumber
let maxl1CostWeiOptWithoutMultiplier: BigNumber
Expand Down Expand Up @@ -4224,81 +4146,6 @@ describe('AutomationRegistry2_3', () => {
})
})

describe('#withdrawOwnerFunds', () => {
it('can only be called by finance admin', async () => {
await evmRevertCustomError(
registry.connect(keeper1).withdrawLink(zeroAddress, 1),
registry,
'OnlyFinanceAdmin',
)
})

itMaybe('withdraws the collected fees to owner', async () => {
await registry.connect(admin).addFunds(upkeepId, toWei('100'))
const financeAdminAddress = await financeAdmin.getAddress()
// Very high min spend, whole balance as cancellation fees
const newMinUpkeepSpend = toWei('1000')
await registry.connect(owner).setConfigTypeSafe(
signerAddresses,
keeperAddresses,
f,
{
checkGasLimit,
stalenessSeconds,
gasCeilingMultiplier,
maxCheckDataSize,
maxPerformDataSize,
maxRevertDataSize,
maxPerformGas,
fallbackGasPrice,
fallbackLinkPrice,
fallbackNativePrice,
transcoder: transcoder.address,
registrars: [],
upkeepPrivilegeManager: upkeepManager,
chainModule: chainModuleBase.address,
reorgProtectionEnabled: true,
financeAdmin: financeAdminAddress,
},
offchainVersion,
offchainBytes,
[linkToken.address],
[
{
gasFeePPB: paymentPremiumPPB,
flatFeeMilliCents,
priceFeed: linkUSDFeed.address,
fallbackPrice: fallbackLinkPrice,
minSpend: newMinUpkeepSpend,
decimals: 18,
},
],
)
const upkeepBalance = (await registry.getUpkeep(upkeepId)).balance
const ownerBefore = await linkToken.balanceOf(await owner.getAddress())

await registry.connect(owner).cancelUpkeep(upkeepId)

// Transfered to owner balance on registry
let ownerRegistryBalance = await registry.linkAvailableForPayment()
assert.isTrue(ownerRegistryBalance.eq(upkeepBalance))

// Now withdraw
await registry
.connect(financeAdmin)
.withdrawLink(await owner.getAddress(), ownerRegistryBalance)

ownerRegistryBalance = await registry.linkAvailableForPayment()
const ownerAfter = await linkToken.balanceOf(await owner.getAddress())

// Owner registry balance should be changed to 0
assert.isTrue(ownerRegistryBalance.eq(BigNumber.from('0')))

// Owner should be credited with the balance
assert.isTrue(ownerBefore.add(upkeepBalance).eq(ownerAfter))
})
})

describe('#cancelUpkeep', () => {
describe('when called by the owner', async () => {
it('immediately prevents upkeep', async () => {
Expand Down

0 comments on commit 49c8926

Please sign in to comment.