Skip to content

Commit

Permalink
improve some nits and refactor foundry tests (#12522)
Browse files Browse the repository at this point in the history
* improve some nits and refactor foundry tests

* add changesets

* fix

* fix tests

* write registerUpkeep() foundry tests for auto v2.3 (#12535)

move addFunds() tests to foundry for auto v2.3

add tests for onTokenTransfer()

---------

Co-authored-by: Ryan Hall <[email protected]>
  • Loading branch information
FelixFan1992 and RyanRHall authored Mar 21, 2024
1 parent a27d466 commit 8862016
Show file tree
Hide file tree
Showing 16 changed files with 479 additions and 558 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-plums-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

improve foundry tests and fix nits
5 changes: 5 additions & 0 deletions contracts/.changeset/curly-guests-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chainlink/contracts": minor
---

improve foundry tests

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions contracts/src/v0.8/automation/dev/test/AutomationRegistrar2_3.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract SetUp is BaseTest {

function setUp() public override {
super.setUp();
(registry, registrar) = deployAndConfigureAll(AutoBase.PayoutMode.ON_CHAIN);
(registry, registrar) = deployAndConfigureRegistryAndRegistrar(AutoBase.PayoutMode.ON_CHAIN);
vm.stopPrank(); // reset identity at the start of each test
}
}
Expand Down Expand Up @@ -51,8 +51,8 @@ contract RegisterUpkeep is SetUp {
function testUSDToken_autoApproveOff_happy() external {
vm.startPrank(UPKEEP_ADMIN);

uint96 amount = uint96(registrar.getMinimumRegistrationAmount(mockERC20));
mockERC20.approve(address(registrar), amount);
uint96 amount = uint96(registrar.getMinimumRegistrationAmount(usdToken));
usdToken.approve(address(registrar), amount);

registrar.registerUpkeep(
AutomationRegistrar2_3.RegistrationParams({
Expand All @@ -61,7 +61,7 @@ contract RegisterUpkeep is SetUp {
adminAddress: UPKEEP_ADMIN,
gasLimit: 10_000,
triggerType: 0,
billingToken: mockERC20,
billingToken: usdToken,
name: "foobar",
encryptedEmail: "",
checkData: bytes("check data"),
Expand All @@ -70,7 +70,7 @@ contract RegisterUpkeep is SetUp {
})
);

assertEq(mockERC20.balanceOf(address(registrar)), amount);
assertEq(usdToken.balanceOf(address(registrar)), amount);
assertEq(registry.getNumUpkeeps(), 0);
}

Expand Down Expand Up @@ -106,8 +106,8 @@ contract RegisterUpkeep is SetUp {
registrar.setTriggerConfig(0, AutomationRegistrar2_3.AutoApproveType.ENABLED_ALL, 1000);

vm.startPrank(UPKEEP_ADMIN);
uint96 amount = uint96(registrar.getMinimumRegistrationAmount(mockERC20));
mockERC20.approve(address(registrar), amount);
uint96 amount = uint96(registrar.getMinimumRegistrationAmount(usdToken));
usdToken.approve(address(registrar), amount);

registrar.registerUpkeep(
AutomationRegistrar2_3.RegistrationParams({
Expand All @@ -116,7 +116,7 @@ contract RegisterUpkeep is SetUp {
adminAddress: UPKEEP_ADMIN,
gasLimit: 10_000,
triggerType: 0,
billingToken: mockERC20,
billingToken: usdToken,
name: "foobar",
encryptedEmail: "",
checkData: bytes("check data"),
Expand All @@ -125,8 +125,8 @@ contract RegisterUpkeep is SetUp {
})
);

assertEq(mockERC20.balanceOf(address(registrar)), 0);
assertEq(mockERC20.balanceOf(address(registry)), amount);
assertEq(usdToken.balanceOf(address(registrar)), 0);
assertEq(usdToken.balanceOf(address(registry)), amount);
assertEq(registry.getNumUpkeeps(), 1);
}

Expand Down
Loading

0 comments on commit 8862016

Please sign in to comment.