configuration.rs 39.2 KB
Newer Older
			Configuration::set_ump_service_total_weight(
				Origin::root(),
				new_config.ump_service_total_weight,
			)
			.unwrap();
			Configuration::set_max_upward_message_size(
				Origin::root(),
				new_config.max_upward_message_size,
			)
			.unwrap();
			Configuration::set_max_upward_message_num_per_candidate(
				Origin::root(),
				new_config.max_upward_message_num_per_candidate,
			)
			.unwrap();
Sergey Pepyakin's avatar
Sergey Pepyakin committed
			Configuration::set_hrmp_open_request_ttl(
				Origin::root(),
				new_config.hrmp_open_request_ttl,
			)
			.unwrap();
			Configuration::set_hrmp_sender_deposit(Origin::root(), new_config.hrmp_sender_deposit)
				.unwrap();
Sergey Pepyakin's avatar
Sergey Pepyakin committed
			Configuration::set_hrmp_recipient_deposit(
				Origin::root(),
				new_config.hrmp_recipient_deposit,
			)
			.unwrap();
Sergey Pepyakin's avatar
Sergey Pepyakin committed
			Configuration::set_hrmp_channel_max_capacity(
				Origin::root(),
				new_config.hrmp_channel_max_capacity,
			)
			.unwrap();
Sergey Pepyakin's avatar
Sergey Pepyakin committed
			Configuration::set_hrmp_channel_max_total_size(
				Origin::root(),
				new_config.hrmp_channel_max_total_size,
			)
			.unwrap();
Sergey Pepyakin's avatar
Sergey Pepyakin committed
			Configuration::set_hrmp_max_parachain_inbound_channels(
				Origin::root(),
				new_config.hrmp_max_parachain_inbound_channels,
			)
			.unwrap();
Sergey Pepyakin's avatar
Sergey Pepyakin committed
			Configuration::set_hrmp_max_parathread_inbound_channels(
				Origin::root(),
				new_config.hrmp_max_parathread_inbound_channels,
			)
			.unwrap();
Sergey Pepyakin's avatar
Sergey Pepyakin committed
			Configuration::set_hrmp_channel_max_message_size(
				Origin::root(),
				new_config.hrmp_channel_max_message_size,
			)
			.unwrap();
Sergey Pepyakin's avatar
Sergey Pepyakin committed
			Configuration::set_hrmp_max_parachain_outbound_channels(
				Origin::root(),
				new_config.hrmp_max_parachain_outbound_channels,
			)
			.unwrap();
Sergey Pepyakin's avatar
Sergey Pepyakin committed
			Configuration::set_hrmp_max_parathread_outbound_channels(
				Origin::root(),
				new_config.hrmp_max_parathread_outbound_channels,
			)
			.unwrap();
Sergey Pepyakin's avatar
Sergey Pepyakin committed
			Configuration::set_hrmp_max_message_num_per_candidate(
				Origin::root(),
				new_config.hrmp_max_message_num_per_candidate,
			)
			.unwrap();
			assert_eq!(
				<Configuration as Store>::PendingConfig::get(shared::SESSION_DELAY),
				Some(new_config)
			);
		})
	}

	#[test]
	fn non_root_cannot_set_config() {
		new_test_ext(Default::default()).execute_with(|| {
			assert!(Configuration::set_validation_upgrade_delay(Origin::signed(1), 100).is_err());
		});
	}

	#[test]
	fn setting_config_to_same_as_current_is_noop() {
		new_test_ext(Default::default()).execute_with(|| {
			Configuration::set_validation_upgrade_delay(Origin::root(), Default::default())
				.unwrap();
			assert!(<Configuration as Store>::PendingConfig::get(shared::SESSION_DELAY).is_none())

	#[test]
	fn verify_externally_accessible() {
		// This test verifies that the value can be accessed through the well known keys and the
		// host configuration decodes into the abridged version.

		use primitives::v1::{well_known_keys, AbridgedHostConfiguration};

		new_test_ext(Default::default()).execute_with(|| {
			let ground_truth = HostConfiguration::default();

			// Make sure that the configuration is stored in the storage.
			<Configuration as Store>::ActiveConfig::put(ground_truth.clone());

			// Extract the active config via the well known key.
			let raw_active_config = sp_io::storage::get(well_known_keys::ACTIVE_CONFIG)
				.expect("config must be present in storage under ACTIVE_CONFIG");
			let abridged_config = AbridgedHostConfiguration::decode(&mut &raw_active_config[..])
				.expect("HostConfiguration must be decodable into AbridgedHostConfiguration");

			assert_eq!(
				abridged_config,
				AbridgedHostConfiguration {
					max_code_size: ground_truth.max_code_size,
					max_head_data_size: ground_truth.max_head_data_size,
					max_upward_queue_count: ground_truth.max_upward_queue_count,
					max_upward_queue_size: ground_truth.max_upward_queue_size,
					max_upward_message_size: ground_truth.max_upward_message_size,
					max_upward_message_num_per_candidate: ground_truth
						.max_upward_message_num_per_candidate,
					hrmp_max_message_num_per_candidate: ground_truth
						.hrmp_max_message_num_per_candidate,
					validation_upgrade_frequency: ground_truth.validation_upgrade_frequency,
					validation_upgrade_delay: ground_truth.validation_upgrade_delay,
				},
			);
		});
	}