Skip to content

Commit

Permalink
update offline testing with registrar mock
Browse files Browse the repository at this point in the history
  • Loading branch information
AnonJon committed Oct 14, 2023
1 parent b4eea6a commit 3a4141d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"solidity.packageDefaultDependenciesContractsDirectory": "contracts",
"solidity.packageDefaultDependenciesDirectory": "lib",
"solidity.compileUsingRemoteVersion": "v0.8.17+commit.8df45f5f",
"solidity.compileUsingRemoteVersion": "v0.8.20",
"solidity.remappings": [
"forge-std/=contracts/lib/forge-std/src/",
"@openzeppelin/=contracts/lib/openzeppelin-contracts/",
Expand Down
24 changes: 24 additions & 0 deletions contracts/src/mock/RegistrarMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract RegistrarMock {
uint256 public currentId = 0;

struct RegistrationParams {
string name;
bytes encryptedEmail;
address upkeepContract;
uint32 gasLimit;
address adminAddress;
bytes checkData;
bytes offchainConfig;
uint96 amount;
}

constructor() {}

function registerUpkeep(RegistrationParams calldata params) external returns (uint256 id) {
currentId++;
return currentId;
}
}
7 changes: 4 additions & 3 deletions contracts/test/GiveawayManager.invariant.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {VRFV2WrapperMock} from "@src/mock/VRFV2WrapperMock.sol";
import {Handler} from "./handlers/Handler.sol";
import {UD60x18, ud, intoUint256} from "@prb/math/UD60x18.sol";
import {AutomationMock} from "@src/mock/AutomationMock.sol";
import {RegistrarMock} from "@src/mock/RegistrarMock.sol";

contract GiveawayManagerInvariants is Test {
GiveawayManager giveawayManager;
Expand All @@ -21,7 +22,7 @@ contract GiveawayManagerInvariants is Test {
uint32 callbackGasLimit;
AutomationMock keeperAddress;
address linkAddress;
address registrarAddress;
RegistrarMock registrarAddress;
ERC677Mock customLINK;
address admin;
address giveawayAdmin;
Expand Down Expand Up @@ -55,7 +56,7 @@ contract GiveawayManagerInvariants is Test {
automationCallbackGas = 500_000;
keeperAddress = new AutomationMock();
linkAddress = address(0x3);
registrarAddress = address(0x4);
registrarAddress = new RegistrarMock();
merkleRoot = 0x344510bd0c324c3912b13373e89df42d1b50450e9764a454b2aa6e2968a4578a;
proofA[0] = 0xd52688a8f926c816ca1e079067caba944f158e764817b83fc43594370ca9cf62;
proofA[1] = 0x5b70e80538acdabd6137353b0f9d8d149f4dba91e8be2e7946e409bfdbe685b9;
Expand All @@ -71,7 +72,7 @@ contract GiveawayManagerInvariants is Test {
callbackGasLimit,
address(keeperAddress),
address(customLINK),
registrarAddress,
address(registrarAddress),
automationCallbackGas
);
customLINK.transfer(giveawayAdmin, 1000000 ether);
Expand Down
9 changes: 5 additions & 4 deletions contracts/test/GiveawayManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {ERC677Mock} from "@src/mock/ERC677Mock.sol";
import {VRFV2WrapperMock} from "@src/mock/VRFV2WrapperMock.sol";
import {AutomationMock} from "@src/mock/AutomationMock.sol";
import {IERC677} from "@chainlink/contracts/src/v0.8/shared/token/ERC677/IERC677.sol";
import {RegistrarMock} from "@src/mock/RegistrarMock.sol";

contract GiveawayManagerTest is Test {
GiveawayManager giveawayManager;
Expand All @@ -19,7 +20,7 @@ contract GiveawayManagerTest is Test {
uint32 callbackGasLimit;
uint32 automationCallbackGasLimit;
AutomationMock keeperAddress;
address registrarAddress;
RegistrarMock registrarAddress;
address linkAddress;
ERC677Mock customLINK;
address admin;
Expand Down Expand Up @@ -60,7 +61,7 @@ contract GiveawayManagerTest is Test {
automationCallbackGasLimit = 500_000;
keeperAddress = new AutomationMock();
linkAddress = address(0x3);
registrarAddress = address(0x4);
registrarAddress = new RegistrarMock();
merkleRoot = 0x344510bd0c324c3912b13373e89df42d1b50450e9764a454b2aa6e2968a4578a;
proofA[0] = 0xd52688a8f926c816ca1e079067caba944f158e764817b83fc43594370ca9cf62;
proofA[1] = 0x5b70e80538acdabd6137353b0f9d8d149f4dba91e8be2e7946e409bfdbe685b9;
Expand All @@ -76,7 +77,7 @@ contract GiveawayManagerTest is Test {
callbackGasLimit,
address(keeperAddress),
address(customLINK),
address(keeperAddress),
address(registrarAddress),
automationCallbackGasLimit
);
customLINK.transfer(giveawayAdmin, 1000000 ether);
Expand Down Expand Up @@ -384,7 +385,7 @@ contract GiveawayManagerTest is Test {
customTokenGiveawayFixture();
vm.startPrank(user1);
customToken.approve(address(giveawayManager), 1 ether);
vm.expectRevert("ERC20: transfer amount exceeds balance");
vm.expectRevert();
giveawayManager.enterGiveaway(0, 1, new bytes32[](0));
vm.stopPrank();
}
Expand Down

0 comments on commit 3a4141d

Please sign in to comment.