git.delta.rocks / unique-network / refs/commits / dd8998750d8f

difftreelog

Apply suggestions from code review

Yaroslav Bolyukin2022-07-22parent: #94da15a.patch.diff
in: master

7 files changed

modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -364,7 +364,7 @@
 
 	/// Returns 10 tokens owners in no particular order.
 	fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {
-		<Pallet<T>>::token_owners(self.id, token).unwrap_or_else(|| vec![])
+		<Pallet<T>>::token_owners(self.id, token).unwrap_or_default()
 	}
 
 	fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -629,7 +629,7 @@
 			.take(10)
 			.collect();
 
-		if res.len() == 0 {
+		if res.is_empty() {
 			None
 		} else {
 			Some(res)
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -440,7 +440,7 @@
 
 	/// Returns 10 token in no particular order.
 	fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {
-		<Pallet<T>>::token_owners(self.id, token).unwrap_or_else(|| vec![])
+		<Pallet<T>>::token_owners(self.id, token).unwrap_or_default()
 	}
 
 	fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -1150,7 +1150,7 @@
 			.take(10)
 			.collect();
 
-		if res.len() == 0 {
+		if res.is_empty() {
 			None
 		} else {
 			Some(res)
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -81,6 +81,6 @@
 		fn next_sponsored(collection: CollectionId, account: CrossAccountId, token: TokenId) -> Result<Option<u64>>;
 		fn effective_collection_limits(collection_id: CollectionId) -> Result<Option<CollectionLimits>>;
 		fn total_pieces(collection_id: CollectionId, token_id: TokenId) -> Result<Option<u128>>;
-		fn token_owners(collection: CollectionId, token: TokenId) -> Result<Vec::<CrossAccountId>>;
+		fn token_owners(collection: CollectionId, token: TokenId) -> Result<Vec<CrossAccountId>>;
 	}
 }
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -100,7 +100,7 @@
       // What to expect
       // tslint:disable-next-line:no-unused-expression
       expect(ids).to.deep.include.members([aliceID, ethAcc, bobId, ...facelessCrowd]);
-      expect(owners.length == 10).to.be.true;
+      expect(owners.length).to.be.equal(10);
       
       const eleven = privateKeyWrapper('11');
       expect(await transfer(api, collectionId, aliceTokenId, alice, eleven, 10n)).to.be.true;
modifiedtests/src/rpc.test.tsdiffbeforeafterboth
before · tests/src/rpc.test.ts
1import {IKeyringPair} from '@polkadot/types/types';2import {expect} from 'chai';3import usingApi from './substrate/substrate-api';4import {createCollection, createCollectionExpectSuccess, createFungibleItemExpectSuccess, CrossAccountId, getTokenOwner, normalizeAccountId, transfer, U128_MAX} from './util/helpers';56let alice: IKeyringPair;7let bob: IKeyringPair;8910describe('integration test: RPC methods', () => {11  before(async () => {12    await usingApi(async (api, privateKeyWrapper) => {13      alice = privateKeyWrapper('//Alice');14      bob = privateKeyWrapper('//Bob');15    });16  });1718  19  it('returns None for fungible collection', async () => {20    await usingApi(async api => {21      const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});22      await expect(getTokenOwner(api, collection, 0)).to.be.rejectedWith(/^owner == null$/);23    });24  });25  26  it('RPC method tokenOnewrs for fungible collection and token', async () => {27    await usingApi(async (api, privateKeyWrapper) => {28      const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};29      const facelessCrowd = Array.from(Array(7).keys()).map(i => normalizeAccountId(privateKeyWrapper(i.toString())));30      31      const createCollectionResult = await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}});32      const collectionId = createCollectionResult.collectionId;33      const aliceTokenId = await createFungibleItemExpectSuccess(alice, collectionId, {Value: U128_MAX}, alice.address);34     35      await transfer(api, collectionId, aliceTokenId, alice, bob, 1000n);36      await transfer(api, collectionId, aliceTokenId, alice, ethAcc, 900n);37            38      for (let i = 0; i < 7; i++) {39        await transfer(api, collectionId, aliceTokenId, alice, facelessCrowd[i], 1);40      } 41      42      const owners = await api.rpc.unique.tokenOwners(collectionId, aliceTokenId);43      const ids = (owners.toJSON() as CrossAccountId[]).map(s => normalizeAccountId(s));44      const aliceID = normalizeAccountId(alice);45      const bobId = normalizeAccountId(bob);4647      // What to expect48      // tslint:disable-next-line:no-unused-expression49      expect(ids).to.deep.include.members([aliceID, ethAcc, bobId, ...facelessCrowd]);50      expect(owners.length == 10).to.be.true;51      52      const eleven = privateKeyWrapper('11');53      expect(await transfer(api, collectionId, aliceTokenId, alice, eleven, 10n)).to.be.true;54      expect((await api.rpc.unique.tokenOwners(collectionId, aliceTokenId)).length).to.be.equal(10);55    });56  });57});