Skip to content

Commit

Permalink
refactor(test): merged random generation functions into one file (#1570)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil42Russia authored Jan 26, 2025
1 parent 24db1f9 commit 72e0f2c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 28 deletions.
4 changes: 2 additions & 2 deletions examples/wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e-emulated/map1.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e-emulated/map2.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e-emulated/math.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/e2e-emulated/optionals.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { randomAddress } from "../utils/randomAddress";
import { randomAddress } from "../utils/random-utils";
import {
ContractWithOptionals,
SomeGenericStruct,
Expand Down
21 changes: 21 additions & 0 deletions src/test/utils/random-utils.ts
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 0 additions & 11 deletions src/test/utils/randomAddress.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/utils/testKey.ts

This file was deleted.

0 comments on commit 72e0f2c

Please sign in to comment.