/ src / tests / tests.util.ts
tests.util.ts
 1  export const randomEthereumAddress = () => {
 2    const randomBytes = crypto.getRandomValues(new Uint8Array(20));
 3  
 4    // Convert bytes to a hexadecimal string
 5    const address = Array.from(randomBytes)
 6      .map((byte) => ("0" + byte.toString(16)).slice(-2)) // Convert to hex and pad with zero
 7      .join("");
 8  
 9    return "0x" + address; // Prefix with '0x'
10  };
11  
12  export const randomString = (length: number) => {
13    const characters =
14      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
15    let result = "";
16    for (let i = 0; i < length; i++) {
17      const randomIndex = Math.floor(Math.random() * characters.length);
18      result += characters[randomIndex];
19    }
20    return result;
21  };
22  
23  export const randomInt = (min: number, max: number) =>
24    Math.floor(Math.random() * (max - min)) + min;