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

difftreelog

Merge pull request #479 from UniqueNetwork/feature/playgrounds

Yaroslav Bolyukin2022-08-12parents: #dcc6bc0 #f1fa9f2.patch.diff
in: master
Feature/playgrounds

5 files changed

modifiedtests/src/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/fungible.test.ts
+++ b/tests/src/fungible.test.ts
@@ -14,25 +14,10 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-import {default as usingApi} from './substrate/substrate-api';
 import {IKeyringPair} from '@polkadot/types/types';
-import {
-  getBalance,
-  createMultipleItemsExpectSuccess,
-  isTokenExists,
-  getLastTokenId,
-  getAllowance,
-  approve,
-  transferFrom,
-  createCollection,
-  transfer,
-  burnItem,
-  normalizeAccountId,
-  CrossAccountId,
-  createFungibleItemExpectSuccess,
-  U128_MAX,
-  burnFromExpectSuccess,
-} from './util/helpers';
+import {U128_MAX} from './util/helpers';
+
+import {usingPlaygrounds} from './util/playgrounds';
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
@@ -44,141 +29,137 @@
 
 describe('integration test: Fungible functionality:', () => {
   before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-      bob = privateKeyWrapper('//Bob');
+    await usingPlaygrounds(async (helper, privateKey) => {
+      alice = privateKey('//Alice');
+      bob = privateKey('//Bob');
     });
   });
 
   it('Create fungible collection and token', async () => {
-    await usingApi(async api => {
-      const createCollectionResult = await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}});
-      expect(createCollectionResult.success).to.be.true;
-      const collectionId  = createCollectionResult.collectionId;
-      const defaultTokenId = await getLastTokenId(api, collectionId);
-      const aliceTokenId = await createFungibleItemExpectSuccess(alice, collectionId, {Value: U128_MAX}, alice.address);
-      const aliceBalance = await getBalance(api, collectionId, alice, aliceTokenId); 
-      const itemCountAfter = await getLastTokenId(api, collectionId);
-      
-      // What to expect
-      // tslint:disable-next-line:no-unused-expression
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'trest'});
+      const defaultTokenId = await collection.getLastTokenId();
+      expect(defaultTokenId).to.be.equal(0);
+
+      await collection.mint(alice, {Substrate: alice.address}, U128_MAX);
+      const aliceBalance = await collection.getBalance({Substrate: alice.address});
+      const itemCountAfter = await collection.getLastTokenId();
+
       expect(itemCountAfter).to.be.equal(defaultTokenId);
       expect(aliceBalance).to.be.equal(U128_MAX);
     });
   });
   
   it('RPC method tokenOnewrs for fungible collection and token', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
+    await usingPlaygrounds(async (helper, privateKey) => {
       const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};
-      const facelessCrowd = Array.from(Array(7).keys()).map(i => normalizeAccountId(privateKeyWrapper(i.toString())));
+      const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));
+
+      const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+
+      await collection.mint(alice, {Substrate: alice.address}, U128_MAX);
+
+      await collection.transfer(alice, {Substrate: bob.address}, 1000n);
+      await collection.transfer(alice, ethAcc, 900n);
       
-      const createCollectionResult = await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}});
-      const collectionId = createCollectionResult.collectionId;
-      const aliceTokenId = await createFungibleItemExpectSuccess(alice, collectionId, {Value: U128_MAX}, alice.address);
-     
-      await transfer(api, collectionId, aliceTokenId, alice, bob, 1000n);
-      await transfer(api, collectionId, aliceTokenId, alice, ethAcc, 900n);
-            
       for (let i = 0; i < 7; i++) {
-        await transfer(api, collectionId, aliceTokenId, alice, facelessCrowd[i], 1);
+        await collection.transfer(alice, facelessCrowd[i], 1n);
       } 
-      
-      const owners = await api.rpc.unique.tokenOwners(collectionId, aliceTokenId);
-      const ids = (owners.toJSON() as CrossAccountId[]).map(s => normalizeAccountId(s));
-      const aliceID = normalizeAccountId(alice);
-      const bobId = normalizeAccountId(bob);
 
+      const owners = await collection.getTop10Owners();
+
       // 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).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);
+      expect(owners.length).to.be.equal(10);
       
-      const eleven = privateKeyWrapper('11');
-      expect(await transfer(api, collectionId, aliceTokenId, alice, eleven, 10n)).to.be.true;
-      expect((await api.rpc.unique.tokenOwners(collectionId, aliceTokenId)).length).to.be.equal(10);
+      const eleven = privateKey('//ALice+11');
+      expect(await collection.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;
+      expect((await collection.getTop10Owners()).length).to.be.equal(10);
     });
   });
   
   it('Transfer token', async () => {
-    await usingApi(async api => {
+    await usingPlaygrounds(async helper => {
       const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}})).collectionId;
-      const tokenId = await createFungibleItemExpectSuccess(alice, collectionId, {Value: 500n}, alice.address);
+      const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      await collection.mint(alice, {Substrate: alice.address}, 500n);
 
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(500n);
-      expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;
-      expect(await transfer(api, collectionId, tokenId, alice, ethAcc, 140n)).to.be.true;
+      expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);
+      expect(await collection.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
+      expect(await collection.transfer(alice, ethAcc, 140n)).to.be.true;
 
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(300n);
-      expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);
-      expect(await getBalance(api, collectionId, ethAcc, tokenId)).to.be.equal(140n);
-      await expect(transfer(api, collectionId, tokenId, alice, bob, 350n)).to.eventually.be.rejected;
+      expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(300n);
+      expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(60n);
+      expect(await collection.getBalance(ethAcc)).to.be.equal(140n);
+
+      await expect(collection.transfer(alice, {Substrate: bob.address}, 350n)).to.eventually.be.rejected;
     });
   });
 
   it('Tokens multiple creation', async () => {
-    await usingApi(async api => {
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}})).collectionId;
-      
-      const args = [
-        {Fungible: {Value: 500n}},
-        {Fungible: {Value: 400n}},
-        {Fungible: {Value: 300n}},
-      ];
-      
-      await createMultipleItemsExpectSuccess(alice, collectionId, args);
-      expect(await getBalance(api, collectionId, alice, 0)).to.be.equal(1200n);
-    });   
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+
+      await collection.mintWithOneOwner(alice, {Substrate: alice.address}, [
+        {value: 500n},
+        {value: 400n},
+        {value: 300n},
+      ]);
+
+      expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1200n);
+    });
   });
 
   it('Burn some tokens ', async () => {
-    await usingApi(async api => {   
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}})).collectionId;
-      const tokenId = (await createFungibleItemExpectSuccess(alice, collectionId, {Value: 500n}, alice.address));
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(500n);
-      expect(await burnItem(api, alice, collectionId, tokenId, 499n)).to.be.true;
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(1n);
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      await collection.mint(alice, {Substrate: alice.address}, 500n);
+
+      expect(await collection.isTokenExists(0)).to.be.true;
+      expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(500n);
+      expect(await collection.burnTokens(alice, 499n)).to.be.true;
+      expect(await collection.isTokenExists(0)).to.be.true;
+      expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(1n);
     });
   });
   
   it('Burn all tokens ', async () => {
-    await usingApi(async api => {   
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}})).collectionId;
-      const tokenId = (await createFungibleItemExpectSuccess(alice, collectionId, {Value: 500n}, alice.address));
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
-      expect(await burnItem(api, alice, collectionId, tokenId, 500n)).to.be.true;
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
-      
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);
-      expect((await api.rpc.unique.totalPieces(collectionId, tokenId)).value.toBigInt()).to.be.equal(0n);
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      await collection.mint(alice, {Substrate: alice.address}, 500n);
+
+      expect(await collection.isTokenExists(0)).to.be.true;
+      expect(await collection.burnTokens(alice, 500n)).to.be.true;
+      expect(await collection.isTokenExists(0)).to.be.true;
+
+      expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(0n);
+      expect(await collection.getTotalPieces()).to.be.equal(0n);
     });
   });
 
   it('Set allowance for token', async () => {
-    await usingApi(async api => {
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'Fungible', decimalPoints: 0}})).collectionId;
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
       const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};
+      await collection.mint(alice, {Substrate: alice.address}, 100n);
+
+      expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(100n);
       
-      const tokenId = (await createFungibleItemExpectSuccess(alice, collectionId, {Value: 100n}, alice.address));
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);
+      expect(await collection.approveTokens(alice, {Substrate: bob.address}, 60n)).to.be.true;
+      expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);
+      expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(0n);
+
+      expect(await collection.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;
+      expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(80n);
+      expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(20n);
+      expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);
 
-      expect(await approve(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;
-      expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(60n);
-      expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(0n);
-      
-      expect(await transferFrom(api, collectionId, tokenId, bob, alice, bob,  20n)).to.be.true;
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(80n);
-      expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(20n);
-      expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(40n);
-      
-      await burnFromExpectSuccess(bob, alice, collectionId, tokenId, 10n);
-     
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(70n);
-      expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(30n);
-      expect(await transferFrom(api, collectionId, tokenId, bob, alice, ethAcc,  10n)).to.be.true;
-      expect(await getBalance(api, collectionId, ethAcc, tokenId)).to.be.equal(10n);
+      await collection.burnTokensFrom(bob, {Substrate: alice.address}, 10n);
+
+      expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(70n);
+      expect(await collection.getApprovedTokens({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(30n);
+      expect(await collection.transferFrom(bob, {Substrate: alice.address}, ethAcc, 10n)).to.be.true;
+      expect(await collection.getBalance(ethAcc)).to.be.equal(10n);
     });
   });
 });
modifiedtests/src/refungible.test.tsdiffbeforeafterboth
--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -14,28 +14,10 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-import {default as usingApi, submitTransactionAsync} from './substrate/substrate-api';
 import {IKeyringPair} from '@polkadot/types/types';
+
+import { usingPlaygrounds } from './util/playgrounds';
 import {
-  createCollectionExpectSuccess,
-  getBalance,
-  createMultipleItemsExpectSuccess,
-  isTokenExists,
-  getLastTokenId,
-  getAllowance,
-  approve,
-  transferFrom,
-  createCollection,
-  createRefungibleToken,
-  transfer,
-  burnItem,
-  repartitionRFT,
-  createCollectionWithPropsExpectSuccess,
-  getDetailedCollectionInfo,
-  normalizeAccountId,
-  CrossAccountId,
-  getCreateItemsResult,
-  getDestroyItemsResult,
   getModuleNames,
   Pallets,
   requirePallets,
@@ -49,246 +31,240 @@
 let alice: IKeyringPair;
 let bob: IKeyringPair;
 
-
-
 describe('integration test: Refungible functionality:', async () => {
   before(async function() {
     await requirePallets(this, [Pallets.ReFungible]);
 
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-      bob = privateKeyWrapper('//Bob');
-      if (!getModuleNames(api).includes(Pallets.ReFungible)) this.skip();
+    await usingPlaygrounds(async (helper, privateKey) => {
+      alice = privateKey('//Alice');
+      bob = privateKey('//Bob');
+      if (!getModuleNames(helper.api!).includes(Pallets.ReFungible)) this.skip();
     });
-    
   });
   
   it('Create refungible collection and token', async () => {
-    await usingApi(async api => {
-      const createCollectionResult = await createCollection(api, alice, {mode: {type: 'ReFungible'}});
-      expect(createCollectionResult.success).to.be.true;
-      const collectionId  = createCollectionResult.collectionId;
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+
+      const itemCountBefore = await collection.getLastTokenId();
+      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);
       
-      const itemCountBefore = await getLastTokenId(api, collectionId);
-      const result = await createRefungibleToken(api, alice, collectionId, 100n);
-      
-      const itemCountAfter = await getLastTokenId(api, collectionId);
+      const itemCountAfter = await collection.getLastTokenId();
       
       // What to expect
-      // tslint:disable-next-line:no-unused-expression
-      expect(result.success).to.be.true;
+      expect(token?.tokenId).to.be.gte(itemCountBefore);
       expect(itemCountAfter).to.be.equal(itemCountBefore + 1);
-      expect(collectionId).to.be.equal(result.collectionId);
-      expect(itemCountAfter.toString()).to.be.equal(result.itemId.toString());
+      expect(itemCountAfter.toString()).to.be.equal(token?.tokenId.toString());
     });
   });
   
   it('RPC method tokenOnewrs for refungible collection and token', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
+    await usingPlaygrounds(async (helper, privateKey) => {
       const ethAcc = {Ethereum: '0x67fb3503a61b284dc83fa96dceec4192db47dc7c'};
-      const facelessCrowd = Array.from(Array(7).keys()).map(i => normalizeAccountId(privateKeyWrapper(i.toString())));
-      
-      const createCollectionResult = await createCollection(api, alice, {mode: {type: 'ReFungible'}});
-      const collectionId = createCollectionResult.collectionId;
-      
-      const result = await createRefungibleToken(api, alice, collectionId, 10_000n);
-      const aliceTokenId = result.itemId;
-      
+      const facelessCrowd = Array(7).fill(0).map((_, i) => ({Substrate: privateKey(`//Alice+${i}`).address}));
+
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+
+      const token = await collection.mintToken(alice, {Substrate: alice.address}, 10_000n);
+
+      await token.transfer(alice, {Substrate: bob.address}, 1000n);
+      await token.transfer(alice, ethAcc, 900n);
       
-      await transfer(api, collectionId, aliceTokenId, alice, bob, 1000n);
-      await transfer(api, collectionId, aliceTokenId, alice, ethAcc, 900n);
-      
       for (let i = 0; i < 7; i++) {
-        await transfer(api, collectionId, aliceTokenId, alice, facelessCrowd[i], 50*(i+1));
+        await token.transfer(alice, facelessCrowd[i], 50n * BigInt(i + 1));
       } 
-      
-      const owners = await api.rpc.unique.tokenOwners(collectionId, aliceTokenId);
-      const ids = (owners.toJSON() as CrossAccountId[]).map(s => normalizeAccountId(s));
-      
-      const aliceID = normalizeAccountId(alice);
-      const bobId = normalizeAccountId(bob);
-      
+
+      const owners = await token.getTop10Owners();
+
       // What to expect
-      // tslint:disable-next-line:no-unused-expression
-      expect(ids).to.deep.include.members([aliceID, ethAcc, bobId, ...facelessCrowd]);
+      expect(owners).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);
       expect(owners.length).to.be.equal(10);
       
-      const eleven = privateKeyWrapper('11');
-      expect(await transfer(api, collectionId, aliceTokenId, alice, eleven, 10n)).to.be.true;
-      expect((await api.rpc.unique.tokenOwners(collectionId, aliceTokenId)).length).to.be.equal(10);
+      const eleven = privateKey('//ALice+11');
+      expect(await token.transfer(alice, {Substrate: eleven.address}, 10n)).to.be.true;
+      expect((await token.getTop10Owners()).length).to.be.equal(10);
     });
   });
   
   it('Transfer token pieces', async () => {
-    await usingApi(async api => {
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
-      const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);
 
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);
-      expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;
-
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(40n);
-      expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);
-      await expect(transfer(api, collectionId, tokenId, alice, bob, 41n)).to.eventually.be.rejected;
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+      expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
+      
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
+      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
+      
+      await expect(token.transfer(alice, {Substrate: bob.address}, 41n)).to.eventually.be.rejected;
     });
   });
 
   it('Create multiple tokens', async () => {
-    const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
-    const args = [
-      {ReFungible: {pieces: 1}},
-      {ReFungible: {pieces: 2}},
-      {ReFungible: {pieces: 100}},
-    ];
-    await createMultipleItemsExpectSuccess(alice, collectionId, args);
-
-    await usingApi(async api => {      
-      const tokenId = await getLastTokenId(api, collectionId);
-      expect(tokenId).to.be.equal(3);
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      // TODO: fix mintMultipleTokens
+      // await collection.mintMultipleTokens(alice, [
+      //   {owner: {Substrate: alice.address}, pieces: 1n},
+      //   {owner: {Substrate: alice.address}, pieces: 2n},
+      //   {owner: {Substrate: alice.address}, pieces: 100n},
+      // ]);
+      await helper.rft.mintMultipleTokensWithOneOwner(alice, collection.collectionId, {Substrate: alice.address}, [
+        {pieces: 1n}, 
+        {pieces: 2n}, 
+        {pieces: 100n},
+      ]);
+      const lastTokenId = await collection.getLastTokenId();
+      expect(lastTokenId).to.be.equal(3);
+      expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);
     });
   });
 
   it('Burn some pieces', async () => {
-    await usingApi(async api => {   
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
-      const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);
-      expect(await burnItem(api, alice, collectionId, tokenId, 99n)).to.be.true;
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(1n);
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);
+      expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+      expect((await token.burn(alice, 99n)).success).to.be.true;
+      expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
     });
   });
 
   it('Burn all pieces', async () => {
-    await usingApi(async api => {   
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
-      const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);
-      expect(await burnItem(api, alice, collectionId, tokenId, 100n)).to.be.true;
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
+    await usingPlaygrounds(async helper => {   
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);
+      
+      expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+
+      expect((await token.burn(alice, 100n)).success).to.be.true;
+      expect(await collection.isTokenExists(token.tokenId)).to.be.false;
     });
   });
 
   it('Burn some pieces for multiple users', async () => {
-    await usingApi(async api => {   
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
-      const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);
+
+      expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+      
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+      expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
+
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
+      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
+
+      expect((await token.burn(alice, 40n)).success).to.be.true;
 
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);
-      expect(await transfer(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;
+      expect(await collection.isTokenExists(token.tokenId)).to.be.true;
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
+
+      expect((await token.burn(bob, 59n)).success).to.be.true;
 
-      
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(40n);
-      expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(60n);
-      expect(await burnItem(api, alice, collectionId, tokenId, 40n)).to.be.true;
+      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
+      expect(await collection.isTokenExists(token.tokenId)).to.be.true;
 
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
-      expect(await burnItem(api, bob, collectionId, tokenId, 59n)).to.be.true;
+      expect((await token.burn(bob, 1n)).success).to.be.true;
 
-      expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(1n);
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.true;
-      expect(await burnItem(api, bob, collectionId, tokenId, 1n)).to.be.true;
-      
-      expect(await isTokenExists(api, collectionId, tokenId)).to.be.false;
+      expect(await collection.isTokenExists(token.tokenId)).to.be.false;
     });
   });
 
   it('Set allowance for token', async () => {
-    await usingApi(async api => {
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
-      const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);
+      
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
 
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(100n);
+      expect(await token.approve(alice, {Substrate: bob.address}, 60n)).to.be.true;
+      expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(60n);
 
-      expect(await approve(api, collectionId, tokenId, alice, bob, 60n)).to.be.true;
-      expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(60n);
-
-      expect(await transferFrom(api, collectionId, tokenId, bob, alice, bob,  20n)).to.be.true;
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(80n);
-      expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(20n);
-      expect(await getAllowance(api, collectionId, alice, bob, tokenId)).to.be.equal(40n);
+      expect(await token.transferFrom(bob, {Substrate: alice.address}, {Substrate: bob.address}, 20n)).to.be.true;
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(80n);
+      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(20n);
+      expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);
     });
   });
 
   it('Repartition', async () => {
-    await usingApi(async api => {
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
-      const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);
 
-      expect(await repartitionRFT(api, collectionId, alice, tokenId, 200n)).to.be.true;
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(200n);
-
-      expect(await transfer(api, collectionId, tokenId, alice, bob, 110n)).to.be.true;
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(90n);
-      expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(110n);
-
-      await expect(repartitionRFT(api, collectionId, alice, tokenId, 80n)).to.eventually.be.rejected;
+      expect(await token.repartition(alice, 200n)).to.be.true;
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);
+      expect(await token.getTotalPieces()).to.be.equal(200n);
+      
+      expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);
+      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);
+      
+      await expect(token.repartition(alice, 80n)).to.eventually.be.rejected;
+      
+      expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;
+      expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
+      expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);
 
-      expect(await transfer(api, collectionId, tokenId, alice, bob, 90n)).to.be.true;
-      expect(await getBalance(api, collectionId, alice, tokenId)).to.be.equal(0n);
-      expect(await getBalance(api, collectionId, bob, tokenId)).to.be.equal(200n);
+      expect(await token.repartition(bob, 150n)).to.be.true;
+      await expect(token.transfer(bob, {Substrate: alice.address}, 160n)).to.eventually.be.rejected;
 
-      expect(await repartitionRFT(api, collectionId, bob, tokenId, 150n)).to.be.true;
-      await expect(transfer(api, collectionId, tokenId, bob, alice, 160n)).to.eventually.be.rejected;
     });
   });
 
   it('Repartition with increased amount', async () => {
-    await usingApi(async api => {
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
-      const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;
-
-      const tx = api.tx.unique.repartition(collectionId, tokenId, 200n);
-      const events = await submitTransactionAsync(alice, tx);
-      const substrateEvents = getCreateItemsResult(events);
-      expect(substrateEvents).to.include.deep.members([
-        {
-          success: true,
-          collectionId,
-          itemId: tokenId,
-          recipient: {Substrate: alice.address},
-          amount: 100,
-        },
-      ]);
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);
+      await token.repartition(alice, 200n);
+      const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);
+      expect(chainEvents).to.include.deep.members([{
+        method: 'ItemCreated',
+        section: 'common',
+        index: '0x4202',
+        data: [ 
+          collection.collectionId.toString(), 
+          token.tokenId.toString(), 
+          {Substrate: alice.address}, 
+          '100',
+        ],
+      }]);
     });
   });
 
   it('Repartition with decreased amount', async () => {
-    await usingApi(async api => {
-      const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
-      const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n)).itemId;
-
-      const tx = api.tx.unique.repartition(collectionId, tokenId, 50n);
-      const events = await submitTransactionAsync(alice, tx);
-      const substrateEvents = getDestroyItemsResult(events);
-      expect(substrateEvents).to.include.deep.members([
-        {
-          success: true,
-          collectionId,
-          itemId: tokenId,
-          owner: {Substrate: alice.address},
-          amount: 50,
-        },
-      ]);
+    await usingPlaygrounds(async helper => {
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      const token = await collection.mintToken(alice, {Substrate: alice.address}, 100n);
+      await token.repartition(alice, 50n);
+      const chainEvents = helper.chainLog.slice(-1)[0].events.map((x: any) => x.event);
+      expect(chainEvents).to.include.deep.members([{
+        method: 'ItemDestroyed',
+        section: 'common',
+        index: '0x4203',
+        data: [ 
+          collection.collectionId.toString(), 
+          token.tokenId.toString(), 
+          {Substrate: alice.address}, 
+          '50',
+        ],
+      }]);
     });
   });
   
-  it('Сreate new collection with properties', async () => {
-    await usingApi(async api => {
+  it('Create new collection with properties', async () => {
+    await usingPlaygrounds(async helper => {
       const properties = [{key: 'key1', value: 'val1'}];
-      const propertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];
-      const collectionId = await createCollectionWithPropsExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'ReFungible'},
-        properties: properties,
-        propPerm: propertyPermissions, 
-      });
-      const collection = (await getDetailedCollectionInfo(api, collectionId))!;
-      expect(collection.properties.toHuman()).to.be.deep.equal(properties);
-      expect(collection.tokenPropertyPermissions.toHuman()).to.be.deep.equal(propertyPermissions);
+      const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];
+      const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test', properties, tokenPropertyPermissions});
+      const info = await collection.getData();
+      expect(info?.raw.properties).to.be.deep.equal(properties);
+      expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);
     });
   });
 });
modifiedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth
--- a/tests/src/removeCollectionAdmin.test.ts
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -16,123 +16,112 @@
 
 import chai from 'chai';
 import chaiAsPromised from 'chai-as-promised';
-import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
-import {createCollectionExpectSuccess, destroyCollectionExpectSuccess, getAdminList, normalizeAccountId, queryCollectionExpectSuccess} from './util/helpers';
+import {usingPlaygrounds} from './util/playgrounds';
 
 chai.use(chaiAsPromised);
 const expect = chai.expect;
 
 describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
   it('Remove collection admin.', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      const collectionId = await createCollectionExpectSuccess();
-      const alice = privateKeyWrapper('//Alice');
-      const bob = privateKeyWrapper('//Bob');
-      const collection = await queryCollectionExpectSuccess(api, collectionId);
-      expect(collection.owner.toString()).to.be.deep.eq(alice.address);
+    await usingPlaygrounds(async (helper, privateKey) => {
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
+      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      const collectionInfo = await collection.getData();
+      expect(collectionInfo?.raw.owner.toString()).to.be.deep.eq(alice.address);
       // first - add collection admin Bob
-      const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
-      await submitTransactionAsync(alice, addAdminTx);
+      await collection.addAdmin(alice, {Substrate: bob.address});
 
-      const adminListAfterAddAdmin = await getAdminList(api, collectionId);
-      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
+      const adminListAfterAddAdmin = await collection.getAdmins();
+      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});
 
       // then remove bob from admins of collection
-      const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
-      await submitTransactionAsync(alice, removeAdminTx);
+      await collection.removeAdmin(alice, {Substrate: bob.address});
 
-      const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);
-      expect(adminListAfterRemoveAdmin).not.to.be.deep.contains(normalizeAccountId(bob.address));
+      const adminListAfterRemoveAdmin = await collection.getAdmins();
+      expect(adminListAfterRemoveAdmin).not.to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});
     });
   });
 
   it('Remove admin from collection that has no admins', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      const alice = privateKeyWrapper('//Alice');
-      const collectionId = await createCollectionExpectSuccess();
+    await usingPlaygrounds(async (helper, privateKey) => {
+      const alice = privateKey('//Alice');
+      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
 
-      const adminListBeforeAddAdmin = await getAdminList(api, collectionId);
+      const adminListBeforeAddAdmin = await collection.getAdmins();
       expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
 
-      const tx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(alice.address));
-      await submitTransactionAsync(alice, tx);
+      // await expect(collection.removeAdmin(alice, {Substrate: alice.address})).to.be.rejectedWith('Unable to remove collection admin');
+      await collection.removeAdmin(alice, {Substrate: alice.address});
     });
   });
 });
 
 describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
   it('Can\'t remove collection admin from not existing collection', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
+    await usingPlaygrounds(async (helper, privateKey) => {
       // tslint:disable-next-line: no-bitwise
       const collectionId = (1 << 32) - 1;
-      const alice = privateKeyWrapper('//Alice');
-      const bob = privateKeyWrapper('//Bob');
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
 
-      const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
-      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
+      await expect(helper.collection.removeAdmin(alice, collectionId, {Substrate: bob.address})).to.be.rejected;
 
       // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
-      await createCollectionExpectSuccess();
+      await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
     });
   });
 
   it('Can\'t remove collection admin from deleted collection', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      // tslint:disable-next-line: no-bitwise
-      const collectionId = await createCollectionExpectSuccess();
-      const alice = privateKeyWrapper('//Alice');
-      const bob = privateKeyWrapper('//Bob');
+    await usingPlaygrounds(async (helper, privateKey) => {
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
+      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
 
-      await destroyCollectionExpectSuccess(collectionId);
+      expect(await collection.burn(alice)).to.be.true;
 
-      const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
-      await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
+      await expect(helper.collection.removeAdmin(alice, collection.collectionId, {Substrate: bob.address})).to.be.rejected;
 
       // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
-      await createCollectionExpectSuccess();
+      await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
     });
   });
 
   it('Regular user can\'t remove collection admin', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      const collectionId = await createCollectionExpectSuccess();
-      const alice = privateKeyWrapper('//Alice');
-      const bob = privateKeyWrapper('//Bob');
-      const charlie = privateKeyWrapper('//Charlie');
+    await usingPlaygrounds(async (helper, privateKey) => {
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
+      const charlie = privateKey('//Charlie');
+      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
 
-      const addAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
-      await submitTransactionAsync(alice, addAdminTx);
+      await collection.addAdmin(alice, {Substrate: bob.address});
 
-      const changeOwnerTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
-      await expect(submitTransactionExpectFailAsync(charlie, changeOwnerTx)).to.be.rejected;
+      await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;
 
       // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
-      await createCollectionExpectSuccess();
+      await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
     });
   });
 
   it('Admin can\'t remove collection admin.', async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      const collectionId = await createCollectionExpectSuccess();
-      const alice = privateKeyWrapper('//Alice');
-      const bob = privateKeyWrapper('//Bob');
-      const charlie = privateKeyWrapper('//Charlie');
-
-      const addBobAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(bob.address));
-      await submitTransactionAsync(alice, addBobAdminTx);
-      const addCharlieAdminTx = api.tx.unique.addCollectionAdmin(collectionId, normalizeAccountId(charlie.address));
-      await submitTransactionAsync(alice, addCharlieAdminTx);
+    await usingPlaygrounds(async (helper, privateKey) => {
+      const alice = privateKey('//Alice');
+      const bob = privateKey('//Bob');
+      const charlie = privateKey('//Charlie');
+      const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+      
+      await collection.addAdmin(alice, {Substrate: bob.address});
+      await collection.addAdmin(alice, {Substrate: charlie.address});
 
-      const adminListAfterAddAdmin = await getAdminList(api, collectionId);
-      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
-      expect(adminListAfterAddAdmin).to.be.deep.contains(normalizeAccountId(charlie.address));
+      const adminListAfterAddAdmin = await collection.getAdmins();
+      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});
+      expect(adminListAfterAddAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});
 
-      const removeAdminTx = api.tx.unique.removeCollectionAdmin(collectionId, normalizeAccountId(bob.address));
-      await expect(submitTransactionExpectFailAsync(charlie, removeAdminTx)).to.be.rejected;
+      await expect(collection.removeAdmin(charlie, {Substrate: bob.address})).to.be.rejected;
 
-      const adminListAfterRemoveAdmin = await getAdminList(api, collectionId);
-      expect(adminListAfterRemoveAdmin).to.be.deep.contains(normalizeAccountId(bob.address));
-      expect(adminListAfterRemoveAdmin).to.be.deep.contains(normalizeAccountId(charlie.address));
+      const adminListAfterRemoveAdmin = await collection.getAdmins();
+      expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(bob.address)});
+      expect(adminListAfterRemoveAdmin).to.be.deep.contains({Substrate: helper.address.normalizeSubstrate(charlie.address)});
     });
   });
 });
addedtests/src/util/playgrounds/index.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/util/playgrounds/index.ts
@@ -0,0 +1,93 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// SPDX-License-Identifier: Apache-2.0
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {UniqueHelper} from './unique';
+import config from '../../config';
+import '../../interfaces/augment-api-events';
+import * as defs from '../../interfaces/definitions';
+import {ApiPromise, WsProvider} from '@polkadot/api';
+
+
+class SilentLogger {
+  log(msg: any, level: any): void {}
+  level = {
+    ERROR: 'ERROR' as const,
+    WARNING: 'WARNING' as const,
+    INFO: 'INFO' as const,
+  };
+}
+
+
+class DevUniqueHelper extends UniqueHelper {
+  async connect(wsEndpoint: string, listeners?: any): Promise<void> {
+    const wsProvider = new WsProvider(wsEndpoint);
+    this.api = new ApiPromise({
+      provider: wsProvider, 
+      signedExtensions: {
+        ContractHelpers: {
+          extrinsic: {},
+          payload: {},
+        },
+        FakeTransactionFinalizer: {
+          extrinsic: {},
+          payload: {},
+        },
+      },
+      rpc: {
+        unique: defs.unique.rpc,
+        rmrk: defs.rmrk.rpc,
+        eth: {
+          feeHistory: {
+            description: 'Dummy',
+            params: [],
+            type: 'u8',
+          },
+          maxPriorityFeePerGas: {
+            description: 'Dummy',
+            params: [],
+            type: 'u8',
+          },
+        },
+      },
+    });
+    await this.api.isReadyOrError;
+    this.network = await UniqueHelper.detectNetwork(this.api);
+  }
+}
+
+export const usingPlaygrounds = async (code: (helper: UniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {
+  // TODO: Remove, this is temporary: Filter unneeded API output
+  // (Jaco promised it will be removed in the next version)
+  const consoleErr = console.error;
+  const consoleLog = console.log;
+  const consoleWarn = console.warn;
+
+  const outFn = (printer: any) => (...args: any[]) => {
+    for (const arg of args) {
+      if (typeof arg !== 'string')
+        continue;
+      if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))
+        return;
+    }
+    printer(...args);
+  };
+
+  console.error = outFn(consoleErr.bind(console));
+  console.log = outFn(consoleLog.bind(console));
+  console.warn = outFn(consoleWarn.bind(console));
+  const helper = new DevUniqueHelper(new SilentLogger());
+
+  try {
+    await helper.connect(config.substrateUrl);
+    const ss58Format = helper.chain.getChainProperties().ss58Format;
+    const privateKey = (seed: string) => helper.util.fromSeed(seed, ss58Format);
+    await code(helper, privateKey);
+  } 
+  finally {
+    await helper.disconnect();
+    console.error = consoleErr;
+    console.log = consoleLog;
+    console.warn = consoleWarn;
+  }
+};
\ No newline at end of file
addedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth

no changes