Skip to content

Commit

Permalink
refactored argstransforms
Browse files Browse the repository at this point in the history
  • Loading branch information
silaslenihan committed Feb 25, 2025
1 parent 2112889 commit fafc794
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions pkg/solana/chainwriter/transform_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ const staticCuOverhead = 1000
func FindTransform(id string) (func(context.Context, any, solana.AccountMetaSlice, map[string]map[string][]*solana.AccountMeta) (any, solana.AccountMetaSlice, []txmutils.SetTxConfig, error), error) {
switch id {
case "CCIPExecute":
return CCIPExecuteArgsTransform, nil
return CCIPExecuteTransform, nil
case "CCIPCommit":
return CCIPCommitAccountTransform, nil
return CCIPCommitTransform, nil
default:
return nil, fmt.Errorf("transform not found")
}
}

// 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, []txmutils.SetTxConfig, error) {
func CCIPExecuteTransform(ctx context.Context, args any, accounts solana.AccountMetaSlice, tableMap map[string]map[string][]*solana.AccountMeta) (any, solana.AccountMetaSlice, []txmutils.SetTxConfig, error) {
var argsTransformed ReportPostTransform
err := mapstructure.Decode(args, &argsTransformed)
if err != nil {
Expand Down Expand Up @@ -99,7 +99,7 @@ func CCIPExecuteArgsTransform(ctx context.Context, args any, accounts solana.Acc
}

// This Transform function trims off the GlobalState account from commit transactions if there are no token or gas price updates
func CCIPCommitAccountTransform(ctx context.Context, args any, accounts solana.AccountMetaSlice, _ map[string]map[string][]*solana.AccountMeta) (any, solana.AccountMetaSlice, []txmutils.SetTxConfig, error) {
func CCIPCommitTransform(ctx context.Context, args any, accounts solana.AccountMetaSlice, _ map[string]map[string][]*solana.AccountMeta) (any, solana.AccountMetaSlice, []txmutils.SetTxConfig, error) {
var tokenPriceVals, gasPriceVals [][]byte
var err error
tokenPriceVals, err = GetValuesAtLocation(args, "Info.TokenPrices.TokenID")
Expand Down
14 changes: 7 additions & 7 deletions pkg/solana/chainwriter/transform_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Test_CCIPExecuteArgsTransform(t *testing.T) {
}
tableMap["PoolLookupTable"][lookupTablePubkey.String()] = poolKeysMeta

transformedArgs, newAccounts, options, err := chainwriter.CCIPExecuteArgsTransform(ctx, args, accounts, tableMap)
transformedArgs, newAccounts, options, err := chainwriter.CCIPExecuteTransform(ctx, args, accounts, tableMap)
require.NoError(t, err)

verifyTxOpts(t, options, true)
Expand All @@ -70,7 +70,7 @@ func Test_CCIPExecuteArgsTransform(t *testing.T) {
})

t.Run("CCIPExecute ArgsTransform includes empty token indexes if lookup table not found", func(t *testing.T) {
transformedArgs, newAccounts, options, err := chainwriter.CCIPExecuteArgsTransform(ctx, args, accounts, nil)
transformedArgs, newAccounts, options, err := chainwriter.CCIPExecuteTransform(ctx, args, accounts, nil)
require.NoError(t, err)
verifyTxOpts(t, options, true)

Expand Down Expand Up @@ -105,7 +105,7 @@ func Test_CCIPExecuteArgsTransform(t *testing.T) {
}},
},
}
transformedArgs, newAccounts, options, err := chainwriter.CCIPExecuteArgsTransform(ctx, args, accounts, nil)
transformedArgs, newAccounts, options, err := chainwriter.CCIPExecuteTransform(ctx, args, accounts, nil)
require.NoError(t, err)

verifyTxOpts(t, options, true)
Expand All @@ -124,7 +124,7 @@ func Test_CCIPExecuteArgsTransform(t *testing.T) {
Report: []uint8{},
Info: ccipocr3.ExecuteReportInfo{},
}
_, _, _, err := chainwriter.CCIPExecuteArgsTransform(ctx, args, accounts, nil)
_, _, _, err := chainwriter.CCIPExecuteTransform(ctx, args, accounts, nil)
require.Contains(t, err.Error(), "Expected 1 report with 1 message")
})

Expand All @@ -140,7 +140,7 @@ func Test_CCIPExecuteArgsTransform(t *testing.T) {
AbstractReports: []ccipocr3.ExecutePluginReportSingleChain{{}, {}},
},
}
_, _, _, err := chainwriter.CCIPExecuteArgsTransform(ctx, args, accounts, nil)
_, _, _, err := chainwriter.CCIPExecuteTransform(ctx, args, accounts, nil)
require.Contains(t, err.Error(), "Expected 1 report with 1 message")
})
}
Expand All @@ -158,7 +158,7 @@ func Test_CCIPCommitAccountTransform(t *testing.T) {
},
}
accounts := []*solana.AccountMeta{{PublicKey: key1}, {PublicKey: key2}}
_, newAccounts, options, err := chainwriter.CCIPCommitAccountTransform(ctx, args, accounts, nil)
_, newAccounts, options, err := chainwriter.CCIPCommitTransform(ctx, args, accounts, nil)
verifyTxOpts(t, options, false)
require.NoError(t, err)
require.Len(t, newAccounts, 2)
Expand All @@ -170,7 +170,7 @@ func Test_CCIPCommitAccountTransform(t *testing.T) {
Info: ccipocr3.CommitReportInfo{},
}
accounts := []*solana.AccountMeta{{PublicKey: key1}, {PublicKey: key2}}
_, newAccounts, options, err := chainwriter.CCIPCommitAccountTransform(ctx, args, accounts, nil)
_, newAccounts, options, err := chainwriter.CCIPCommitTransform(ctx, args, accounts, nil)
verifyTxOpts(t, options, false)

require.NoError(t, err)
Expand Down

0 comments on commit fafc794

Please sign in to comment.