Skip to content

Commit

Permalink
Updated ccip execute args transform to use mapstructure to decode args
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-momin committed Feb 24, 2025
1 parent 1f41de9 commit ba80069
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkg/solana/chainwriter/chain_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ func TestChainWriter_CCIPOfframp(t *testing.T) {
encodedReport, err := json.Marshal(abstractReport)
require.NoError(t, err)

args := chainwriter.ReportPreTransform{
args := ReportPreTransform{
ReportContext: [2][32]byte{{0x01}, {0x02}},
Report: encodedReport,
Info: ccipocr3.ExecuteReportInfo{
Expand Down
22 changes: 5 additions & 17 deletions pkg/solana/chainwriter/transform_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ import (
"fmt"

"github.com/gagliardetto/solana-go"
"github.com/mitchellh/mapstructure"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_offramp"
"github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
)

// TODO: make this type in the chainlink-common CW package
type ReportPreTransform struct {
ReportContext [2][32]byte
Report []byte
Info ccipocr3.ExecuteReportInfo
AbstractReport ccip_offramp.ExecutionReportSingleChain
}

type ReportPostTransform struct {
ReportContext [2][32]byte
Report []byte
Expand All @@ -40,15 +33,10 @@ func FindTransform(id string) (func(context.Context, any, solana.AccountMetaSlic
// This Transform function looks up the token pool addresses in the accounts slice and augments the args
// with the indexes of the token pool addresses in the accounts slice.
func CCIPExecuteArgsTransform(ctx context.Context, args any, accounts solana.AccountMetaSlice, tableMap map[string]map[string][]*solana.AccountMeta) (any, solana.AccountMetaSlice, error) {
argsTyped, ok := args.(ReportPreTransform)
if !ok {
return nil, nil, fmt.Errorf("args is not of type ReportPreTransform")
}
argsTransformed := ReportPostTransform{
ReportContext: argsTyped.ReportContext,
Report: argsTyped.Report,
AbstractReport: argsTyped.AbstractReport,
Info: argsTyped.Info,
var argsTransformed ReportPostTransform
err := mapstructure.Decode(args, &argsTransformed)
if err != nil {
return nil, nil, err
}

registryTables, exists := tableMap["PoolLookupTable"]
Expand Down
25 changes: 24 additions & 1 deletion pkg/solana/chainwriter/transform_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@ import (
"testing"

"github.com/gagliardetto/solana-go"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/ccip_offramp"
"github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-solana/pkg/solana/chainwriter"
)

type ReportPreTransform struct {
ReportContext [2][32]byte
Report []byte
Info ccipocr3.ExecuteReportInfo
AbstractReport ccip_offramp.ExecutionReportSingleChain
}

func Test_CCIPExecuteArgsTransform(t *testing.T) {
ctx := tests.Context(t)

destTokenAddr := chainwriter.GetRandomPubKey(t)
poolKeys := []solana.PublicKey{destTokenAddr}
poolKeys = append(poolKeys, chainwriter.CreateTestPubKeys(t, 1)...)

args := chainwriter.ReportPreTransform{
args := ReportPreTransform{
Info: ccipocr3.ExecuteReportInfo{
AbstractReports: []ccipocr3.ExecutePluginReportSingleChain{{
Messages: []ccipocr3.Message{{
Expand Down Expand Up @@ -63,6 +71,21 @@ func Test_CCIPExecuteArgsTransform(t *testing.T) {
require.NotNil(t, typedArgs.TokenIndexes)
require.Len(t, typedArgs.TokenIndexes, 0)
})

t.Run("CCIPExecute ArgsTransform does not get args that conform to ReportPreTransform", func(t *testing.T) {
args := struct {
ReportContext [2][32]uint8
Report []uint8
}{
ReportContext: [2][32]uint8{},
Report: []uint8{},
}
transformedArgs, newAccounts, err := chainwriter.CCIPExecuteArgsTransform(ctx, args, accounts, nil)
require.NoError(t, err)
_, ok := transformedArgs.(chainwriter.ReportPostTransform)
require.True(t, ok)
require.Len(t, newAccounts, 2)
})
}

func Test_CCIPCommitAccountTransform(t *testing.T) {
Expand Down

0 comments on commit ba80069

Please sign in to comment.