difftreelog
test get rid of AccountId::default
in: master
5 files changed
tests/src/interfaces/augment-api-rpc.tsdiffbeforeafterboth--- 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<PalletEvmAccountBasicCrossAccountIdRepr>>;
+ tokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<PalletEvmAccountBasicCrossAccountIdRepr>>>;
/**
* 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<PalletEvmAccountBasicCrossAccountIdRepr>>;
+ topmostTokenOwner: AugmentedRpc<(collection: u32 | AnyNumber | Uint8Array, tokenId: u32 | AnyNumber | Uint8Array, at?: Hash | string | Uint8Array) => Observable<Option<PalletEvmAccountBasicCrossAccountIdRepr>>>;
/**
* Get token variable metadata
**/
tests/src/interfaces/unique/definitions.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import types from '../lookup';1819type RpcParam = {20 name: string;21 type: string;22 isOptional?: true;23};2425const CROSS_ACCOUNT_ID_TYPE = 'PalletEvmAccountBasicCrossAccountIdRepr';2627const collectionParam = {name: 'collection', type: 'u32'};28const tokenParam = {name: 'tokenId', type: 'u32'};29const crossAccountParam = (name = 'account') => ({name, type: CROSS_ACCOUNT_ID_TYPE});30const atParam = {name: 'at', type: 'Hash', isOptional: true};3132const fun = (description: string, params: RpcParam[], type: string) => ({33 description,34 params: [...params, atParam],35 type,36});3738export default {39 types,40 rpc: {41 adminlist: fun('Get admin list', [collectionParam], 'Vec<PalletEvmAccountBasicCrossAccountIdRepr>'),42 allowlist: fun('Get allowlist', [collectionParam], 'Vec<PalletEvmAccountBasicCrossAccountIdRepr>'),4344 accountTokens: fun('Get tokens owned by account', [collectionParam, crossAccountParam()], 'Vec<u32>'),45 collectionTokens: fun('Get tokens contained in collection', [collectionParam], 'Vec<u32>'),4647 lastTokenId: fun('Get last token id', [collectionParam], 'u32'),48 accountBalance: fun('Get amount of different user tokens', [collectionParam, crossAccountParam()], 'u32'),49 balance: fun('Get amount of specific account token', [collectionParam, crossAccountParam(), tokenParam], 'u128'),50 allowance: fun('Get allowed amount', [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam], 'u128'),51 tokenOwner: fun('Get token owner', [collectionParam, tokenParam], CROSS_ACCOUNT_ID_TYPE),52 topmostTokenOwner: fun('Get token owner, in case of nested token - find parent recursive', [collectionParam, tokenParam], CROSS_ACCOUNT_ID_TYPE),53 constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),54 variableMetadata: fun('Get token variable metadata', [collectionParam, tokenParam], 'Vec<u8>'),55 tokenExists: fun('Check if token exists', [collectionParam, tokenParam], 'bool'),56 collectionById: fun('Get collection by specified id', [collectionParam], 'Option<UpDataStructsRpcCollection>'),57 collectionStats: fun('Get collection stats', [], 'UpDataStructsCollectionStats'),58 allowed: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam()], 'bool'),59 nextSponsored: fun('Get number of blocks when sponsored transaction is available', [collectionParam, crossAccountParam(), tokenParam], 'Option<u64>'),60 effectiveCollectionLimits: fun('Get effective collection limits', [collectionParam], 'Option<UpDataStructsCollectionLimits>'),61 },62};1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import types from '../lookup';1819type RpcParam = {20 name: string;21 type: string;22 isOptional?: true;23};2425const CROSS_ACCOUNT_ID_TYPE = 'PalletEvmAccountBasicCrossAccountIdRepr';2627const collectionParam = {name: 'collection', type: 'u32'};28const tokenParam = {name: 'tokenId', type: 'u32'};29const crossAccountParam = (name = 'account') => ({name, type: CROSS_ACCOUNT_ID_TYPE});30const atParam = {name: 'at', type: 'Hash', isOptional: true};3132const fun = (description: string, params: RpcParam[], type: string) => ({33 description,34 params: [...params, atParam],35 type,36});3738export default {39 types,40 rpc: {41 adminlist: fun('Get admin list', [collectionParam], 'Vec<PalletEvmAccountBasicCrossAccountIdRepr>'),42 allowlist: fun('Get allowlist', [collectionParam], 'Vec<PalletEvmAccountBasicCrossAccountIdRepr>'),4344 accountTokens: fun('Get tokens owned by account', [collectionParam, crossAccountParam()], 'Vec<u32>'),45 collectionTokens: fun('Get tokens contained in collection', [collectionParam], 'Vec<u32>'),4647 lastTokenId: fun('Get last token id', [collectionParam], 'u32'),48 accountBalance: fun('Get amount of different user tokens', [collectionParam, crossAccountParam()], 'u32'),49 balance: fun('Get amount of specific account token', [collectionParam, crossAccountParam(), tokenParam], 'u128'),50 allowance: fun('Get allowed amount', [collectionParam, crossAccountParam('sender'), crossAccountParam('spender'), tokenParam], 'u128'),51 tokenOwner: fun('Get token owner', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),52 topmostTokenOwner: fun('Get token owner, in case of nested token - find parent recursive', [collectionParam, tokenParam], `Option<${CROSS_ACCOUNT_ID_TYPE}>`),53 constMetadata: fun('Get token constant metadata', [collectionParam, tokenParam], 'Vec<u8>'),54 variableMetadata: fun('Get token variable metadata', [collectionParam, tokenParam], 'Vec<u8>'),55 tokenExists: fun('Check if token exists', [collectionParam, tokenParam], 'bool'),56 collectionById: fun('Get collection by specified id', [collectionParam], 'Option<UpDataStructsRpcCollection>'),57 collectionStats: fun('Get collection stats', [], 'UpDataStructsCollectionStats'),58 allowed: fun('Check if user is allowed to use collection', [collectionParam, crossAccountParam()], 'bool'),59 nextSponsored: fun('Get number of blocks when sponsored transaction is available', [collectionParam, crossAccountParam(), tokenParam], 'Option<u64>'),60 effectiveCollectionLimits: fun('Get effective collection limits', [collectionParam], 'Option<UpDataStructsCollectionLimits>'),61 },62};tests/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');
tests/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
tests/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,