Skip to content

Commit

Permalink
chore: decrease loop amount and update test (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-llimos authored Aug 28, 2023
1 parent f7ea727 commit 8bc9dc6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
6 changes: 3 additions & 3 deletions contracts/mocks/CFTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ contract CFTester is CFReceiver, Shared {

uint256[] public iterations;

// This will consume ~6.5M gas (iterations + overhead)
// This will consume ~6.5M gas (iterations + overhead) for the whole tx
uint256 public defaultNumIterations = 300;
// This will consume ~215k
uint256 public defaultStepIterations = 10;
// This will consume ~21.5k per loop
uint256 public defaultStepIterations = 1;

string public constant GAS_TEST = "GasTest";
bytes public constant GAS_MESSAGE_ENCODED = bytes(GAS_TEST);
Expand Down
23 changes: 13 additions & 10 deletions tests/unit/vault/test_executexSwapAndCall.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def test_executexSwapAndCallToken(
]


def test_executexSwapAndCallToken_gasTest(
def test_executexSwapAndCallToken_gasTest400(
cf,
cfTester,
token,
Expand All @@ -303,7 +303,12 @@ def test_executexSwapAndCallToken_gasTest(
token.transfer(cf.vault, amount * 2, {"from": cf.SAFEKEEPER})

# Currently the gasLimit is hardcoded at 400k in the state chain.
message = encode_abi(["string", "uint256"], ["GasTest", 210000])

## GasTest 270k makes the whole transaction consume 392k with ccmTestGasUsed: 272k
# => overhead = 120k, that's including a bunch of logic in the receiver contract.
# With no code in the receiver (except checking the vault address) it's 112k
# Depending on the tx number it reverts between 270 and 300k.
message = encode_abi(["string", "uint256"], ["GasTest", 270000])
args = [
[token, cfTester.address, amount],
srcChain,
Expand All @@ -313,19 +318,17 @@ def test_executexSwapAndCallToken_gasTest(
sigData = AGG_SIGNER_1.getSigDataWithNonces(
cf.keyManager, cf.vault.executexSwapAndCall, nonces, *args
)
cf.vault.executexSwapAndCall(
tx = cf.vault.executexSwapAndCall(
sigData,
*args,
{"from": cf.ALICE, "gas": 400000},
)

message = encode_abi(["string", "uint256"], ["GasTest", 230000])
args = [
[token, cfTester.address, amount],
srcChain,
st_srcAddress,
message,
]
assert tx.events["ReceivedxSwapAndCall"]["ccmTestGasUsed"] >= 270000

# overhead = tx.gas_used - tx.events["ReceivedxSwapAndCall"]["ccmTestGasUsed"]
message = encode_abi(["string", "uint256"], ["GasTest", 300000])
args[3] = message
sigData = AGG_SIGNER_1.getSigDataWithNonces(
cf.keyManager, cf.vault.executexSwapAndCall, nonces, *args
)
Expand Down

0 comments on commit 8bc9dc6

Please sign in to comment.