From c6003d35c2e1b2349fa3c9e11795e759a684abf7 Mon Sep 17 00:00:00 2001 From: lei shi Date: Mon, 25 Mar 2024 13:46:40 -0700 Subject: [PATCH] add test for billing overrides --- .changeset/tiny-suns-end.md | 5 +++++ contracts/.changeset/tasty-rings-bow.md | 5 +++++ .../dev/test/AutomationRegistry2_3.t.sol | 19 +++++++++++++++++++ .../v0.8/automation/dev/test/BaseTest.t.sol | 14 ++++++++------ 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 .changeset/tiny-suns-end.md create mode 100644 contracts/.changeset/tasty-rings-bow.md diff --git a/.changeset/tiny-suns-end.md b/.changeset/tiny-suns-end.md new file mode 100644 index 00000000000..3bdd12ea362 --- /dev/null +++ b/.changeset/tiny-suns-end.md @@ -0,0 +1,5 @@ +--- +"chainlink": patch +--- + +add test for billing override diff --git a/contracts/.changeset/tasty-rings-bow.md b/contracts/.changeset/tasty-rings-bow.md new file mode 100644 index 00000000000..828050c6eeb --- /dev/null +++ b/contracts/.changeset/tasty-rings-bow.md @@ -0,0 +1,5 @@ +--- +"@chainlink/contracts": patch +--- + +add billing override test diff --git a/contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol b/contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol index 4f0f8fa4f80..c03c1156dda 100644 --- a/contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol +++ b/contracts/src/v0.8/automation/dev/test/AutomationRegistry2_3.t.sol @@ -948,4 +948,23 @@ contract BillingOverrides is SetUp { emit BillingConfigOverrideRemoved(linkUpkeepID); registry.removeBillingOverrides(linkUpkeepID); } + + function test_Happy_MaxGasPayment_WithBillingOverrides() public { + uint96 maxPayment1 = registry.getMaxPaymentForGas(linkUpkeepID, 0, 5_000_000, address(linkToken)); + + // Double the two billing values + AutomationRegistryBase2_3.BillingOverrides memory billingOverrides = AutomationRegistryBase2_3.BillingOverrides({ + gasFeePPB: DEFAULT_GAS_FEE_PPB * 2, + flatFeeMilliCents: DEFAULT_FLAT_FEE_MILLI_CENTS * 2 + }); + + vm.startPrank(PRIVILEGE_MANAGER); + registry.setBillingOverrides(linkUpkeepID, billingOverrides); + + // maxPayment2 should be greater than maxPayment1 after the overrides + // The 2 numbers should follow this: maxPayment2 - maxPayment1 == 2 * recepit.premium + // We do not apply the exact equation since we couldn't get the receipt.premium value + uint96 maxPayment2 = registry.getMaxPaymentForGas(linkUpkeepID, 0, 5_000_000, address(linkToken)); + assertGt(maxPayment2, maxPayment1); + } } diff --git a/contracts/src/v0.8/automation/dev/test/BaseTest.t.sol b/contracts/src/v0.8/automation/dev/test/BaseTest.t.sol index 9f2d3ad5e5b..a09dd8ad719 100644 --- a/contracts/src/v0.8/automation/dev/test/BaseTest.t.sol +++ b/contracts/src/v0.8/automation/dev/test/BaseTest.t.sol @@ -30,6 +30,8 @@ contract BaseTest is Test { // constants address internal constant ZERO_ADDRESS = address(0); + uint32 internal constant DEFAULT_GAS_FEE_PPB = 10_000_000; + uint24 internal constant DEFAULT_FLAT_FEE_MILLI_CENTS = 2_000; // config uint8 internal constant F = 1; // number of faulty nodes @@ -153,22 +155,22 @@ contract BaseTest is Test { AutomationRegistryBase2_3.BillingConfig[] memory billingTokenConfigs = new AutomationRegistryBase2_3.BillingConfig[](billingTokens.length); billingTokenConfigs[0] = AutomationRegistryBase2_3.BillingConfig({ - gasFeePPB: 10_000_000, // 15% - flatFeeMilliCents: 2_000, // 2 cents + gasFeePPB: DEFAULT_GAS_FEE_PPB, // 15% + flatFeeMilliCents: DEFAULT_FLAT_FEE_MILLI_CENTS, // 2 cents priceFeed: address(USDTOKEN_USD_FEED), fallbackPrice: 100_000_000, // $1 minSpend: 100000000000000000000 // 100 USD }); billingTokenConfigs[1] = AutomationRegistryBase2_3.BillingConfig({ - gasFeePPB: 10_000_000, // 15% - flatFeeMilliCents: 2_000, // 2 cents + gasFeePPB: DEFAULT_GAS_FEE_PPB, // 15% + flatFeeMilliCents: DEFAULT_FLAT_FEE_MILLI_CENTS, // 2 cents priceFeed: address(NATIVE_USD_FEED), fallbackPrice: 100_000_000, // $1 minSpend: 5000000000000000000 // 5 Native }); billingTokenConfigs[2] = AutomationRegistryBase2_3.BillingConfig({ - gasFeePPB: 10_000_000, // 10% - flatFeeMilliCents: 2_000, // 2 cents + gasFeePPB: DEFAULT_GAS_FEE_PPB, // 10% + flatFeeMilliCents: DEFAULT_FLAT_FEE_MILLI_CENTS, // 2 cents priceFeed: address(LINK_USD_FEED), fallbackPrice: 1_000_000_000, // $10 minSpend: 5000000000000000000 // 5 LINK