difftreelog
NFTPAR-91: SIT: Connection can be established. Fixed unhandled promise rejection. Fixed unknown type warnings.
in: master
5 files changed
README.mddiffbeforeafterboth191 "Sponsor": "AccountId",191 "Sponsor": "AccountId",192 "UnconfirmedSponsor": "AccountId"192 "UnconfirmedSponsor": "AccountId"193 },193 },194 "ApprovePermissions": {195 "Approved": "AccountId",196 "Amount": "u64"197 },194 "RawData": "Vec<u8>",198 "RawData": "Vec<u8>",195 "Address": "AccountId",199 "Address": "AccountId",196 "LookupSource": "AccountId",200 "LookupSource": "AccountId",tests/src/config.tsdiffbeforeafterboth223const config = {3const config = {4 substrateUrl: process.env.substrateUrl || 'ws://127.0.0.1:9944',4 substrateUrl: process.env.substrateUrl || 'ws://127.0.0.1:9944',5 customTypes: process.env.customTypes || `{5 customTypes: process.env.customTypes || `{6 "Schedule": {6 "Schedule": {7 "version": "u32",7 "version": "u32",8 "put_code_per_byte_cost": "Gas",8 "put_code_per_byte_cost": "Gas",9 "grow_mem_cost": "Gas",9 "grow_mem_cost": "Gas",10 "regular_op_cost": "Gas",10 "regular_op_cost": "Gas",11 "return_data_per_byte_cost": "Gas",11 "return_data_per_byte_cost": "Gas",12 "event_data_per_byte_cost": "Gas",12 "event_data_per_byte_cost": "Gas",13 "event_per_topic_cost": "Gas",13 "event_per_topic_cost": "Gas",14 "event_base_cost": "Gas",14 "event_base_cost": "Gas",15 "call_base_cost": "Gas",15 "call_base_cost": "Gas",16 "instantiate_base_cost": "Gas",16 "instantiate_base_cost": "Gas",17 "dispatch_base_cost": "Gas",17 "dispatch_base_cost": "Gas",18 "sandbox_data_read_cost": "Gas",18 "sandbox_data_read_cost": "Gas",19 "sandbox_data_write_cost": "Gas",19 "sandbox_data_write_cost": "Gas",20 "transfer_cost": "Gas",20 "transfer_cost": "Gas",21 "instantiate_cost": "Gas",21 "instantiate_cost": "Gas",22 "max_event_topics": "u32",22 "max_event_topics": "u32",23 "max_stack_height": "u32",23 "max_stack_height": "u32",24 "max_memory_pages": "u32",24 "max_memory_pages": "u32",25 "max_table_size": "u32",25 "max_table_size": "u32",26 "enable_println": "bool",26 "enable_println": "bool",27 "max_subject_len": "u32"27 "max_subject_len": "u32"28 },28 },29 "CollectionMode": {29 "CollectionMode": {30 "_enum": {30 "_enum": {31 "Invalid": null,31 "Invalid": null,32 "NFT": "u32",32 "NFT": "u32",33 "Fungible": "u32",33 "Fungible": "u32",34 "ReFungible": "(u32, u32)"34 "ReFungible": "(u32, u32)"35 }35 }36 },36 },37 "NftItemType": {37 "Ownership": {38 "Owner": "AccountId",39 "Fraction": "u128"40 },41 "FungibleItemType": {42 "Collection": "u64",43 "Owner": "AccountId",44 "Value": "u128"45 },46 "ReFungibleItemType": {47 "Collection": "u64",48 "Owner": "Vec<Ownership>",49 "Data": "Vec<u8>"50 },51 "NftItemType": {38 "Collection": "u64",52 "Collection": "u64",39 "Owner": "AccountId",53 "Owner": "AccountId",40 "Data": "Vec<u8>"54 "Data": "Vec<u8>"41 },55 },42 "Ownership": {56 "Ownership": {43 "owner": "AccountId",57 "owner": "AccountId",44 "fraction": "u128"58 "fraction": "u128"45 },59 },46 "ReFungibleItemType": {60 "ReFungibleItemType": {47 "Collection": "u64",61 "Collection": "u64",48 "Owner": "Vec<Ownership<AccountId>>",62 "Owner": "Vec<Ownership<AccountId>>",49 "Data": "Vec<u8>"63 "Data": "Vec<u8>"50 },64 },51 "CollectionType": {65 "CollectionType": {52 "Owner": "AccountId",66 "Owner": "AccountId",53 "Mode": "CollectionMode",67 "Mode": "CollectionMode",54 "Access": "u8",68 "Access": "u8",55 "DecimalPoints": "u32",69 "DecimalPoints": "u32",56 "Name": "Vec<u16>",70 "Name": "Vec<u16>",57 "Description": "Vec<u16>",71 "Description": "Vec<u16>",58 "TokenPrefix": "Vec<u8>",72 "TokenPrefix": "Vec<u8>",59 "CustomDataSize": "u32",73 "CustomDataSize": "u32",60 "OffchainSchema": "Vec<u8>",74 "MintMode": "bool",75 "OffchainSchema": "Vec<u8>",61 "Sponsor": "AccountId",76 "Sponsor": "AccountId",62 "UnconfirmedSponsor": "AccountId"77 "UnconfirmedSponsor": "AccountId"78 },79 "ApprovePermissions": {80 "Approved": "AccountId",81 "Amount": "u64"63 },82 },64 "RawData": "Vec<u8>",83 "RawData": "Vec<u8>",65 "Address": "AccountId",84 "Address": "AccountId",66 "LookupSource": "AccountId",85 "LookupSource": "AccountId",67 "Weight": "u64"86 "Weight": "u64"68 }`87 }`69}88}708971export default config;90export default config;tests/src/connection.test.tsdiffbeforeafterboth15 });15 });16 });16 });171718 it('Cannot connect to 0.0.0.0', () => {18 it('Cannot connect to 255.255.255.255', async () => {19 const neverConnectProvider = new WsProvider('ws://0.0.0.0:9944');19 const neverConnectProvider = new WsProvider('ws://255.255.255.255:9944');20 expect((async () => {20 await expect((async () => {21 await usingApi(async api => {21 await usingApi(async api => {22 const health = await api.rpc.system.health();22 const health = await api.rpc.system.health();23 }, { provider: neverConnectProvider });23 }, { provider: neverConnectProvider });tests/src/substrate/promisify-substrate.tsdiffbeforeafterboth445export default function promisifySubstrate<T extends (...args: any[]) => any>(api: ApiPromise, action: T): (...args: Parameters<T>) => Promise<PromiseType<ReturnType<T>>> {5export default function promisifySubstrate<T extends (...args: any[]) => any>(api: ApiPromise, action: T): (...args: Parameters<T>) => Promise<PromiseType<ReturnType<T>>> {6 return (...args: Parameters<T>) => {6 return (...args: Parameters<T>) => {7 const promise = new Promise<PromiseType<ReturnType<T>>>((resolve, reject) => {7 const promise = new Promise<PromiseType<ReturnType<T>>>((resolve: ((result: PromiseType<ReturnType<T>>) => void) | undefined, reject: ((error: any) => void) | undefined) => {8 const cleanup = () => {8 const cleanup = () => {9 api.off('disconnected', fail);9 api.off('disconnected', fail);10 api.off('error', fail);10 api.off('error', fail);11 resolve = undefined;12 reject = undefined;11 };13 };121413 const success = (r: any) => {15 const success = (r: any) => {14 cleanup();16 resolve && resolve(r);15 resolve(r);17 cleanup();16 };18 };17 const fail = (error: any) => {19 const fail = (error: any) => {18 cleanup();20 reject && reject(error);19 reject(error);21 cleanup();20 };22 };21 23 22 api.on('disconnected', fail);24 api.on('disconnected', fail);tests/src/substrate/substrate-api.tsdiffbeforeafterboth101011export default async function usingApi(action: (api: ApiPromise) => Promise<void>, settings: ApiOptions | undefined = undefined): Promise<void> {11export default async function usingApi(action: (api: ApiPromise) => Promise<void>, settings: ApiOptions | undefined = undefined): Promise<void> {12 settings = settings || defaultApiOptions();12 settings = settings || defaultApiOptions();13 let api: ApiPromise | undefined = undefined;13 let api: ApiPromise = new ApiPromise(settings);141415 try {15 try {16 api = new ApiPromise(settings);17 await promisifySubstrate(api, () => api && api.isReady)();16 await promisifySubstrate(api, async () => {18 await action(api);17 if(api) {18 await api.isReadyOrError;19 await action(api);20 }21 })();19 } finally {22 } finally {20 api && api.disconnect();23 await api.disconnect();21 }24 }22}25}