Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: pre-compute test users #753

Merged
merged 13 commits into from
Mar 17, 2023
21 changes: 4 additions & 17 deletions _tasks/downloads.ts → _tasks/generate_artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { hex } from "../crypto/mod.ts"
import { testUser } from "../crypto/mod.ts"
import * as $ from "../deps/scale.ts"
import dprintConfig from "../dprint.json" assert { type: "json" }
import { DEFAULT_TEST_USER_COUNT, publicKeysPath } from "../providers/frame/common.ts"

const GENERATION_NOTICE = `// This file was generated by \`_tasks/downloads.ts\``

Expand All @@ -23,24 +26,8 @@ tsFormatter.setConfig({ indentWidth, lineWidth }, config)
`,
)

const generateTestUserPublicKeysPath = new URL(
"../util/generateTestUserPublicKeys.ts",
import.meta.url,
)
await Deno.writeTextFile(
generateTestUserPublicKeysPath,
`${GENERATION_NOTICE}
import { testUser } from "../crypto/mod.ts"
import * as $ from "../deps/scale.ts"

export const DEFAULT_TEST_USER_COUNT = 100_000
const publicKeys = []
for (let i = 0; i < DEFAULT_TEST_USER_COUNT; i++) {
publicKeys.push(testUser(i).publicKey)
}
await Deno.writeFile(
new URL("../providers/frame/test_users_public_keys.scale", import.meta.url),
$.array($.sizedUint8Array(32)).encode(publicKeys),
)
`,
)
await Deno.writeFile(publicKeysPath, $.array($.sizedUint8Array(32)).encode(publicKeys))
3 changes: 1 addition & 2 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
],
"excludes": [
"target",
"util/tsFormatter.ts",
"util/generateTestUserPublicKeys.ts"
"util/tsFormatter.ts"
],
"plugins": [
"https://plugins.dprint.dev/dockerfile-0.3.0.wasm",
Expand Down
7 changes: 3 additions & 4 deletions providers/frame/common.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ss58 } from "../../crypto/mod.ts"
import * as $ from "../../deps/scale.ts"
import { DEFAULT_TEST_USER_COUNT } from "../../util/generateTestUserPublicKeys.ts"

export const DEFAULT_TEST_USER_COUNT = 100_000
const DEFAULT_TEST_USER_INITIAL_FUNDS = 1_000_000_000_000_000_000
export const publicKeysPath = new URL("./test_users_public_keys.scale", import.meta.url)
kratico marked this conversation as resolved.
Show resolved Hide resolved

export async function createCustomChainSpec(
bin: string,
Expand All @@ -14,9 +15,7 @@ export async function createCustomChainSpec(
})
const chainSpec = JSON.parse(new TextDecoder().decode((await buildSpecCmd.output()).stdout))
const balances: [string, number][] = chainSpec.genesis.runtime.balances.balances
const publicKeys = $.array($.sizedUint8Array(32)).decode(
await Deno.readFile(new URL(`./test_users_public_keys.scale`, import.meta.url)),
)
const publicKeys = $.array($.sizedUint8Array(32)).decode(await Deno.readFile(publicKeysPath))
for (let i = 0; i < DEFAULT_TEST_USER_COUNT; i++) {
balances.push([ss58.encode(networkPrefix, publicKeys[i]!), DEFAULT_TEST_USER_INITIAL_FUNDS])
}
Expand Down
13 changes: 0 additions & 13 deletions util/generateTestUserPublicKeys.ts

This file was deleted.

2 changes: 1 addition & 1 deletion util/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// moderate --exclude cache port.ts tsFormatter.ts generateTestUserPublicKeys.ts
// moderate --exclude cache port.ts tsFormatter.ts

export * from "./ArrayOfLength.ts"
export * from "./clock.ts"
Expand Down