git.delta.rocks / unique-network / refs/commits / 54d73b995f4b

difftreelog

Merge branch 'develop' into release/v2.0.0

Greg Zaitsev2021-02-18parents: #3003f76 #99e7555.patch.diff
in: master

4 files changed

modifieddoc/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
 
modifiedpallets/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(())
     }
modifiedtests/package.jsondiffbeforeafterboth
before · tests/package.json
1{2  "name": "NftTests",3  "version": "1.0.0",4  "description": "Substrate Nft tests",5  "main": "",6  "devDependencies": {7    "@polkadot/dev": "^0.61.24",8    "@polkadot/ts": "^0.3.59",9    "@polkadot/typegen": "^3.6.4",10    "@polkadot/util-crypto": "^5.4.4",11    "@types/chai": "^4.2.12",12    "@types/chai-as-promised": "^7.1.3",13    "@types/mocha": "^8.0.3",14    "chai": "^4.2.0",15    "mocha": "^8.1.1",16    "ts-node": "^9.0.0",17    "tslint": "^5.20.1",18    "typescript": "^3.9.7"19  },20  "scripts": {21    "test": "mocha --timeout 9999999 -r ts-node/register ./**/*.test.ts",22    "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",23    "loadTransfer": "ts-node src/transfer.nload.ts",24    "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",25    "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",26    "testSetVariableMetaData": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetaData.test.ts",27    "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",28    "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",29    "testRemoveFromWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromWhiteList.test.ts",30    "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",31    "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",32    "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",33    "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",34    "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",35    "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",36    "testToggleContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractWhiteList.test.ts",37    "testAddToContractWhiteList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractWhiteList.test.ts",38    "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",39    "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",40    "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",41    "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",42    "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",43    "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",44    "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",45    "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts"46  },47  "author": "",48  "license": "SEE LICENSE IN ../LICENSE",49  "homepage": "",50  "dependencies": {51    "@polkadot/api": "3.8.1",52    "@polkadot/api-contract": "3.8.1",53    "@polkadot/util": "5.6.2",54    "bignumber.js": "^9.0.0",55    "chai-as-promised": "^7.1.1"56  },57  "standard": {58    "globals": [59      "it",60      "assert",61      "beforeEach",62      "afterEach",63      "describe",64      "contract",65      "artifacts"66    ]67  }68}
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -36,6 +36,16 @@
   success: boolean;
   collectionId: number;
   itemId: number;
+  recipient: string;
+}
+
+interface TransferResult {
+  success: boolean;
+  collectionId: number;
+  itemId: number;
+  sender: string;
+  recipient: string;
+  value: bigint;
 }
 
 interface IReFungibleOwner {
@@ -94,6 +104,7 @@
   let success = false;
   let collectionId: number = 0;
   let itemId: number = 0;
+  let recipient: string = '';
   events.forEach(({ phase, event: { data, method, section } }) => {
     // console.log(`    ${phase}: ${section}.${method}:: ${data}`);
     if (method == 'ExtrinsicSuccess') {
@@ -101,13 +112,40 @@
     } else if ((section == 'nft') && (method == 'ItemCreated')) {
       collectionId = parseInt(data[0].toString());
       itemId = parseInt(data[1].toString());
+      recipient = data[2].toString();
     }
   });
   const result: CreateItemResult = {
     success,
     collectionId,
     itemId,
+    recipient,
+  };
+  return result;
+}
+
+export function getTransferResult(events: EventRecord[]): TransferResult {
+  const result: TransferResult = {
+    success: false,
+    collectionId: 0,
+    itemId: 0,
+    sender: '',
+    recipient: '',
+    value: 0n,
   };
+
+  events.forEach(({event: {data, method, section}}) => {
+    if (method === 'ExtrinsicSuccess') {
+      result.success = true;
+    } else if (section === 'nft' && method === 'Transfer') {
+      result.collectionId = +data[0].toString();
+      result.itemId = +data[1].toString();
+      result.sender = data[2].toString();
+      result.recipient = data[3].toString();
+      result.value = BigInt(data[4].toString());
+    }
+  });
+
   return result;
 }
 
@@ -620,9 +658,14 @@
     }
     const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);
     const events = await submitTransactionAsync(sender, transferTx);
-    const result = getCreateItemResult(events);
+    const result = getTransferResult(events);
     // tslint:disable-next-line:no-unused-expression
     expect(result.success).to.be.true;
+    expect(result.collectionId).to.be.equal(collectionId);
+    expect(result.itemId).to.be.equal(tokenId);
+    expect(result.sender).to.be.equal(sender.address);
+    expect(result.recipient).to.be.equal(recipient.address);
+    expect(result.value.toString()).to.be.equal(value.toString());
     if (type === 'NFT') {
       const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;
       expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);
@@ -736,6 +779,7 @@
     }
     expect(collectionId).to.be.equal(result.collectionId);
     expect(BItemCount).to.be.equal(result.itemId);
+    expect(owner).to.be.equal(result.recipient);
     newItemId = result.itemId;
   });
   return newItemId;