11import { Blockchain , SandboxContract , TreasuryContract } from '@ton/sandbox'
2- import {
3- Address ,
4- beginCell ,
5- Cell ,
6- contractAddress ,
7- Dictionary ,
8- fromNano ,
9- StateInit ,
10- toNano ,
11- } from '@ton/core'
2+ import { Address , beginCell , Cell , contractAddress , Dictionary , StateInit , toNano } from '@ton/core'
123import { compile } from '@ton/blueprint'
134import {
145 Any2TVMRampMessage ,
@@ -26,7 +17,6 @@ import {
2617 SourceChainConfig ,
2718 OffRamp ,
2819 OffRampError ,
29- ReceiveExecutorError ,
3020} from '../../wrappers/ccip/OffRamp'
3121import {
3222 MerkleRootError ,
@@ -75,6 +65,7 @@ const CHAINSEL_TON = 13879075125137744094n
7565const EVM_SENDER_ADDRESS_TEST = 0x1a5fdbc891c5d4e6ad68064ae45d43146d4f9f3an
7666const EVM_ONRAMP_ADDRESS_TEST = 0x111111c891c5d4e6ad68064ae45d43146d4f9f3an
7767const LEAF_DOMAIN_SEPARATOR = beginCell ( ) . storeUint ( 0 , 256 ) . asSlice ( )
68+ const PERMISSIONLESS_EXECUTION_THRESHOLD_SECONDS = 60
7869
7970// These have to match the EVM states
8071const EXECUTION_STATE_IN_PROGRESS = 1n
@@ -165,7 +156,7 @@ async function deployOffRampContract(
165156 feeQuoter : ZERO_ADDRESS ,
166157 router : owner . address , // used to determine who can send RMN updates
167158 chainSelector : CHAINSEL_TON ,
168- permissionlessExecutionThresholdSeconds : 60 ,
159+ permissionlessExecutionThresholdSeconds : PERMISSIONLESS_EXECUTION_THRESHOLD_SECONDS ,
169160 latestPriceSequenceNumber : 0n ,
170161 }
171162
@@ -1416,6 +1407,79 @@ describe('OffRamp - Unit Tests', () => {
14161407 } )
14171408 } )
14181409
1410+ it ( 'Manual execute after permissionlessExecutionThresholdSeconds' , async ( ) => {
1411+ const message = createTestMessage ( 1n , 1n , receiver . address ) // empty data (Cell.EMPTY)
1412+ await setupAndCommitMessage ( message )
1413+ const report = createExecuteReport ( [ message ] )
1414+
1415+ // Try manual exec when is not enabled
1416+ const manualExecFirstAttempt = await manualExecuteReport ( report )
1417+ expect ( manualExecFirstAttempt . transactions ) . toHaveTransaction ( {
1418+ from : offRamp . address ,
1419+ success : false ,
1420+ exitCode : MerkleRootError . ManualExecutionNotYetEnabled ,
1421+ } )
1422+
1423+ // Almost there, still needs to fail
1424+ warpTime ( PERMISSIONLESS_EXECUTION_THRESHOLD_SECONDS )
1425+
1426+ const manualExecSecondAttempt = await manualExecuteReport ( report )
1427+ expect ( manualExecSecondAttempt . transactions ) . toHaveTransaction ( {
1428+ from : offRamp . address ,
1429+ success : false ,
1430+ exitCode : MerkleRootError . ManualExecutionNotYetEnabled ,
1431+ } )
1432+
1433+ // One more sec and we are ready to go
1434+ warpTime ( 1 )
1435+
1436+ const manualExecThirdAttempt = await manualExecuteReport ( report , undefined , true )
1437+ expect ( manualExecThirdAttempt . transactions ) . toHaveTransaction ( {
1438+ from : router . address ,
1439+ to : receiver . address ,
1440+ value : message . gasLimit ,
1441+ success : true ,
1442+ } )
1443+
1444+ assertLog (
1445+ manualExecThirdAttempt . transactions ,
1446+ offRamp . address ,
1447+ CCIPLogs . LogTypes . ExecutionStateChanged ,
1448+ {
1449+ sourceChainSelector : CHAINSEL_EVM_TEST_90000001 ,
1450+ sequenceNumber : 1n ,
1451+ messageId : 1n ,
1452+ state : EXECUTION_STATE_IN_PROGRESS ,
1453+ } ,
1454+ )
1455+
1456+ assertLog (
1457+ manualExecThirdAttempt . transactions ,
1458+ offRamp . address ,
1459+ CCIPLogs . LogTypes . ExecutionStateChanged ,
1460+ {
1461+ sourceChainSelector : CHAINSEL_EVM_TEST_90000001 ,
1462+ sequenceNumber : 1n ,
1463+ messageId : 1n ,
1464+ state : EXECUTION_STATE_SUCCESS ,
1465+ } ,
1466+ )
1467+
1468+ assertLog (
1469+ manualExecThirdAttempt . transactions ,
1470+ receiver . address ,
1471+ CCIPLogs . LogTypes . ReceiverCCIPMessageReceived ,
1472+ {
1473+ message : {
1474+ messageId : message . header . messageId ,
1475+ sourceChainSelector : CHAINSEL_EVM_TEST_90000001 ,
1476+ sender : message . sender ,
1477+ data : message . data ,
1478+ } ,
1479+ } ,
1480+ )
1481+ } )
1482+
14191483 it ( 'Manual execute: receiver fails, then succeeds' , async ( ) => {
14201484 const message = createTestMessage ( 1n , 1n , receiver . address ) // empty data (Cell.EMPTY)
14211485 await setupAndCommitMessage ( message )
0 commit comments