git.delta.rocks / unique-network / refs/commits / 99e7555e5ee6

difftreelog

Merge pull request #104 from usetech-llc/feature/NFTPAR-301_transfer_event

Greg Zaitsev2021-02-18parents: #dcb255f #04b203b.patch.diff
in: master
Add Transfer event

2 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
508 /// item_id: Identifier of burned NFT.508 /// item_id: Identifier of burned NFT.
509 ItemDestroyed(CollectionId, TokenId),509 ItemDestroyed(CollectionId, TokenId),
510
511 /// Item was transferred
512 ///
513 /// * collection_id: Id of collection to which item is belong
514 ///
515 /// * item_id: Id of an item
516 ///
517 /// * sender: Original owner of item
518 ///
519 /// * recipient: New owner of item
520 ///
521 /// * amount: Always 1 for NFT
522 Transfer(CollectionId, TokenId, AccountId, AccountId, u128),
510 }523 }
511);524);
512525
15581571
1559 match target_collection.mode1572 match target_collection.mode
1560 {1573 {
1561 CollectionMode::NFT => Self::transfer_nft(collection_id, item_id, sender.clone(), recipient)?,1574 CollectionMode::NFT => Self::transfer_nft(collection_id, item_id, sender.clone(), recipient.clone())?,
1562 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,1575 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,
1563 CollectionMode::ReFungible => Self::transfer_refungible(collection_id, item_id, value, sender.clone(), recipient)?,1576 CollectionMode::ReFungible => Self::transfer_refungible(collection_id, item_id, value, sender.clone(), recipient.clone())?,
1564 _ => ()1577 _ => ()
1565 };1578 };
1579
1580 Self::deposit_event(RawEvent::Transfer(collection_id, item_id, sender, recipient, value));
15661581
1567 Ok(())1582 Ok(())
1568 }1583 }
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -39,6 +39,15 @@
   recipient: string;
 }
 
+interface TransferResult {
+  success: boolean;
+  collectionId: number;
+  itemId: number;
+  sender: string;
+  recipient: string;
+  value: bigint;
+}
+
 interface IReFungibleOwner {
   Fraction: BN;
   Owner: number[];
@@ -115,6 +124,31 @@
   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;
+}
+
 interface Invalid {
   type: 'Invalid';
 }
@@ -624,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);