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
1919
20// 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'});
2424
25 return keyring.addFromUri(account);25 return keyring.addFromUri(account);
26}26}
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
24import 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';
2728
2829
29function defaultApiOptions(): ApiOptions {30function defaultApiOptions(): ApiOptions {
58 };59 };
59}60}
6061
61export 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 {