@@ -799,221 +799,6 @@ func TestChainWriter_CCIPRouter(t *testing.T) {
799
799
})
800
800
}
801
801
802
- func TestChainWriter_CCIPRouter (t * testing.T ) {
803
- t .Parallel ()
804
-
805
- // setup admin key
806
- adminPk , err := solana .NewRandomPrivateKey ()
807
- require .NoError (t , err )
808
- admin := adminPk .PublicKey ()
809
-
810
- routerAddr := chainwriter .GetRandomPubKey (t )
811
- destTokenAddr := chainwriter .GetRandomPubKey (t )
812
-
813
- poolKeys := []solana.PublicKey {destTokenAddr }
814
- poolKeys = append (poolKeys , chainwriter .CreateTestPubKeys (t , 3 )... )
815
-
816
- // simplified CCIP Config - does not contain full account list
817
- ccipCWConfig := chainwriter.ChainWriterConfig {
818
- Programs : map [string ]chainwriter.ProgramConfig {
819
- "ccip_router" : {
820
- Methods : map [string ]chainwriter.MethodConfig {
821
- "execute" : {
822
- FromAddress : admin .String (),
823
- InputModifications : []codec.ModifierConfig {
824
- & codec.RenameModifierConfig {
825
- Fields : map [string ]string {"ReportContextByteWords" : "ReportContext" },
826
- },
827
- & codec.RenameModifierConfig {
828
- Fields : map [string ]string {"RawExecutionReport" : "Report" },
829
- },
830
- },
831
- ChainSpecificName : "execute" ,
832
- ArgsTransform : "CCIP" ,
833
- LookupTables : chainwriter.LookupTables {},
834
- Accounts : []chainwriter.Lookup {
835
- chainwriter.AccountConstant {
836
- Name : "testAcc1" ,
837
- Address : chainwriter .GetRandomPubKey (t ).String (),
838
- },
839
- chainwriter.AccountConstant {
840
- Name : "testAcc2" ,
841
- Address : chainwriter .GetRandomPubKey (t ).String (),
842
- },
843
- chainwriter.AccountConstant {
844
- Name : "testAcc3" ,
845
- Address : chainwriter .GetRandomPubKey (t ).String (),
846
- },
847
- chainwriter.AccountConstant {
848
- Name : "poolAddr1" ,
849
- Address : poolKeys [0 ].String (),
850
- },
851
- chainwriter.AccountConstant {
852
- Name : "poolAddr2" ,
853
- Address : poolKeys [1 ].String (),
854
- },
855
- chainwriter.AccountConstant {
856
- Name : "poolAddr3" ,
857
- Address : poolKeys [2 ].String (),
858
- },
859
- chainwriter.AccountConstant {
860
- Name : "poolAddr4" ,
861
- Address : poolKeys [3 ].String (),
862
- },
863
- },
864
- },
865
- "commit" : {
866
- FromAddress : admin .String (),
867
- InputModifications : []codec.ModifierConfig {
868
- & codec.RenameModifierConfig {
869
- Fields : map [string ]string {"ReportContextByteWords" : "ReportContext" },
870
- },
871
- & codec.RenameModifierConfig {
872
- Fields : map [string ]string {"RawReport" : "Report" },
873
- },
874
- },
875
- ChainSpecificName : "commit" ,
876
- ArgsTransform : "" ,
877
- LookupTables : chainwriter.LookupTables {},
878
- Accounts : []chainwriter.Lookup {
879
- chainwriter.AccountConstant {
880
- Name : "testAcc1" ,
881
- Address : chainwriter .GetRandomPubKey (t ).String (),
882
- },
883
- chainwriter.AccountConstant {
884
- Name : "testAcc2" ,
885
- Address : chainwriter .GetRandomPubKey (t ).String (),
886
- },
887
- chainwriter.AccountConstant {
888
- Name : "testAcc3" ,
889
- Address : chainwriter .GetRandomPubKey (t ).String (),
890
- },
891
- },
892
- },
893
- },
894
- IDL : ccipRouterIDL ,
895
- },
896
- },
897
- }
898
-
899
- ctx := tests .Context (t )
900
- // mock client
901
- rw := clientmocks .NewReaderWriter (t )
902
- // mock estimator
903
- ge := feemocks .NewEstimator (t )
904
-
905
- t .Run ("CCIP execute is encoded successfully and ArgsTransform is applied correctly." , func (t * testing.T ) {
906
- // mock txm
907
- txm := txmMocks .NewTxManager (t )
908
- // initialize chain writer
909
- cw , err := chainwriter .NewSolanaChainWriterService (testutils .NewNullLogger (), rw , txm , ge , ccipCWConfig )
910
- require .NoError (t , err )
911
-
912
- recentBlockHash := solana.Hash {}
913
- rw .On ("LatestBlockhash" , mock .Anything ).Return (& rpc.GetLatestBlockhashResult {Value : & rpc.LatestBlockhashResult {Blockhash : recentBlockHash , LastValidBlockHeight : uint64 (100 )}}, nil ).Once ()
914
-
915
- pda , _ , err := solana .FindProgramAddress ([][]byte {[]byte ("token_admin_registry" ), destTokenAddr .Bytes ()}, routerAddr )
916
- require .NoError (t , err )
917
-
918
- lookupTable := mockTokenAdminRegistryLookupTable (t , rw , pda )
919
-
920
- mockFetchLookupTableAddresses (t , rw , lookupTable , poolKeys )
921
-
922
- txID := uuid .NewString ()
923
- txm .On ("Enqueue" , mock .Anything , admin .String (), mock .MatchedBy (func (tx * solana.Transaction ) bool {
924
- txData := tx .Message .Instructions [0 ].Data
925
- payload := txData [8 :]
926
- var decoded ccip_router.Execute
927
- dec := ag_binary .NewBorshDecoder (payload )
928
- err = dec .Decode (& decoded )
929
- require .NoError (t , err )
930
-
931
- tokenIndexes := * decoded .TokenIndexes
932
-
933
- require .Len (t , tokenIndexes , 1 )
934
- require .Equal (t , uint8 (3 ), tokenIndexes [0 ])
935
- return true
936
- }), & txID , mock .Anything ).Return (nil ).Once ()
937
-
938
- // stripped back report just for purposes of example
939
- abstractReport := ccipocr3.ExecutePluginReportSingleChain {
940
- Messages : []ccipocr3.Message {
941
- {
942
- TokenAmounts : []ccipocr3.RampTokenAmount {
943
- {
944
- DestTokenAddress : destTokenAddr .Bytes (),
945
- },
946
- },
947
- },
948
- },
949
- }
950
-
951
- // Marshal the abstract report to json just for testing purposes.
952
- encodedReport , err := json .Marshal (abstractReport )
953
- require .NoError (t , err )
954
-
955
- args := chainwriter.ReportPreTransform {
956
- ReportContext : [2 ][32 ]byte {{0x01 }, {0x02 }},
957
- Report : encodedReport ,
958
- Info : ccipocr3.ExecuteReportInfo {
959
- MerkleRoots : []ccipocr3.MerkleRootChain {},
960
- AbstractReports : []ccipocr3.ExecutePluginReportSingleChain {abstractReport },
961
- },
962
- }
963
-
964
- submitErr := cw .SubmitTransaction (ctx , "ccip_router" , "execute" , args , txID , routerAddr .String (), nil , nil )
965
- require .NoError (t , submitErr )
966
- })
967
-
968
- t .Run ("CCIP commit is encoded successfully" , func (t * testing.T ) {
969
- // mock txm
970
- txm := txmMocks .NewTxManager (t )
971
- // initialize chain writer
972
- cw , err := chainwriter .NewSolanaChainWriterService (testutils .NewNullLogger (), rw , txm , ge , ccipCWConfig )
973
- require .NoError (t , err )
974
-
975
- recentBlockHash := solana.Hash {}
976
- rw .On ("LatestBlockhash" , mock .Anything ).Return (& rpc.GetLatestBlockhashResult {Value : & rpc.LatestBlockhashResult {Blockhash : recentBlockHash , LastValidBlockHeight : uint64 (100 )}}, nil ).Once ()
977
-
978
- type CommitArgs struct {
979
- ReportContext [2 ][32 ]byte
980
- Report []byte
981
- Rs [][32 ]byte
982
- Ss [][32 ]byte
983
- RawVs [32 ]byte
984
- Info ccipocr3.CommitReportInfo
985
- }
986
-
987
- txID := uuid .NewString ()
988
-
989
- // TODO: Replace with actual type from ccipocr3
990
- args := CommitArgs {
991
- ReportContext : [2 ][32 ]byte {{0x01 }, {0x02 }},
992
- Report : []byte {0x01 , 0x02 },
993
- Rs : [][32 ]byte {{0x01 , 0x02 }},
994
- Ss : [][32 ]byte {{0x01 , 0x02 }},
995
- RawVs : [32 ]byte {0x01 , 0x02 },
996
- Info : ccipocr3.CommitReportInfo {
997
- RemoteF : 1 ,
998
- MerkleRoots : []ccipocr3.MerkleRootChain {},
999
- },
1000
- }
1001
-
1002
- txm .On ("Enqueue" , mock .Anything , admin .String (), mock .MatchedBy (func (tx * solana.Transaction ) bool {
1003
- txData := tx .Message .Instructions [0 ].Data
1004
- payload := txData [8 :]
1005
- var decoded ccip_router.Commit
1006
- dec := ag_binary .NewBorshDecoder (payload )
1007
- err := dec .Decode (& decoded )
1008
- require .NoError (t , err )
1009
- return true
1010
- }), & txID , mock .Anything ).Return (nil ).Once ()
1011
-
1012
- submitErr := cw .SubmitTransaction (ctx , "ccip_router" , "commit" , args , txID , routerAddr .String (), nil , nil )
1013
- require .NoError (t , submitErr )
1014
- })
1015
- }
1016
-
1017
802
func TestChainWriter_GetTransactionStatus (t * testing.T ) {
1018
803
t .Parallel ()
1019
804
0 commit comments