Skip to content

Commit

Permalink
make old tests pass + test for recover gas tx cost
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlinaric committed Oct 18, 2024
1 parent f4819c8 commit bbc8bbf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Test

on:
push:
branches:
- mpetrun5/add-revert-gas
pull_request:
types: [opened, synchronize, reopened]

jobs:
test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract TwapNativeTokenFeeHandler is TwapFeeHandler {
if (depositData.length > (pointer + 64)) {
uint256 gas = abi.decode(depositData[pointer:], (uint256));
maxFee += gas;
maxFee += _recoverGas;
maxFee += uint256(_recoverGas);
}
uint256 destinationCoinPrice = twapOracle.getPrice(destinationNativeCoinWrap[destinationDomainID]);
if (destinationCoinPrice == 0) revert IncorrectPrice();
Expand Down
4 changes: 2 additions & 2 deletions testUnderForked/collectFeeERC20EVM.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ contract("TwapNativeTokenFeeHandler - [collectFee]", async (accounts) => {
const fee = Ethers.BigNumber.from(expectedFee.toString()).div(2);

const errorValues = await Helpers.expectToRevertWithCustomError(
BridgeInstance.deposit(
BridgeInstance.deposit.call(
destinationDomainID,
resourceID,
depositData,
Expand All @@ -243,7 +243,7 @@ contract("TwapNativeTokenFeeHandler - [collectFee]", async (accounts) => {
await TwapOracleInstance.setPrice(MATIC_ADDRESS, 0);

await Helpers.expectToRevertWithCustomError(
BridgeInstance.deposit(
BridgeInstance.deposit.call(
destinationDomainID,
resourceID,
depositData,
Expand Down
4 changes: 2 additions & 2 deletions testUnderForked/collectFeeGenericEVM.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ contract("TwapGenericFeeHandler - [collectFee]", async (accounts) => {
const fee = Ethers.BigNumber.from(expectedFee.toString()).div(2);

const errorValues = await Helpers.expectToRevertWithCustomError(
BridgeInstance.deposit(
BridgeInstance.deposit.call(
destinationDomainID,
resourceID,
depositData,
Expand All @@ -238,7 +238,7 @@ contract("TwapGenericFeeHandler - [collectFee]", async (accounts) => {
await TwapOracleInstance.setPrice(MATIC_ADDRESS, 0);

await Helpers.expectToRevertWithCustomError(
BridgeInstance.deposit(
BridgeInstance.deposit.call(
destinationDomainID,
resourceID,
depositData,
Expand Down
53 changes: 53 additions & 0 deletions testUnderForked/optionalContractCall/calculateFeeERC20EVM.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ contract("TwapFeeHandler - [calculateFee]", async (accounts) => {
const higherExecutionGasAmount = 30000000;
const lowerExecutionGasAmount = 3000000;
const feeData = "0x";
const feePercentage = 1000; // 10%

let UniswapFactoryInstance;
let TwapOracleInstance;
Expand Down Expand Up @@ -176,4 +177,56 @@ contract("TwapFeeHandler - [calculateFee]", async (accounts) => {

expect(higherExecutionGasAmountRes.fee.toNumber()).to.be.gt(lowerExecutionGasAmountRes.fee.toNumber())
});

it("[percentage protocol fee] should calculate in recover gas for tx cost", async () => {
const mintableERC20Iface = new Ethers.utils.Interface(["function mint(address to, uint256 amount)"]);
const actions = [{
nativeValue: 0,
callTo: ERC20MintableInstance.address,
approveTo: Ethers.constants.AddressZero,
tokenSend: Ethers.constants.AddressZero,
tokenReceive: Ethers.constants.AddressZero,
data: mintableERC20Iface.encodeFunctionData("mint", [recipientAddress, "20"]),
}]
const message = Helpers.createMessageCallData(
transactionId,
actions,
recipientAddress
);

const depositData = Helpers.createOptionalContractCallDepositData(
transferredAmount,
Ethers.constants.AddressZero,
higherExecutionGasAmount,
message
);

await DynamicFeeHandlerInstance.setGasPrice(
destinationDomainID,
gasPrice, // Polygon gas price is 200 Gwei
ProtocolFeeType.Percentage,
feePercentage
);

const resWithoutRecoverGas = await FeeHandlerRouterInstance.calculateFee.call(
sender,
originDomainID,
destinationDomainID,
resourceID,
depositData,
"0x00"
);

await DynamicFeeHandlerInstance.setRecoverGas(gasUsed);

const resWithRecoverGas = await FeeHandlerRouterInstance.calculateFee.call(
sender,
originDomainID,
destinationDomainID,
resourceID,
depositData,
"0x00"
);
expect(resWithRecoverGas.fee.toNumber()).to.be.gt(resWithoutRecoverGas.fee.toNumber());
});
});

0 comments on commit bbc8bbf

Please sign in to comment.