Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added XcmTestHelper + allow XCM Transact for Gov/Identity/System calls #1003

Merged
merged 19 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .baedeker/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.bdk-env
/rewrites.jsonnet
/rewrites*.jsonnet
/vendor
/baedeker-library
!/rewrites.example.jsonnet
2 changes: 1 addition & 1 deletion .github/workflows/xcm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
with:
matrix: |
network {opal}, relay_branch {${{ env.UNIQUEWEST_MAINNET_BRANCH }}}, acala_version {${{ env.ACALA_BUILD_BRANCH }}}, moonbeam_version {${{ env.MOONBEAM_BUILD_BRANCH }}}, cumulus_version {${{ env.WESTMINT_BUILD_BRANCH }}}, astar_version {${{ env.ASTAR_BUILD_BRANCH }}}, polkadex_version {${{ env.POLKADEX_BUILD_BRANCH }}}, runtest {testXcmOpal}, runtime_features {opal-runtime}
network {quartz}, relay_branch {${{ env.KUSAMA_MAINNET_BRANCH }}}, acala_version {${{ env.KARURA_BUILD_BRANCH }}}, moonbeam_version {${{ env.MOONRIVER_BUILD_BRANCH }}}, cumulus_version {${{ env.STATEMINE_BUILD_BRANCH }}}, astar_version {${{ env.SHIDEN_BUILD_BRANCH }}}, polkadex_version {${{ env.POLKADEX_BUILD_BRANCH }}}, runtest {testXcmQuartz}, runtime_features {quartz-runtime}
network {quartz}, relay_branch {${{ env.KUSAMA_MAINNET_BRANCH }}}, acala_version {${{ env.KARURA_BUILD_BRANCH }}}, moonbeam_version {${{ env.MOONRIVER_BUILD_BRANCH }}}, cumulus_version {${{ env.STATEMINE_BUILD_BRANCH }}}, astar_version {${{ env.SHIDEN_BUILD_BRANCH }}}, polkadex_version {${{ env.POLKADEX_BUILD_BRANCH }}}, runtest {testFullXcmQuartz}, runtime_features {quartz-runtime}
network {unique}, relay_branch {${{ env.POLKADOT_MAINNET_BRANCH }}}, acala_version {${{ env.ACALA_BUILD_BRANCH }}}, moonbeam_version {${{ env.MOONBEAM_BUILD_BRANCH }}}, cumulus_version {${{ env.STATEMINT_BUILD_BRANCH }}}, astar_version {${{ env.ASTAR_BUILD_BRANCH }}}, polkadex_version {${{ env.POLKADEX_BUILD_BRANCH }}}, runtest {testFullXcmUnique}, runtime_features {unique-runtime}

xcm:
Expand Down
54 changes: 50 additions & 4 deletions runtime/common/config/xcm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.

use frame_support::{
traits::{Everything, Nothing, Get, ConstU32, ProcessMessageError},
traits::{Everything, Nothing, Get, ConstU32, ProcessMessageError, Contains},
parameter_types,
};
use frame_system::EnsureRoot;
Expand Down Expand Up @@ -162,6 +162,54 @@ where

pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;

pub struct XcmCallFilter;
impl XcmCallFilter {
fn allow_gov_and_sys_call(call: &RuntimeCall) -> bool {
match call {
RuntimeCall::System(..) => true,

#[cfg(feature = "governance")]
RuntimeCall::Identity(..)
| RuntimeCall::Preimage(..)
| RuntimeCall::Democracy(..)
| RuntimeCall::Council(..)
| RuntimeCall::TechnicalCommittee(..)
| RuntimeCall::CouncilMembership(..)
| RuntimeCall::TechnicalCommitteeMembership(..)
| RuntimeCall::FellowshipCollective(..)
| RuntimeCall::FellowshipReferenda(..) => true,
_ => false,
}
}

fn allow_utility_call(call: &RuntimeCall) -> bool {
match call {
RuntimeCall::Utility(pallet_utility::Call::batch { calls, .. }) => {
calls.iter().all(Self::allow_gov_and_sys_call)
}
RuntimeCall::Utility(pallet_utility::Call::batch_all { calls, .. }) => {
calls.iter().all(Self::allow_gov_and_sys_call)
}
RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) => {
Self::allow_gov_and_sys_call(call)
}
RuntimeCall::Utility(pallet_utility::Call::dispatch_as { call, .. }) => {
Self::allow_gov_and_sys_call(call)
}
RuntimeCall::Utility(pallet_utility::Call::force_batch { calls, .. }) => {
calls.iter().all(Self::allow_gov_and_sys_call)
}
_ => false,
}
}
}

impl Contains<RuntimeCall> for XcmCallFilter {
fn contains(call: &RuntimeCall) -> bool {
Self::allow_gov_and_sys_call(call) || Self::allow_utility_call(call)
}
}

pub struct XcmExecutorConfig<T>(PhantomData<T>);
impl<T> xcm_executor::Config for XcmExecutorConfig<T>
where
Expand Down Expand Up @@ -191,9 +239,7 @@ where
type MessageExporter = ();
type UniversalAliases = Nothing;
type CallDispatcher = RuntimeCall;

// Deny all XCM Transacts.
type SafeCallFilter = Nothing;
type SafeCallFilter = XcmCallFilter;
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
17 changes: 14 additions & 3 deletions runtime/opal/src/xcm_barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.

use frame_support::traits::Everything;
use xcm_builder::{AllowTopLevelPaidExecutionFrom, TakeWeightCredit};
use frame_support::{match_types, traits::Everything};
use xcm::latest::{Junctions::*, MultiLocation};
use xcm_builder::{AllowTopLevelPaidExecutionFrom, TakeWeightCredit, AllowExplicitUnpaidExecutionFrom};

pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom<Everything>);
match_types! {
pub type ParentOnly: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here }
};
}

pub type Barrier = (
TakeWeightCredit,
AllowExplicitUnpaidExecutionFrom<ParentOnly>,
AllowTopLevelPaidExecutionFrom<Everything>,
);
7 changes: 6 additions & 1 deletion runtime/quartz/src/xcm_barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ use frame_support::{match_types, traits::Everything};
use xcm::latest::{Junctions::*, MultiLocation};
use xcm_builder::{
AllowKnownQueryResponses, AllowSubscriptionsFrom, TakeWeightCredit,
AllowTopLevelPaidExecutionFrom,
AllowTopLevelPaidExecutionFrom, AllowExplicitUnpaidExecutionFrom,
};

use crate::PolkadotXcm;

match_types! {
pub type ParentOnly: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here }
};

pub type ParentOrSiblings: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here } |
MultiLocation { parents: 1, interior: X1(_) }
Expand All @@ -32,6 +36,7 @@ match_types! {

pub type Barrier = (
TakeWeightCredit,
AllowExplicitUnpaidExecutionFrom<ParentOnly>,
AllowTopLevelPaidExecutionFrom<Everything>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
Expand Down
7 changes: 6 additions & 1 deletion runtime/unique/src/xcm_barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ use frame_support::{match_types, traits::Everything};
use xcm::latest::{Junctions::*, MultiLocation};
use xcm_builder::{
AllowKnownQueryResponses, AllowSubscriptionsFrom, TakeWeightCredit,
AllowTopLevelPaidExecutionFrom,
AllowTopLevelPaidExecutionFrom, AllowExplicitUnpaidExecutionFrom,
};

use crate::PolkadotXcm;

match_types! {
pub type ParentOnly: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here }
};

pub type ParentOrSiblings: impl Contains<MultiLocation> = {
MultiLocation { parents: 1, interior: Here } |
MultiLocation { parents: 1, interior: X1(_) }
Expand All @@ -32,6 +36,7 @@ match_types! {

pub type Barrier = (
TakeWeightCredit,
AllowExplicitUnpaidExecutionFrom<ParentOnly>,
AllowTopLevelPaidExecutionFrom<Everything>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
Expand Down
2 changes: 2 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@
"testXcmUnique": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmUnique.test.ts",
"testFullXcmUnique": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/*Unique.test.ts",
"testXcmQuartz": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmQuartz.test.ts",
"testLowLevelXcmQuartz": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/lowLevelXcmQuartz.test.ts",
"testFullXcmQuartz": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/*Quartz.test.ts",
"testXcmOpal": "RUN_XCM_TESTS=1 yarn _test ./**/xcm/xcmOpal.test.ts",
"testXcmTransferAcala": "yarn _test ./**/xcm/xcmTransferAcala.test.ts acalaId=2000 uniqueId=5000",
"testXcmTransferStatemine": "yarn _test ./**/xcm/xcmTransferStatemine.test.ts statemineId=1000 uniqueId=5000",
Expand Down
41 changes: 39 additions & 2 deletions tests/src/util/playgrounds/unique.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as defs from '../../interfaces/definitions';
import {IKeyringPair} from '@polkadot/types/types';
import {EventRecord} from '@polkadot/types/interfaces';
import {ICrossAccountId, ILogger, IPovInfo, ISchedulerOptions, ITransactionResult, TSigner} from './types';
import {FrameSystemEventRecord, XcmV2TraitsError} from '@polkadot/types/lookup';
import {FrameSystemEventRecord, XcmV2TraitsError, XcmV3TraitsOutcome} from '@polkadot/types/lookup';
import {SignerOptions, VoidFn} from '@polkadot/api/types';
import {Pallets} from '..';
import {spawnSync} from 'child_process';
Expand Down Expand Up @@ -260,6 +260,12 @@ export class Event {
outcome: eventData<XcmV2TraitsError>(data, 1),
}));
};

static DmpQueue = class extends EventSection('dmpQueue') {
static ExecutedDownward = this.Method('ExecutedDownward', data => ({
outcome: eventData<XcmV3TraitsOutcome>(data, 1),
}));
};
}

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand Down Expand Up @@ -559,6 +565,12 @@ export class DevRelayHelper extends RelayHelper {
super(logger, options);
this.wait = new WaitGroup(this);
}

getSudo() {
// eslint-disable-next-line @typescript-eslint/naming-convention
const SudoHelperType = SudoHelper(this.helperBase);
return this.clone(SudoHelperType) as DevRelayHelper;
}
}

export class DevWestmintHelper extends WestmintHelper {
Expand Down Expand Up @@ -968,6 +980,31 @@ export class ArrangeGroup {
],
};
}

makeUnpaidSudoTransactProgram(info: {weightMultiplier: number, call: string}) {
return {
V3: [
{
UnpaidExecution: {
weightLimit: 'Unlimited',
checkOrigin: null,
},
},
{
Transact: {
originKind: 'Superuser',
requireWeightAtMost: {
refTime: info.weightMultiplier * 200000000,
proofSize: info.weightMultiplier * 3000,
},
call: {
encoded: info.call,
},
},
},
],
};
}
}

class MoonbeamAccountGroup {
Expand Down Expand Up @@ -1501,4 +1538,4 @@ function ScheduledUniqueHelper<T extends UniqueHelperConstructor>(Base: T) {
);
}
};
}
}
Loading
Loading