From 925c30451b34b8ecc9d1859de0482bb953cf0c7b Mon Sep 17 00:00:00 2001 From: sotmorskiy Date: Tue, 29 Sep 2020 06:50:16 +0000 Subject: [PATCH] NFTPAR-91: SIT: Connection can be established. Fixed unhandled promise rejection. Fixed unknown type warnings. --- --- a/README.md +++ b/README.md @@ -191,6 +191,10 @@ "Sponsor": "AccountId", "UnconfirmedSponsor": "AccountId" }, + "ApprovePermissions": { + "Approved": "AccountId", + "Amount": "u64" + }, "RawData": "Vec", "Address": "AccountId", "LookupSource": "AccountId", --- a/tests/src/config.ts +++ b/tests/src/config.ts @@ -34,6 +34,20 @@ "ReFungible": "(u32, u32)" } }, + "Ownership": { + "Owner": "AccountId", + "Fraction": "u128" + }, + "FungibleItemType": { + "Collection": "u64", + "Owner": "AccountId", + "Value": "u128" + }, + "ReFungibleItemType": { + "Collection": "u64", + "Owner": "Vec", + "Data": "Vec" + }, "NftItemType": { "Collection": "u64", "Owner": "AccountId", @@ -57,10 +71,15 @@ "Description": "Vec", "TokenPrefix": "Vec", "CustomDataSize": "u32", + "MintMode": "bool", "OffchainSchema": "Vec", "Sponsor": "AccountId", "UnconfirmedSponsor": "AccountId" }, + "ApprovePermissions": { + "Approved": "AccountId", + "Amount": "u64" + }, "RawData": "Vec", "Address": "AccountId", "LookupSource": "AccountId", --- a/tests/src/connection.test.ts +++ b/tests/src/connection.test.ts @@ -15,9 +15,9 @@ }); }); - it('Cannot connect to 0.0.0.0', () => { - const neverConnectProvider = new WsProvider('ws://0.0.0.0:9944'); - expect((async () => { + it('Cannot connect to 255.255.255.255', async () => { + const neverConnectProvider = new WsProvider('ws://255.255.255.255:9944'); + await expect((async () => { await usingApi(async api => { const health = await api.rpc.system.health(); }, { provider: neverConnectProvider }); --- a/tests/src/substrate/promisify-substrate.ts +++ b/tests/src/substrate/promisify-substrate.ts @@ -4,19 +4,21 @@ export default function promisifySubstrate any>(api: ApiPromise, action: T): (...args: Parameters) => Promise>> { return (...args: Parameters) => { - const promise = new Promise>>((resolve, reject) => { + const promise = new Promise>>((resolve: ((result: PromiseType>) => void) | undefined, reject: ((error: any) => void) | undefined) => { const cleanup = () => { api.off('disconnected', fail); api.off('error', fail); + resolve = undefined; + reject = undefined; }; const success = (r: any) => { + resolve && resolve(r); cleanup(); - resolve(r); }; const fail = (error: any) => { + reject && reject(error); cleanup(); - reject(error); }; api.on('disconnected', fail); --- a/tests/src/substrate/substrate-api.ts +++ b/tests/src/substrate/substrate-api.ts @@ -10,13 +10,16 @@ export default async function usingApi(action: (api: ApiPromise) => Promise, settings: ApiOptions | undefined = undefined): Promise { settings = settings || defaultApiOptions(); - let api: ApiPromise | undefined = undefined; + let api: ApiPromise = new ApiPromise(settings); try { - api = new ApiPromise(settings); - await promisifySubstrate(api, () => api && api.isReady)(); - await action(api); + await promisifySubstrate(api, async () => { + if(api) { + await api.isReadyOrError; + await action(api); + } + })(); } finally { - api && api.disconnect(); + await api.disconnect(); } } \ No newline at end of file -- gitstuff