From 5a0f9b0e220ff320d47a79983596439f0537afd5 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sat, 25 Jan 2025 19:50:51 +0300 Subject: [PATCH 1/2] merged random generation functions for tests into one file --- examples/wallet.spec.ts | 4 ++-- src/test/e2e-emulated/map1.spec.ts | 2 +- src/test/e2e-emulated/map2.spec.ts | 2 +- src/test/e2e-emulated/math.spec.ts | 2 +- src/test/e2e-emulated/optionals.spec.ts | 2 +- src/test/utils/random-utils.ts | 21 +++++++++++++++++++++ src/test/utils/randomAddress.ts | 11 ----------- src/test/utils/testKey.ts | 11 ----------- 8 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 src/test/utils/random-utils.ts delete mode 100644 src/test/utils/randomAddress.ts delete mode 100644 src/test/utils/testKey.ts diff --git a/examples/wallet.spec.ts b/examples/wallet.spec.ts index 247d973fa..13ecee240 100644 --- a/examples/wallet.spec.ts +++ b/examples/wallet.spec.ts @@ -2,7 +2,7 @@ import { storeTransfer, Transfer, Wallet } from "./output/wallet_Wallet"; import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox"; import { beginCell, toNano } from "@ton/core"; import { sign } from "@ton/crypto"; -import { testKey } from "../src/test/utils/testKey"; +import { randomKey } from "../src/test/utils/random-utils"; import "@ton/test-utils"; describe("wallet", () => { @@ -16,7 +16,7 @@ describe("wallet", () => { blockchain.verbosity.print = false; treasure = await blockchain.treasury("treasure"); - key = testKey("wallet-key"); + key = randomKey("wallet-key"); const publicKey = beginCell() .storeBuffer(key.publicKey) .endCell() diff --git a/src/test/e2e-emulated/map1.spec.ts b/src/test/e2e-emulated/map1.spec.ts index d7a0d600e..1f67d2b24 100644 --- a/src/test/e2e-emulated/map1.spec.ts +++ b/src/test/e2e-emulated/map1.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { randomAddress } from "../utils/randomAddress"; +import { randomAddress } from "../utils/random-utils"; import { MapTestContract, MapTestContract$Data, diff --git a/src/test/e2e-emulated/map2.spec.ts b/src/test/e2e-emulated/map2.spec.ts index c5375a3d6..55b62c8e1 100644 --- a/src/test/e2e-emulated/map2.spec.ts +++ b/src/test/e2e-emulated/map2.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { randomAddress } from "../utils/randomAddress"; +import { randomAddress } from "../utils/randomUtils"; import { MapTestContract, MapTestContract$Data, diff --git a/src/test/e2e-emulated/math.spec.ts b/src/test/e2e-emulated/math.spec.ts index 0bec83dec..ba1336ce6 100644 --- a/src/test/e2e-emulated/math.spec.ts +++ b/src/test/e2e-emulated/math.spec.ts @@ -2,7 +2,7 @@ import { beginCell, Dictionary, toNano } from "@ton/core"; import { Blockchain, SandboxContract, TreasuryContract } from "@ton/sandbox"; import { MathTester } from "./contracts/output/math_MathTester"; import "@ton/test-utils"; -import { randomAddress } from "../utils/randomAddress"; +import { randomAddress } from "../utils/random-utils"; describe("math", () => { let blockchain: Blockchain; diff --git a/src/test/e2e-emulated/optionals.spec.ts b/src/test/e2e-emulated/optionals.spec.ts index 921afcdf9..8e4ec1bf6 100644 --- a/src/test/e2e-emulated/optionals.spec.ts +++ b/src/test/e2e-emulated/optionals.spec.ts @@ -1,4 +1,4 @@ -import { randomAddress } from "../utils/randomAddress"; +import { randomAddress } from "../utils/random-utils"; import { ContractWithOptionals, SomeGenericStruct, diff --git a/src/test/utils/random-utils.ts b/src/test/utils/random-utils.ts new file mode 100644 index 000000000..c271e577d --- /dev/null +++ b/src/test/utils/random-utils.ts @@ -0,0 +1,21 @@ +import Prando from "prando"; +import { KeyPair, keyPairFromSeed } from "@ton/crypto"; +import { Address } from "@ton/core"; + +export function randomKey(seed: string): KeyPair { + const random = new Prando(seed); + const res = Buffer.alloc(32); + for (let i = 0; i < res.length; i++) { + res[i] = random.nextInt(0, 256); + } + return keyPairFromSeed(res); +} + +export function randomAddress(workchain: number, seed: string): Address { + const random = new Prando(seed); + const hash = Buffer.alloc(32); + for (let i = 0; i < hash.length; i++) { + hash[i] = random.nextInt(0, 255); + } + return new Address(workchain, hash); +} diff --git a/src/test/utils/randomAddress.ts b/src/test/utils/randomAddress.ts deleted file mode 100644 index 43d3cd2f5..000000000 --- a/src/test/utils/randomAddress.ts +++ /dev/null @@ -1,11 +0,0 @@ -import Prando from "prando"; -import { Address } from "@ton/core"; - -export function randomAddress(workchain: number, seed: string) { - const random = new Prando(seed); - const hash = Buffer.alloc(32); - for (let i = 0; i < hash.length; i++) { - hash[i] = random.nextInt(0, 255); - } - return new Address(workchain, hash); -} diff --git a/src/test/utils/testKey.ts b/src/test/utils/testKey.ts deleted file mode 100644 index 734661cbc..000000000 --- a/src/test/utils/testKey.ts +++ /dev/null @@ -1,11 +0,0 @@ -import Prando from "prando"; -import { keyPairFromSeed } from "@ton/crypto"; - -export function testKey(seed: string) { - const random = new Prando(seed); - const res = Buffer.alloc(32); - for (let i = 0; i < res.length; i++) { - res[i] = random.nextInt(0, 256); - } - return keyPairFromSeed(res); -} From 558740f960ed5459dd43c44de6245aad3946a907 Mon Sep 17 00:00:00 2001 From: Danil Ovchinnikov Date: Sun, 26 Jan 2025 18:10:52 +0300 Subject: [PATCH 2/2] fixed an error when importing a file --- src/test/e2e-emulated/map2.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/e2e-emulated/map2.spec.ts b/src/test/e2e-emulated/map2.spec.ts index 55b62c8e1..0d4e12384 100644 --- a/src/test/e2e-emulated/map2.spec.ts +++ b/src/test/e2e-emulated/map2.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { randomAddress } from "../utils/randomUtils"; +import { randomAddress } from "../utils/random-utils"; import { MapTestContract, MapTestContract$Data,