@@ -587,14 +587,6 @@ func TestChainWriter_SubmitTransaction(t *testing.T) {
587
587
func TestChainWriter_CCIPRouter (t * testing.T ) {
588
588
t .Parallel ()
589
589
590
- ctx := tests .Context (t )
591
- // mock client
592
- rw := clientmocks .NewReaderWriter (t )
593
- // mock estimator
594
- ge := feemocks .NewEstimator (t )
595
- // mock txm
596
- txm := txmMocks .NewTxManager (t )
597
-
598
590
// setup admin key
599
591
adminPk , err := solana .NewRandomPrivateKey ()
600
592
require .NoError (t , err )
@@ -603,16 +595,9 @@ func TestChainWriter_CCIPRouter(t *testing.T) {
603
595
routerAddr := chainwriter .GetRandomPubKey (t )
604
596
destTokenAddr := chainwriter .GetRandomPubKey (t )
605
597
606
- pda , _ , err := solana .FindProgramAddress ([][]byte {[]byte ("token_admin_registry" ), destTokenAddr .Bytes ()}, routerAddr )
607
- require .NoError (t , err )
608
-
609
- lookupTable := mockTokenAdminRegistryLookupTable (t , rw , pda )
610
-
611
598
poolKeys := []solana.PublicKey {destTokenAddr }
612
599
poolKeys = append (poolKeys , chainwriter .CreateTestPubKeys (t , 3 )... )
613
600
614
- mockFetchLookupTableAddresses (t , rw , lookupTable , poolKeys )
615
-
616
601
// simplified CCIP Config - does not contain full account list
617
602
ccipCWConfig := chainwriter.ChainWriterConfig {
618
603
Programs : map [string ]chainwriter.ProgramConfig {
@@ -625,7 +610,7 @@ func TestChainWriter_CCIPRouter(t *testing.T) {
625
610
Fields : map [string ]string {"ReportContextByteWords" : "ReportContext" },
626
611
},
627
612
& codec.RenameModifierConfig {
628
- Fields : map [string ]string {"ExecutionReport " : "AbstractReport " },
613
+ Fields : map [string ]string {"RawExecutionReport " : "Report " },
629
614
},
630
615
},
631
616
ChainSpecificName : "execute" ,
@@ -662,27 +647,70 @@ func TestChainWriter_CCIPRouter(t *testing.T) {
662
647
},
663
648
},
664
649
},
650
+ "commit" : {
651
+ FromAddress : admin .String (),
652
+ InputModifications : []codec.ModifierConfig {
653
+ & codec.RenameModifierConfig {
654
+ Fields : map [string ]string {"ReportContextByteWords" : "ReportContext" },
655
+ },
656
+ & codec.RenameModifierConfig {
657
+ Fields : map [string ]string {"RawReport" : "Report" },
658
+ },
659
+ },
660
+ ChainSpecificName : "commit" ,
661
+ ArgsTransform : "" ,
662
+ LookupTables : chainwriter.LookupTables {},
663
+ Accounts : []chainwriter.Lookup {
664
+ chainwriter.AccountConstant {
665
+ Name : "testAcc1" ,
666
+ Address : chainwriter .GetRandomPubKey (t ).String (),
667
+ },
668
+ chainwriter.AccountConstant {
669
+ Name : "testAcc2" ,
670
+ Address : chainwriter .GetRandomPubKey (t ).String (),
671
+ },
672
+ chainwriter.AccountConstant {
673
+ Name : "testAcc3" ,
674
+ Address : chainwriter .GetRandomPubKey (t ).String (),
675
+ },
676
+ },
677
+ },
665
678
},
666
679
IDL : ccipRouterIDL ,
667
680
},
668
681
},
669
682
}
670
683
671
- // initialize chain writer
672
- cw , err := chainwriter .NewSolanaChainWriterService (testutils .NewNullLogger (), rw , txm , ge , ccipCWConfig )
673
- require .NoError (t , err )
684
+ ctx := tests .Context (t )
685
+ // mock client
686
+ rw := clientmocks .NewReaderWriter (t )
687
+ // mock estimator
688
+ ge := feemocks .NewEstimator (t )
674
689
675
- t .Run ("ArgsTransform works" , func (t * testing.T ) {
676
- txID := uuid .NewString ()
677
- recentBlockHash := solana.Hash {}
690
+ t .Run ("CCIP execute is encoded successfully and ArgsTransform is applied correctly." , func (t * testing.T ) {
691
+ // mock txm
692
+ txm := txmMocks .NewTxManager (t )
693
+ // initialize chain writer
694
+ cw , err := chainwriter .NewSolanaChainWriterService (testutils .NewNullLogger (), rw , txm , ge , ccipCWConfig )
695
+ require .NoError (t , err )
678
696
697
+ recentBlockHash := solana.Hash {}
679
698
rw .On ("LatestBlockhash" , mock .Anything ).Return (& rpc.GetLatestBlockhashResult {Value : & rpc.LatestBlockhashResult {Blockhash : recentBlockHash , LastValidBlockHeight : uint64 (100 )}}, nil ).Once ()
699
+
700
+ pda , _ , err := solana .FindProgramAddress ([][]byte {[]byte ("token_admin_registry" ), destTokenAddr .Bytes ()}, routerAddr )
701
+ require .NoError (t , err )
702
+
703
+ lookupTable := mockTokenAdminRegistryLookupTable (t , rw , pda )
704
+
705
+ mockFetchLookupTableAddresses (t , rw , lookupTable , poolKeys )
706
+
707
+ txID := uuid .NewString ()
680
708
txm .On ("Enqueue" , mock .Anything , admin .String (), mock .MatchedBy (func (tx * solana.Transaction ) bool {
681
709
txData := tx .Message .Instructions [0 ].Data
682
710
payload := txData [8 :]
683
711
var decoded ccip_router.Execute
684
712
dec := ag_binary .NewBorshDecoder (payload )
685
- err : = dec .Decode (& decoded )
713
+ err = dec .Decode (& decoded )
686
714
require .NoError (t , err )
687
715
688
716
tokenIndexes := * decoded .TokenIndexes
@@ -692,63 +720,83 @@ func TestChainWriter_CCIPRouter(t *testing.T) {
692
720
return true
693
721
}), & txID , mock .Anything ).Return (nil ).Once ()
694
722
695
- abstractReport := ccip_router.ExecutionReportSingleChain {
696
- SourceChainSelector : 1 ,
697
- Message : ccip_router.Any2SVMRampMessage {
698
- Header : ccip_router.RampMessageHeader {
699
- MessageId : ccipocr3.Bytes32 {0x1 },
700
- SourceChainSelector : 1 ,
701
- DestChainSelector : 2 ,
702
- SequenceNumber : 1 ,
703
- Nonce : 0 ,
704
- },
705
- Sender : admin .Bytes (),
706
- Data : ccipocr3.Bytes {0x1 },
707
- LogicReceiver : chainwriter .GetRandomPubKey (t ),
708
- TokenReceiver : admin ,
709
- TokenAmounts : []ccip_router.Any2SVMTokenTransfer {
710
- {
711
- SourcePoolAddress : chainwriter .GetRandomPubKey (t ).Bytes (),
712
- DestTokenAddress : destTokenAddr ,
713
- ExtraData : ccipocr3.Bytes {0x1 },
714
- Amount : ccip_router.CrossChainAmount {LeBytes : [32 ]uint8 {0x1 }},
715
- DestGasAmount : 2 ,
716
- },
717
- },
718
- ExtraArgs : ccip_router.SVMExtraArgs {
719
- ComputeUnits : 1 ,
720
- IsWritableBitmap : 6 ,
721
- Accounts : []solana.PublicKey {
722
- chainwriter .GetRandomPubKey (t ),
723
+ // stripped back report just for purposes of example
724
+ abstractReport := ccipocr3.ExecutePluginReportSingleChain {
725
+ Messages : []ccipocr3.Message {
726
+ {
727
+ TokenAmounts : []ccipocr3.RampTokenAmount {
728
+ {
729
+ DestTokenAddress : destTokenAddr .Bytes (),
730
+ },
723
731
},
724
732
},
725
- OnRampAddress : []byte {0x1 },
726
733
},
727
- OffchainTokenData : [][]byte {{0x1 }},
728
- Proofs : [][32 ]byte {{0x1 }},
729
734
}
730
735
731
736
// Marshal the abstract report to json just for testing purposes.
732
- encodededReport , err := json .Marshal (abstractReport )
737
+ encodedReport , err := json .Marshal (abstractReport )
733
738
require .NoError (t , err )
734
739
735
740
args := chainwriter.ReportPreTransform {
736
- ReportContext : [3 ][32 ]uint8 {{0x01 , 0x02 , 0x03 }},
737
- Report : encodededReport ,
741
+ ReportContext : [2 ][32 ]byte {{0x01 }, { 0x02 }},
742
+ Report : encodedReport ,
738
743
Info : ccipocr3.ExecuteReportInfo {
739
- {
740
- ChainSel : 1 ,
741
- OnRampAddress : chainwriter .GetRandomPubKey (t ).Bytes (),
742
- SeqNumsRange : ccipocr3 .NewSeqNumRange (1 , 2 ),
743
- MerkleRoot : [32 ]byte {0x01 , 0x02 , 0x03 },
744
- },
744
+ MerkleRoots : []ccipocr3.MerkleRootChain {},
745
+ AbstractReports : []ccipocr3.ExecutePluginReportSingleChain {abstractReport },
745
746
},
746
- AbstractReport : abstractReport ,
747
747
}
748
748
749
749
submitErr := cw .SubmitTransaction (ctx , "ccip_router" , "execute" , args , txID , routerAddr .String (), nil , nil )
750
750
require .NoError (t , submitErr )
751
751
})
752
+
753
+ t .Run ("CCIP commit is encoded successfully" , func (t * testing.T ) {
754
+ // mock txm
755
+ txm := txmMocks .NewTxManager (t )
756
+ // initialize chain writer
757
+ cw , err := chainwriter .NewSolanaChainWriterService (testutils .NewNullLogger (), rw , txm , ge , ccipCWConfig )
758
+ require .NoError (t , err )
759
+
760
+ recentBlockHash := solana.Hash {}
761
+ rw .On ("LatestBlockhash" , mock .Anything ).Return (& rpc.GetLatestBlockhashResult {Value : & rpc.LatestBlockhashResult {Blockhash : recentBlockHash , LastValidBlockHeight : uint64 (100 )}}, nil ).Once ()
762
+
763
+ type CommitArgs struct {
764
+ ReportContext [2 ][32 ]byte
765
+ Report []byte
766
+ Rs [][32 ]byte
767
+ Ss [][32 ]byte
768
+ RawVs [32 ]byte
769
+ Info ccipocr3.CommitReportInfo
770
+ }
771
+
772
+ txID := uuid .NewString ()
773
+
774
+ // TODO: Replace with actual type from ccipocr3
775
+ args := CommitArgs {
776
+ ReportContext : [2 ][32 ]byte {{0x01 }, {0x02 }},
777
+ Report : []byte {0x01 , 0x02 },
778
+ Rs : [][32 ]byte {{0x01 , 0x02 }},
779
+ Ss : [][32 ]byte {{0x01 , 0x02 }},
780
+ RawVs : [32 ]byte {0x01 , 0x02 },
781
+ Info : ccipocr3.CommitReportInfo {
782
+ RemoteF : 1 ,
783
+ MerkleRoots : []ccipocr3.MerkleRootChain {},
784
+ },
785
+ }
786
+
787
+ txm .On ("Enqueue" , mock .Anything , admin .String (), mock .MatchedBy (func (tx * solana.Transaction ) bool {
788
+ txData := tx .Message .Instructions [0 ].Data
789
+ payload := txData [8 :]
790
+ var decoded ccip_router.Commit
791
+ dec := ag_binary .NewBorshDecoder (payload )
792
+ err := dec .Decode (& decoded )
793
+ require .NoError (t , err )
794
+ return true
795
+ }), & txID , mock .Anything ).Return (nil ).Once ()
796
+
797
+ submitErr := cw .SubmitTransaction (ctx , "ccip_router" , "commit" , args , txID , routerAddr .String (), nil , nil )
798
+ require .NoError (t , submitErr )
799
+ })
752
800
}
753
801
754
802
func TestChainWriter_CCIPRouter (t * testing.T ) {
0 commit comments