Skip to content

Commit

Permalink
Fix NFT transfer (#1695)
Browse files Browse the repository at this point in the history
Update version to 6.3.3
  • Loading branch information
adamdossa authored Jul 29, 2024
1 parent acaa947 commit 2519d25
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 = "6.3.2"
version = "6.3.3"
authors = ["PolymeshAssociation"]
build = "build.rs"
edition = "2021"
Expand Down
9 changes: 8 additions & 1 deletion pallets/nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ decl_error! {
/// The receiver has an invalid CDD.
InvalidNFTTransferInvalidReceiverCDD,
/// The sender has an invalid CDD.
InvalidNFTTransferInvalidSenderCDD
InvalidNFTTransferInvalidSenderCDD,
/// Ticker and NFT ticker don't match
InvalidNFTTransferInconsistentTicker,
}
}

Expand Down Expand Up @@ -618,13 +620,18 @@ impl<T: Config> Module<T> {
source_portfolio: PortfolioId,
callers_portfolio_kind: PortfolioKind,
) -> DispatchResult {
ensure!(
&ticker == nfts.ticker(),
Error::<T>::InvalidNFTTransferInconsistentTicker
);
// Ensure origin is agent with custody and permissions for portfolio.
let caller_portfolio = Asset::<T>::ensure_origin_ticker_and_portfolio_permissions(
origin,
ticker,
callers_portfolio_kind,
true,
)?;

// Verifies if all rules for transfering the NFTs are being respected
Self::validate_nft_transfer(&source_portfolio, &caller_portfolio, &nfts, true, None)?;
// Transfer ownership of the NFTs
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 @@ -57,7 +57,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: 6_003_020,
spec_version: 6_003_030,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
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: 6_003_020,
spec_version: 6_003_030,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
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 @@ -55,7 +55,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: 6_003_020,
spec_version: 6_003_030,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
Expand Down
50 changes: 50 additions & 0 deletions pallets/runtime/tests/src/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,3 +1126,53 @@ fn controller_transfer_nft_not_owned() {
);
});
}

#[test]
fn controller_transfer_unauthorized_agent2() {
ExtBuilder::default().build().execute_with(|| {
let alice: User = User::new(AccountKeyring::Alice);
let bob: User = User::new(AccountKeyring::Bob);
let nft_ticker = Ticker::from_slice_truncated(b"TICKER".as_ref());
let non_nft_ticker = Ticker::from_slice_truncated(b"NONNFT".as_ref());

// Creates one asset that bob controls
Asset::create_asset(
bob.origin(),
b"MyAsset".into(),
non_nft_ticker,
true,
AssetType::Fund,
Vec::new(),
None,
)
.unwrap();

// Creates one NFT collection for Alice
create_nft_collection(
alice.clone(),
nft_ticker.clone(),
AssetType::NonFungible(NonFungibleType::Derivative),
Vec::new().into(),
);
mint_nft(
alice.clone(),
nft_ticker.clone(),
Vec::new(),
PortfolioKind::Default,
);
ComplianceManager::pause_asset_compliance(alice.origin(), nft_ticker.clone()).unwrap();

// Bob calls controller transfer
let nfts = NFTs::new(nft_ticker, vec![NFTId(1)]).unwrap();
assert_noop!(
NFT::controller_transfer(
bob.origin(),
non_nft_ticker,
nfts.clone(),
PortfolioId::new(alice.did, PortfolioKind::Default),
PortfolioKind::Default
),
NFTError::InvalidNFTTransferInconsistentTicker
);
});
}

0 comments on commit 2519d25

Please sign in to comment.