-
Notifications
You must be signed in to change notification settings - Fork 36
fix(contracts-rfq): gas estimation tests [SLT-275] #3204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a94e3e6
refactor: isolate common utils for SRC tests
ChiTimesChi ac9a58e
test: gas benchmark for SRC actions
ChiTimesChi 43e0aab
test: gas benchmark for DST actions
ChiTimesChi b63ccc9
test: rework bench tests with mroe isolation
ChiTimesChi bb1cd07
fix: set non-zero initial balances for asset receivers
ChiTimesChi 129cde2
ci: use gas bench tests only
ChiTimesChi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {FastBridgeV2, FastBridgeV2Test, IFastBridge} from "./FastBridgeV2.t.sol"; | ||
|
||
// solhint-disable func-name-mixedcase, ordering | ||
8000 contract FastBridgeV2DstBaseTest is FastBridgeV2Test { | ||
uint256 public constant LEFTOVER_BALANCE = 1 ether; | ||
|
||
function setUp() public override { | ||
vm.chainId(DST_CHAIN_ID); | ||
super.setUp(); | ||
} | ||
|
||
function deployFastBridge() public override returns (FastBridgeV2) { | ||
return new FastBridgeV2(address(this)); | ||
} | ||
|
||
function mintTokens() public virtual override { | ||
dstToken.mint(address(relayerA), LEFTOVER_BALANCE + tokenParams.destAmount); | ||
dstToken.mint(address(relayerB), LEFTOVER_BALANCE + tokenParams.destAmount); | ||
deal(relayerA, LEFTOVER_BALANCE + ethParams.destAmount); | ||
deal(relayerB, LEFTOVER_BALANCE + ethParams.destAmount); | ||
vm.prank(relayerA); | ||
dstToken.approve(address(fastBridge), type(uint256).max); | ||
vm.prank(relayerB); | ||
dstToken.approve(address(fastBridge), type(uint256).max); | ||
ChiTimesChi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// ══════════════════════════════════════════════════ HELPERS ══════════════════════════════════════════════════════ | ||
|
||
function relay(address caller, uint256 msgValue, IFastBridge.BridgeTransaction memory bridgeTx) public { | ||
bytes memory request = abi.encode(bridgeTx); | ||
vm.prank({msgSender: caller, txOrigin: caller}); | ||
fastBridge.relay{value: msgValue}(request); | ||
} | ||
|
||
function relayWithAddress( | ||
address caller, | ||
address relayer, | ||
uint256 msgValue, | ||
IFastBridge.BridgeTransaction memory bridgeTx | ||
) | ||
public | ||
{ | ||
bytes memory request = abi.encode(bridgeTx); | ||
vm.prank({msgSender: caller, txOrigin: caller}); | ||
fastBridge.relay{value: msgValue}(request, relayer); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
packages/contracts-rfq/test/FastBridgeV2.GasBench.Dst.t.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {FastBridgeV2DstBaseTest} from "./FastBridgeV2.Dst.Base.t.sol"; | ||
|
||
// solhint-disable func-name-mixedcase, ordering | ||
/// @notice This test is used to estimate the gas cost of FastBridgeV2 destination chain functions. | ||
/// Very little state checks are performed, make sure to do full coverage in different tests. | ||
contract FastBridgeV2DstGasBenchmarkTest is FastBridgeV2DstBaseTest { | ||
uint256 public constant INITIAL_USER_BALANCE = 100 ether; | ||
|
||
function mintTokens() public virtual override { | ||
super.mintTokens(); | ||
deal(userB, INITIAL_USER_BALANCE); | ||
dstToken.mint(userB, INITIAL_USER_BALANCE); | ||
} | ||
|
||
// ═══════════════════════════════════════════════════ TOKEN ═══════════════════════════════════════════════════════ | ||
|
||
function test_relay_token() public { | ||
bytes32 txId = getTxId(tokenTx); | ||
relay({caller: relayerA, msgValue: 0, bridgeTx: tokenTx}); | ||
(uint256 blockNumber, uint256 blockTimestamp, address relayer) = fastBridge.bridgeRelayDetails(txId); | ||
assertEq(blockNumber, block.number); | ||
assertEq(blockTimestamp, block.timestamp); | ||
assertEq(relayer, relayerA); | ||
assertEq(dstToken.balanceOf(userB), INITIAL_USER_BALANCE + tokenParams.destAmount); | ||
assertEq(dstToken.balanceOf(relayerA), LEFTOVER_BALANCE); | ||
} | ||
|
||
function test_relay_token_withRelayerAddress() public { | ||
bytes32 txId = getTxId(tokenTx); | ||
relayWithAddress({caller: relayerB, relayer: relayerA, msgValue: 0, bridgeTx: tokenTx}); | ||
(uint256 blockNumber, uint256 blockTimestamp, address relayer) = fastBridge.bridgeRelayDetails(txId); | ||
assertEq(blockNumber, block.number); | ||
assertEq(blockTimestamp, block.timestamp); | ||
assertEq(relayer, relayerA); | ||
assertEq(dstToken.balanceOf(userB), INITIAL_USER_BALANCE + tokenParams.destAmount); | ||
assertEq(dstToken.balanceOf(relayerB), LEFTOVER_BALANCE); | ||
} | ||
ChiTimesChi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// ════════════════════════════════════════════════════ ETH ════════════════════════════════════════════════════════ | ||
|
||
function test_relay_eth() public { | ||
bytes32 txId = getTxId(ethTx); | ||
relay({caller: relayerA, msgValue: ethParams.destAmount, bridgeTx: ethTx}); | ||
(uint256 blockNumber, uint256 blockTimestamp, address relayer) = fastBridge.bridgeRelayDetails(txId); | ||
assertEq(blockNumber, block.number); | ||
assertEq(blockTimestamp, block.timestamp); | ||
assertEq(relayer, relayerA); | ||
assertEq(address(userB).balance, INITIAL_USER_BALANCE + ethParams.destAmount); | ||
assertEq(address(relayerA).balance, LEFTOVER_BALANCE); | ||
} | ||
|
||
function test_relay_eth_withRelayerAddress() public { | ||
bytes32 txId = getTxId(ethTx); | ||
relayWithAddress({caller: relayerB, relayer: relayerA, msgValue: ethParams.destAmount, bridgeTx: ethTx}); | ||
(uint256 blockNumber, uint256 blockTimestamp, address relayer) = fastBridge.bridgeRelayDetails(txId); | ||
assertEq(blockNumber, block.number); | ||
assertEq(blockTimestamp, block.timestamp); | ||
assertEq(relayer, relayerA); | ||
assertEq(address(userB).balance, INITIAL_USER_BALANCE + ethParams.destAmount); | ||
assertEq(address(relayerB).balance, LEFTOVER_BALANCE); | ||
} | ||
ChiTimesChi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
36 changes: 36 additions & 0 deletions
36
packages/contracts-rfq/test/FastBridgeV2.GasBench.Src.PFees.t.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {FastBridgeV2GasBenchmarkSrcTest} from "./FastBridgeV2.GasBench.Src.t.sol"; | ||
|
||
// solhint-disable func-name-mixedcase, ordering | ||
contract FastBridgeV2GasBenchmarkSrcProtocolFeesTest is FastBridgeV2GasBenchmarkSrcTest { | ||
function configureFastBridge() public virtual override { | ||
super.configureFastBridge(); | ||
fastBridge.grantRole(fastBridge.GOVERNOR_ROLE(), address(this)); | ||
fastBridge.setProtocolFeeRate(1e4); // 1% | ||
} | ||
|
||
function createFixtures() public virtual override { | ||
super.createFixtures(); | ||
tokenTx.originFeeAmount = 0.01e6; | ||
tokenTx.originAmount = 0.99e6; | ||
tokenTx.destAmount = 0.98e6; | ||
tokenParams.destAmount = 0.98e6; | ||
ethTx.originFeeAmount = 0.01 ether; | ||
ethTx.originAmount = 0.99 ether; | ||
ethTx.destAmount = 0.98 ether; | ||
ethParams.destAmount = 0.98 ether; | ||
|
||
// Copy txs to bridged and proven with different nonce | ||
bridgedTokenTx = tokenTx; | ||
provenTokenTx = tokenTx; | ||
bridgedEthTx = ethTx; | ||
provenEthTx = ethTx; | ||
|
||
bridgedTokenTx.nonce = 0; | ||
bridgedEthTx.nonce = 1; | ||
provenTokenTx.nonce = 2; | ||
provenEthTx.nonce = 3; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.