Skip to content

Commit

Permalink
Use BoundedBTreeSet for list of portfolios. (#1733)
Browse files Browse the repository at this point in the history
* Use BoundedBTreeSet for list of portfolios.

* Export constant.

---------

Co-authored-by: Adam Dossa <[email protected]>
  • Loading branch information
Neopallium and adamdossa authored Oct 21, 2024
1 parent 2474e84 commit 6a40d4b
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 148 deletions.
1 change: 1 addition & 0 deletions pallets/runtime/common/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ macro_rules! misc_pallet_impls {
type MaxNumberOfNFTsPerLeg = MaxNumberOfNFTsPerLeg;
type MaxNumberOfNFTs = MaxNumberOfNFTs;
type MaxNumberOfOffChainAssets = MaxNumberOfOffChainAssets;
type MaxNumberOfPortfolios = MaxNumberOfPortfolios;
type MaxNumberOfVenueSigners = MaxNumberOfVenueSigners;
type MaxInstructionMediators = MaxInstructionMediators;
}
Expand Down
1 change: 1 addition & 0 deletions pallets/runtime/develop/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ parameter_types! {
pub const MaxNumberOfFungibleAssets: u32 = 10;
pub const MaxNumberOfNFTsPerLeg: u32 = 10;
pub const MaxNumberOfNFTs: u32 = 100;
pub const MaxNumberOfPortfolios: u32 = (10 + 100) * 2;
pub const MaxNumberOfVenueSigners: u32 = 50;
pub const MaxInstructionMediators: u32 = 4;

Expand Down
1 change: 1 addition & 0 deletions pallets/runtime/mainnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ parameter_types! {
pub const MaxNumberOfFungibleAssets: u32 = 10;
pub const MaxNumberOfNFTsPerLeg: u32 = 10;
pub const MaxNumberOfNFTs: u32 = 100;
pub const MaxNumberOfPortfolios: u32 = (10 + 100) * 2;
pub const MaxNumberOfVenueSigners: u32 = 50;
pub const MaxInstructionMediators: u32 = 4;

Expand Down
1 change: 1 addition & 0 deletions pallets/runtime/testnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ parameter_types! {
pub const MaxNumberOfFungibleAssets: u32 = 10;
pub const MaxNumberOfNFTsPerLeg: u32 = 10;
pub const MaxNumberOfNFTs: u32 = 100;
pub const MaxNumberOfPortfolios: u32 = (10 + 100) * 2;
pub const MaxNumberOfVenueSigners: u32 = 50;
pub const MaxInstructionMediators: u32 = 4;

Expand Down
4 changes: 2 additions & 2 deletions pallets/runtime/tests/src/asset_pallet/base_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use polymesh_primitives::{
};

use super::setup::{create_and_issue_sample_asset, create_and_issue_sample_nft, ISSUE_AMOUNT};
use crate::storage::User;
use crate::storage::{default_portfolio_btreeset, User};
use crate::{ExtBuilder, TestStorage};

type Asset = pallet_asset::Module<TestStorage>;
Expand Down Expand Up @@ -229,7 +229,7 @@ fn base_transfer_locked_asset() {
asset_id,
amount: ISSUE_AMOUNT,
}],
vec![alice_default_portfolio],
default_portfolio_btreeset(alice.did),
None,
));
let mut weight_meter = WeightMeter::max_limit_no_minimum();
Expand Down
4 changes: 2 additions & 2 deletions pallets/runtime/tests/src/asset_pallet/controller_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use polymesh_primitives::settlement::{
use polymesh_primitives::{AuthorizationData, PortfolioId, PortfolioKind, Signatory};

use super::setup::{create_and_issue_sample_asset, ISSUE_AMOUNT};
use crate::storage::User;
use crate::storage::{default_portfolio_btreeset, User};
use crate::{ExtBuilder, TestStorage};

type Asset = pallet_asset::Module<TestStorage>;
Expand Down Expand Up @@ -71,7 +71,7 @@ fn controller_transfer_locked_asset() {
assert_ok!(Settlement::affirm_instruction(
alice.origin(),
InstructionId(0),
vec![alice_default_portfolio]
default_portfolio_btreeset(alice.did),
),);

// Controller transfer should fail since the tokens are locked
Expand Down
6 changes: 3 additions & 3 deletions pallets/runtime/tests/src/asset_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ use crate::asset_pallet::setup::{
use crate::ext_builder::ExtBuilder;
use crate::nft::create_nft_collection;
use crate::storage::{
add_secondary_key, add_secondary_key_with_perms, register_keyring_account, root, Checkpoint,
TestStorage, User,
add_secondary_key, add_secondary_key_with_perms, default_portfolio_btreeset,
register_keyring_account, root, Checkpoint, TestStorage, User,
};

type BaseError = pallet_base::Error<TestStorage>;
Expand Down Expand Up @@ -1954,7 +1954,7 @@ fn controller_transfer_locked_asset() {
assert_ok!(Settlement::affirm_instruction(
alice.origin(),
InstructionId(0),
vec![alice_default_portfolio]
default_portfolio_btreeset(alice.did),
),);

// Controller transfer should fail since the tokens are locked
Expand Down
6 changes: 3 additions & 3 deletions pallets/runtime/tests/src/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sp_keyring::AccountKeyring;
use super::asset_test::{get_asset_details, set_timestamp};
use crate::asset_pallet::setup::{create_and_issue_sample_asset, create_and_issue_sample_nft};
use crate::ext_builder::ExtBuilder;
use crate::storage::{TestStorage, User};
use crate::storage::{default_portfolio_btreeset, TestStorage, User};

type Asset = pallet_asset::Module<TestStorage>;
type ComplianceManager = pallet_compliance_manager::Module<TestStorage>;
Expand Down Expand Up @@ -1179,7 +1179,7 @@ fn redeem_locked_nft() {
None,
None,
legs,
vec![PortfolioId::default_portfolio(alice.did)],
default_portfolio_btreeset(alice.did),
None,
));

Expand Down Expand Up @@ -1221,7 +1221,7 @@ fn reject_instruction_with_locked_asset() {
None,
None,
legs,
vec![PortfolioId::default_portfolio(alice.did)],
default_portfolio_btreeset(alice.did),
None,
));

Expand Down
4 changes: 2 additions & 2 deletions pallets/runtime/tests/src/portfolio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sp_keyring::AccountKeyring;
use super::asset_pallet::setup::{create_and_issue_sample_asset, ISSUE_AMOUNT};
use super::asset_test::max_len_bytes;
use super::nft::{create_nft_collection, mint_nft};
use super::storage::{EventTest, System, TestStorage, User};
use super::storage::{user_portfolio_btreeset, EventTest, System, TestStorage, User};
use super::ExtBuilder;

type Asset = pallet_asset::Module<TestStorage>;
Expand Down Expand Up @@ -683,7 +683,7 @@ fn delete_portfolio_with_locked_nfts() {
None,
None,
legs,
vec![PortfolioId::user_portfolio(alice.did, PortfolioNumber(1))],
user_portfolio_btreeset(alice.did, PortfolioNumber(1)),
Some(Memo::default()),
));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use polymesh_primitives::PortfolioId;

use super::setup::create_and_issue_sample_asset_with_venue;
use crate::asset_pallet::setup::create_and_issue_sample_asset;
use crate::storage::User;
use crate::storage::{default_portfolio_btreeset, User};
use crate::{next_block, ExtBuilder, TestStorage};

type Settlement = pallet_settlement::Module<TestStorage>;
Expand Down Expand Up @@ -50,12 +50,12 @@ fn execute_instruction_storage_pruning() {
assert_ok!(Settlement::affirm_instruction(
alice.origin(),
instruction_id,
vec![alice_default_portfolio]
default_portfolio_btreeset(alice.did),
));
assert_ok!(Settlement::affirm_instruction(
bob.origin(),
instruction_id,
vec![bob_default_portfolio]
default_portfolio_btreeset(bob.did),
));
next_block();

Expand Down Expand Up @@ -144,12 +144,12 @@ fn execute_instruction_storage_rollback() {
assert_ok!(Settlement::affirm_instruction(
alice.origin(),
instruction_id,
vec![alice_default_portfolio]
default_portfolio_btreeset(alice.did),
));
assert_ok!(Settlement::affirm_instruction(
bob.origin(),
instruction_id,
vec![bob_default_portfolio]
default_portfolio_btreeset(bob.did),
));
// Removes asset_id2 balance to force an error
BalanceOf::insert(asset_id2, alice.did, 0);
Expand Down
Loading

0 comments on commit 6a40d4b

Please sign in to comment.