git.delta.rocks / unique-network / refs/commits / 4c0220909a7c

difftreelog

tests: allow returning result from usingApi

Yaroslav Bolyukin2021-01-28parent: #dddaa3d.patch.diff
in: master

1 file changed

modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
18 return { provider: wsProvider, types: rtt };18 return { provider: wsProvider, types: rtt };
19}19}
2020
21export default async function usingApi(action: (api: ApiPromise) => Promise<void>, settings: ApiOptions | undefined = undefined): Promise<void> {21export default async function usingApi<T = void>(action: (api: ApiPromise) => Promise<T>, settings: ApiOptions | undefined = undefined): Promise<T> {
22 settings = settings || defaultApiOptions();22 settings = settings || defaultApiOptions();
23 let api: ApiPromise = new ApiPromise(settings);23 let api: ApiPromise = new ApiPromise(settings);
24 let result: T = null as unknown as T;
2425
25 // TODO: Remove, this is temporary: Filter unneeded API output 26 // TODO: Remove, this is temporary: Filter unneeded API output
26 // (Jaco promised it will be removed in the next version)27 // (Jaco promised it will be removed in the next version)
40 await promisifySubstrate(api, async () => {41 await promisifySubstrate(api, async () => {
41 if(api) {42 if (api) {
42 await api.isReadyOrError;43 await api.isReadyOrError;
43 await action(api);44 result = await action(api);
44 }45 }
45 })();46 })();
46 } finally {47 } finally {
47 await api.disconnect();48 await api.disconnect();
48 console.log = consoleLog;49 console.log = consoleLog;
49 console.error = consoleErr;50 console.error = consoleErr;
50 }51 }
52 return result as T;
51}53}
5254
53enum TransactionStatus {55enum TransactionStatus {