Skip to content

Commit

Permalink
Rename struct (#1702)
Browse files Browse the repository at this point in the history
* Rename struct

* Rename functions

---------

Co-authored-by: Robert Gabriel Jakabosky <[email protected]>
  • Loading branch information
HenriqueNogara and Neopallium authored Aug 15, 2024
1 parent a80bebd commit d2749e2
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 128 deletions.
16 changes: 8 additions & 8 deletions pallets/asset/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn set_ticker_registration_config<T: Config>() {
});
}

/// Creates a new [`SecurityToken`] considering the worst case scenario.
/// Creates a new [`AssetDetails`] considering the worst case scenario.
pub(crate) fn create_sample_asset<T: Config>(asset_owner: &User<T>, divisible: bool) -> AssetID {
let asset_name = AssetName::from(vec![b'N'; T::AssetNameMaxLength::get() as usize].as_slice());
let funding_round_name =
Expand Down Expand Up @@ -303,7 +303,7 @@ benchmarks! {
}: _(bob.origin.clone(), new_owner_auth_id)
verify {
assert_eq!(
SecurityTokens::get(&asset_id).unwrap().owner_did,
Assets::get(&asset_id).unwrap().owner_did,
bob.did()
);
assert_eq!(
Expand Down Expand Up @@ -334,8 +334,8 @@ benchmarks! {
}: _(alice.origin.clone(), asset_name.clone(), true, AssetType::default(), asset_identifiers.clone(), Some(funding_round_name.clone()))
verify {
assert_eq!(
SecurityTokens::get(&asset_id),
Some(SecurityToken::new(0, alice.did(), true, AssetType::default()))
Assets::get(&asset_id),
Some(AssetDetails::new(0, alice.did(), true, AssetType::default()))
);
assert_eq!(
SecurityTokensOwnedByUser::get(alice.did(), &asset_id),
Expand Down Expand Up @@ -391,7 +391,7 @@ benchmarks! {
}: _(alice.origin, asset_id, (1_000_000 * POLY).into(), portfolio_id.kind)
verify {
assert_eq!(
SecurityTokens::get(&asset_id).unwrap().total_supply,
Assets::get(&asset_id).unwrap().total_supply,
(1_000_000 * POLY).into()
);
}
Expand All @@ -411,7 +411,7 @@ benchmarks! {
}: _(alice.origin, asset_id, (600_000 * POLY).into(), portfolio_id.kind)
verify {
assert_eq!(
SecurityTokens::get(&asset_id).unwrap().total_supply,
Assets::get(&asset_id).unwrap().total_supply,
(400_000 * POLY).into()
);
}
Expand All @@ -422,7 +422,7 @@ benchmarks! {
}: _(alice.origin, asset_id)
verify {
assert_eq!(
SecurityTokens::get(&asset_id).unwrap().divisible,
Assets::get(&asset_id).unwrap().divisible,
true
);
}
Expand Down Expand Up @@ -576,7 +576,7 @@ benchmarks! {
}: _(alice.origin, asset_id, AssetType::EquityPreferred)
verify {
assert_eq!(
SecurityTokens::get(&asset_id).unwrap().asset_type,
Assets::get(&asset_id).unwrap().asset_type,
AssetType::EquityPreferred
);
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/asset/src/checkpoint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl<T: Config> Module<T> {
/// - mapping the the ID to the `time`.
fn create_at(caller_did: Option<IdentityId>, asset_id: AssetID, id: CheckpointId, at: Moment) {
// Record total supply at checkpoint ID.
let supply = <Asset<T>>::try_get_security_token(&asset_id)
let supply = <Asset<T>>::try_get_asset_details(&asset_id)
.map(|t| t.total_supply)
.unwrap_or_default();
TotalSupply::insert(asset_id, id, supply);
Expand Down
137 changes: 66 additions & 71 deletions pallets/asset/src/lib.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions pallets/asset/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ mod v4 {
pub Tickers get(fn ticker_registration):
map hasher(blake2_128_concat) Ticker => Option<TickerRegistration<T::Moment>>;

// This storage was renamed to SecurityTokens and changed the Ticker key to AssetID.
pub Tokens get(fn tokens): map hasher(blake2_128_concat) Ticker => Option<SecurityToken>;
// This storage was renamed to Assets and changed the Ticker key to AssetID.
pub Tokens get(fn tokens): map hasher(blake2_128_concat) Ticker => Option<AssetDetails>;

// This storage changed the Ticker key to AssetID.
pub AssetNames get(fn asset_names):
Expand Down Expand Up @@ -114,13 +114,13 @@ pub(crate) fn migrate_to_v5<T: Config>() {
log::info!("{:?} items migrated", count);

let mut count = 0;
log::info!("Moving items from Tokens to SecurityTokens");
v4::Tokens::drain().for_each(|(ticker, security_token)| {
log::info!("Moving items from Tokens to Assets");
v4::Tokens::drain().for_each(|(ticker, asset_details)| {
count += 1;
let asset_id = ticker_to_asset_id
.entry(ticker)
.or_insert(AssetID::from(ticker));
SecurityTokens::insert(asset_id, security_token);
Assets::insert(asset_id, asset_details);
});
log::info!("{:?} items migrated", count);

Expand Down
6 changes: 3 additions & 3 deletions pallets/asset/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum AssetOwnershipRelation {

/// Stores the details of a security token.
#[derive(Clone, Debug, Decode, Default, Encode, TypeInfo, PartialEq, Eq)]
pub struct SecurityToken {
pub struct AssetDetails {
/// Total [`Balance`] that has been issued.
pub total_supply: Balance,
/// [`IdentityId`] of the token owner.
Expand All @@ -29,8 +29,8 @@ pub struct SecurityToken {
pub asset_type: AssetType,
}

impl SecurityToken {
/// Creates a new [`SecurityToken`] instance.
impl AssetDetails {
/// Creates a new [`AssetDetails`] instance.
pub fn new(
total_supply: Balance,
owner_did: IdentityId,
Expand Down
2 changes: 1 addition & 1 deletion pallets/common/src/traits/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub trait WeightInfo {
}

pub trait AssetFnTrait<Account, Origin> {
/// Returns `Ok` if [`SecurityToken::divisible`] or `value` % ONE_UNIT == 0.
/// Returns `Ok` if [`AssetDetails::divisible`] or `value` % ONE_UNIT == 0.
fn ensure_granular(asset_id: &AssetID, value: Balance) -> DispatchResult;

/// Returns `true` if the given `identity_id` is exempt from affirming the receivement of `asset_id`, otherwise returns `false`.
Expand Down
2 changes: 1 addition & 1 deletion pallets/compliance-manager/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn split_conditions(count: u32) -> (u32, u32) {
(s, r)
}

/// Creates a new [`SecurityToken`] and issues 1_000_000 tokens for that token.
/// Creates a new [`AssetDetails`] and issues 1_000_000 tokens for that token.
pub fn create_and_issue_sample_asset<T: Config>(
asset_owner: &User<T>,
asset_name: Vec<u8>,
Expand Down
12 changes: 3 additions & 9 deletions pallets/runtime/tests/src/asset_pallet/issue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use frame_support::{assert_noop, assert_ok};
use frame_support::{StorageDoubleMap, StorageMap};
use sp_keyring::AccountKeyring;

use pallet_asset::{BalanceOf, SecurityTokens};
use pallet_asset::{Assets, BalanceOf};
use pallet_portfolio::{PortfolioAssetBalances, PortfolioAssetCount, PortfolioLockedAssets};
use polymesh_primitives::asset::{AssetType, NonFungibleType};
use polymesh_primitives::{
Expand Down Expand Up @@ -40,10 +40,7 @@ fn issue_tokens_default_portfolio() {
0
);
assert_eq!(BalanceOf::get(&asset_id, &alice.did), ISSUE_AMOUNT);
assert_eq!(
SecurityTokens::get(&asset_id).unwrap().total_supply,
ISSUE_AMOUNT
);
assert_eq!(Assets::get(&asset_id).unwrap().total_supply, ISSUE_AMOUNT);
assert_eq!(PortfolioAssetCount::get(alice_default_portfolio), 1);
});
}
Expand Down Expand Up @@ -87,10 +84,7 @@ fn issue_tokens_user_portfolio() {
0
);
assert_eq!(BalanceOf::get(asset_id, &alice.did), ISSUE_AMOUNT);
assert_eq!(
SecurityTokens::get(asset_id).unwrap().total_supply,
ISSUE_AMOUNT
);
assert_eq!(Assets::get(asset_id).unwrap().total_supply, ISSUE_AMOUNT);
});
}

Expand Down
4 changes: 2 additions & 2 deletions pallets/runtime/tests/src/asset_pallet/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn register_unique_ticker(ticker_owner: &User, ticker: Ticker) {
}

/// Creates a divisible asset where all values for its attributes are set to their default values.
/// The [`SecurityToken::total_supply`] will be set to [`ISSUE_AMOUNT`].
/// The [`AssetDetails::total_supply`] will be set to [`ISSUE_AMOUNT`].
pub fn create_and_issue_sample_asset(asset_owner: &User) -> AssetID {
let asset_id = Asset::generate_asset_id(asset_owner.acc(), false);

Expand Down Expand Up @@ -88,7 +88,7 @@ pub fn create_and_issue_sample_nft(asset_owner: &User) -> AssetID {
asset_id
}

/// Creates an asset setting the attributes for the [`SecurityToken`] using the values in the parameters.
/// Creates an asset setting the attributes for the [`AssetDetails`] using the values in the parameters.
/// If `issue_tokens`` is `true` also mints [`ISSUE_AMOUNT`] tokens in the `issue_portfolio`.
pub fn create_asset(
asset_owner: &User,
Expand Down
43 changes: 22 additions & 21 deletions pallets/runtime/tests/src/asset_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ use sp_std::convert::{From, TryFrom, TryInto};
use sp_std::iter;

use pallet_asset::{
AssetDocuments, AssetIdentifiers, AssetMetadataLocalKeyToName, AssetMetadataLocalNameToKey,
AssetMetadataLocalSpecs, AssetMetadataValues, AssetsExemptFromAffirmation, BalanceOf,
Config as AssetConfig, CustomTypeIdSequence, CustomTypes, CustomTypesInverse,
MandatoryMediators, PreApprovedAsset, SecurityToken, SecurityTokens, SecurityTokensOwnedByUser,
AssetDetails, AssetDocuments, AssetIdentifiers, AssetMetadataLocalKeyToName,
AssetMetadataLocalNameToKey, AssetMetadataLocalSpecs, AssetMetadataValues, Assets,
AssetsExemptFromAffirmation, BalanceOf, Config as AssetConfig, CustomTypeIdSequence,
CustomTypes, CustomTypesInverse, MandatoryMediators, PreApprovedAsset,
SecurityTokensOwnedByUser,
};
use pallet_portfolio::{
NextPortfolioNumber, PortfolioAssetBalances, PortfolioAssetCount, PortfolioLockedAssets,
Expand Down Expand Up @@ -121,14 +122,14 @@ pub(crate) fn statistics_investor_count(asset_id: AssetID) -> u128 {
)
}

/// Returns the [`SecurityToken`] associated to the given `asset_id`.
pub(crate) fn get_security_token(asset_id: &AssetID) -> SecurityToken {
SecurityTokens::get(asset_id).unwrap()
/// Returns the [`AssetDetails`] associated to the given `asset_id`.
pub(crate) fn get_asset_details(asset_id: &AssetID) -> AssetDetails {
Assets::get(asset_id).unwrap()
}

/// Returns a [`SecurityToken`] where [`SecurityToken::total_supply`] is [`TOTAL_SUPPLY`] and the owner is `token_owner_did`.
pub(crate) fn sample_security_token(token_owner_did: IdentityId) -> SecurityToken {
SecurityToken::new(TOTAL_SUPPLY, token_owner_did, true, AssetType::default())
/// Returns a [`AssetDetails`] where [`AssetDetails::total_supply`] is [`TOTAL_SUPPLY`] and the owner is `token_owner_did`.
pub(crate) fn sample_security_token(token_owner_did: IdentityId) -> AssetDetails {
AssetDetails::new(TOTAL_SUPPLY, token_owner_did, true, AssetType::default())
}

fn enable_investor_count(asset_id: AssetID, owner: User) {
Expand Down Expand Up @@ -240,7 +241,7 @@ fn issuers_can_create_and_rename_tokens() {
assert_eq!(statistics_investor_count(asset_id), 1);

// A correct entry is added
assert_eq!(get_security_token(&asset_id), sample_security_token);
assert_eq!(get_asset_details(&asset_id), sample_security_token);
assert_eq!(SecurityTokensOwnedByUser::get(owner.did, asset_id), true);
assert_eq!(Asset::funding_round(asset_id), funding_round_name.clone());

Expand All @@ -251,7 +252,7 @@ fn issuers_can_create_and_rename_tokens() {
EAError::UnauthorizedAgent
);
// The token should remain unchanged in storage.
assert_eq!(get_security_token(&asset_id), sample_security_token);
assert_eq!(get_asset_details(&asset_id), sample_security_token);
// Rename the token and check storage has been updated.
let new: AssetName = [0x42].into();
assert_ok!(Asset::rename_asset(owner.origin(), asset_id, new.clone()));
Expand Down Expand Up @@ -319,7 +320,7 @@ fn issuers_can_redeem_tokens() {

assert_eq!(PortfolioAssetCount::get(owner_portfolio_id), 0);
assert_eq!(Asset::balance_of(&asset_id, owner.did), 0);
assert_eq!(get_security_token(&asset_id).total_supply, 0);
assert_eq!(get_asset_details(&asset_id).total_supply, 0);

assert_noop!(
Asset::redeem(owner.origin(), asset_id, 1, PortfolioKind::Default),
Expand Down Expand Up @@ -436,7 +437,7 @@ fn transfer_token_ownership() {
)
.unwrap();

assert_eq!(get_security_token(&asset_id).owner_did, owner.did);
assert_eq!(get_asset_details(&asset_id).owner_did, owner.did);

assert_noop!(
Asset::accept_asset_ownership_transfer(alice.origin(), auth_id_alice + 1),
Expand All @@ -449,7 +450,7 @@ fn transfer_token_ownership() {
alice.origin(),
auth_id_alice
));
assert_eq!(get_security_token(&asset_id).owner_did, alice.did);
assert_eq!(get_asset_details(&asset_id).owner_did, alice.did);
assert_eq!(SecurityTokensOwnedByUser::get(owner.did, asset_id), false);
assert_eq!(SecurityTokensOwnedByUser::get(alice.did, asset_id), true);

Expand Down Expand Up @@ -516,7 +517,7 @@ fn transfer_token_ownership() {
bob.origin(),
auth_id
));
assert_eq!(get_security_token(&asset_id).owner_did, bob.did);
assert_eq!(get_asset_details(&asset_id).owner_did, bob.did);
})
}

Expand Down Expand Up @@ -678,7 +679,7 @@ fn frozen_secondary_keys_create_asset_we() {
// 2. Bob can create token
let asset_id = create_and_issue_sample_asset(&alice);
assert_eq!(
get_security_token(&asset_id),
get_asset_details(&asset_id),
sample_security_token(alice.did)
);

Expand Down Expand Up @@ -967,7 +968,7 @@ fn secondary_key_not_authorized_for_asset_test() {
));

assert_eq!(
get_security_token(&asset_id).total_supply,
get_asset_details(&asset_id).total_supply,
ISSUE_AMOUNT + 1_000
);
});
Expand Down Expand Up @@ -1265,7 +1266,7 @@ fn issuers_can_redeem_tokens_from_portfolio() {
));

assert_eq!(Asset::balance_of(&asset_id, owner.did), ISSUE_AMOUNT / 2);
assert_eq!(get_security_token(&asset_id).total_supply, ISSUE_AMOUNT / 2);
assert_eq!(get_asset_details(&asset_id).total_supply, ISSUE_AMOUNT / 2);

// Add auth for custody to be moved to bob
let auth_id = Identity::add_auth(
Expand Down Expand Up @@ -1365,7 +1366,7 @@ fn issuers_can_change_asset_type() {
AssetType::EquityPreferred
));
assert_eq!(
get_security_token(&asset_id).asset_type,
get_asset_details(&asset_id).asset_type,
AssetType::EquityPreferred
);
})
Expand Down Expand Up @@ -2005,7 +2006,7 @@ fn issue_tokens_user_portfolio() {
0
);
assert_eq!(BalanceOf::get(&asset_id, &alice.did), ISSUE_AMOUNT);
assert_eq!(get_security_token(&asset_id).total_supply, ISSUE_AMOUNT);
assert_eq!(get_asset_details(&asset_id).total_supply, ISSUE_AMOUNT);
assert_eq!(PortfolioAssetCount::get(alice_user_portfolio), 1);
assert_eq!(PortfolioAssetCount::get(alice_default_portfolio), 0);
});
Expand Down
4 changes: 2 additions & 2 deletions pallets/runtime/tests/src/corporate_actions_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use frame_support::{
dispatch::{DispatchError, DispatchResult},
IterableStorageDoubleMap, StorageDoubleMap, StorageMap,
};
use pallet_asset::SecurityTokens;
use pallet_asset::Assets;
use pallet_corporate_actions::{
ballot::{BallotMeta, BallotTimeRange, BallotVote, Motion, Votes},
distribution::{self, Distribution, PER_SHARE_PRECISION},
Expand Down Expand Up @@ -2158,7 +2158,7 @@ fn dist_claim_rounding_indivisible() {

// Make `currency` indivisible.
// This the crucial aspect different about this test.
SecurityTokens::mutate(currency, |t| {
Assets::mutate(currency, |t| {
if let Some(t) = t {
t.divisible = false;
}
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 @@ -23,7 +23,7 @@ use polymesh_primitives::{
};
use sp_keyring::AccountKeyring;

use super::asset_test::{get_security_token, set_timestamp};
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};
Expand Down Expand Up @@ -55,9 +55,9 @@ fn create_collection_unregistered_ticker() {
Some(nft_type),
collection_keys
));
assert_eq!(get_security_token(&asset_id).divisible, false);
assert_eq!(get_asset_details(&asset_id).divisible, false);
assert_eq!(
get_security_token(&asset_id).asset_type,
get_asset_details(&asset_id).asset_type,
AssetType::NonFungible(nft_type)
);
});
Expand Down
2 changes: 1 addition & 1 deletion pallets/settlement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ impl<T: Config> Module<T> {

/// Returns true if the asset_id is on-chain and false otherwise.
fn is_on_chain_asset(asset_id: &AssetID) -> bool {
pallet_asset::SecurityTokens::contains_key(asset_id)
pallet_asset::Assets::contains_key(asset_id)
}

fn base_execute_manual_instruction(
Expand Down

0 comments on commit d2749e2

Please sign in to comment.