Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated ccip execute args transform to use mapstructure to decode args #1103

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading