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
--- 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});
       });
     });
   });
modifiedtests/src/substrate/privateKey.tsdiffbeforeafterboth
before · tests/src/substrate/privateKey.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {Keyring} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';1920// WARNING: the WASM interface must be initialized before this function is called. 21// Use either `usingApi`, or `cryptoWaitReady` for consistency.22export default function privateKey(account: string): IKeyringPair {23  const keyring = new Keyring({type: 'sr25519'});2425  return keyring.addFromUri(account);26}
after · tests/src/substrate/privateKey.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {Keyring} from '@polkadot/api';18import {IKeyringPair} from '@polkadot/types/types';1920// WARNING: the WASM interface must be initialized before this function is called. 21// Use either `usingApi`, or `cryptoWaitReady` for consistency.22export default function privateKey(account: string, ss58Format?: number): IKeyringPair {23  const keyring = new Keyring({ss58Format, type: 'sr25519'});2425  return keyring.addFromUri(account);26}
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 {