git.delta.rocks / unique-network / refs/commits / 52ec20b9c55b

difftreelog

feat calculatePovInfo playgrnd method

Daniel Shiposha2022-11-24parent: #2aae8ed.patch.diff
in: master

3 files changed

modifiedtests/src/util/playgrounds/types.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/types.ts
+++ b/tests/src/util/playgrounds/types.ts
@@ -171,6 +171,14 @@
   amount: bigint,
 }
 
+export interface IPovInfo {
+  proofSize: number,
+  compactProofSize: number,
+  compressedProofSize: number,
+  results: any[],
+  kv: any,
+}
+
 export interface ISchedulerOptions {
   scheduledId?: string,
   priority?: number,
modifiedtests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -8,10 +8,11 @@
 import * as defs from '../../interfaces/definitions';
 import {IKeyringPair} from '@polkadot/types/types';
 import {EventRecord} from '@polkadot/types/interfaces';
-import {ICrossAccountId, TSigner} from './types';
+import {ICrossAccountId, IPovInfo, TSigner} from './types';
 import {FrameSystemEventRecord} from '@polkadot/types/lookup';
 import {VoidFn} from '@polkadot/api/types';
 import {Pallets} from '..';
+import {spawnSync} from 'child_process';
 
 export class SilentLogger {
   log(_msg: any, _level: any): void { }
@@ -322,6 +323,34 @@
     return balance;
   }
 
+  async calculatePoVInfo(txs: any[]): Promise<IPovInfo> {
+    const rawPovInfo = await this.helper.callRpc('api.rpc.unique.estimateExtrinsicPoV', [txs]);
+
+    const kvJson: {[key: string]: string} = {};
+
+    for (const kv of rawPovInfo.keyValues) {
+      kvJson[kv.key.toHex()] = kv.value.toHex();
+    }
+
+    const kvStr = JSON.stringify(kvJson);
+
+    const chainql = spawnSync(
+      'chainql', 
+      [
+        `--tla-code=data=${kvStr}`,
+        '-e', 'function(data) cql.dump(cql.chain("wss://ws-opal.unique.network:443").latest._meta, data, {omit_empty:true})',
+      ],
+    );
+
+    return {
+      proofSize: rawPovInfo.proofSize.toNumber(),
+      compactProofSize: rawPovInfo.compactProofSize.toNumber(),
+      compressedProofSize: rawPovInfo.compressedProofSize.toNumber(),
+      results: rawPovInfo.results,
+      kv: JSON.parse(chainql.stdout.toString()),
+    };
+  }
+
   calculatePalletAddress(palletId: any) {
     const address = stringToU8a(('modl' + palletId).padEnd(32, '\0'));
     return encodeAddress(address, this.helper.chain.getChainProperties().ss58Format);
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
586 });586 });
587 }587 }
588
589 async signTransactionWithoutSending(signer: TSigner, tx: any) {
590 const api = this.getApi();
591 const signingInfo = await api.derive.tx.signingInfo(signer.address);
592
593 tx.sign(signer, {
594 blockHash: api.genesisHash,
595 genesisHash: api.genesisHash,
596 runtimeVersion: api.runtimeVersion,
597 nonce: signingInfo.nonce,
598 });
599
600 return tx.toHex();
601 }
588602
589 async getPaymentInfo(signer: TSigner, tx: any, len: number | null) {603 async getPaymentInfo(signer: TSigner, tx: any, len: number | null) {
590 const api = this.getApi();604 const api = this.getApi();