forked from Lilly-Protocol/lily-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwallet-address-generation.test.ts
More file actions
54 lines (46 loc) · 1.86 KB
/
Copy pathwallet-address-generation.test.ts
File metadata and controls
54 lines (46 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { describe, it, expect, beforeEach } from "vitest";
import request from "supertest";
import { createApp } from "../src/app";
import { agentsService } from "../src/modules/agents/agents.service";
describe("Wallet address generation uniqueness and normalization (issue #128)", () => {
const app = createApp();
const createAgent = async (name: string) => {
const res = await request(app)
.post("/api/v1/agents")
.send({
name,
description: "Testing wallet address generation",
capabilities: ["test"],
});
expect(res.status).toBe(201);
return res.body.data.agent;
};
beforeEach(() => {
agentsService.reset?.();
});
it("should produce a 56-character address starting with G", async () => {
const agent = await createAgent("Test Agent");
expect(agent.walletAddress).toHaveLength(56);
expect(agent.walletAddress).toMatch(/^G[A-Z0-9]{55}$/);
});
it("should strip punctuation and normalize names to uppercase", async () => {
const agent1 = await createAgent("hello-world");
agentsService.reset?.();
const agent2 = await createAgent("HELLO WORLD");
expect(agent1.walletAddress).toBe(agent2.walletAddress);
});
it("should produce distinct addresses for distinct alphanumeric seeds", async () => {
const agent1 = await createAgent("Alpha");
const agent2 = await createAgent("Beta");
expect(agent1.walletAddress).not.toBe(agent2.walletAddress);
});
it("should handle minimum-length names without error", async () => {
const agent = await createAgent("AB");
expect(agent.walletAddress).toHaveLength(56);
expect(agent.walletAddress).toMatch(/^G[A-Z0-9]{55}$/);
});
it("should pad short seeds with zeros to reach 55 characters after G", async () => {
const agent = await createAgent("AB");
expect(agent.walletAddress).toBe("GAB" + "0".repeat(53));
});
});