-
Notifications
You must be signed in to change notification settings - Fork 0
Out of bounds marketplace application #41
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
Merged
sebastianmontero
merged 7 commits into
feature/benchmarks
from
feature/benchmark/ticket/29
Mar 19, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e97d36e
- Introduced a new helper function `validate_fields` in the Gated Mar…
didiermis e89fe52
- Corrected the condition in the `validate_fields` helper function in…
didiermis 34bfd70
- Overhauled the `set_up_application` function in the Gated Marketpla…
didiermis 3d96012
ntroduced two new test cases in the Gated Marketplace pallet to valid…
didiermis 0b8e196
Added a new test case, `apply_to_marketplace_without_fields_shouldnt_…
didiermis a92088c
Updated test name
didiermis ae9340d
Updated test name
didiermis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -338,6 +338,12 @@ pub mod pallet { | |
| OwnerNotInMarketplace, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| /// MappedAssetId not found | ||
| AssetNotFound, | ||
| /// Not enough custodian fields provided | ||
| InsufficientCustodianFields, | ||
| /// Fields not provided for the application | ||
| FieldsNotProvided, | ||
| /// Exceeds the maximum number of files | ||
| ExceedMaxFilesApplication, | ||
| } | ||
|
|
||
| #[pallet::call] | ||
|
|
@@ -435,7 +441,7 @@ pub mod pallet { | |
| ) -> DispatchResult { | ||
| let who = ensure_signed(origin)?; | ||
|
|
||
| let (custodian, fields) = Self::set_up_application(fields, custodian_fields); | ||
| let (custodian, fields) = Self::set_up_application(fields, custodian_fields)?; | ||
|
|
||
| let application = Application::<T> { | ||
| status: ApplicationStatus::default(), | ||
|
|
@@ -473,7 +479,7 @@ pub mod pallet { | |
| ) -> DispatchResult { | ||
| let who = ensure_signed(origin)?; | ||
|
|
||
| let (custodian, fields) = Self::set_up_application(fields, custodian_fields); | ||
| let (custodian, fields) = Self::set_up_application(fields, custodian_fields)?; | ||
|
|
||
| let application = Application::<T> { | ||
| status: ApplicationStatus::default(), | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| use crate as pallet_gated_marketplace; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| use frame_system::RawOrigin; | ||
| use sp_runtime::traits::Lookup; | ||
|
|
||
| use frame_support::{ | ||
|
|
@@ -22,6 +21,7 @@ use sp_runtime::{ | |
| use system::EnsureSigned; | ||
| type AccountId = u64; | ||
| type AssetId = u32; | ||
|
|
||
| // Configure a mock runtime to test the pallet. | ||
| frame_support::construct_runtime!( | ||
| pub enum Test | ||
|
|
@@ -163,24 +163,25 @@ impl pallet_balances::Config for Test { | |
| } | ||
|
|
||
| parameter_types! { | ||
| pub const MaxScopesPerPallet: u32 = 2; | ||
| pub const MaxRolesPerPallet: u32 = 6; | ||
| pub const RoleMaxLen: u32 = 25; | ||
| pub const PermissionMaxLen: u32 = 25; | ||
| pub const MaxPermissionsPerRole: u32 = 30; | ||
| pub const MaxRolesPerUser: u32 = 2; | ||
| pub const MaxUsersPerRole: u32 = 2; | ||
| pub const MaxScopesPerPallet: u32 = 2; | ||
| pub const MaxRolesPerPallet: u32 = 6; | ||
| pub const RoleMaxLen: u32 = 25; | ||
| pub const PermissionMaxLen: u32 = 25; | ||
| pub const MaxPermissionsPerRole: u32 = 30; | ||
| pub const MaxRolesPerUser: u32 = 2; | ||
| pub const MaxUsersPerRole: u32 = 2; | ||
| } | ||
| impl pallet_rbac::Config for Test { | ||
| type RuntimeEvent = RuntimeEvent; | ||
| type RemoveOrigin = EnsureRoot<Self::AccountId>; | ||
| type MaxScopesPerPallet = MaxScopesPerPallet; | ||
| type MaxRolesPerPallet = MaxRolesPerPallet; | ||
| type RoleMaxLen = RoleMaxLen; | ||
| type PermissionMaxLen = PermissionMaxLen; | ||
| type MaxPermissionsPerRole = MaxPermissionsPerRole; | ||
| type MaxRolesPerUser = MaxRolesPerUser; | ||
| type MaxUsersPerRole = MaxUsersPerRole; | ||
| type RemoveOrigin = EnsureRoot<Self::AccountId>; | ||
| type WeightInfo = (); | ||
| } | ||
|
|
||
| // Build genesis storage according to the mock runtime. | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -244,6 +244,33 @@ fn apply_to_marketplace_works() { | |
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| #[test] | ||
| fn apply_to_marketplace_without_fields_shouldnt_work() { | ||
| new_test_ext().execute_with(|| { | ||
| Balances::make_free_balance_be(&1, 100); | ||
| // Dispatch a signed extrinsic. | ||
| let m_label = create_label("my marketplace"); | ||
| assert_ok!(GatedMarketplace::create_marketplace( | ||
| RuntimeOrigin::signed(1), | ||
| 2, | ||
| m_label.clone(), | ||
| 500, | ||
| 600, | ||
| 1, | ||
| )); | ||
| let m_id = get_marketplace_id("my marketplace", 500, 600, 1); | ||
| assert_noop!( | ||
| GatedMarketplace::apply( | ||
| RuntimeOrigin::signed(3), | ||
| m_id, | ||
| create_application_fields(0), | ||
| None | ||
| ), | ||
| Error::<Test>::FieldsNotProvided | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn apply_with_custodian_works() { | ||
| new_test_ext().execute_with(|| { | ||
|
|
@@ -273,6 +300,60 @@ fn apply_with_custodian_works() { | |
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn apply_with_mismatched_number_of_fields_and_custodian_fields_shouldnt_work() { | ||
| new_test_ext().execute_with(|| { | ||
| Balances::make_free_balance_be(&1, 100); | ||
| // Dispatch a signed extrinsic. | ||
| let m_label = create_label("my marketplace"); | ||
| assert_ok!(GatedMarketplace::create_marketplace( | ||
| RuntimeOrigin::signed(1), | ||
| 2, | ||
| m_label.clone(), | ||
| 500, | ||
| 600, | ||
| 1, | ||
| )); | ||
| let m_id = get_marketplace_id("my marketplace", 500, 600, 1); | ||
| assert_noop!( | ||
| GatedMarketplace::apply( | ||
| RuntimeOrigin::signed(3), | ||
| m_id, | ||
| create_application_fields(2), | ||
| create_custodian_fields(4, 1) | ||
| ), | ||
| Error::<Test>::InsufficientCustodianFields | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn apply_with_custodian_but_no_custodian_fields_shouldnt_work() { | ||
| new_test_ext().execute_with(|| { | ||
| Balances::make_free_balance_be(&1, 100); | ||
| // Dispatch a signed extrinsic. | ||
| let m_label = create_label("my marketplace"); | ||
| assert_ok!(GatedMarketplace::create_marketplace( | ||
| RuntimeOrigin::signed(1), | ||
| 2, | ||
| m_label.clone(), | ||
| 500, | ||
| 600, | ||
| 1, | ||
| )); | ||
| let m_id = get_marketplace_id("my marketplace", 500, 600, 1); | ||
| assert_noop!( | ||
| GatedMarketplace::apply( | ||
| RuntimeOrigin::signed(3), | ||
| m_id, | ||
| create_application_fields(2), | ||
| create_custodian_fields(4, 0) | ||
| ), | ||
| Error::<Test>::InsufficientCustodianFields | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn apply_with_same_account_as_custodian_shouldnt_work() { | ||
| new_test_ext().execute_with(|| { | ||
|
|
@@ -378,6 +459,7 @@ fn apply_twice_shouldnt_work() { | |
| 1, | ||
| )); | ||
| let m_id = get_marketplace_id("my marketplace", 500, 600, 1); | ||
|
|
||
| assert_ok!(GatedMarketplace::apply( | ||
| RuntimeOrigin::signed(3), | ||
| m_id, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPT summary of f3ad44 - 3d8ee6:
Error: couldn't generate summary