Skip to content

Commit dd7b4c7

Browse files
vladjdktechnicallytyaljo242
authored
test: add nested precompile reversion test case (#535)
* add nested precompile reversion test case adds complex precompile reversions that occur within nested try catch blocks to test for cache stack reversions to specific IDs * changelog * Update tests/integration/precompiles/staking/test_integration.go Co-authored-by: Tyler <[email protected]> * remove changelog entry for test --------- Co-authored-by: Tyler <[email protected]> Co-authored-by: Alex | Interchain Labs <[email protected]>
1 parent 1518fe3 commit dd7b4c7

File tree

5 files changed

+138
-3
lines changed

5 files changed

+138
-3
lines changed

contracts/solidity/precompiles/testutil/contracts/StakingReverter.sol

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ contract StakingReverter {
4949
STAKING_CONTRACT.delegate(address(this), validatorAddress, 10);
5050
}
5151

52+
/// @dev nestedTryCatchDelegations performs nested try/catch calls to precompile
53+
/// where inner calls revert intentionally. Only the successful delegations
54+
/// outside the reverting scope should persist.
55+
///
56+
/// Expected successful delegations: 1 (before loop) + outerTimes (after each catch) + 1 (after loop)
57+
function nestedTryCatchDelegations(uint outerTimes, uint innerTimes, string calldata validatorAddress) external {
58+
// Initial successful delegate before any nested reverts
59+
STAKING_CONTRACT.delegate(address(this), validatorAddress, 10);
60+
61+
for (uint i = 0; i < outerTimes; i++) {
62+
// Outer call that will revert and be caught
63+
try StakingReverter(address(this)).performDelegation(validatorAddress) {
64+
// no-op
65+
} catch {
66+
// After catching the revert, perform a successful delegate
67+
STAKING_CONTRACT.delegate(address(this), validatorAddress, 10);
68+
69+
// Inner nested loop of reverting calls
70+
for (uint j = 0; j < innerTimes; j++) {
71+
try StakingReverter(address(this)).performDelegation(validatorAddress) {
72+
// no-op
73+
} catch {}
74+
}
75+
}
76+
}
77+
78+
// Final successful delegate after the loops
79+
STAKING_CONTRACT.delegate(address(this), validatorAddress, 10);
80+
}
81+
5282
function performDelegation(string calldata validatorAddress) external {
5383
STAKING_CONTRACT.delegate(address(this), validatorAddress, 10);
5484
revert();

0 commit comments

Comments
 (0)