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
before · tests/src/config.ts
1import process from 'process';23const config = {4  substrateUrl: process.env.substrateUrl || 'ws://127.0.0.1:9944',5  customTypes: process.env.customTypes || `{6    "Schedule": {7      "version": "u32",8      "put_code_per_byte_cost": "Gas",9      "grow_mem_cost": "Gas",10      "regular_op_cost": "Gas",11      "return_data_per_byte_cost": "Gas",12      "event_data_per_byte_cost": "Gas",13      "event_per_topic_cost": "Gas",14      "event_base_cost": "Gas",15      "call_base_cost": "Gas",16      "instantiate_base_cost": "Gas",17      "dispatch_base_cost": "Gas",18      "sandbox_data_read_cost": "Gas",19      "sandbox_data_write_cost": "Gas",20      "transfer_cost": "Gas",21      "instantiate_cost": "Gas",22      "max_event_topics": "u32",23      "max_stack_height": "u32",24      "max_memory_pages": "u32",25      "max_table_size": "u32",26      "enable_println": "bool",27      "max_subject_len": "u32"28    },29    "CollectionMode": {30      "_enum": {31        "Invalid": null,32        "NFT": "u32",33        "Fungible": "u32",34        "ReFungible": "(u32, u32)"35      }36    },37    "NftItemType": {38      "Collection": "u64",39      "Owner": "AccountId",40      "Data": "Vec<u8>"41    },42    "Ownership": {43      "owner": "AccountId",44      "fraction": "u128"45    },46    "ReFungibleItemType": {47      "Collection": "u64",48      "Owner": "Vec<Ownership<AccountId>>",49      "Data": "Vec<u8>"50    },51    "CollectionType": {52      "Owner": "AccountId",53      "Mode": "CollectionMode",54      "Access": "u8",55      "DecimalPoints": "u32",56      "Name": "Vec<u16>",57      "Description": "Vec<u16>",58      "TokenPrefix": "Vec<u8>",59      "CustomDataSize": "u32",60      "OffchainSchema": "Vec<u8>",61      "Sponsor": "AccountId",62      "UnconfirmedSponsor": "AccountId"63    },64    "RawData": "Vec<u8>",65    "Address": "AccountId",66    "LookupSource": "AccountId",67    "Weight": "u64"68  }`69}7071export default config;
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
--- a/tests/src/substrate/promisify-substrate.ts
+++ b/tests/src/substrate/promisify-substrate.ts
@@ -4,19 +4,21 @@
 
 export default function promisifySubstrate<T extends (...args: any[]) => any>(api: ApiPromise, action: T): (...args: Parameters<T>) => Promise<PromiseType<ReturnType<T>>> {
   return (...args: Parameters<T>) => {
-    const promise = new Promise<PromiseType<ReturnType<T>>>((resolve, reject) => {
+    const promise = new Promise<PromiseType<ReturnType<T>>>((resolve: ((result: PromiseType<ReturnType<T>>) => 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);
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