git.delta.rocks / unique-network / refs/commits / 925c30451b34

difftreelog

NFTPAR-91: SIT: Connection can be established. Fixed unhandled promise rejection. Fixed unknown type warnings.

sotmorskiy2020-09-29parent: #8d30d14.patch.diff
in: master

5 files changed

modifiedREADME.mddiffbeforeafterboth
--- a/README.md
+++ b/README.md
@@ -191,6 +191,10 @@
     "Sponsor": "AccountId",
     "UnconfirmedSponsor": "AccountId"
   },
+  "ApprovePermissions": {
+    "Approved": "AccountId",
+    "Amount": "u64"
+  },
   "RawData": "Vec<u8>",
   "Address": "AccountId",
   "LookupSource": "AccountId",
modifiedtests/src/config.tsdiffbeforeafterboth
--- 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<Ownership>",
+      "Data": "Vec<u8>"
+    },
     "NftItemType": {
       "Collection": "u64",
       "Owner": "AccountId",
@@ -57,10 +71,15 @@
       "Description": "Vec<u16>",
       "TokenPrefix": "Vec<u8>",
       "CustomDataSize": "u32",
+      "MintMode": "bool",
       "OffchainSchema": "Vec<u8>",
       "Sponsor": "AccountId",
       "UnconfirmedSponsor": "AccountId"
     },
+    "ApprovePermissions": {
+      "Approved": "AccountId",
+      "Amount": "u64"
+    },
     "RawData": "Vec<u8>",
     "Address": "AccountId",
     "LookupSource": "AccountId",
modifiedtests/src/connection.test.tsdiffbeforeafterboth
--- 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 });
modifiedtests/src/substrate/promisify-substrate.tsdiffbeforeafterboth
before · tests/src/substrate/promisify-substrate.ts
1import ApiPromise from "@polkadot/api/promise/Api";23type PromiseType<T> = T extends PromiseLike<infer TInner> ? TInner : T;45export default function promisifySubstrate<T extends (...args: any[]) => any>(api: ApiPromise, action: T): (...args: Parameters<T>) => Promise<PromiseType<ReturnType<T>>> {6  return (...args: Parameters<T>) => {7    const promise = new Promise<PromiseType<ReturnType<T>>>((resolve, reject) => {8      const cleanup = () => {9        api.off('disconnected', fail);10        api.off('error', fail);11      };1213      const success = (r: any) => {14        cleanup();15        resolve(r);16      };17      const fail = (error: any) => {18        cleanup();19        reject(error);20      };21      22      api.on('disconnected', fail);23      api.on('error', fail);2425      const result = action(...args);26      Promise.resolve(result)27        .then(success, fail);2829    });30    return promise as any;31  };32}
after · tests/src/substrate/promisify-substrate.ts
1import ApiPromise from "@polkadot/api/promise/Api";23type PromiseType<T> = T extends PromiseLike<infer TInner> ? TInner : T;45export default function promisifySubstrate<T extends (...args: any[]) => any>(api: ApiPromise, action: T): (...args: Parameters<T>) => Promise<PromiseType<ReturnType<T>>> {6  return (...args: Parameters<T>) => {7    const promise = new Promise<PromiseType<ReturnType<T>>>((resolve: ((result: PromiseType<ReturnType<T>>) => void) | undefined, reject: ((error: any) => void) | undefined) => {8      const cleanup = () => {9        api.off('disconnected', fail);10        api.off('error', fail);11        resolve = undefined;12        reject = undefined;13      };1415      const success = (r: any) => {16        resolve && resolve(r);17        cleanup();18      };19      const fail = (error: any) => {20        reject && reject(error);21        cleanup();22      };23      24      api.on('disconnected', fail);25      api.on('error', fail);2627      const result = action(...args);28      Promise.resolve(result)29        .then(success, fail);3031    });32    return promise as any;33  };34}
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
--- 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<void>, settings: ApiOptions | undefined = undefined): Promise<void> {
   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