2
2
pragma solidity ^ 0.8.20 ;
3
3
4
4
import "./helpers/IBCTestHelper.t.sol " ;
5
- import {Vm} from "forge-std/Test.sol " ;
5
+ import {Vm, console2 } from "forge-std/Test.sol " ;
6
6
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol " ;
7
7
import {Upgrade, UpgradeFields, Timeout} from "../../../contracts/proto/Channel.sol " ;
8
8
import {LocalhostClientLib} from "../../../contracts/clients/09-localhost/LocalhostClient.sol " ;
9
9
import {LocalhostHelper} from "../../../contracts/clients/09-localhost/LocalhostHelper.sol " ;
10
10
import {IIBCChannelRecvPacket, IIBCChannelAcknowledgePacket} from "../../../contracts/core/04-channel/IIBCChannel.sol " ;
11
- import {IIBCChannelUpgrade, IIBCChannelUpgradeBase} from "../../../contracts/core/04-channel/IIBCChannelUpgrade.sol " ;
11
+ import {IIBCChannelUpgradeBase} from "../../../contracts/core/04-channel/IIBCChannelUpgrade.sol " ;
12
12
import {TestIBCChannelUpgradableMockApp} from "./helpers/TestIBCChannelUpgradableMockApp.t.sol " ;
13
13
import {ICS04UpgradeTestHelper} from "./helpers/ICS04UpgradeTestHelper.t.sol " ;
14
14
import {ICS04PacketEventTestHelper} from "./helpers/ICS04PacketTestHelper.t.sol " ;
@@ -412,8 +412,8 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
412
412
413
413
Timeout.Data[3 ] memory timeouts = [
414
414
Timeout.Data ({height: H (block .number ), timestamp: 0 }),
415
- Timeout.Data ({height: H (0 ), timestamp: uint64 ( block . timestamp )}),
416
- Timeout.Data ({height: H (block .number ), timestamp: uint64 ( block . timestamp )})
415
+ Timeout.Data ({height: H (0 ), timestamp: getTimestamp ( 0 )}),
416
+ Timeout.Data ({height: H (block .number ), timestamp: getTimestamp ( )})
417
417
];
418
418
HandshakeCallbacks memory callbacks = emptyCallbacks ();
419
419
callbacks.openInitAndFlushing.callback = _testUpgradeTimeoutAbortAck;
@@ -457,8 +457,8 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
457
457
458
458
Timeout.Data[3 ] memory timeouts = [
459
459
Timeout.Data ({height: H (block .number ), timestamp: 0 }),
460
- Timeout.Data ({height: H (0 ), timestamp: uint64 ( block . timestamp )}),
461
- Timeout.Data ({height: H (block .number ), timestamp: uint64 ( block . timestamp )})
460
+ Timeout.Data ({height: H (0 ), timestamp: getTimestamp ( )}),
461
+ Timeout.Data ({height: H (block .number ), timestamp: getTimestamp ( )})
462
462
];
463
463
HandshakeCallbacks memory callbacks = emptyCallbacks ();
464
464
callbacks.flushingAndFlushing.callback = _testUpgradeTimeoutAbortConfirm;
@@ -497,7 +497,7 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
497
497
}
498
498
499
499
function testUpgradeTimeoutUpgrade () public {
500
- CallbacksTimeout[] memory cases = new CallbacksTimeout [](10 );
500
+ CallbacksTimeout[] memory cases = new CallbacksTimeout [](16 );
501
501
for (uint256 i = 0 ; i < cases.length ; i++ ) {
502
502
cases[i].callbacks = emptyCallbacks ();
503
503
}
@@ -511,8 +511,8 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
511
511
i++ ;
512
512
513
513
cases[i].callbacks.flushingAndFlushing.callback = _testUpgradeTimeoutUpgradeSuccess;
514
- cases[i].t0 = Timeout.Data ({height: H (0 ), timestamp: uint64 ( block . timestamp + 1 )});
515
- cases[i].t1 = Timeout.Data ({height: H (0 ), timestamp: uint64 ( block . timestamp + 1 )});
514
+ cases[i].t0 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp ( 1 )});
515
+ cases[i].t1 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp ( 1 )});
516
516
i++ ;
517
517
518
518
cases[i].callbacks.openInitAndFlushing.callback = _testUpgradeTimeoutUpgradeSuccess;
@@ -521,50 +521,85 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
521
521
cases[i].t1 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
522
522
i++ ;
523
523
524
+ cases[i].callbacks.openInitAndFlushing.callback = _testUpgradeTimeoutUpgradeSuccess;
525
+ cases[i].callbacks.openInitAndFlushing.reverse = true ;
526
+ cases[i].t0 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
527
+ cases[i].t1 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
528
+ i++ ;
529
+
524
530
cases[i].callbacks.flushingAndComplete.callback = _testUpgradeTimeoutUpgradeSuccess;
525
531
cases[i].callbacks.flushingAndComplete.reverse = true ;
526
532
cases[i].t0 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
527
533
cases[i].t1 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
528
534
i++ ;
529
535
536
+ cases[i].callbacks.flushingAndComplete.callback = _testUpgradeTimeoutUpgradeSuccess;
537
+ cases[i].callbacks.flushingAndComplete.reverse = true ;
538
+ cases[i].t0 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
539
+ cases[i].t1 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
540
+ i++ ;
541
+
530
542
// ------------------------------ Failure Cases ------------------------------ //
531
543
532
- cases[i].callbacks.flushingAndFlushing.callback = _testUpgradeTimeoutUpgradeFailNotReached ;
544
+ cases[i].callbacks.flushingAndFlushing.callback = _testUpgradeTimeoutUpgradeFailTimeoutHeightNotReached ;
533
545
cases[i].t0 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
534
546
cases[i].t1 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
535
547
i++ ;
536
548
537
- cases[i].callbacks.flushingAndFlushing.callback = _testUpgradeTimeoutUpgradeFailNotReached ;
538
- cases[i].t0 = Timeout.Data ({height: H (0 ), timestamp: uint64 ( block . timestamp + 1 )});
539
- cases[i].t1 = Timeout.Data ({height: H (0 ), timestamp: uint64 ( block . timestamp + 1 )});
549
+ cases[i].callbacks.flushingAndFlushing.callback = _testUpgradeTimeoutUpgradeFailTimeoutTimestampNotReached ;
550
+ cases[i].t0 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp ( 1 )});
551
+ cases[i].t1 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp ( 1 )});
540
552
i++ ;
541
553
542
554
cases[i].callbacks.flushingAndComplete.callback = _testUpgradeTimeoutUpgradeFailReached;
543
555
cases[i].t0 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
544
556
cases[i].t1 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
545
557
i++ ;
546
558
559
+ cases[i].callbacks.flushingAndComplete.callback = _testUpgradeTimeoutUpgradeFailReached;
560
+ cases[i].t0 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
561
+ cases[i].t1 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
562
+ i++ ;
563
+
547
564
cases[i].callbacks.openSucAndComplete.callback = _testUpgradeTimeoutUpgradeFailReachedAlreadyUpgraded;
548
565
cases[i].callbacks.openSucAndComplete.reverse = true ;
549
566
cases[i].t0 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
550
567
cases[i].t1 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
551
568
i++ ;
552
569
570
+ cases[i].callbacks.openSucAndComplete.callback = _testUpgradeTimeoutUpgradeFailReachedAlreadyUpgraded;
571
+ cases[i].callbacks.openSucAndComplete.reverse = true ;
572
+ cases[i].t0 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
573
+ cases[i].t1 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
574
+ i++ ;
575
+
553
576
cases[i].callbacks.completeAndComplete.callback = _testUpgradeTimeoutUpgradeFailReachedAlreadyCompleted;
554
577
cases[i].t0 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
555
578
cases[i].t1 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
556
579
i++ ;
557
580
581
+ cases[i].callbacks.completeAndComplete.callback = _testUpgradeTimeoutUpgradeFailReachedAlreadyCompleted;
582
+ cases[i].t0 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
583
+ cases[i].t1 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
584
+ i++ ;
585
+
558
586
cases[i].callbacks.completeAndComplete.callback = _testUpgradeTimeoutUpgradeFailReachedAlreadyCompleted;
559
587
cases[i].callbacks.completeAndComplete.reverse = true ;
560
588
cases[i].t0 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
561
589
cases[i].t1 = Timeout.Data ({height: H (block .number + 1 ), timestamp: 0 });
562
590
i++ ;
563
591
592
+ cases[i].callbacks.completeAndComplete.callback = _testUpgradeTimeoutUpgradeFailReachedAlreadyCompleted;
593
+ cases[i].callbacks.completeAndComplete.reverse = true ;
594
+ cases[i].t0 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
595
+ cases[i].t1 = Timeout.Data ({height: H (0 ), timestamp: getTimestamp (1 )});
596
+ i++ ;
597
+
564
598
require (i == cases.length , "invalid number of cases " );
565
599
566
600
for (uint256 i = 0 ; i < cases.length ; i++ ) {
567
- (uint256 height , uint256 timestamp ) = (block .number , block .timestamp );
601
+ console2.log ("case: " , i);
602
+ (uint256 height , uint256 timestampSec ) = (block .number , block .timestamp );
568
603
(ChannelInfo memory channel0 , ChannelInfo memory channel1 ) =
569
604
createMockAppLocalhostChannel (Channel.Order.ORDER_UNORDERED);
570
605
handshakeUpgradeWithCallbacks (
@@ -589,7 +624,7 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
589
624
);
590
625
// restore the block height and timestamp
591
626
vm.roll (height);
592
- vm.warp (timestamp );
627
+ vm.warp (timestampSec );
593
628
}
594
629
}
595
630
@@ -1822,7 +1857,7 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
1822
1857
vm.roll (uint256 (timeout.height.revision_height));
1823
1858
}
1824
1859
if (timeout.timestamp != 0 ) {
1825
- vm.warp (uint256 (timeout.timestamp));
1860
+ vm.warp (uint256 (timeout.timestamp / 1e9 ));
1826
1861
}
1827
1862
(Channel.Data memory counterpartyChannel ,) = handler.getChannel (channel1.portId, channel1.channelId);
1828
1863
handler.timeoutChannelUpgrade (
@@ -1848,7 +1883,7 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
1848
1883
return false ;
1849
1884
}
1850
1885
1851
- function _testUpgradeTimeoutUpgradeFailNotReached (
1886
+ function _testUpgradeTimeoutUpgradeFailTimeoutHeightNotReached (
1852
1887
IIBCHandler handler ,
1853
1888
ChannelInfo memory channel0 ,
1854
1889
ChannelInfo memory channel1
@@ -1861,8 +1896,25 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
1861
1896
proofChannel: LocalhostClientLib.sentinelProof (),
1862
1897
proofHeight: H (block .number )
1863
1898
});
1864
- // IBCChannelUpgradeTimeoutHeightNotReached or IBCChannelUpgradeTimeoutTimestampNotReached
1865
- vm.expectRevert ();
1899
+ vm.expectRevert (IIBCChannelUpgradeErrors.IBCChannelUpgradeTimeoutHeightNotReached.selector );
1900
+ handler.timeoutChannelUpgrade (msg_);
1901
+ return true ;
1902
+ }
1903
+
1904
+ function _testUpgradeTimeoutUpgradeFailTimeoutTimestampNotReached (
1905
+ IIBCHandler handler ,
1906
+ ChannelInfo memory channel0 ,
1907
+ ChannelInfo memory channel1
1908
+ ) internal returns (bool ) {
1909
+ (Channel.Data memory counterpartyChannel ,) = handler.getChannel (channel1.portId, channel1.channelId);
1910
+ IIBCChannelUpgradeBase.MsgTimeoutChannelUpgrade memory msg_ = IIBCChannelUpgradeBase.MsgTimeoutChannelUpgrade ({
1911
+ portId: channel0.portId,
1912
+ channelId: channel0.channelId,
1913
+ counterpartyChannel: counterpartyChannel,
1914
+ proofChannel: LocalhostClientLib.sentinelProof (),
1915
+ proofHeight: H (block .number )
1916
+ });
1917
+ vm.expectRevert (IIBCChannelUpgradeErrors.IBCChannelUpgradeTimeoutTimestampNotReached.selector );
1866
1918
handler.timeoutChannelUpgrade (msg_);
1867
1919
return true ;
1868
1920
}
@@ -1877,7 +1929,7 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
1877
1929
vm.roll (uint256 (timeout.height.revision_height));
1878
1930
}
1879
1931
if (timeout.timestamp != 0 ) {
1880
- vm.warp (uint256 (timeout.timestamp));
1932
+ vm.warp (uint256 (timeout.timestamp / 1e9 ));
1881
1933
}
1882
1934
(Channel.Data memory counterpartyChannel ,) = handler.getChannel (channel1.portId, channel1.channelId);
1883
1935
IIBCChannelUpgradeBase.MsgTimeoutChannelUpgrade memory msg_ = IIBCChannelUpgradeBase.MsgTimeoutChannelUpgrade ({
@@ -1923,7 +1975,7 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
1923
1975
vm.roll (uint256 (timeout.height.revision_height));
1924
1976
}
1925
1977
if (timeout.timestamp != 0 ) {
1926
- vm.warp (uint256 (timeout.timestamp));
1978
+ vm.warp (uint256 (timeout.timestamp / 1e9 ));
1927
1979
}
1928
1980
(Channel.Data memory counterpartyChannel ,) = handler.getChannel (channel1.portId, channel1.channelId);
1929
1981
IIBCChannelUpgradeBase.MsgTimeoutChannelUpgrade memory msg_ = IIBCChannelUpgradeBase.MsgTimeoutChannelUpgrade ({
0 commit comments