git.delta.rocks / unique-network / refs/commits / 6f234a4dd6c2

difftreelog

test get rid of AccountId::default

Yaroslav Bolyukin2022-04-08parent: #7e32db5.patch.diff
in: master

5 files changed

modifiedtests/src/interfaces/augment-api-rpc.tsdiffbeforeafterboth
633 /**633 /**
634 * Get token owner634 * Get token owner
635 **/635 **/
636 tokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<PalletEvmAccountBasicCrossAccountIdRepr>>;636 tokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<PalletEvmAccountBasicCrossAccountIdRepr>>>;
637 /**637 /**
638 * Get token owner, in case of nested token - find parent recursive638 * Get token owner, in case of nested token - find parent recursive
639 **/639 **/
640 topmostTokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<PalletEvmAccountBasicCrossAccountIdRepr>>;640 topmostTokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<PalletEvmAccountBasicCrossAccountIdRepr>>>;
641 /**641 /**
642 * Get token variable metadata642 * Get token variable metadata
643 **/643 **/
modifiedtests/src/interfaces/unique/definitions.tsdiffbeforeafterboth
--- a/tests/src/interfaces/unique/definitions.ts
+++ b/tests/src/interfaces/unique/definitions.ts
@@ -48,8 +48,8 @@
     accountBalance: fun('Get amount of different user tokens', [collectionParam, crossAccountParam()], 'u32'),
     balance: fun('Get amount of specific account token', [collectionParam, crossAccountParam(), tokenParam], 'u128'),
     allowance: fun('Get allowed amount', [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam], 'u128'),
-    tokenOwner: fun('Get token owner', [collectionParam, tokenParam], CROSS_ACCOUNT_ID_TYPE),
-    topmostTokenOwner: fun('Get token owner, in case of nested token - find parent recursive', [collectionParam, tokenParam], CROSS_ACCOUNT_ID_TYPE),
+    tokenOwner: fun('Get token owner', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),
+    topmostTokenOwner: fun('Get token owner, in case of nested token - find parent recursive', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),
     constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),
     variableMetadata: fun('Get token variable metadata', [collectionParam, tokenParam], 'Vec<u8>'),
     tokenExists: fun('Check if token exists', [collectionParam, tokenParam], 'bool'),
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -4,7 +4,7 @@
 import usingApi from '../substrate/substrate-api';
 import {createCollectionExpectSuccess, createItemExpectSuccess, getTokenOwner, getTopmostTokenOwner, setCollectionLimitsExpectSuccess, transferExpectSuccess, transferFromExpectSuccess} from '../util/helpers';
 
-describe.only('nesting', () => {
+describe('nesting', () => {
   it('allows to nest/unnest token', async () => {
     await usingApi(async api => {
       const alice = privateKey('//Alice');
addedtests/src/rpc.test.tsdiffbeforeafterboth
--- /dev/null
+++ b/tests/src/rpc.test.ts
@@ -0,0 +1,12 @@
+import {expect} from 'chai';
+import usingApi from './substrate/substrate-api';
+import {createCollectionExpectSuccess, getTokenOwner} from './util/helpers';
+
+describe('getTokenOwner', () => {
+  it('returns None for fungible collection', async () => {
+    await usingApi(async api => {
+      const collection = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+      await expect(getTokenOwner(api, collection, 0)).to.be.rejectedWith(/^owner == null$/);
+    });
+  });
+});
\ No newline at end of file
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -985,14 +985,18 @@
   collectionId: number,
   token: number,
 ): Promise<CrossAccountId> {
-  return normalizeAccountId((await api.rpc.unique.tokenOwner(collectionId, token)).toJSON() as any);
+  const owner = (await api.rpc.unique.tokenOwner(collectionId, token)).toJSON() as any;
+  if (owner == null) throw new Error('owner == null');
+  return normalizeAccountId(owner);
 }
 export async function getTopmostTokenOwner(
   api: ApiPromise,
   collectionId: number,
   token: number,
 ): Promise<CrossAccountId> {
-  return normalizeAccountId((await api.rpc.unique.topmostTokenOwner(collectionId, token)).toJSON() as any);
+  const owner = (await api.rpc.unique.topmostTokenOwner(collectionId, token)).toJSON() as any;
+  if (owner == null) throw new Error('owner == null');
+  return normalizeAccountId(owner);
 }
 export async function isTokenExists(
   api: ApiPromise,