Skip to content

Commit aa71d84

Browse files
committed
Updated PDALookup internal field to use codec
1 parent cb6a64f commit aa71d84

File tree

3 files changed

+116
-66
lines changed

3 files changed

+116
-66
lines changed

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
606606
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
607607
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
608608
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
609+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
609610
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
610611
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
611612
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
@@ -617,6 +618,9 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
617618
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
618619
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
619620
github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
621+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
622+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
623+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
620624
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
621625
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
622626
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=

pkg/solana/chainwriter/ccip_example_config.go

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package chainwriter
22

33
import (
4-
"reflect"
5-
64
"github.com/gagliardetto/solana-go"
75
"github.com/smartcontractkit/chainlink-common/pkg/codec"
86
)

pkg/solana/chainwriter/chain_writer_test.go

+112-64
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,6 @@ func TestChainWriter_SubmitTransaction(t *testing.T) {
587587
func TestChainWriter_CCIPRouter(t *testing.T) {
588588
t.Parallel()
589589

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-
598590
// setup admin key
599591
adminPk, err := solana.NewRandomPrivateKey()
600592
require.NoError(t, err)
@@ -603,16 +595,9 @@ func TestChainWriter_CCIPRouter(t *testing.T) {
603595
routerAddr := chainwriter.GetRandomPubKey(t)
604596
destTokenAddr := chainwriter.GetRandomPubKey(t)
605597

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-
611598
poolKeys := []solana.PublicKey{destTokenAddr}
612599
poolKeys = append(poolKeys, chainwriter.CreateTestPubKeys(t, 3)...)
613600

614-
mockFetchLookupTableAddresses(t, rw, lookupTable, poolKeys)
615-
616601
// simplified CCIP Config - does not contain full account list
617602
ccipCWConfig := chainwriter.ChainWriterConfig{
618603
Programs: map[string]chainwriter.ProgramConfig{
@@ -625,7 +610,7 @@ func TestChainWriter_CCIPRouter(t *testing.T) {
625610
Fields: map[string]string{"ReportContextByteWords": "ReportContext"},
626611
},
627612
&codec.RenameModifierConfig{
628-
Fields: map[string]string{"ExecutionReport": "AbstractReport"},
613+
Fields: map[string]string{"RawExecutionReport": "Report"},
629614
},
630615
},
631616
ChainSpecificName: "execute",
@@ -662,27 +647,70 @@ func TestChainWriter_CCIPRouter(t *testing.T) {
662647
},
663648
},
664649
},
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+
},
665678
},
666679
IDL: ccipRouterIDL,
667680
},
668681
},
669682
}
670683

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)
674689

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)
678696

697+
recentBlockHash := solana.Hash{}
679698
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()
680708
txm.On("Enqueue", mock.Anything, admin.String(), mock.MatchedBy(func(tx *solana.Transaction) bool {
681709
txData := tx.Message.Instructions[0].Data
682710
payload := txData[8:]
683711
var decoded ccip_router.Execute
684712
dec := ag_binary.NewBorshDecoder(payload)
685-
err := dec.Decode(&decoded)
713+
err = dec.Decode(&decoded)
686714
require.NoError(t, err)
687715

688716
tokenIndexes := *decoded.TokenIndexes
@@ -692,63 +720,83 @@ func TestChainWriter_CCIPRouter(t *testing.T) {
692720
return true
693721
}), &txID, mock.Anything).Return(nil).Once()
694722

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+
},
723731
},
724732
},
725-
OnRampAddress: []byte{0x1},
726733
},
727-
OffchainTokenData: [][]byte{{0x1}},
728-
Proofs: [][32]byte{{0x1}},
729734
}
730735

731736
// Marshal the abstract report to json just for testing purposes.
732-
encodededReport, err := json.Marshal(abstractReport)
737+
encodedReport, err := json.Marshal(abstractReport)
733738
require.NoError(t, err)
734739

735740
args := chainwriter.ReportPreTransform{
736-
ReportContext: [3][32]uint8{{0x01, 0x02, 0x03}},
737-
Report: encodededReport,
741+
ReportContext: [2][32]byte{{0x01}, {0x02}},
742+
Report: encodedReport,
738743
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},
745746
},
746-
AbstractReport: abstractReport,
747747
}
748748

749749
submitErr := cw.SubmitTransaction(ctx, "ccip_router", "execute", args, txID, routerAddr.String(), nil, nil)
750750
require.NoError(t, submitErr)
751751
})
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+
})
752800
}
753801

754802
func TestChainWriter_CCIPRouter(t *testing.T) {

0 commit comments

Comments
 (0)