diff --git a/Cargo.lock b/Cargo.lock index 4130b4b4f6..7a8e6b65eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6807,6 +6807,7 @@ dependencies = [ "pallet-moonbeam-orbiters", "pallet-multisig", "pallet-parachain-staking", + "pallet-parameters", "pallet-precompile-benchmarks", "pallet-preimage", "pallet-proxy", @@ -6928,6 +6929,7 @@ dependencies = [ "pallet-xcm-weight-trader", "parity-scale-codec", "precompile-utils", + "scale-info", "sp-api", "sp-consensus-slots", "sp-core", @@ -7237,6 +7239,7 @@ dependencies = [ "pallet-moonbeam-orbiters", "pallet-multisig", "pallet-parachain-staking", + "pallet-parameters", "pallet-precompile-benchmarks", "pallet-preimage", "pallet-proxy", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 981cf21e66..d3c3027be3 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -86,6 +86,7 @@ xcm-runtime-apis = { workspace = true } # Parity parity-scale-codec = { workspace = true } +scale-info = { workspace = true } account = { workspace = true } @@ -118,6 +119,7 @@ std = [ "pallet-xcm-weight-trader/std", "pallet-message-queue/std", "parity-scale-codec/std", + "scale-info/std", "precompile-utils/std", "sp-consensus-slots/std", "sp-core/std", diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 747a8a326b..ccde3fffa5 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -24,6 +24,7 @@ mod impl_self_contained_call; mod impl_xcm_evm_runner; pub mod migrations; pub mod timestamp; +pub mod types; pub mod weights; #[cfg(feature = "runtime-benchmarks")] diff --git a/runtime/common/src/types.rs b/runtime/common/src/types.rs new file mode 100644 index 0000000000..a6aeefc913 --- /dev/null +++ b/runtime/common/src/types.rs @@ -0,0 +1,136 @@ +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . +use parity_scale_codec::{Decode, Encode, EncodeLike, MaxEncodedLen}; +use scale_info::TypeInfo; +use sp_std::prelude::*; + +#[derive(Debug, PartialEq, Eq, Clone, Copy, Encode, TypeInfo, MaxEncodedLen)] +#[scale_info(skip_type_params(LOWER, UPPER))] +pub struct BoundedU128(u128); + +impl BoundedU128 { + // Create a new instance with a value. If the value is out of bounds, it will return an error. + pub fn new(value: u128) -> Result { + if value < L || value > U { + return Err("Value out of bounds"); + } + Ok(Self(value)) + } + + /// Create a new instance with a constant value. If the value is out of bounds, it will be + /// clamped to the nearest bound. + pub fn const_new() -> Self { + if VAL < L { + Self(L) + } else if VAL > U { + Self(U) + } else { + Self(VAL) + } + } + + /// Get the value. + pub fn value(&self) -> u128 { + self.0 + } +} + +impl Decode for BoundedU128 { + fn decode( + input: &mut I, + ) -> Result { + let value = u128::decode(input)?; + if value < L || value > U { + return Err("Value out of bounds".into()); + } + Ok(Self(value)) + } +} + +impl EncodeLike for BoundedU128 {} + +/// Expose a `Get` implementation form a `Get` type. +#[macro_export] +macro_rules! expose_u128_get { + ($name:ident,$bounded_get:ty) => { + pub struct $name; + + impl sp_core::Get for $name { + fn get() -> u128 { + <$bounded_get>::get().value() + } + } + }; +} + +#[cfg(test)] +mod tests { + use frame_support::parameter_types; + use sp_core::Get; + + use super::*; + + #[test] + fn test_bounded_u128() { + let bounded = BoundedU128::<1, 10>::new(5).unwrap(); + assert_eq!(bounded.value(), 5); + + let bounded = BoundedU128::<1, 10>::new(0); + assert_eq!(bounded, Err("Value out of bounds")); + + let bounded = BoundedU128::<1, 10>::new(11); + assert_eq!(bounded, Err("Value out of bounds")); + + let bounded = BoundedU128::<1, 10>::const_new::<0>(); + assert_eq!(bounded.value(), 1); + + let bounded = BoundedU128::<1, 10>::const_new::<5>(); + assert_eq!(bounded.value(), 5); + + let bounded = BoundedU128::<1, 10>::const_new::<11>(); + assert_eq!(bounded.value(), 10); + } + + #[test] + fn test_expose_u128_get() { + parameter_types! { + pub Bounded: BoundedU128::<1, 10> = BoundedU128::<1, 10>::new(4).unwrap(); + } + expose_u128_get!(Exposed, Bounded); + assert_eq!(Bounded::get().value(), Exposed::get()); + } + + #[test] + fn test_encode_decode() { + let bounded = BoundedU128::<1, 10>::new(5).unwrap(); + let encoded = bounded.encode(); + let decoded = BoundedU128::<1, 10>::decode(&mut &encoded[..]).unwrap(); + assert_eq!(bounded, decoded); + } + + #[test] + fn test_encode_invalid() { + let bounded = BoundedU128::<1, 10>::new(9); + let encoded = bounded.encode(); + let decoded = BoundedU128::<1, 3>::decode(&mut &encoded[..]); + assert_eq!(decoded, Err("Value out of bounds".into())); + + let bounded = BoundedU128::<1, 10>::new(9); + let encoded = bounded.encode(); + let decoded = BoundedU128::<100, 500>::decode(&mut &encoded[..]); + assert_eq!(decoded, Err("Value out of bounds".into())); + } +} diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index e06469486c..0d51e602f2 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1345,7 +1345,7 @@ impl pallet_randomness::Config for Runtime { type Currency = Balances; type BabeDataGetter = BabeDataGetter; type VrfKeyLookup = AuthorMapping; - type Deposit = ConstU128<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>; + type Deposit = runtime_params::PalletRandomnessDepositU128; type MaxRandomWords = ConstU8<100>; type MinBlockDelay = ConstU32<2>; type MaxBlockDelay = ConstU32<2_000>; diff --git a/runtime/moonbase/src/runtime_params.rs b/runtime/moonbase/src/runtime_params.rs index 4916cc27df..2ac2a86141 100644 --- a/runtime/moonbase/src/runtime_params.rs +++ b/runtime/moonbase/src/runtime_params.rs @@ -14,9 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moonbeam. If not, see . -//! Dynamic runtime parametes. -use crate::Runtime; +//! Dynamic runtime parameters for moonbase. + +use crate::{currency, Runtime}; use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; +use moonbeam_runtime_common::expose_u128_get; +use moonbeam_runtime_common::types::BoundedU128; use sp_runtime::Perbill; #[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] @@ -29,8 +32,23 @@ pub mod dynamic_params { #[codec(index = 0)] pub static FeesTreasuryProportion: Perbill = Perbill::from_percent(20); } + + #[dynamic_pallet_params] + #[codec(index = 1)] + pub mod pallet_randomness { + #[codec(index = 0)] + pub static Deposit: BoundedU128< + { 1 * currency::UNIT * currency::SUPPLY_FACTOR }, + { 1_000 * currency::UNIT * currency::SUPPLY_FACTOR }, + > = BoundedU128::const_new::<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>(); + } } +expose_u128_get!( + PalletRandomnessDepositU128, + dynamic_params::pallet_randomness::Deposit +); + #[cfg(feature = "runtime-benchmarks")] impl Default for RuntimeParameters { fn default() -> Self { diff --git a/runtime/moonbeam/Cargo.toml b/runtime/moonbeam/Cargo.toml index c52ea28aeb..b8e0bde163 100644 --- a/runtime/moonbeam/Cargo.toml +++ b/runtime/moonbeam/Cargo.toml @@ -91,6 +91,7 @@ pallet-conviction-voting = { workspace = true } pallet-identity = { workspace = true } pallet-multisig = { workspace = true } pallet-preimage = { workspace = true } +pallet-parameters = { workspace = true } pallet-proxy = { workspace = true } pallet-referenda = { workspace = true } pallet-root-testing = { workspace = true } @@ -272,6 +273,7 @@ std = [ "pallet-parachain-staking/std", "pallet-precompile-benchmarks/std", "pallet-preimage/std", + "pallet-parameters/std", "pallet-proxy-genesis-companion/std", "pallet-proxy/std", "pallet-randomness/std", @@ -362,6 +364,7 @@ runtime-benchmarks = [ "pallet-parachain-staking/runtime-benchmarks", "pallet-precompile-benchmarks/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", + "pallet-parameters/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", "pallet-randomness/runtime-benchmarks", "pallet-referenda/runtime-benchmarks", @@ -405,6 +408,7 @@ try-runtime = [ "pallet-parachain-staking/try-runtime", "pallet-precompile-benchmarks/try-runtime", "pallet-preimage/try-runtime", + "pallet-parameters/try-runtime", "pallet-referenda/try-runtime", "pallet-relay-storage-roots/try-runtime", "pallet-root-testing/try-runtime", diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index e4d2e81796..12bf20574b 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -104,6 +104,8 @@ use xcm_runtime_apis::{ fees::Error as XcmPaymentApiError, }; +use runtime_params::*; + #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; @@ -123,6 +125,7 @@ pub type Precompiles = MoonbeamPrecompiles; pub mod asset_config; pub mod governance; +pub mod runtime_params; pub mod xcm_config; use governance::councils::*; @@ -348,8 +351,11 @@ where mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { - // for fees, 80% are burned, 20% to the treasury - let (_, to_treasury) = fees.ration(80, 20); + let treasury_perbill = + runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); + let treasury_part = treasury_perbill.deconstruct(); + let burn_part = Perbill::one().deconstruct() - treasury_part; + let (_, to_treasury) = fees.ration(burn_part, treasury_part); // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly ResolveTo::, pallet_balances::Pallet>::on_unbalanced( @@ -1336,7 +1342,7 @@ impl pallet_randomness::Config for Runtime { type Currency = Balances; type BabeDataGetter = BabeDataGetter; type VrfKeyLookup = AuthorMapping; - type Deposit = ConstU128<{ 1 * currency::GLMR * currency::SUPPLY_FACTOR }>; + type Deposit = runtime_params::PalletRandomnessDepositU128; type MaxRandomWords = ConstU8<100>; type MinBlockDelay = ConstU32<2>; type MaxBlockDelay = ConstU32<2_000>; @@ -1377,6 +1383,13 @@ impl pallet_precompile_benchmarks::Config for Runtime { type WeightInfo = moonbeam_weights::pallet_precompile_benchmarks::WeightInfo; } +impl pallet_parameters::Config for Runtime { + type AdminOrigin = EnsureRoot; + type RuntimeEvent = RuntimeEvent; + type RuntimeParameters = RuntimeParameters; + type WeightInfo = moonbeam_weights::pallet_parameters::WeightInfo; +} + construct_runtime! { pub enum Runtime { @@ -1409,6 +1422,7 @@ construct_runtime! { ProxyGenesisCompanion: pallet_proxy_genesis_companion::{Pallet, Config} = 35, Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 36, MoonbeamLazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call, Storage} = 37, + Parameters: pallet_parameters = 38, // Has been permanently removed for safety reasons. // Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 40, diff --git a/runtime/moonbeam/src/runtime_params.rs b/runtime/moonbeam/src/runtime_params.rs new file mode 100644 index 0000000000..7c37dbaf81 --- /dev/null +++ b/runtime/moonbeam/src/runtime_params.rs @@ -0,0 +1,62 @@ +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +//! Dynamic runtime parameters for moonbeam. + +use crate::{currency, Runtime}; +use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; +use moonbeam_runtime_common::expose_u128_get; +use moonbeam_runtime_common::types::BoundedU128; +use sp_runtime::Perbill; + +#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] +pub mod dynamic_params { + use super::*; + #[dynamic_pallet_params] + #[codec(index = 0)] + pub mod runtime_config { + // for fees, 80% are burned, 20% to the treasury + #[codec(index = 0)] + pub static FeesTreasuryProportion: Perbill = Perbill::from_percent(20); + } + + #[dynamic_pallet_params] + #[codec(index = 1)] + pub mod pallet_randomness { + #[codec(index = 0)] + pub static Deposit: BoundedU128< + { 1 * currency::GLMR * currency::SUPPLY_FACTOR }, + { 1_000 * currency::GLMR * currency::SUPPLY_FACTOR }, + > = BoundedU128::const_new::<{ 1 * currency::GLMR * currency::SUPPLY_FACTOR }>(); + } +} + +expose_u128_get!( + PalletRandomnessDepositU128, + dynamic_params::pallet_randomness::Deposit +); + +#[cfg(feature = "runtime-benchmarks")] +impl Default for RuntimeParameters { + fn default() -> Self { + RuntimeParameters::RuntimeConfig( + dynamic_params::runtime_config::Parameters::FeesTreasuryProportion( + dynamic_params::runtime_config::FeesTreasuryProportion, + Some(Perbill::from_percent(20)), + ), + ) + } +} diff --git a/runtime/moonriver/Cargo.toml b/runtime/moonriver/Cargo.toml index 1347ed8ca9..bfdfdb853e 100644 --- a/runtime/moonriver/Cargo.toml +++ b/runtime/moonriver/Cargo.toml @@ -91,6 +91,7 @@ pallet-conviction-voting = { workspace = true } pallet-identity = { workspace = true } pallet-multisig = { workspace = true } pallet-preimage = { workspace = true } +pallet-parameters = { workspace = true } pallet-proxy = { workspace = true } pallet-referenda = { workspace = true } pallet-root-testing = { workspace = true } @@ -272,6 +273,7 @@ std = [ "pallet-parachain-staking/std", "pallet-precompile-benchmarks/std", "pallet-preimage/std", + "pallet-parameters/std", "pallet-proxy-genesis-companion/std", "pallet-proxy/std", "pallet-randomness/std", @@ -367,6 +369,7 @@ runtime-benchmarks = [ "pallet-parachain-staking/runtime-benchmarks", "pallet-precompile-benchmarks/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", + "pallet-parameters/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", "pallet-randomness/runtime-benchmarks", "pallet-referenda/runtime-benchmarks", @@ -408,6 +411,7 @@ try-runtime = [ "pallet-parachain-staking/try-runtime", "pallet-precompile-benchmarks/try-runtime", "pallet-preimage/try-runtime", + "pallet-parameters/try-runtime", "pallet-referenda/try-runtime", "pallet-relay-storage-roots/try-runtime", "pallet-root-testing/try-runtime", diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 080d1c9bd5..fb5733e1d8 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -104,6 +104,8 @@ use xcm_runtime_apis::{ fees::Error as XcmPaymentApiError, }; +use runtime_params::*; + use smallvec::smallvec; #[cfg(feature = "std")] use sp_version::NativeVersion; @@ -122,6 +124,7 @@ pub type Precompiles = MoonriverPrecompiles; pub mod asset_config; pub mod governance; +pub mod runtime_params; pub mod xcm_config; mod migrations; @@ -350,8 +353,11 @@ where mut fees_then_tips: impl Iterator>>, ) { if let Some(fees) = fees_then_tips.next() { - // for fees, 80% are burned, 20% to the treasury - let (_, to_treasury) = fees.ration(80, 20); + let treasury_perbill = + runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get(); + let treasury_part = treasury_perbill.deconstruct(); + let burn_part = Perbill::one().deconstruct() - treasury_part; + let (_, to_treasury) = fees.ration(burn_part, treasury_part); // Balances pallet automatically burns dropped Credits by decreasing // total_supply accordingly ResolveTo::, pallet_balances::Pallet>::on_unbalanced( @@ -1340,7 +1346,7 @@ impl pallet_randomness::Config for Runtime { type Currency = Balances; type BabeDataGetter = BabeDataGetter; type VrfKeyLookup = AuthorMapping; - type Deposit = ConstU128<{ 1 * currency::MOVR * currency::SUPPLY_FACTOR }>; + type Deposit = runtime_params::PalletRandomnessDepositU128; type MaxRandomWords = ConstU8<100>; type MinBlockDelay = ConstU32<2>; type MaxBlockDelay = ConstU32<2_000>; @@ -1381,6 +1387,13 @@ impl pallet_precompile_benchmarks::Config for Runtime { type WeightInfo = moonriver_weights::pallet_precompile_benchmarks::WeightInfo; } +impl pallet_parameters::Config for Runtime { + type AdminOrigin = EnsureRoot; + type RuntimeEvent = RuntimeEvent; + type RuntimeParameters = RuntimeParameters; + type WeightInfo = moonriver_weights::pallet_parameters::WeightInfo; +} + construct_runtime! { pub enum Runtime { @@ -1413,6 +1426,7 @@ construct_runtime! { ProxyGenesisCompanion: pallet_proxy_genesis_companion::{Pallet, Config} = 35, Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 36, MoonbeamLazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call, Storage} = 37, + Parameters: pallet_parameters = 38, // Sudo was previously index 40 diff --git a/runtime/moonriver/src/runtime_params.rs b/runtime/moonriver/src/runtime_params.rs new file mode 100644 index 0000000000..054a89ed26 --- /dev/null +++ b/runtime/moonriver/src/runtime_params.rs @@ -0,0 +1,62 @@ +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +//! Dynamic runtime parameters for moonriver. + +use crate::{currency, Runtime}; +use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; +use moonbeam_runtime_common::expose_u128_get; +use moonbeam_runtime_common::types::BoundedU128; +use sp_runtime::Perbill; + +#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] +pub mod dynamic_params { + use super::*; + #[dynamic_pallet_params] + #[codec(index = 0)] + pub mod runtime_config { + // for fees, 80% are burned, 20% to the treasury + #[codec(index = 0)] + pub static FeesTreasuryProportion: Perbill = Perbill::from_percent(20); + } + + #[dynamic_pallet_params] + #[codec(index = 1)] + pub mod pallet_randomness { + #[codec(index = 0)] + pub static Deposit: BoundedU128< + { 1 * currency::MOVR * currency::SUPPLY_FACTOR }, + { 1_000 * currency::MOVR * currency::SUPPLY_FACTOR }, + > = BoundedU128::const_new::<{ 1 * currency::MOVR * currency::SUPPLY_FACTOR }>(); + } +} + +expose_u128_get!( + PalletRandomnessDepositU128, + dynamic_params::pallet_randomness::Deposit +); + +#[cfg(feature = "runtime-benchmarks")] +impl Default for RuntimeParameters { + fn default() -> Self { + RuntimeParameters::RuntimeConfig( + dynamic_params::runtime_config::Parameters::FeesTreasuryProportion( + dynamic_params::runtime_config::FeesTreasuryProportion, + Some(Perbill::from_percent(20)), + ), + ) + } +} diff --git a/test/suites/dev/moonbase/test-parameters/test-parameters.ts b/test/suites/dev/moonbase/test-parameters/test-parameters.ts index 8ff2b8cd9a..46638a2be7 100644 --- a/test/suites/dev/moonbase/test-parameters/test-parameters.ts +++ b/test/suites/dev/moonbase/test-parameters/test-parameters.ts @@ -1,7 +1,7 @@ import { describeSuite, DevModeContext, expect } from "@moonwall/cli"; import "@moonbeam-network/api-augment"; import { alith } from "@moonwall/util"; - +import { fail } from "assert"; const UNIT = 1_000_000_000_000_000_000n; const RUNTIME = "MoonbaseRuntime"; @@ -83,5 +83,59 @@ describeSuite({ } testParam("RuntimeConfig", "FeesTreasuryProportion", ["Perbill", 200_000_000]); + testParam("PalletRandomness", "Deposit", ["u128", UNIT * 100n]); + + it({ + id: `T${testCounter++} - PalletRandomness - Deposit - CustomTests`, + title: "Deposit parameter should only be accepted in bounds", + test: async () => { + const MIN = 1n * UNIT; + const MAX = 1000n * UNIT; + + // used as an acceptable value + const AVG = (MIN + MAX) / 2n; + + const param1 = parameterType(context, "PalletRandomness", "Deposit", MIN - 1n); + try { + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param1.toU8a())) + .signAsync(alith), + { allowFailures: false } + ); + fail("An extrinsic should not be created, since the parameter is invalid"); + } catch (error) { + expect(error.toString().toLowerCase()).to.contain("value out of bounds"); + } + + const param2 = parameterType(context, "PalletRandomness", "Deposit", MAX + 1n); + try { + await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param2.toU8a())) + .signAsync(alith), + { allowFailures: false } + ); + fail("An extrinsic should not be created, since the parameter is invalid"); + } catch (error) { + expect(error.toString().toLowerCase()).to.contain("value out of bounds"); + } + + const param3 = parameterType(context, "PalletRandomness", "Deposit", AVG); + const res3 = await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param3.toU8a())) + .signAsync(alith), + { allowFailures: false } + ); + expect( + res3.result?.successful, + "An extrinsic should be created, since the parameter is valid" + ).to.be.true; + }, + }); }, });