浏览代码

tests: write key gen info to output.json

Mokhtar Naamani 3 年之前
父节点
当前提交
b5df4e727b
共有 3 个文件被更改,包括 23 次插入12 次删除
  1. 2 0
      tests/network-tests/.gitignore
  2. 8 8
      tests/network-tests/src/Api.ts
  3. 13 4
      tests/network-tests/src/Scenario.ts

+ 2 - 0
tests/network-tests/.gitignore

@@ -0,0 +1,2 @@
+output.json
+

+ 8 - 8
tests/network-tests/src/Api.ts

@@ -111,17 +111,17 @@ export class ApiFactory {
     return keys
   }
 
-  public keyGenInfo(): string {
+  public keyGenInfo(): { start: number; final: number } {
     const start = 0
     const final = this.keyId
-    return JSON.stringify({
+    return {
       start,
       final,
-    })
+    }
   }
 
-  public dumpAccounts(): void {
-    console.log(this.addressesToKeyId)
+  public getAllGeneratedAccounts(): { [k: string]: number } {
+    return Object.fromEntries(this.addressesToKeyId)
   }
 }
 
@@ -151,12 +151,12 @@ export class Api {
     return this.factory.createKeyPairs(n)
   }
 
-  public keyGenInfo(): string {
+  public keyGenInfo(): { start: number; final: number } {
     return this.factory.keyGenInfo()
   }
 
-  public dumpAccounts(): void {
-    this.factory.dumpAccounts()
+  public getAllgeneratedAccounts(): { [k: string]: number } {
+    return this.factory.getAllGeneratedAccounts()
   }
 
   // Well known WorkingGroup enum defined in runtime

+ 13 - 4
tests/network-tests/src/Scenario.ts

@@ -9,6 +9,7 @@ import { Job } from './Job'
 import { JobManager } from './JobManager'
 import { ResourceManager } from './Resources'
 import fetch from 'cross-fetch'
+import fs from 'fs'
 
 export type ScenarioProps = {
   env: NodeJS.ProcessEnv
@@ -67,11 +68,19 @@ export async function scenario(scene: (props: ScenarioProps) => Promise<void>):
     exitCode = -1
   }
 
-  // print out address to key id map
-  api.dumpAccounts()
+  // account to key ids
+  const accounts = api.getAllgeneratedAccounts()
 
-  // print out the first and last key id used to generate keys in this scenario
-  console.log(api.keyGenInfo())
+  // first and last key id used to generate keys in this scenario
+  const keyIds = api.keyGenInfo()
+
+  const output = {
+    accounts,
+    keyIds,
+    miniSecret,
+  }
+
+  fs.writeFileSync('output.json', JSON.stringify(output, undefined, 2))
 
   // Note: disconnecting and then reconnecting to the chain in the same process
   // doesn't seem to work!