|
| 1 | +package changesets |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/gagliardetto/solana-go" |
| 8 | + chainselectors "github.com/smartcontractkit/chain-selectors" |
| 9 | + cldf_chain "github.com/smartcontractkit/chainlink-deployments-framework/chain" |
| 10 | + cldf_solana "github.com/smartcontractkit/chainlink-deployments-framework/chain/solana" |
| 11 | + cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" |
| 12 | + cldfproposalutils "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalutils" |
| 13 | + mcmstypes "github.com/smartcontractkit/mcms/types" |
| 14 | + "github.com/stretchr/testify/require" |
| 15 | + |
| 16 | + timelockbindings "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/v0_1_1/timelock" |
| 17 | +) |
| 18 | + |
| 19 | +func TestGrantRoleTimelockSolana_VerifyPreconditions(t *testing.T) { |
| 20 | + t.Parallel() |
| 21 | + |
| 22 | + sel := chainselectors.TEST_22222222222222222222222222222222222222222222.Selector |
| 23 | + missingSel := uint64(999991) |
| 24 | + acct := solana.NewWallet().PublicKey() |
| 25 | + |
| 26 | + tests := []struct { |
| 27 | + name string |
| 28 | + env func(t *testing.T) cldf.Environment |
| 29 | + config GrantRoleTimelockSolanaConfig |
| 30 | + expectedError string |
| 31 | + }{ |
| 32 | + { |
| 33 | + name: "All preconditions satisfied", |
| 34 | + env: func(t *testing.T) cldf.Environment { |
| 35 | + t.Helper() |
| 36 | + ab := cldf.NewMemoryAddressBook() |
| 37 | + saveMCMSAddresses(t, ab, sel, true) |
| 38 | + |
| 39 | + return testEnvironment(t, ab, cldf_chain.NewBlockChains(map[uint64]cldf_chain.BlockChain{ |
| 40 | + sel: cldf_solana.Chain{Selector: sel}, |
| 41 | + })) |
| 42 | + }, |
| 43 | + config: GrantRoleTimelockSolanaConfig{ |
| 44 | + Accounts: map[uint64][]solana.PublicKey{sel: {acct}}, |
| 45 | + Role: timelockbindings.Executor_Role, |
| 46 | + MCMS: &cldfproposalutils.TimelockConfig{MCMSAction: mcmstypes.TimelockActionSchedule}, |
| 47 | + }, |
| 48 | + expectedError: "", |
| 49 | + }, |
| 50 | + { |
| 51 | + name: "Nil MCMS allowed", |
| 52 | + env: func(t *testing.T) cldf.Environment { |
| 53 | + t.Helper() |
| 54 | + ab := cldf.NewMemoryAddressBook() |
| 55 | + saveMCMSAddresses(t, ab, sel, true) |
| 56 | + |
| 57 | + return testEnvironment(t, ab, cldf_chain.NewBlockChains(map[uint64]cldf_chain.BlockChain{ |
| 58 | + sel: cldf_solana.Chain{Selector: sel}, |
| 59 | + })) |
| 60 | + }, |
| 61 | + config: GrantRoleTimelockSolanaConfig{ |
| 62 | + Accounts: map[uint64][]solana.PublicKey{sel: {acct}}, |
| 63 | + Role: timelockbindings.Bypasser_Role, |
| 64 | + MCMS: nil, |
| 65 | + }, |
| 66 | + expectedError: "", |
| 67 | + }, |
| 68 | + { |
| 69 | + name: "No Solana chains in environment", |
| 70 | + env: func(t *testing.T) cldf.Environment { |
| 71 | + t.Helper() |
| 72 | + |
| 73 | + return testEnvironment(t, cldf.NewMemoryAddressBook(), cldf_chain.NewBlockChains(nil)) |
| 74 | + }, |
| 75 | + config: GrantRoleTimelockSolanaConfig{ |
| 76 | + Accounts: map[uint64][]solana.PublicKey{sel: {acct}}, |
| 77 | + Role: timelockbindings.Proposer_Role, |
| 78 | + }, |
| 79 | + expectedError: "no solana chains provided", |
| 80 | + }, |
| 81 | + { |
| 82 | + name: "Chain selector not found in environment", |
| 83 | + env: func(t *testing.T) cldf.Environment { |
| 84 | + t.Helper() |
| 85 | + |
| 86 | + return testEnvironment(t, cldf.NewMemoryAddressBook(), cldf_chain.NewBlockChains(map[uint64]cldf_chain.BlockChain{ |
| 87 | + sel: cldf_solana.Chain{Selector: sel}, |
| 88 | + })) |
| 89 | + }, |
| 90 | + config: GrantRoleTimelockSolanaConfig{ |
| 91 | + Accounts: map[uint64][]solana.PublicKey{missingSel: {acct}}, |
| 92 | + Role: timelockbindings.Proposer_Role, |
| 93 | + }, |
| 94 | + expectedError: fmt.Sprintf("solana chain not found for selector %d", missingSel), |
| 95 | + }, |
| 96 | + { |
| 97 | + name: "Invalid MCMS action", |
| 98 | + env: func(t *testing.T) cldf.Environment { |
| 99 | + t.Helper() |
| 100 | + ab := cldf.NewMemoryAddressBook() |
| 101 | + saveMCMSAddresses(t, ab, sel, true) |
| 102 | + |
| 103 | + return testEnvironment(t, ab, cldf_chain.NewBlockChains(map[uint64]cldf_chain.BlockChain{ |
| 104 | + sel: cldf_solana.Chain{Selector: sel}, |
| 105 | + })) |
| 106 | + }, |
| 107 | + config: GrantRoleTimelockSolanaConfig{ |
| 108 | + Accounts: map[uint64][]solana.PublicKey{sel: {acct}}, |
| 109 | + Role: timelockbindings.Proposer_Role, |
| 110 | + MCMS: &cldfproposalutils.TimelockConfig{ |
| 111 | + MCMSAction: mcmstypes.TimelockAction("unsupported-action"), |
| 112 | + }, |
| 113 | + }, |
| 114 | + expectedError: "invalid mcms action", |
| 115 | + }, |
| 116 | + { |
| 117 | + name: "Incomplete MCMS address fixture", |
| 118 | + env: func(t *testing.T) cldf.Environment { |
| 119 | + t.Helper() |
| 120 | + ab := cldf.NewMemoryAddressBook() |
| 121 | + saveMCMSAddresses(t, ab, sel, false) |
| 122 | + |
| 123 | + return testEnvironment(t, ab, cldf_chain.NewBlockChains(map[uint64]cldf_chain.BlockChain{ |
| 124 | + sel: cldf_solana.Chain{Selector: sel}, |
| 125 | + })) |
| 126 | + }, |
| 127 | + config: GrantRoleTimelockSolanaConfig{ |
| 128 | + Accounts: map[uint64][]solana.PublicKey{sel: {acct}}, |
| 129 | + Role: timelockbindings.Proposer_Role, |
| 130 | + }, |
| 131 | + expectedError: "timelock program not deployed for chain", |
| 132 | + }, |
| 133 | + } |
| 134 | + |
| 135 | + cs := GrantRoleTimelockSolana{} |
| 136 | + |
| 137 | + for _, tt := range tests { |
| 138 | + t.Run(tt.name, func(t *testing.T) { |
| 139 | + t.Parallel() |
| 140 | + |
| 141 | + err := cs.VerifyPreconditions(tt.env(t), tt.config) |
| 142 | + if tt.expectedError == "" { |
| 143 | + require.NoError(t, err) |
| 144 | + } else { |
| 145 | + require.Error(t, err) |
| 146 | + require.ErrorContains(t, err, tt.expectedError) |
| 147 | + } |
| 148 | + }) |
| 149 | + } |
| 150 | +} |
0 commit comments