Skip to content
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
45 changes: 45 additions & 0 deletions sdk/sui/chain_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
14 changes: 14 additions & 0 deletions sdk/sui/sui_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sui

import (
"encoding/json"
"errors"
"fmt"

suibindings "github.com/smartcontractkit/chainlink-sui/bindings"
Expand All @@ -25,3 +26,16 @@ func SuiMetadata(chainMetadata types.ChainMetadata) (AdditionalFieldsMetadata, e
}

var NewCCIPEntrypointArgEncoder = suibindings.NewCCIPEntrypointArgEncoder

func SuiRoleFromAction(action types.TimelockAction) (TimelockRole, error) {
Comment thread
FelixFan1992 marked this conversation as resolved.
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")
}
}
Loading