From 22d5f2d2bd88280eb16350d5088f08682f30f218 Mon Sep 17 00:00:00 2001 From: FelixFan1992 Date: Mon, 17 Aug 2026 18:43:17 -0400 Subject: [PATCH] CCIP-13068: expose a function to infer roles from action --- sdk/sui/chain_metadata_test.go | 45 ++++++++++++++++++++++++++++++++++ sdk/sui/sui_helpers.go | 14 +++++++++++ 2 files changed, 59 insertions(+) diff --git a/sdk/sui/chain_metadata_test.go b/sdk/sui/chain_metadata_test.go index 67c777d78..f29021f8e 100644 --- a/sdk/sui/chain_metadata_test.go +++ b/sdk/sui/chain_metadata_test.go @@ -92,6 +92,51 @@ func TestTimelockRole_Constants(t *testing.T) { assert.Equal(t, TimelockRoleProposer, TimelockRole(2)) } +func TestSuiRoleFromAction(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + action types.TimelockAction + want TimelockRole + wantErr bool + }{ + { + name: "bypass action", + action: types.TimelockActionBypass, + want: TimelockRoleBypasser, + }, + { + name: "schedule action", + action: types.TimelockActionSchedule, + want: TimelockRoleProposer, + }, + { + name: "cancel action", + action: types.TimelockActionCancel, + want: TimelockRoleCanceller, + }, + { + name: "unknown action", + action: types.TimelockAction("unknown"), + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + got, err := SuiRoleFromAction(tt.action) + if tt.wantErr { + require.Error(t, err) + return + } + require.NoError(t, err) + assert.Equal(t, tt.want, got) + }) + } +} + func TestAdditionalFieldsMetadata_JSON(t *testing.T) { t.Parallel() diff --git a/sdk/sui/sui_helpers.go b/sdk/sui/sui_helpers.go index a45d44d99..ed2c98c92 100644 --- a/sdk/sui/sui_helpers.go +++ b/sdk/sui/sui_helpers.go @@ -2,6 +2,7 @@ package sui import ( "encoding/json" + "errors" "fmt" suibindings "github.com/smartcontractkit/chainlink-sui/bindings" @@ -25,3 +26,16 @@ func SuiMetadata(chainMetadata types.ChainMetadata) (AdditionalFieldsMetadata, e } var NewCCIPEntrypointArgEncoder = suibindings.NewCCIPEntrypointArgEncoder + +func SuiRoleFromAction(action types.TimelockAction) (TimelockRole, error) { + switch action { + case types.TimelockActionBypass: + return TimelockRoleBypasser, nil + case types.TimelockActionSchedule: + return TimelockRoleProposer, nil + case types.TimelockActionCancel: + return TimelockRoleCanceller, nil + default: + return 0, errors.New("unknown timelock action") + } +}