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.rsdiffbeforeafterboth495 /// * collection_id: Id of the collection where item was created.495 /// * collection_id: Id of the collection where item was created.496 /// 496 /// 497 /// * item_id: Id of an item. Unique within the collection.497 /// * item_id: Id of an item. Unique within the collection.498 ///499 /// * recipient: Owner of newly created item 498 ItemCreated(CollectionId, TokenId),500 ItemCreated(CollectionId, TokenId, AccountId),499501500 /// Collection item was burned.502 /// Collection item was burned.501 /// 503 /// 506 /// item_id: Identifier of burned NFT.508 /// item_id: Identifier of burned NFT.507 ItemDestroyed(CollectionId, TokenId),509 ItemDestroyed(CollectionId, TokenId),510511 /// Item was transferred512 ///513 /// * collection_id: Id of collection to which item is belong514 ///515 /// * item_id: Id of an item516 ///517 /// * sender: Original owner of item518 ///519 /// * recipient: New owner of item520 ///521 /// * amount: Always 1 for NFT522 Transfer(CollectionId, TokenId, AccountId, AccountId, u128),508 }523 }509);524);510525155615711557 match target_collection.mode1572 match target_collection.mode1558 {1573 {1559 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())?,1560 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,1575 CollectionMode::Fungible(_) => Self::transfer_fungible(collection_id, value, &sender, &recipient)?,1561 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())?,1562 _ => ()1577 _ => ()1563 };1578 };15791580 Self::deposit_event(RawEvent::Transfer(collection_id, item_id, sender, recipient, value));156415811565 Ok(())1582 Ok(())1566 }1583 }1635 {1652 {1636 CreateItemData::NFT(data) => {1653 CreateItemData::NFT(data) => {1637 let item = NftItemType {1654 let item = NftItemType {1638 owner,1655 owner: owner.clone(),1639 const_data: data.const_data,1656 const_data: data.const_data,1640 variable_data: data.variable_data1657 variable_data: data.variable_data1641 };1658 };1660 };1677 };166116781662 // call event1679 // call event1663 Self::deposit_event(RawEvent::ItemCreated(collection_id, <ItemListIndex>::get(collection_id)));1680 Self::deposit_event(RawEvent::ItemCreated(collection_id, <ItemListIndex>::get(collection_id), owner));166416811665 Ok(())1682 Ok(())1666 }1683 }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.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;