Skip to content

Commit

Permalink
Merge pull request #84 from RegionX-Labs/utility-pallet
Browse files Browse the repository at this point in the history
add utility pallet
  • Loading branch information
cuteolaf authored Apr 18, 2024
2 parents 74dcd9e + 9faccb4 commit cf57e84
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pallet-sudo = { version = "28.0.0", default-features = false }
pallet-timestamp = { version = "27.0.0", default-features = false }
pallet-transaction-payment = { version = "28.0.0", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { version = "28.0.0", default-features = false }
pallet-utility = { version = "28.0.0", default-features = false}
pallet-message-queue = { version = "31.0.0", default-features = false }
sp-api = { version = "26.0.0", default-features = false }
sp-blockchain = { version = "28.0.0", default-features = false }
Expand Down
6 changes: 4 additions & 2 deletions pallets/regions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ sp-runtime = { workspace = true, default-features = false }
hex = { workspace = true }
serde = { workspace = true }
pallet-balances = { workspace = true, default-features = false }
pallet-utility = { workspace = true, default-features = false}
ismp-testsuite = { workspace = true }

[features]
default = ["std"]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks", "pallet-utility/runtime-benchmarks"]
std = [
"log/std",
"parity-scale-codec/std",
Expand All @@ -50,5 +51,6 @@ std = [
"frame-system/std",
"pallet-balances/std",
"pallet-ismp/std",
"pallet-utility/std"
]
try-runtime = [ "frame-support/try-runtime" ]
try-runtime = [ "frame-support/try-runtime", "pallet-utility/try-runtime" ]
8 changes: 8 additions & 0 deletions pallets/regions/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ frame_support::construct_runtime!(
{
System: frame_system::{Pallet, Call, Config<T>, Storage, Event<T>},
Balances: pallet_balances,
Utility: pallet_utility,
Regions: crate::{Pallet, Call, Storage, Event<T>},
}
);
Expand Down Expand Up @@ -84,6 +85,13 @@ impl pallet_balances::Config for Test {
type MaxFreezes = ();
}

impl pallet_utility::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type WeightInfo = pallet_utility::weights::SubstrateWeight<Test>;
}

parameter_types! {
pub const CoretimeChain: StateMachine = StateMachine::Kusama(1005); // coretime-kusama
}
Expand Down
39 changes: 37 additions & 2 deletions pallets/regions/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// along with RegionX. If not, see <https://www.gnu.org/licenses/>.

use crate::{
ismp_mock::requests, mock::*, pallet::Regions as RegionsStorage, utils, Error, Event,
IsmpCustomError, IsmpModuleCallback, Record, Region,
ismp_mock::requests, mock::*, pallet::Regions as RegionsStorage, utils, Call as RegionsCall,
Error, Event, IsmpCustomError, IsmpModuleCallback, Record, Region,
};
use frame_support::{assert_err, assert_ok, pallet_prelude::*, traits::nonfungible::Mutate};
use ismp::{
Expand Down Expand Up @@ -246,6 +246,41 @@ fn on_accept_works() {
});
}

#[test]
fn utlity_pallet_works() {
new_test_ext().execute_with(|| {
let region1_id = RegionId { begin: 112830, core: 81, mask: CoreMask::complete() };
let region2_id = RegionId { begin: 112830, core: 82, mask: CoreMask::complete() };

assert_ok!(Regions::mint_into(&region1_id.into(), &1));
assert_ok!(Regions::mint_into(&region2_id.into(), &1));

assert_ok!(Utility::batch(
RuntimeOrigin::signed(1),
vec![
RuntimeCall::Regions(RegionsCall::transfer {
region_id: region1_id.clone(),
new_owner: 2
}),
RuntimeCall::Regions(RegionsCall::transfer {
region_id: region2_id.clone(),
new_owner: 2
})
]
));

// check the new owners
assert_eq!(
Regions::regions(&region1_id).unwrap(),
Region { owner: 2, record: Record::Pending }
);
assert_eq!(
Regions::regions(&region2_id).unwrap(),
Region { owner: 2, record: Record::Pending }
);
});
}

#[test]
fn utils_read_value_works() {
new_test_ext().execute_with(|| {
Expand Down
4 changes: 4 additions & 0 deletions runtime/regionx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pallet-sudo = { workspace = true }
pallet-timestamp = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-utility = { workspace = true }
sp-api = { workspace = true }
sp-block-builder = { workspace = true }
sp-consensus-aura = { workspace = true }
Expand Down Expand Up @@ -126,6 +127,7 @@ std = [
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-utility/std",
"pallet-xcm/std",
"parachain-info/std",
"parachains-common/std",
Expand Down Expand Up @@ -170,6 +172,7 @@ runtime-benchmarks = [
"pallet-regions/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"parachains-common/runtime-benchmarks",
"polkadot-parachain-primitives/runtime-benchmarks",
Expand Down Expand Up @@ -203,6 +206,7 @@ try-runtime = [
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-utility/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"polkadot-runtime-common/try-runtime",
Expand Down
9 changes: 9 additions & 0 deletions runtime/regionx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ impl pallet_timestamp::Config for Runtime {
type WeightInfo = ();
}

impl pallet_utility::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
}

impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
type EventHandler = (CollatorSelection,);
Expand Down Expand Up @@ -588,6 +595,7 @@ construct_runtime!(
ParachainSystem: cumulus_pallet_parachain_system = 1,
Timestamp: pallet_timestamp = 2,
ParachainInfo: parachain_info = 3,
Utility: pallet_utility = 4,

// Monetary stuff.
Balances: pallet_balances = 10,
Expand Down Expand Up @@ -628,6 +636,7 @@ mod benches {
[pallet_balances, Balances]
[pallet_session, SessionBench::<Runtime>]
[pallet_timestamp, Timestamp]
[pallet_utility, Utility],
[pallet_sudo, Sudo]
[pallet_collator_selection, CollatorSelection]
[cumulus_pallet_xcmp_queue, XcmpQueue]
Expand Down

0 comments on commit cf57e84

Please sign in to comment.