From 6f234a4dd6c25c92a4cfce6d667c9614c1552847 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Fri, 08 Apr 2022 10:55:53 +0000 Subject: [PATCH] test: get rid of AccountId::default --- --- a/tests/src/interfaces/augment-api-rpc.ts +++ b/tests/src/interfaces/augment-api-rpc.ts @@ -633,11 +633,11 @@ /** * Get token owner **/ - tokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable>; + tokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable>>; /** * Get token owner, in case of nested token - find parent recursive **/ - topmostTokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable>; + topmostTokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable>>; /** * Get token variable metadata **/ --- 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'), variableMetadata: fun('Get token variable metadata', [collectionParam, tokenParam], 'Vec'), tokenExists: fun('Check if token exists', [collectionParam, tokenParam], 'bool'), --- 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'); --- /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 --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -985,14 +985,18 @@ collectionId: number, token: number, ): Promise { - 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 { - 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, -- gitstuff