Skip to content

Commit

Permalink
Fix portfolio move bug and bump to 5.1.3 (#1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdossa committed Jan 11, 2023
1 parent 09e4e12 commit 4566932
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polymesh"
version = "5.1.2"
version = "5.1.3"
authors = ["Polymath"]
build = "build.rs"
edition = "2021"
Expand Down
7 changes: 6 additions & 1 deletion pallets/portfolio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ use polymesh_primitives::{
};
use scale_info::TypeInfo;
use sp_arithmetic::traits::Zero;
use sp_std::collections::btree_set::BTreeSet;
use sp_std::prelude::Vec;

type Identity<T> = identity::Module<T>;
Expand Down Expand Up @@ -150,7 +151,9 @@ decl_error! {
/// The portfolio still has some asset balance left
PortfolioNotEmpty,
/// The portfolios belong to different identities
DifferentIdentityPortfolios
DifferentIdentityPortfolios,
/// Duplicate asset among the items.
NoDuplicateAssetsAllowed
}
}

Expand Down Expand Up @@ -254,7 +257,9 @@ decl_module! {
Self::ensure_user_portfolio_permission(secondary_key.as_ref(), to)?;

// Ensure there are sufficient funds for all moves.
let mut unique_tickers = BTreeSet::new();
for item in &items {
ensure!(unique_tickers.insert(item.ticker.clone()), Error::<T>::NoDuplicateAssetsAllowed);
Self::ensure_sufficient_balance(&from, &item.ticker, item.amount)?;
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/develop/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 1,
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
// N.B. `d` is unpinned from the binary version
spec_version: 5_001_020,
spec_version: 5_001_030,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 3,
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/mainnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 1,
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
// N.B. `d` is unpinned from the binary version
spec_version: 5_001_020,
spec_version: 5_001_030,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 3,
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/testnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 1,
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
// N.B. `d` is unpinned from the binary version
spec_version: 5_001_020,
spec_version: 5_001_030,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 3,
Expand Down
51 changes: 49 additions & 2 deletions pallets/runtime/tests/src/portfolio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ use super::{
use frame_support::storage::StorageDoubleMap;
use frame_support::{assert_noop, assert_ok, StorageMap};
use frame_system::EventRecord;
use pallet_portfolio::{Event, MovePortfolioItem, NameToNumber};
use pallet_portfolio::{Event, MovePortfolioItem, NameToNumber, PortfolioAssetBalances};
use polymesh_common_utilities::balances::Memo;
use polymesh_common_utilities::portfolio::PortfolioSubTrait;
use polymesh_primitives::{
AuthorizationData, AuthorizationError, PortfolioId, PortfolioName, PortfolioNumber, Signatory,
AuthorizationData, AuthorizationError, PortfolioId, PortfolioKind, PortfolioName,
PortfolioNumber, Signatory,
};
use test_client::AccountKeyring;

Expand Down Expand Up @@ -574,3 +575,49 @@ fn quit_portfolio_custody() {
assert_owner_is_custodian!(user_portfolio);
});
}

#[test]
fn move_more_funds() {
ExtBuilder::default().build().execute_with(|| {
let alice: User = User::new(AccountKeyring::Alice);
let alice_default_portfolio = PortfolioId {
did: alice.did,
kind: PortfolioKind::Default,
};
let alice_custom_portfolio = PortfolioId {
did: alice.did,
kind: PortfolioKind::User(PortfolioNumber(1)),
};
let (ticker, _) = create_token(alice);
assert_eq!(
PortfolioAssetBalances::get(&alice_default_portfolio, &ticker),
1_000_000_000
);
assert_ok!(Portfolio::create_portfolio(
alice.origin(),
PortfolioName(b"MyOwnPortfolio".to_vec())
));

let items = vec![
MovePortfolioItem {
ticker: ticker,
amount: 1_000_000_000,
memo: None,
},
MovePortfolioItem {
ticker: ticker,
amount: 1_000_000_000,
memo: None,
},
];
assert_noop!(
Portfolio::move_portfolio_funds(
alice.origin(),
alice_default_portfolio,
alice_custom_portfolio,
items,
),
Error::NoDuplicateAssetsAllowed
);
});
}

0 comments on commit 4566932

Please sign in to comment.