difftreelog
Merge branch 'develop' into release/v2.0.0
in: master
4 files changed
doc/application_development.mddiffbeforeafterboth--- a/doc/application_development.md
+++ b/doc/application_development.md
@@ -101,10 +101,9 @@
- Owner: Address, initial owner of the NFT
##### Events
-
-- ItemCreated
- - ItemId: Identifier of newly created NFT, which is unique within the Collection, so the NFT is uniquely
- identified with a pair of values: CollectionId and ItemId.
+ItemCreated
+ItemId: Identifier of newly created NFT, which is unique within the Collection, so the NFT is uniquely identified with a pair of values: CollectionId and ItemId.
+Recipient: Address, owner of newly created item
#### BurnItem
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -495,7 +495,9 @@
/// * collection_id: Id of the collection where item was created.
///
/// * item_id: Id of an item. Unique within the collection.
- ItemCreated(CollectionId, TokenId),
+ ///
+ /// * recipient: Owner of newly created item
+ ItemCreated(CollectionId, TokenId, AccountId),
/// Collection item was burned.
///
@@ -505,6 +507,19 @@
///
/// item_id: Identifier of burned NFT.
ItemDestroyed(CollectionId, TokenId),
+
+ /// Item was transferred
+ ///
+ /// * collection_id: Id of collection to which item is belong
+ ///
+ /// * item_id: Id of an item
+ ///
+ /// * sender: Original owner of item
+ ///
+ /// * recipient: New owner of item
+ ///
+ /// * amount: Always 1 for NFT
+ Transfer(CollectionId, TokenId, AccountId, AccountId, u128),
}
);
@@ -1556,12 +1571,14 @@
match target_collection.mode
{
- CollectionMode::NFT => Self::transfer_nft(collection_id, item_id, sender.clone(), recipient)?,
+ CollectionMode::NFT => Self::transfer_nft(collection_id, item_id, sender.clone(), recipient.clone())?,
CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,
- CollectionMode::ReFungible => Self::transfer_refungible(collection_id, item_id, value, sender.clone(), recipient)?,
+ CollectionMode::ReFungible => Self::transfer_refungible(collection_id, item_id, value, sender.clone(), recipient.clone())?,
_ => ()
};
+ Self::deposit_event(RawEvent::Transfer(collection_id, item_id, sender, recipient, value));
+
Ok(())
}
@@ -1635,7 +1652,7 @@
{
CreateItemData::NFT(data) => {
let item = NftItemType {
- owner,
+ owner: owner.clone(),
const_data: data.const_data,
variable_data: data.variable_data
};
@@ -1660,7 +1677,7 @@
};
// call event
- Self::deposit_event(RawEvent::ItemCreated(collection_id, <ItemListIndex>::get(collection_id)));
+ Self::deposit_event(RawEvent::ItemCreated(collection_id, <ItemListIndex>::get(collection_id), owner));
Ok(())
}
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -29,6 +29,7 @@
"testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",
"testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
"testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
+ "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",
"testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",
"testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
"testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",
tests/src/util/helpers.tsdiffbeforeafterboth36 success: boolean;36 success: boolean;37 collectionId: number;37 collectionId: number;38 itemId: number;38 itemId: number;39 recipient: string;39}40}4142interface TransferResult {43 success: boolean;44 collectionId: number;45 itemId: number;46 sender: string;47 recipient: string;48 value: bigint;49}405041interface IReFungibleOwner {51interface IReFungibleOwner {42 Fraction: BN;52 Fraction: BN;94 let success = false;104 let success = false;95 let collectionId: number = 0;105 let collectionId: number = 0;96 let itemId: number = 0;106 let itemId: number = 0;107 let recipient: string = '';97 events.forEach(({ phase, event: { data, method, section } }) => {108 events.forEach(({ phase, event: { data, method, section } }) => {98 // console.log(` ${phase}: ${section}.${method}:: ${data}`);109 // console.log(` ${phase}: ${section}.${method}:: ${data}`);99 if (method == 'ExtrinsicSuccess') {110 if (method == 'ExtrinsicSuccess') {100 success = true;111 success = true;101 } else if ((section == 'nft') && (method == 'ItemCreated')) {112 } else if ((section == 'nft') && (method == 'ItemCreated')) {102 collectionId = parseInt(data[0].toString());113 collectionId = parseInt(data[0].toString());103 itemId = parseInt(data[1].toString());114 itemId = parseInt(data[1].toString());115 recipient = data[2].toString();104 }116 }105 });117 });106 const result: CreateItemResult = {118 const result: CreateItemResult = {107 success,119 success,108 collectionId,120 collectionId,109 itemId,121 itemId,122 recipient,110 };123 };111 return result;124 return result;112}125}126127export function getTransferResult(events: EventRecord[]): TransferResult {128 const result: TransferResult = {129 success: false,130 collectionId: 0,131 itemId: 0,132 sender: '',133 recipient: '',134 value: 0n,135 };136137 events.forEach(({event: {data, method, section}}) => {138 if (method === 'ExtrinsicSuccess') {139 result.success = true;140 } else if (section === 'nft' && method === 'Transfer') {141 result.collectionId = +data[0].toString();142 result.itemId = +data[1].toString();143 result.sender = data[2].toString();144 result.recipient = data[3].toString();145 result.value = BigInt(data[4].toString());146 }147 });148149 return result;150}113151114interface Invalid {152interface Invalid {115 type: 'Invalid';153 type: 'Invalid';620 }658 }621 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);659 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);622 const events = await submitTransactionAsync(sender, transferTx);660 const events = await submitTransactionAsync(sender, transferTx);623 const result = getCreateItemResult(events);661 const result = getTransferResult(events);624 // tslint:disable-next-line:no-unused-expression662 // tslint:disable-next-line:no-unused-expression625 expect(result.success).to.be.true;663 expect(result.success).to.be.true;664 expect(result.collectionId).to.be.equal(collectionId);665 expect(result.itemId).to.be.equal(tokenId);666 expect(result.sender).to.be.equal(sender.address);667 expect(result.recipient).to.be.equal(recipient.address);668 expect(result.value.toString()).to.be.equal(value.toString());626 if (type === 'NFT') {669 if (type === 'NFT') {627 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;670 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;628 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);671 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);736 }779 }737 expect(collectionId).to.be.equal(result.collectionId);780 expect(collectionId).to.be.equal(result.collectionId);738 expect(BItemCount).to.be.equal(result.itemId);781 expect(BItemCount).to.be.equal(result.itemId);782 expect(owner).to.be.equal(result.recipient);739 newItemId = result.itemId;783 newItemId = result.itemId;740 });784 });741 return newItemId;785 return newItemId;