Skip to content

Commit

Permalink
test with test files
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed Aug 7, 2024
1 parent d65d1e7 commit d15a224
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/actions/validate-artifact-scope/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ runs:
echo "Files: ${files[@]}"
for file in "${files[@]}"; do
missing_files+="$file"
missing_files+="$file,"
product=$(echo "$file" | awk -F'src/v0.8/' '{if ($2 ~ /\//) print substr($2, 1, index($2, "/")-1); else print "shared"}')
if [[ ! " ${products[@]} " =~ " ${product} " ]]; then
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/solidity-hardhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:

env:
FOUNDRY_PROFILE: ci
product: "shared"
product: "automation"
base_ref: "7b7b9ddac6de536bc84b3b45bd6104948bbf2650"

jobs:
Expand Down
14 changes: 14 additions & 0 deletions contracts/src/v0.8/automation/BaseTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Test.sol";

contract BaseTest is Test {
address internal OWNER = 0x00007e64E1fB0C487F25dd6D3601ff6aF8d32e4e;
address internal constant STRANGER = address(999);

function setUp() public virtual {
vm.startPrank(OWNER);
deal(OWNER, 1e20);
}
}
17 changes: 17 additions & 0 deletions contracts/src/v0.8/automation/mocks/ERC20Mock6DecimalsNew.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pragma solidity ^0.8.0;

import {ERC20Mock} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/mocks/ERC20Mock.sol";

// mock ERC20 with 6 decimals
contract ERC20Mock6Decimals is ERC20Mock {
constructor(
string memory name,
string memory symbol,
address initialAccount,
uint256 initialBalance
) payable ERC20Mock(name, symbol, initialAccount, initialBalance) {}

function decimals() public view virtual override returns (uint8) {
return 6;
}
}
74 changes: 74 additions & 0 deletions contracts/src/v0.8/automation/test/AutomationForwarderNew.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.16;

import {IAutomationForwarder} from "../interfaces/IAutomationForwarder.sol";
import {AutomationForwarder} from "../AutomationForwarder.sol";
import {AutomationForwarderLogic} from "../AutomationForwarderLogic.sol";
import "forge-std/Test.sol";

// in contracts directory, run
// forge test --match-path src/v0.8/automation/test/AutomationForwarder.t.sol

contract Target {
function handler() external pure {}

function handlerRevert() external pure {
revert("revert");
}
}

contract AutomationForwarderTestSetUp is Test {
address internal constant REGISTRY = 0x3e19ef5Aaa2606655f5A677A97E085cf3811067c;
address internal constant STRANGER = 0x618fae5d04963B2CEf533F247Eb2C46Bf1801D3b;

IAutomationForwarder internal forwarder;
address internal TARGET;

function setUp() public {
TARGET = address(new Target());
AutomationForwarderLogic logicContract = new AutomationForwarderLogic();
forwarder = IAutomationForwarder(address(new AutomationForwarder(TARGET, REGISTRY, address(logicContract))));
}
}

contract AutomationForwarderTest_constructor is AutomationForwarderTestSetUp {
function testInitialValues() external {
assertEq(address(forwarder.getRegistry()), REGISTRY);
assertEq(forwarder.getTarget(), TARGET);
}

function testTypeAndVersion() external {
assertEq(forwarder.typeAndVersion(), "AutomationForwarder 1.0.0");
}
}

contract AutomationForwarderTest_forward is AutomationForwarderTestSetUp {
function testOnlyCallableByTheRegistry() external {
vm.prank(REGISTRY);
forwarder.forward(100000, abi.encodeWithSelector(Target.handler.selector));
vm.prank(STRANGER);
vm.expectRevert();
forwarder.forward(100000, abi.encodeWithSelector(Target.handler.selector));
}

function testReturnsSuccessValueAndGasUsed() external {
vm.startPrank(REGISTRY);
(bool success, uint256 gasUsed) = forwarder.forward(100000, abi.encodeWithSelector(Target.handler.selector));
assertTrue(success);
assertGt(gasUsed, 0);
(success, gasUsed) = forwarder.forward(100000, abi.encodeWithSelector(Target.handlerRevert.selector));
assertFalse(success);
assertGt(gasUsed, 0);
}
}

contract AutomationForwarderTest_updateRegistry is AutomationForwarderTestSetUp {
function testOnlyCallableByTheActiveRegistry() external {
address newRegistry = address(1);
vm.startPrank(REGISTRY);
forwarder.updateRegistry(newRegistry);
assertEq(address(forwarder.getRegistry()), newRegistry);
vm.expectRevert();
forwarder.updateRegistry(REGISTRY);
}
}
14 changes: 14 additions & 0 deletions contracts/src/v0.8/mocks/BaseTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Test.sol";

contract BaseTest is Test {
address internal OWNER = 0x00007e64E1fB0C487F25dd6D3601ff6aF8d32e4e;
address internal constant STRANGER = address(999);

function setUp() public virtual {
vm.startPrank(OWNER);
deal(OWNER, 1e20);
}
}
80 changes: 80 additions & 0 deletions contracts/src/v0.8/mocks/FunctionsBillingRegistryEventsMockNew.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: MIT
// Warning: this is an autogenerated file! DO NOT EDIT.

pragma solidity ^0.8.6;

contract FunctionsBillingRegistryEventsMock {
struct Commitment {uint64 subscriptionId;address client;uint32 gasLimit;uint256 gasPrice;address don;uint96 donFee;uint96 registryFee;uint96 estimatedCost;uint256 timestamp; }
event AuthorizedSendersChanged(address[] senders,address changedBy);
event BillingEnd(bytes32 indexed requestId,uint64 subscriptionId,uint96 signerPayment,uint96 transmitterPayment,uint96 totalCost,bool success);
event BillingStart(bytes32 indexed requestId,Commitment commitment);
event ConfigSet(uint32 maxGasLimit,uint32 stalenessSeconds,uint256 gasAfterPaymentCalculation,int256 fallbackWeiPerUnitLink,uint32 gasOverhead);
event FundsRecovered(address to,uint256 amount);
event Initialized(uint8 version);
event OwnershipTransferRequested(address indexed from,address indexed to);
event OwnershipTransferred(address indexed from,address indexed to);
event Paused(address account);
event RequestTimedOut(bytes32 indexed requestId);
event SubscriptionCanceled(uint64 indexed subscriptionId,address to,uint256 amount);
event SubscriptionConsumerAdded(uint64 indexed subscriptionId,address consumer);
event SubscriptionConsumerRemoved(uint64 indexed subscriptionId,address consumer);
event SubscriptionCreated(uint64 indexed subscriptionId,address owner);
event SubscriptionFunded(uint64 indexed subscriptionId,uint256 oldBalance,uint256 newBalance);
event SubscriptionOwnerTransferRequested(uint64 indexed subscriptionId,address from,address to);
event SubscriptionOwnerTransferred(uint64 indexed subscriptionId,address from,address to);
event Unpaused(address account);
function emitAuthorizedSendersChanged(address[] memory senders,address changedBy) public {
emit AuthorizedSendersChanged(senders,changedBy);
}
function emitBillingEnd(bytes32 requestId,uint64 subscriptionId,uint96 signerPayment,uint96 transmitterPayment,uint96 totalCost,bool success) public {
emit BillingEnd(requestId,subscriptionId,signerPayment,transmitterPayment,totalCost,success);
}
function emitBillingStart(bytes32 requestId,Commitment memory commitment) public {
emit BillingStart(requestId,commitment);
}
function emitConfigSet(uint32 maxGasLimit,uint32 stalenessSeconds,uint256 gasAfterPaymentCalculation,int256 fallbackWeiPerUnitLink,uint32 gasOverhead) public {
emit ConfigSet(maxGasLimit,stalenessSeconds,gasAfterPaymentCalculation,fallbackWeiPerUnitLink,gasOverhead);
}
function emitFundsRecovered(address to,uint256 amount) public {
emit FundsRecovered(to,amount);
}
function emitInitialized(uint8 version) public {
emit Initialized(version);
}
function emitOwnershipTransferRequested(address from,address to) public {
emit OwnershipTransferRequested(from,to);
}
function emitOwnershipTransferred(address from,address to) public {
emit OwnershipTransferred(from,to);
}
function emitPaused(address account) public {
emit Paused(account);
}
function emitRequestTimedOut(bytes32 requestId) public {
emit RequestTimedOut(requestId);
}
function emitSubscriptionCanceled(uint64 subscriptionId,address to,uint256 amount) public {
emit SubscriptionCanceled(subscriptionId,to,amount);
}
function emitSubscriptionConsumerAdded(uint64 subscriptionId,address consumer) public {
emit SubscriptionConsumerAdded(subscriptionId,consumer);
}
function emitSubscriptionConsumerRemoved(uint64 subscriptionId,address consumer) public {
emit SubscriptionConsumerRemoved(subscriptionId,consumer);
}
function emitSubscriptionCreated(uint64 subscriptionId,address owner) public {
emit SubscriptionCreated(subscriptionId,owner);
}
function emitSubscriptionFunded(uint64 subscriptionId,uint256 oldBalance,uint256 newBalance) public {
emit SubscriptionFunded(subscriptionId,oldBalance,newBalance);
}
function emitSubscriptionOwnerTransferRequested(uint64 subscriptionId,address from,address to) public {
emit SubscriptionOwnerTransferRequested(subscriptionId,from,to);
}
function emitSubscriptionOwnerTransferred(uint64 subscriptionId,address from,address to) public {
emit SubscriptionOwnerTransferred(subscriptionId,from,to);
}
function emitUnpaused(address account) public {
emit Unpaused(account);
}
}
14 changes: 14 additions & 0 deletions contracts/src/v0.8/tests/BaseTest.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Test.sol";

contract BaseTest is Test {
address internal OWNER = 0x00007e64E1fB0C487F25dd6D3601ff6aF8d32e4e;
address internal constant STRANGER = address(999);

function setUp() public virtual {
vm.startPrank(OWNER);
deal(OWNER, 1e20);
}
}

0 comments on commit d15a224

Please sign in to comment.