--- 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}); }); }); }); --- 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); } --- 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(action: (api: ApiPromise) => Promise, settings: ApiOptions | undefined = undefined): Promise { +export default async function usingApi(action: (api: ApiPromise, privateKeyWrapper?: (account: string) => IKeyringPair) => Promise, settings: ApiOptions | undefined = undefined): Promise { 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 {