git.delta.rocks / unique-network / refs/commits / 05870fcbad39

difftreelog

feat(ss58Format) Added ss58Format for usingApi() and wrapp keyring into function

h3lpkey2022-06-01parent: #fb4beb0.patch.diff
in: master

3 files changed

modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
127 expect(result.success).to.be.true;127 expect(result.success).to.be.true;
128}128}
129129
130export async function itWeb3(name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any, opts: { only?: boolean, skip?: boolean } = {}) {130export async function itWeb3(name: string, cb: (apis: { web3: Web3, api: ApiPromise, privateKeyWrapper?: (account: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean } = {}) {
131 let i: any = it;131 let i: any = it;
132 if (opts.only) i = i.only;132 if (opts.only) i = i.only;
133 else if (opts.skip) i = i.skip;133 else if (opts.skip) i = i.skip;
134 i(name, async () => {134 i(name, async () => {
135 await usingApi(async api => {135 await usingApi(async (api, privateKeyWrapper) => {
136 await usingWeb3(async web3 => {136 await usingWeb3(async web3 => {
137 await cb({api, web3});137 await cb({api, web3, privateKeyWrapper});
138 });138 });
139 });139 });
140 });140 });
modifiedtests/src/substrate/privateKey.tsdiffbeforeafterboth
--- a/tests/src/substrate/privateKey.ts
+++ b/tests/src/substrate/privateKey.ts
@@ -19,8 +19,8 @@
 
 // WARNING: the WASM interface must be initialized before this function is called. 
 // Use either `usingApi`, or `cryptoWaitReady` for consistency.
-export default function privateKey(account: string): IKeyringPair {
-  const keyring = new Keyring({type: 'sr25519'});
+export default function privateKey(account: string, ss58Format?: number): IKeyringPair {
+  const keyring = new Keyring({ss58Format, type: 'sr25519'});
 
   return keyring.addFromUri(account);
 }
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -24,6 +24,7 @@
 import promisifySubstrate from './promisify-substrate';
 import {ApiOptions, SubmittableExtrinsic, ApiTypes} from '@polkadot/api/types';
 import * as defs from '../interfaces/definitions';
+import privateKey from './privateKey';
 
 
 function defaultApiOptions(): ApiOptions {
@@ -58,7 +59,7 @@
   };
 }
 
-export default async function usingApi<T = void>(action: (api: ApiPromise) => Promise<T>, settings: ApiOptions | undefined = undefined): Promise<T> {
+export default async function usingApi<T = void>(action: (api: ApiPromise, privateKeyWrapper?: (account: string) => IKeyringPair) => Promise<T>, settings: ApiOptions | undefined = undefined): Promise<T> {
   settings = settings || defaultApiOptions();
   const api: ApiPromise = new ApiPromise(settings);
   let result: T = null as unknown as T;
@@ -87,7 +88,12 @@
     await promisifySubstrate(api, async () => {
       if (api) {
         await api.isReadyOrError;
-        result = await action(api);
+        const chainProperties = api.registry.getChainProperties();
+        if (chainProperties) {
+          const ss58Format = (chainProperties).toHuman().ss58Format;
+          const privateKeyWrapper = (account: string) => privateKey(account, Number(ss58Format));
+          result = await action(api, privateKeyWrapper);
+        } 
       }
     })();
   } finally {