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

Refactors pallet-nfts to use fungible traits #1804

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improvements
jsidorenko committed Oct 12, 2023
commit 7e1ea2404154ce03f93a99a2a0902eb0e0d14f82
2 changes: 1 addition & 1 deletion substrate/frame/nfts/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -857,7 +857,7 @@ benchmarks_instance_pallet! {
let signer_public = sr25519_generate(0.into(), None);
let signer: T::AccountId = MultiSigner::Sr25519(signer_public).into_account().into();

set_default_balance::<T, I>(&item_owner);
set_default_balance::<T, I>(&item_owner);

let item = T::Helper::item(0);
assert_ok!(Nfts::<T, I>::force_mint(
6 changes: 3 additions & 3 deletions substrate/frame/nfts/src/features/transfer.rs
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
use crate::*;
use frame_support::{
pallet_prelude::*,
traits::tokens::{Fortitude, Restriction},
traits::tokens::{Fortitude, Precision::Exact, Restriction},
};

impl<T: Config<I>, I: 'static> Pallet<T, I> {
@@ -148,7 +148,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
&details.owner,
&new_owner,
details.owner_deposit,
BestEffort,
Exact,
Restriction::OnHold,
Fortitude::Polite,
)?;
@@ -225,7 +225,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
&details.owner,
&new_owner,
details.owner_deposit,
BestEffort,
Exact,
Restriction::OnHold,
Fortitude::Polite,
)?;
34 changes: 14 additions & 20 deletions substrate/frame/nfts/src/tests.rs
Original file line number Diff line number Diff line change
@@ -396,7 +396,7 @@ fn mint_should_work() {
account(2),
Some(MintWitness { mint_price: Some(1), ..Default::default() })
));
assert_eq!(<Test as Config>::Currency::total_balance(&account(2)), 99);
assert_eq!(Balances::total_balance(&account(2)), 99);

// validate types
assert_ok!(Nfts::force_create(
@@ -612,8 +612,8 @@ fn transfer_owner_should_work() {
assert_ok!(Nfts::transfer_ownership(RuntimeOrigin::signed(account(1)), 0, account(2)));

assert_eq!(collections(), vec![(account(2), 0)]);
assert_eq!(<Test as Config>::Currency::total_balance(&account(1)), 98);
assert_eq!(<Test as Config>::Currency::total_balance(&account(2)), 102);
assert_eq!(Balances::total_balance(&account(1)), 98);
assert_eq!(Balances::total_balance(&account(2)), 102);
assert_eq!(Balances::reserved_balance(&account(1)), 0);
assert_eq!(Balances::reserved_balance(&account(2)), 2);

@@ -635,8 +635,8 @@ fn transfer_owner_should_work() {
assert_ok!(Nfts::set_accept_ownership(RuntimeOrigin::signed(account(3)), Some(0)));
assert_ok!(Nfts::transfer_ownership(RuntimeOrigin::signed(account(2)), 0, account(3)));
assert_eq!(collections(), vec![(account(3), 0)]);
assert_eq!(<Test as Config>::Currency::total_balance(&account(2)), 58);
assert_eq!(<Test as Config>::Currency::total_balance(&account(3)), 144);
assert_eq!(Balances::total_balance(&account(2)), 58);
assert_eq!(Balances::total_balance(&account(3)), 144);
assert_eq!(Balances::reserved_balance(&account(2)), 0);
assert_eq!(Balances::reserved_balance(&account(3)), 44);

@@ -2416,14 +2416,8 @@ fn buy_item_should_work() {
// validate the new owner & balances
let item = Item::<Test>::get(collection_id, item_1).unwrap();
assert_eq!(item.owner, user_2.clone());
assert_eq!(
<Test as Config>::Currency::total_balance(&user_1.clone()),
initial_balance + price_1
);
assert_eq!(
<Test as Config>::Currency::total_balance(&user_2.clone()),
initial_balance - price_1
);
assert_eq!(Balances::total_balance(&user_1.clone()), initial_balance + price_1);
assert_eq!(Balances::total_balance(&user_2.clone()), initial_balance - price_1);

// can't buy from yourself
assert_noop!(
@@ -2561,9 +2555,9 @@ fn pay_tips_should_work() {
]
));

assert_eq!(<Test as Config>::Currency::total_balance(&user_1), initial_balance - tip * 2);
assert_eq!(<Test as Config>::Currency::total_balance(&user_2), initial_balance + tip);
assert_eq!(<Test as Config>::Currency::total_balance(&user_3), initial_balance + tip);
assert_eq!(Balances::total_balance(&user_1), initial_balance - tip * 2);
assert_eq!(Balances::total_balance(&user_2), initial_balance + tip);
assert_eq!(Balances::total_balance(&user_3), initial_balance + tip);

let events = events();
assert!(events.contains(&Event::<Test>::TipSent {
@@ -2895,8 +2889,8 @@ fn claim_swap_should_work() {
assert_eq!(item.owner, user_1.clone());

// validate the balances
assert_eq!(<Test as Config>::Currency::total_balance(&user_1), initial_balance + price);
assert_eq!(<Test as Config>::Currency::total_balance(&user_2), initial_balance - price);
assert_eq!(Balances::total_balance(&user_1), initial_balance + price);
assert_eq!(Balances::total_balance(&user_2), initial_balance - price);

// ensure we reset the swap
assert!(!PendingSwapOf::<Test>::contains_key(collection_id, item_1));
@@ -2941,8 +2935,8 @@ fn claim_swap_should_work() {
let item = Item::<Test>::get(collection_id, item_4).unwrap();
assert_eq!(item.owner, user_2);

assert_eq!(<Test as Config>::Currency::total_balance(&user_1), initial_balance - price);
assert_eq!(<Test as Config>::Currency::total_balance(&user_2), initial_balance + price);
assert_eq!(Balances::total_balance(&user_1), initial_balance - price);
assert_eq!(Balances::total_balance(&user_2), initial_balance + price);
});
}