|
| 1 | +/* |
| 2 | +Copyright IBM Corp. 2016 All Rights Reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package configtx |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "testing" |
| 22 | + |
| 23 | + ab "github.com/hyperledger/fabric/orderer/atomicbroadcast" |
| 24 | + "github.com/hyperledger/fabric/orderer/common/policies" |
| 25 | + |
| 26 | + "github.com/golang/protobuf/proto" |
| 27 | +) |
| 28 | + |
| 29 | +var defaultChain = []byte("DefaultChainID") |
| 30 | + |
| 31 | +func defaultHandlers() map[ab.Configuration_ConfigurationType]Handler { |
| 32 | + handlers := make(map[ab.Configuration_ConfigurationType]Handler) |
| 33 | + for ctype := range ab.Configuration_ConfigurationType_name { |
| 34 | + handlers[ab.Configuration_ConfigurationType(ctype)] = NewBytesHandler() |
| 35 | + } |
| 36 | + return handlers |
| 37 | +} |
| 38 | + |
| 39 | +// mockPolicy always returns the error set as policyResult |
| 40 | +type mockPolicy struct { |
| 41 | + policyResult error |
| 42 | +} |
| 43 | + |
| 44 | +func (mp *mockPolicy) Evaluate(msg []byte, sigs []*ab.SignedData) error { |
| 45 | + if mp == nil { |
| 46 | + return fmt.Errorf("Invoked nil policy") |
| 47 | + } |
| 48 | + return mp.policyResult |
| 49 | +} |
| 50 | + |
| 51 | +// mockPolicyManager always returns the policy set as policy, note that if unset, the default policy always returns error when evaluated |
| 52 | +type mockPolicyManager struct { |
| 53 | + policy *mockPolicy |
| 54 | +} |
| 55 | + |
| 56 | +func (mpm *mockPolicyManager) GetPolicy(id string) (policies.Policy, bool) { |
| 57 | + return mpm.policy, (mpm.policy != nil) |
| 58 | +} |
| 59 | + |
| 60 | +func makeConfiguration(id, modificationPolicy string, lastModified uint64, data []byte) *ab.Configuration { |
| 61 | + return &ab.Configuration{ |
| 62 | + ChainID: defaultChain, |
| 63 | + ID: id, |
| 64 | + Data: data, |
| 65 | + ModificationPolicy: modificationPolicy, |
| 66 | + LastModified: lastModified, |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +func makeConfigurationEntry(id, modificationPolicy string, lastModified uint64, data []byte) *ab.ConfigurationEntry { |
| 71 | + config := makeConfiguration(id, modificationPolicy, lastModified, data) |
| 72 | + marshaledConfig, err := proto.Marshal(config) |
| 73 | + if err != nil { |
| 74 | + panic(err) |
| 75 | + } |
| 76 | + return &ab.ConfigurationEntry{ |
| 77 | + Configuration: marshaledConfig, |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +// TestOmittedHandler tests that startup fails if not all configuration types have an associated handler |
| 82 | +func TestOmittedHandler(t *testing.T) { |
| 83 | + _, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 84 | + Sequence: 0, |
| 85 | + ChainID: defaultChain, |
| 86 | + }, &mockPolicyManager{&mockPolicy{}}, map[ab.Configuration_ConfigurationType]Handler{}) |
| 87 | + |
| 88 | + if err == nil { |
| 89 | + t.Fatalf("Should have failed to construct manager because handlers were missing") |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +// TestWrongChainID tests that a configuration update for a different chain ID fails |
| 94 | +func TestWrongChainID(t *testing.T) { |
| 95 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 96 | + Sequence: 0, |
| 97 | + ChainID: defaultChain, |
| 98 | + }, &mockPolicyManager{&mockPolicy{}}, defaultHandlers()) |
| 99 | + |
| 100 | + if err != nil { |
| 101 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 102 | + } |
| 103 | + |
| 104 | + newConfig := &ab.ConfigurationEnvelope{ |
| 105 | + Sequence: 1, |
| 106 | + ChainID: []byte("wrongChain"), |
| 107 | + } |
| 108 | + |
| 109 | + err = cm.Validate(newConfig) |
| 110 | + if err == nil { |
| 111 | + t.Errorf("Should have errored when validating a new configuration set the wrong chain ID") |
| 112 | + } |
| 113 | + |
| 114 | + err = cm.Apply(newConfig) |
| 115 | + if err == nil { |
| 116 | + t.Errorf("Should have errored when applying a new configuration with the wrong chain ID") |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +// TestOldConfigReplay tests that resubmitting a config for a sequence number which is not newer is ignored |
| 121 | +func TestOldConfigReplay(t *testing.T) { |
| 122 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 123 | + Sequence: 0, |
| 124 | + ChainID: defaultChain, |
| 125 | + }, &mockPolicyManager{&mockPolicy{}}, defaultHandlers()) |
| 126 | + |
| 127 | + if err != nil { |
| 128 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 129 | + } |
| 130 | + |
| 131 | + newConfig := &ab.ConfigurationEnvelope{ |
| 132 | + Sequence: 0, |
| 133 | + ChainID: defaultChain, |
| 134 | + } |
| 135 | + |
| 136 | + err = cm.Validate(newConfig) |
| 137 | + if err == nil { |
| 138 | + t.Errorf("Should have errored when validating a configuration that is not a newer sequence number") |
| 139 | + } |
| 140 | + |
| 141 | + err = cm.Apply(newConfig) |
| 142 | + if err == nil { |
| 143 | + t.Errorf("Should have errored when applying a configuration that is not a newer sequence number") |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +// TestInvalidInitialConfigByStructure tests to make sure that if the config contains corrupted configuration that construction results in error |
| 148 | +func TestInvalidInitialConfigByStructure(t *testing.T) { |
| 149 | + entries := []*ab.ConfigurationEntry{makeConfigurationEntry("foo", "foo", 0, []byte("foo"))} |
| 150 | + entries[0].Configuration = []byte("Corrupted") |
| 151 | + _, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 152 | + Sequence: 0, |
| 153 | + ChainID: defaultChain, |
| 154 | + Entries: entries, |
| 155 | + }, &mockPolicyManager{&mockPolicy{}}, defaultHandlers()) |
| 156 | + |
| 157 | + if err == nil { |
| 158 | + t.Fatalf("Should have failed to construct configuration by policy") |
| 159 | + } |
| 160 | +} |
| 161 | + |
| 162 | +// TestValidConfigChange tests the happy path of updating a configuration value with no defaultModificationPolicy |
| 163 | +func TestValidConfigChange(t *testing.T) { |
| 164 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 165 | + Sequence: 0, |
| 166 | + ChainID: defaultChain, |
| 167 | + }, &mockPolicyManager{}, defaultHandlers()) |
| 168 | + |
| 169 | + if err != nil { |
| 170 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 171 | + } |
| 172 | + |
| 173 | + newConfig := &ab.ConfigurationEnvelope{ |
| 174 | + Sequence: 1, |
| 175 | + ChainID: defaultChain, |
| 176 | + Entries: []*ab.ConfigurationEntry{makeConfigurationEntry("foo", "foo", 1, []byte("foo"))}, |
| 177 | + } |
| 178 | + |
| 179 | + err = cm.Validate(newConfig) |
| 180 | + if err != nil { |
| 181 | + t.Errorf("Should not have errored validating config: %s", err) |
| 182 | + } |
| 183 | + |
| 184 | + err = cm.Apply(newConfig) |
| 185 | + if err != nil { |
| 186 | + t.Errorf("Should not have errored applying config: %s", err) |
| 187 | + } |
| 188 | +} |
| 189 | + |
| 190 | +// TestConfigChangeNoUpdatedSequence tests that a new submitted config is rejected if it increments the |
| 191 | +// sequence number without a corresponding config item with that sequence number |
| 192 | +func TestConfigChangeNoUpdatedSequence(t *testing.T) { |
| 193 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 194 | + Sequence: 0, |
| 195 | + ChainID: defaultChain, |
| 196 | + }, &mockPolicyManager{&mockPolicy{}}, defaultHandlers()) |
| 197 | + |
| 198 | + if err != nil { |
| 199 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 200 | + } |
| 201 | + |
| 202 | + newConfig := &ab.ConfigurationEnvelope{ |
| 203 | + Sequence: 1, |
| 204 | + ChainID: defaultChain, |
| 205 | + // Note that the entries do not contain any config items with seqNo=1, so this is invalid |
| 206 | + Entries: []*ab.ConfigurationEntry{makeConfigurationEntry("foo", "foo", 0, []byte("foo"))}, |
| 207 | + } |
| 208 | + |
| 209 | + err = cm.Validate(newConfig) |
| 210 | + if err == nil { |
| 211 | + t.Errorf("Should have errored validating config because no new sequence number matches") |
| 212 | + } |
| 213 | + |
| 214 | + err = cm.Apply(newConfig) |
| 215 | + if err == nil { |
| 216 | + t.Errorf("Should have errored applying config because no new sequence number matches") |
| 217 | + } |
| 218 | +} |
| 219 | + |
| 220 | +// TestConfigChangeRegressedSequence tests to make sure that a new config cannot roll back one of the |
| 221 | +// config values while advancing another |
| 222 | +func TestConfigChangeRegressedSequence(t *testing.T) { |
| 223 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 224 | + Sequence: 1, |
| 225 | + ChainID: defaultChain, |
| 226 | + Entries: []*ab.ConfigurationEntry{makeConfigurationEntry("foo", "foo", 1, []byte("foo"))}, |
| 227 | + }, &mockPolicyManager{&mockPolicy{}}, defaultHandlers()) |
| 228 | + |
| 229 | + if err != nil { |
| 230 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 231 | + } |
| 232 | + |
| 233 | + newConfig := &ab.ConfigurationEnvelope{ |
| 234 | + Sequence: 2, |
| 235 | + ChainID: defaultChain, |
| 236 | + Entries: []*ab.ConfigurationEntry{ |
| 237 | + makeConfigurationEntry("foo", "foo", 0, []byte("foo")), |
| 238 | + makeConfigurationEntry("bar", "bar", 2, []byte("bar")), |
| 239 | + }, |
| 240 | + } |
| 241 | + |
| 242 | + err = cm.Validate(newConfig) |
| 243 | + if err == nil { |
| 244 | + t.Errorf("Should have errored validating config because foo's sequence number regressed") |
| 245 | + } |
| 246 | + |
| 247 | + err = cm.Apply(newConfig) |
| 248 | + if err == nil { |
| 249 | + t.Errorf("Should have errored applying config because foo's sequence number regressed") |
| 250 | + } |
| 251 | +} |
| 252 | + |
| 253 | +// TestConfigImplicitDelete tests to make sure that a new config does not implicitly delete config items |
| 254 | +// by omitting them in the new config |
| 255 | +func TestConfigImplicitDelete(t *testing.T) { |
| 256 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 257 | + Sequence: 0, |
| 258 | + ChainID: defaultChain, |
| 259 | + Entries: []*ab.ConfigurationEntry{ |
| 260 | + makeConfigurationEntry("foo", "foo", 0, []byte("foo")), |
| 261 | + makeConfigurationEntry("bar", "bar", 0, []byte("bar")), |
| 262 | + }, |
| 263 | + }, &mockPolicyManager{&mockPolicy{}}, defaultHandlers()) |
| 264 | + |
| 265 | + if err != nil { |
| 266 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 267 | + } |
| 268 | + |
| 269 | + newConfig := &ab.ConfigurationEnvelope{ |
| 270 | + Sequence: 1, |
| 271 | + ChainID: defaultChain, |
| 272 | + Entries: []*ab.ConfigurationEntry{ |
| 273 | + makeConfigurationEntry("bar", "bar", 1, []byte("bar")), |
| 274 | + }, |
| 275 | + } |
| 276 | + |
| 277 | + err = cm.Validate(newConfig) |
| 278 | + if err == nil { |
| 279 | + t.Errorf("Should have errored validating config because foo was implicitly deleted") |
| 280 | + } |
| 281 | + |
| 282 | + err = cm.Apply(newConfig) |
| 283 | + if err == nil { |
| 284 | + t.Errorf("Should have errored applying config because foo was implicitly deleted") |
| 285 | + } |
| 286 | +} |
| 287 | + |
| 288 | +// TestConfigModifyWithoutFullIncrease tests to make sure that if an item is modified in a config change |
| 289 | +// that it not only increments its LastModified, but also increments it to the current sequence number |
| 290 | +func TestConfigModifyWithoutFullIncrease(t *testing.T) { |
| 291 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 292 | + Sequence: 0, |
| 293 | + ChainID: defaultChain, |
| 294 | + Entries: []*ab.ConfigurationEntry{ |
| 295 | + makeConfigurationEntry("foo", "foo", 0, []byte("foo")), |
| 296 | + makeConfigurationEntry("bar", "bar", 0, []byte("bar")), |
| 297 | + }, |
| 298 | + }, &mockPolicyManager{&mockPolicy{}}, defaultHandlers()) |
| 299 | + |
| 300 | + if err != nil { |
| 301 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 302 | + } |
| 303 | + |
| 304 | + newConfig := &ab.ConfigurationEnvelope{ |
| 305 | + Sequence: 1, |
| 306 | + ChainID: defaultChain, |
| 307 | + Entries: []*ab.ConfigurationEntry{ |
| 308 | + makeConfigurationEntry("foo", "foo", 0, []byte("foo")), |
| 309 | + makeConfigurationEntry("bar", "bar", 1, []byte("bar")), |
| 310 | + }, |
| 311 | + } |
| 312 | + |
| 313 | + err = cm.Validate(newConfig) |
| 314 | + if err != nil { |
| 315 | + t.Errorf("Should not have errored validating config: %s", err) |
| 316 | + } |
| 317 | + |
| 318 | + err = cm.Apply(newConfig) |
| 319 | + if err != nil { |
| 320 | + t.Errorf("Should not have errored applying config: %s", err) |
| 321 | + } |
| 322 | + |
| 323 | + newConfig = &ab.ConfigurationEnvelope{ |
| 324 | + Sequence: 2, |
| 325 | + ChainID: defaultChain, |
| 326 | + Entries: []*ab.ConfigurationEntry{ |
| 327 | + makeConfigurationEntry("foo", "foo", 1, []byte("foo")), |
| 328 | + makeConfigurationEntry("bar", "bar", 2, []byte("bar")), |
| 329 | + }, |
| 330 | + } |
| 331 | + |
| 332 | + err = cm.Validate(newConfig) |
| 333 | + if err == nil { |
| 334 | + t.Errorf("Should have errored validating config because foo was modified, but its lastModifiedSeqNo did not increase to the current seqNo") |
| 335 | + } |
| 336 | + |
| 337 | + err = cm.Apply(newConfig) |
| 338 | + if err == nil { |
| 339 | + t.Errorf("Should have errored applying config because foo was modified, but its lastModifiedSeqNo did not increase to the current seqNo") |
| 340 | + } |
| 341 | +} |
| 342 | + |
| 343 | +// TestSilentConfigModification tests to make sure that even if a validly signed new configuration for an existing sequence number |
| 344 | +// is substituted into an otherwise valid new config, that the new config is rejected for attempting a modification without |
| 345 | +// increasing the config item's LastModified |
| 346 | +func TestSilentConfigModification(t *testing.T) { |
| 347 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 348 | + Sequence: 0, |
| 349 | + ChainID: defaultChain, |
| 350 | + Entries: []*ab.ConfigurationEntry{ |
| 351 | + makeConfigurationEntry("foo", "foo", 0, []byte("foo")), |
| 352 | + makeConfigurationEntry("bar", "bar", 0, []byte("bar")), |
| 353 | + }, |
| 354 | + }, &mockPolicyManager{&mockPolicy{}}, defaultHandlers()) |
| 355 | + |
| 356 | + if err != nil { |
| 357 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 358 | + } |
| 359 | + |
| 360 | + newConfig := &ab.ConfigurationEnvelope{ |
| 361 | + Sequence: 1, |
| 362 | + ChainID: defaultChain, |
| 363 | + Entries: []*ab.ConfigurationEntry{ |
| 364 | + makeConfigurationEntry("foo", "foo", 0, []byte("different")), |
| 365 | + makeConfigurationEntry("bar", "bar", 1, []byte("bar")), |
| 366 | + }, |
| 367 | + } |
| 368 | + |
| 369 | + err = cm.Validate(newConfig) |
| 370 | + if err == nil { |
| 371 | + t.Errorf("Should not errored validating config because foo was silently modified (despite modification allowed by policy)") |
| 372 | + } |
| 373 | + |
| 374 | + err = cm.Apply(newConfig) |
| 375 | + if err == nil { |
| 376 | + t.Errorf("Should not errored applying config because foo was silently modified (despite modification allowed by policy)") |
| 377 | + } |
| 378 | +} |
| 379 | + |
| 380 | +// TestInvalidInitialConfigByPolicy tests to make sure that if an existing policies does not validate the config that |
| 381 | +// even construction fails |
| 382 | +func TestInvalidInitialConfigByPolicy(t *testing.T) { |
| 383 | + _, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 384 | + Sequence: 0, |
| 385 | + ChainID: defaultChain, |
| 386 | + Entries: []*ab.ConfigurationEntry{makeConfigurationEntry("foo", "foo", 0, []byte("foo"))}, |
| 387 | + }, &mockPolicyManager{&mockPolicy{fmt.Errorf("err")}}, defaultHandlers()) |
| 388 | + // mockPolicyManager will return non-validating defualt policy |
| 389 | + |
| 390 | + if err == nil { |
| 391 | + t.Fatalf("Should have failed to construct configuration by policy") |
| 392 | + } |
| 393 | +} |
| 394 | + |
| 395 | +// TestConfigChangeViolatesPolicy checks to make sure that if policy rejects the validation of a config item that |
| 396 | +// it is rejected in a config update |
| 397 | +func TestConfigChangeViolatesPolicy(t *testing.T) { |
| 398 | + mpm := &mockPolicyManager{} |
| 399 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 400 | + Sequence: 0, |
| 401 | + ChainID: defaultChain, |
| 402 | + }, mpm, defaultHandlers()) |
| 403 | + |
| 404 | + if err != nil { |
| 405 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 406 | + } |
| 407 | + // Set the mock policy to error |
| 408 | + mpm.policy = &mockPolicy{fmt.Errorf("err")} |
| 409 | + |
| 410 | + newConfig := &ab.ConfigurationEnvelope{ |
| 411 | + Sequence: 1, |
| 412 | + ChainID: defaultChain, |
| 413 | + Entries: []*ab.ConfigurationEntry{makeConfigurationEntry("foo", "foo", 1, []byte("foo"))}, |
| 414 | + } |
| 415 | + |
| 416 | + err = cm.Validate(newConfig) |
| 417 | + if err == nil { |
| 418 | + t.Errorf("Should have errored validating config because policy rejected modification") |
| 419 | + } |
| 420 | + |
| 421 | + err = cm.Apply(newConfig) |
| 422 | + if err == nil { |
| 423 | + t.Errorf("Should have errored applying config because policy rejected modification") |
| 424 | + } |
| 425 | +} |
| 426 | + |
| 427 | +type failHandler struct{} |
| 428 | + |
| 429 | +func (fh failHandler) BeginConfig() {} |
| 430 | +func (fh failHandler) RollbackConfig() {} |
| 431 | +func (fh failHandler) CommitConfig() {} |
| 432 | +func (fh failHandler) ProposeConfig(item *ab.Configuration) error { |
| 433 | + return fmt.Errorf("Fail") |
| 434 | +} |
| 435 | + |
| 436 | +// TestInvalidProposal checks that even if the policy allows the transaction and the sequence etc. is well formed, |
| 437 | +// that if the handler does not accept the config, it is rejected |
| 438 | +func TestInvalidProposal(t *testing.T) { |
| 439 | + handlers := defaultHandlers() |
| 440 | + handlers[ab.Configuration_ConfigurationType(0)] = failHandler{} |
| 441 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 442 | + Sequence: 0, |
| 443 | + ChainID: defaultChain, |
| 444 | + }, &mockPolicyManager{&mockPolicy{}}, handlers) |
| 445 | + |
| 446 | + if err != nil { |
| 447 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 448 | + } |
| 449 | + |
| 450 | + newConfig := &ab.ConfigurationEnvelope{ |
| 451 | + Sequence: 1, |
| 452 | + ChainID: defaultChain, |
| 453 | + Entries: []*ab.ConfigurationEntry{makeConfigurationEntry("foo", "foo", 1, []byte("foo"))}, |
| 454 | + } |
| 455 | + |
| 456 | + err = cm.Validate(newConfig) |
| 457 | + if err == nil { |
| 458 | + t.Errorf("Should have errored validating config because the handler rejected it") |
| 459 | + } |
| 460 | + |
| 461 | + err = cm.Apply(newConfig) |
| 462 | + if err == nil { |
| 463 | + t.Errorf("Should have errored applying config because the handler rejected it") |
| 464 | + } |
| 465 | +} |
| 466 | + |
| 467 | +// TestConfigItemOnWrongChain tests to make sure that a config is rejected if it contains an item for the wrong chain |
| 468 | +func TestConfigItemOnWrongChain(t *testing.T) { |
| 469 | + cm, err := NewConfigurationManager(&ab.ConfigurationEnvelope{ |
| 470 | + Sequence: 0, |
| 471 | + ChainID: defaultChain, |
| 472 | + }, &mockPolicyManager{&mockPolicy{}}, defaultHandlers()) |
| 473 | + |
| 474 | + if err != nil { |
| 475 | + t.Fatalf("Error constructing configuration manager: %s", err) |
| 476 | + } |
| 477 | + |
| 478 | + config := makeConfiguration("foo", "foo", 1, []byte("foo")) |
| 479 | + config.ChainID = []byte("Wrong") |
| 480 | + marshaledConfig, err := proto.Marshal(config) |
| 481 | + if err != nil { |
| 482 | + t.Fatalf("Should have been able marshal config: %s", err) |
| 483 | + } |
| 484 | + newConfig := &ab.ConfigurationEnvelope{ |
| 485 | + Sequence: 1, |
| 486 | + ChainID: defaultChain, |
| 487 | + Entries: []*ab.ConfigurationEntry{&ab.ConfigurationEntry{Configuration: marshaledConfig}}, |
| 488 | + } |
| 489 | + |
| 490 | + err = cm.Validate(newConfig) |
| 491 | + if err == nil { |
| 492 | + t.Errorf("Should have errored validating config because new config item is for a different chain") |
| 493 | + } |
| 494 | + |
| 495 | + err = cm.Apply(newConfig) |
| 496 | + if err == nil { |
| 497 | + t.Errorf("Should have errored applying config because new config item is for a different chain") |
| 498 | + } |
| 499 | +} |
0 commit comments