|
1 | 1 | package keeper_test
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" |
4 | 5 | "testing"
|
5 | 6 | "time"
|
6 | 7 |
|
@@ -176,4 +177,84 @@ func TestUpdateConsumer(t *testing.T) {
|
176 | 177 | require.Equal(t, providertypes.ConsumerIds{
|
177 | 178 | Ids: []string{consumerId},
|
178 | 179 | }, consumerIds)
|
| 180 | + |
| 181 | + // assert that we CANNOT update the initialization parameters of a launched chain |
| 182 | + providerKeeper.SetConsumerPhase(ctx, consumerId, providertypes.CONSUMER_PHASE_LAUNCHED) |
| 183 | + _, err = msgServer.UpdateConsumer(ctx, |
| 184 | + &providertypes.MsgUpdateConsumer{ |
| 185 | + Owner: expectedOwnerAddress, ConsumerId: consumerId, |
| 186 | + Metadata: nil, |
| 187 | + InitializationParameters: &expectedInitializationParameters, |
| 188 | + PowerShapingParameters: nil, |
| 189 | + }) |
| 190 | + require.ErrorContains(t, err, "cannot update the initialization parameters of an an already launched chain") |
| 191 | + |
| 192 | + // assert that we can update the consumer metadata of a launched chain |
| 193 | + providerKeeper.SetConsumerPhase(ctx, consumerId, providertypes.CONSUMER_PHASE_LAUNCHED) |
| 194 | + expectedConsumerMetadata.Name = "name of a launched chain" |
| 195 | + _, err = msgServer.UpdateConsumer(ctx, |
| 196 | + &providertypes.MsgUpdateConsumer{ |
| 197 | + Owner: expectedOwnerAddress, ConsumerId: consumerId, |
| 198 | + Metadata: &expectedConsumerMetadata, |
| 199 | + InitializationParameters: nil, |
| 200 | + PowerShapingParameters: nil, |
| 201 | + }) |
| 202 | + require.NoError(t, err) |
| 203 | + actualConsumerMetadata, err = providerKeeper.GetConsumerMetadata(ctx, consumerId) |
| 204 | + require.NoError(t, err) |
| 205 | + require.Equal(t, expectedConsumerMetadata, actualConsumerMetadata) |
| 206 | + |
| 207 | + // assert that we can update the power-shaping parameters of a launched chain |
| 208 | + providerKeeper.SetConsumerPhase(ctx, consumerId, providertypes.CONSUMER_PHASE_LAUNCHED) |
| 209 | + expectedPowerShapingParameters.ValidatorSetCap = 123 |
| 210 | + _, err = msgServer.UpdateConsumer(ctx, |
| 211 | + &providertypes.MsgUpdateConsumer{ |
| 212 | + Owner: expectedOwnerAddress, ConsumerId: consumerId, |
| 213 | + Metadata: nil, |
| 214 | + InitializationParameters: nil, |
| 215 | + PowerShapingParameters: &expectedPowerShapingParameters, |
| 216 | + }) |
| 217 | + require.NoError(t, err) |
| 218 | + actualPowerShapingParameters, err = providerKeeper.GetConsumerPowerShapingParameters(ctx, consumerId) |
| 219 | + require.NoError(t, err) |
| 220 | + require.Equal(t, expectedPowerShapingParameters, actualPowerShapingParameters) |
| 221 | + |
| 222 | + // assert that if we call `MsgUpdateConsumer` with a spawn time of zero on an initialized chain, the chain |
| 223 | + // will not be scheduled to launch and will move back to its Registered phase |
| 224 | + providerKeeper.SetConsumerPhase(ctx, consumerId, providertypes.CONSUMER_PHASE_INITIALIZED) |
| 225 | + // first assert that the chain is scheduled to launch |
| 226 | + previousSpawnTime = expectedInitializationParameters.SpawnTime |
| 227 | + consumerIds, err = providerKeeper.GetConsumersToBeLaunched(ctx, previousSpawnTime) |
| 228 | + require.NoError(t, err) |
| 229 | + require.Equal(t, providertypes.ConsumerIds{ |
| 230 | + Ids: []string{consumerId}, |
| 231 | + }, consumerIds) |
| 232 | + |
| 233 | + // then, update with a spawn time of zero to prevent the chain from launching |
| 234 | + expectedInitializationParameters.SpawnTime = time.Time{} |
| 235 | + // also update an arbitrary field of the initialization parameters |
| 236 | + // to verify that the parameters of the chain get updated |
| 237 | + expectedInitializationParameters.InitialHeight = types.NewHeight(1, 123456) |
| 238 | + _, err = msgServer.UpdateConsumer(ctx, |
| 239 | + &providertypes.MsgUpdateConsumer{ |
| 240 | + Owner: expectedOwnerAddress, ConsumerId: consumerId, |
| 241 | + Metadata: nil, |
| 242 | + InitializationParameters: &expectedInitializationParameters, |
| 243 | + PowerShapingParameters: nil, |
| 244 | + }) |
| 245 | + // assert the chain is not scheduled to launch |
| 246 | + consumerIds, err = providerKeeper.GetConsumersToBeLaunched(ctx, previousSpawnTime) |
| 247 | + require.NoError(t, err) |
| 248 | + require.Empty(t, consumerIds) |
| 249 | + // also assert that no chain is scheduled to launch at zero time |
| 250 | + consumerIds, err = providerKeeper.GetConsumersToBeLaunched(ctx, time.Time{}) |
| 251 | + require.NoError(t, err) |
| 252 | + require.Empty(t, consumerIds) |
| 253 | + // assert that the chain has moved to the registered phase because it is not ready to launch |
| 254 | + phase = providerKeeper.GetConsumerPhase(ctx, consumerId) |
| 255 | + require.Equal(t, providertypes.CONSUMER_PHASE_REGISTERED, phase) |
| 256 | + // assert that the initialization parameters of the chain were nevertheless updated |
| 257 | + actualInitializationParameters, err = providerKeeper.GetConsumerInitializationParameters(ctx, consumerId) |
| 258 | + require.NoError(t, err) |
| 259 | + require.Equal(t, expectedInitializationParameters, actualInitializationParameters) |
179 | 260 | }
|
0 commit comments