-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pallet_parameters (moonbase only) (#2923)
* add pallet parameters * XcmFeesAccount * add copyrights * add FeesTreasuryProportion --------- Co-authored-by: Rodrigo Quelhas <[email protected]>
- Loading branch information
Showing
10 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2019-2022 PureStake Inc. | ||
// 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 <http://www.gnu.org/licenses/>. | ||
|
||
//! Autogenerated weights for `pallet_parameters` | ||
//! | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 | ||
//! DATE: 2024-08-06, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` | ||
//! WORST CASE MAP SIZE: `1000000` | ||
//! HOSTNAME: `COV0706`, CPU: `AMD Ryzen 9 7950X 16-Core Processor` | ||
//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 | ||
// Executed Command: | ||
// ./target/release/moonbeam | ||
// benchmark | ||
// pallet | ||
// --chain=moonbase-dev | ||
// --steps=50 | ||
// --repeat=20 | ||
// --pallet=pallet_parameters | ||
// --extrinsic=* | ||
// --wasm-execution=compiled | ||
// --header=./file_header.txt | ||
// --template=./benchmarking/frame-weight-template.hbs | ||
// --output=./runtime/common/src/weights/ | ||
|
||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
#![allow(unused_parens)] | ||
#![allow(unused_imports)] | ||
|
||
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; | ||
use sp_std::marker::PhantomData; | ||
|
||
/// Weights for `pallet_parameters`. | ||
pub struct WeightInfo<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> pallet_parameters::WeightInfo for WeightInfo<T> { | ||
/// Storage: `Parameters::Parameters` (r:1 w:1) | ||
/// Proof: `Parameters::Parameters` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) | ||
fn set_parameter() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `3` | ||
// Estimated: `3501` | ||
// Minimum execution time: 5_480_000 picoseconds. | ||
Weight::from_parts(5_610_000, 3501) | ||
.saturating_add(T::DbWeight::get().reads(1_u64)) | ||
.saturating_add(T::DbWeight::get().writes(1_u64)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 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 <http://www.gnu.org/licenses/>. | ||
|
||
//! Dynamic runtime parametes. | ||
use crate::Runtime; | ||
use frame_support::dynamic_params::{dynamic_pallet_params, dynamic_params}; | ||
use sp_runtime::Perbill; | ||
|
||
#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::<Runtime>)] | ||
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); | ||
} | ||
} | ||
|
||
#[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)), | ||
), | ||
) | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
test/suites/dev/moonbase/test-parameters/test-parameters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { describeSuite, DevModeContext, expect } from "@moonwall/cli"; | ||
import "@moonbeam-network/api-augment"; | ||
import { alith } from "@moonwall/util"; | ||
|
||
const UNIT = 1_000_000_000_000_000_000n; | ||
|
||
const RUNTIME = "MoonbaseRuntime"; | ||
const CRATE = "RuntimeParams"; | ||
const ALL_PARAMS = "DynamicParams"; | ||
|
||
function parameterType(context: DevModeContext, module: string, name: string, value: unknown) { | ||
const paramWrapper = context | ||
.polkadotJs() | ||
.createType(`${RUNTIME}${CRATE}${ALL_PARAMS}${module}Parameters`, { | ||
[name]: [null, value], | ||
}); | ||
|
||
const runtimeParameter = context.polkadotJs().createType(`${RUNTIME}${CRATE}RuntimeParameters`, { | ||
[module]: paramWrapper, | ||
}); | ||
|
||
return runtimeParameter; | ||
} | ||
|
||
function parameterKey(context: DevModeContext, module: string, name: string) { | ||
const key = context | ||
.polkadotJs() | ||
.createType(`${RUNTIME}${CRATE}${ALL_PARAMS}${module}ParametersKey`, { | ||
[name]: null, | ||
}); | ||
|
||
const keyWrapper = context.polkadotJs().createType(`${RUNTIME}${CRATE}RuntimeParametersKey`, { | ||
[module]: key, | ||
}); | ||
|
||
return keyWrapper; | ||
} | ||
|
||
describeSuite({ | ||
id: "DTemp01", | ||
title: "Parameters", | ||
foundationMethods: "dev", | ||
testCases: ({ it, context, log }) => { | ||
let testCounter = 0; | ||
function testParam(module: string, name: string, valueCreation: [string, unknown]) { | ||
it({ | ||
id: `T${testCounter++} - ${module} - ${name}`, | ||
title: "Parameters cannot be changed by normal user", | ||
test: async () => { | ||
const value = context.polkadotJs().createType(valueCreation[0], valueCreation[1]); | ||
const param = parameterType(context, module, name, value); | ||
|
||
const res = await context.createBlock( | ||
context.polkadotJs().tx.parameters.setParameter(param.toU8a()).signAsync(alith), | ||
{ allowFailures: true } | ||
); | ||
expect(res.result?.error?.name).toEqual("BadOrigin"); | ||
}, | ||
}); | ||
|
||
it({ | ||
id: `T${testCounter++} - ${module} - ${name}`, | ||
title: "Parameters can be changed by root user", | ||
test: async () => { | ||
const value = context.polkadotJs().createType(valueCreation[0], valueCreation[1]); | ||
const param = parameterType(context, module, name, value); | ||
|
||
await context.createBlock( | ||
context | ||
.polkadotJs() | ||
.tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a())) | ||
.signAsync(alith), | ||
{ allowFailures: false } | ||
); | ||
|
||
const key = parameterKey(context, module, name); | ||
|
||
const wrappedValue = await context.polkadotJs().query.parameters.parameters(key.toU8a()); | ||
const gotValue = wrappedValue.value.value.value.toU8a(); | ||
expect(gotValue).toEqual(value.toU8a()); | ||
}, | ||
}); | ||
} | ||
|
||
testParam("RuntimeConfig", "FeesTreasuryProportion", ["Perbill", 200_000_000]); | ||
}, | ||
}); |