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.tsdiffbeforeafterboth191920// WARNING: the WASM interface must be initialized before this function is called. 20// WARNING: the WASM interface must be initialized before this function is called. 21// Use either `usingApi`, or `cryptoWaitReady` for consistency.21// Use either `usingApi`, or `cryptoWaitReady` for consistency.22export default function privateKey(account: string): IKeyringPair {22export default function privateKey(account: string, ss58Format?: number): IKeyringPair {23 const keyring = new Keyring({type: 'sr25519'});23 const keyring = new Keyring({ss58Format, type: 'sr25519'});242425 return keyring.addFromUri(account);25 return keyring.addFromUri(account);26}26}tests/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 {