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

Disable pallet uniques calls #154

Merged
merged 3 commits into from
May 31, 2022
Merged

Disable pallet uniques calls #154

merged 3 commits into from
May 31, 2022

Conversation

ilionic
Copy link
Contributor

@ilionic ilionic commented May 29, 2022

Fixes #151
Fixes #150

@ilionic ilionic requested review from HashWarlock and bmacer May 29, 2022 14:52
Copy link
Contributor

@HashWarlock HashWarlock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@bmacer
Copy link
Contributor

bmacer commented May 31, 2022

Looks good. I tried to implement a test of this on rmrk-core but failed. Not sure how I did it wrong.

I added this to the mock.rs

pub struct BaseFilter;
impl Contains<Call> for BaseFilter {
fn contains(call: &Call) -> bool {
// Disable direct calls to pallet_uniques
!matches!(
call,
Call::Uniques(pallet_uniques::Call::approve_transfer { .. }) |
Call::Uniques(pallet_uniques::Call::burn { .. }) |
Call::Uniques(pallet_uniques::Call::cancel_approval { .. }) |
Call::Uniques(pallet_uniques::Call::clear_class_metadata { .. }) |
Call::Uniques(pallet_uniques::Call::clear_metadata { .. }) |
Call::Uniques(pallet_uniques::Call::create { .. }) |
Call::Uniques(pallet_uniques::Call::destroy { .. }) |
Call::Uniques(pallet_uniques::Call::force_asset_status { .. }) |
Call::Uniques(pallet_uniques::Call::force_create { .. }) |
Call::Uniques(pallet_uniques::Call::freeze_class { .. }) |
Call::Uniques(pallet_uniques::Call::mint { .. }) |
Call::Uniques(pallet_uniques::Call::redeposit { .. }) |
Call::Uniques(pallet_uniques::Call::set_class_metadata { .. }) |
Call::Uniques(pallet_uniques::Call::thaw_class { .. }) |
Call::Uniques(pallet_uniques::Call::transfer { .. }) |
Call::Uniques(pallet_uniques::Call::transfer_ownership { .. })
)
}
}

Changed BaseCallFilter to equal BaseFilter

type BaseCallFilter = BaseFilter;

And wrote this test (not really a test yet just a println, but the result is unexpected/unwanted "Ok(())"

/// Uniques: Unable to call directly
#[test]
fn calling_uniques_directly_fails() {
	ExtBuilder::default().build().execute_with(|| {
		println!("{:?}", Uniques::create(Origin::signed(ALICE),1, ALICE));
	});
}

If a test for this doesn't matter that much, go ahead and merge. Otherwise, any ideas?

Copy link
Contributor

@bmacer bmacer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good unless you want to pursue testing this behavior

@HashWarlock
Copy link
Contributor

Looks good. I tried to implement a test of this on rmrk-core but failed. Not sure how I did it wrong.

I added this to the mock.rs

pub struct BaseFilter;
impl Contains<Call> for BaseFilter {
fn contains(call: &Call) -> bool {
// Disable direct calls to pallet_uniques
!matches!(
call,
Call::Uniques(pallet_uniques::Call::approve_transfer { .. }) |
Call::Uniques(pallet_uniques::Call::burn { .. }) |
Call::Uniques(pallet_uniques::Call::cancel_approval { .. }) |
Call::Uniques(pallet_uniques::Call::clear_class_metadata { .. }) |
Call::Uniques(pallet_uniques::Call::clear_metadata { .. }) |
Call::Uniques(pallet_uniques::Call::create { .. }) |
Call::Uniques(pallet_uniques::Call::destroy { .. }) |
Call::Uniques(pallet_uniques::Call::force_asset_status { .. }) |
Call::Uniques(pallet_uniques::Call::force_create { .. }) |
Call::Uniques(pallet_uniques::Call::freeze_class { .. }) |
Call::Uniques(pallet_uniques::Call::mint { .. }) |
Call::Uniques(pallet_uniques::Call::redeposit { .. }) |
Call::Uniques(pallet_uniques::Call::set_class_metadata { .. }) |
Call::Uniques(pallet_uniques::Call::thaw_class { .. }) |
Call::Uniques(pallet_uniques::Call::transfer { .. }) |
Call::Uniques(pallet_uniques::Call::transfer_ownership { .. })
)
}
}

Changed BaseCallFilter to equal BaseFilter

type BaseCallFilter = BaseFilter;

And wrote this test (not really a test yet just a println, but the result is unexpected/unwanted "Ok(())"

/// Uniques: Unable to call directly
#[test]
fn calling_uniques_directly_fails() {
	ExtBuilder::default().build().execute_with(|| {
		println!("{:?}", Uniques::create(Origin::signed(ALICE),1, ALICE));
	});
}

If a test for this doesn't matter that much, go ahead and merge. Otherwise, any ideas?

Check out the test file in substrate and this example https://github.com/paritytech/substrate/blob/master/frame/utility/src/tests.rs#L277-L292

We should get an frame_system::Error::<Test>::CallFiltered.

@ilionic
Copy link
Contributor Author

ilionic commented May 31, 2022

Will merge for now as filtered Calls not part of rmrk pallets technically. But I guess good to add a test anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restrict direct pallet_uniques calls Minting in Uniques Pallet Corrupts RMRK Minting
3 participants