difftreelog
feat(ss58Format) Added ss58Format for usingApi() and wrapp keyring into function
in: master
3 files changed
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -127,14 +127,14 @@
expect(result.success).to.be.true;
}
-export async function itWeb3(name: string, cb: (apis: { web3: Web3, api: ApiPromise }) => any, opts: { only?: boolean, skip?: boolean } = {}) {
+export async function itWeb3(name: string, cb: (apis: { web3: Web3, api: ApiPromise, privateKeyWrapper?: (account: string) => IKeyringPair }) => any, opts: { only?: boolean, skip?: boolean } = {}) {
let i: any = it;
if (opts.only) i = i.only;
else if (opts.skip) i = i.skip;
i(name, async () => {
- await usingApi(async api => {
+ await usingApi(async (api, privateKeyWrapper) => {
await usingWeb3(async web3 => {
- await cb({api, web3});
+ await cb({api, web3, privateKeyWrapper});
});
});
});
tests/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);
}
tests/src/substrate/substrate-api.tsdiffbeforeafterboth24import promisifySubstrate from './promisify-substrate';24import promisifySubstrate from './promisify-substrate';25import {ApiOptions, SubmittableExtrinsic, ApiTypes} from '@polkadot/api/types';25import {ApiOptions, SubmittableExtrinsic, ApiTypes} from '@polkadot/api/types';26import * as defs from '../interfaces/definitions';26import * as defs from '../interfaces/definitions';27import privateKey from './privateKey';2728282929function defaultApiOptions(): ApiOptions {30function defaultApiOptions(): ApiOptions {58 };59 };59}60}606161export default async function usingApi<T = void>(action: (api: ApiPromise) => Promise<T>, settings: ApiOptions | undefined = undefined): Promise<T> {62export default async function usingApi<T = void>(action: (api: ApiPromise, privateKeyWrapper?: (account: string) => IKeyringPair) => Promise<T>, settings: ApiOptions | undefined = undefined): Promise<T> {62 settings = settings || defaultApiOptions();63 settings = settings || defaultApiOptions();63 const api: ApiPromise = new ApiPromise(settings);64 const api: ApiPromise = new ApiPromise(settings);64 let result: T = null as unknown as T;65 let result: T = null as unknown as T;87 await promisifySubstrate(api, async () => {88 await promisifySubstrate(api, async () => {88 if (api) {89 if (api) {89 await api.isReadyOrError;90 await api.isReadyOrError;91 const chainProperties = api.registry.getChainProperties();92 if (chainProperties) {93 const ss58Format = (chainProperties).toHuman().ss58Format;94 const privateKeyWrapper = (account: string) => privateKey(account, Number(ss58Format));90 result = await action(api);95 result = await action(api, privateKeyWrapper);96 } 91 }97 }92 })();98 })();93 } finally {99 } finally {