From f4cf6bbb6f2fa626c5274ae84d86844df755fa42 Mon Sep 17 00:00:00 2001 From: johnsonchin Date: Mon, 2 Mar 2026 15:02:17 +0800 Subject: [PATCH 1/3] feat: updated tests to reflect latest acpJob.ts --- test/unit/acpJob.test.ts | 103 ++++++++++++++++++++++++++++++++++----- 1 file changed, 91 insertions(+), 12 deletions(-) diff --git a/test/unit/acpJob.test.ts b/test/unit/acpJob.test.ts index 582c858..c8364ec 100644 --- a/test/unit/acpJob.test.ts +++ b/test/unit/acpJob.test.ts @@ -56,6 +56,9 @@ describe("AcpJob Unit Testing", () => { getAccountByJobId: jest .fn() .mockResolvedValue({ id: 1, clientAddress: "0xClient" }), + createMemoContent: jest + .fn() + .mockResolvedValue({ url: "https://example.com/memo/1" }), } as any; acpJob = new AcpJob( @@ -70,6 +73,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.REQUEST, { testContext: "data" }, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", 100, ); }); @@ -103,6 +107,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.REQUEST, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); expect(job.name).toBe("API Integration Task"); @@ -137,6 +142,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.REQUEST, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); expect(job.name).toBe("Legacy Service"); @@ -166,6 +172,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); expect(job.name).toBeUndefined(); @@ -197,6 +204,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.REQUEST, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); expect(job.name).toBeUndefined(); @@ -231,6 +239,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.REQUEST, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); expect(job.name).toBe("Simple Task"); @@ -264,7 +273,7 @@ describe("AcpJob Unit Testing", () => { expect(result.contractAddress).toBe("0xBaseFare"); }); - it("should get deliverable from COMPLETED memo", () => { + it("should get deliverable from COMPLETED memo", async () => { const completedMemo = { ...mockMemo, content: "Here is the deliverable", @@ -283,13 +292,35 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.EVALUATION, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); - expect(jobWithDeliverable.deliverable).toBe("Here is the deliverable"); + expect(await jobWithDeliverable.getDeliverable()).toBe( + "https://acpx.virtuals.gg/api/test-memo/1", + ); }); - it("should return undefined when no deliverable exists", () => { - expect(acpJob.deliverable).toBeUndefined(); + it("should return undefined when no deliverable exists", async () => { + const completedMemo = { + ...mockMemo, + content: "Here is the deliverable", + nextPhase: AcpJobPhases.COMPLETED, + }; + const jobWithDeliverable = new AcpJob( + mockAcpClient, + 124, + "0xClient" as Address, + "0xProvider" as Address, + "0xEvaluator" as Address, + 100, + "0xToken" as Address, + [mockMemo as AcpMemo, completedMemo as AcpMemo], + AcpJobPhases.TRANSACTION, + {}, + "0xContract" as Address, + null, + ); + expect(await jobWithDeliverable.getDeliverable()).toBeNull(); }); it("should get rejection reason from signed reason", () => { @@ -312,6 +343,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.NEGOTIATION, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); expect(rejectedJob.rejectionReason).toBe("Too Expensive"); @@ -336,6 +368,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.REJECTED, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); expect(rejectedJob.rejectionReason).toBe("Budget Constraints"); @@ -511,6 +544,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.REQUEST, {}, "0xContract" as Address, + null, 100, ); @@ -622,6 +656,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.EVALUATION, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); const reason = "Accepted"; @@ -650,6 +685,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.EVALUATION, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); const reason = "Irrelevant"; @@ -783,6 +819,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); await expect(jobWithTxPhase.accept()).rejects.toThrow( @@ -833,6 +870,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.REQUEST, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); await expect(jobWithWrongPhase.reject("reason")).rejects.toThrow( @@ -853,6 +891,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); const reason = "The job cannot be completed"; @@ -890,6 +929,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); const mockCreateMemoResult = { type: "CREATE_MEMO_REJECTED" }; @@ -1045,6 +1085,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.REQUEST, {}, "0xContract" as Address, + null, ); const mockApproveResult = { type: "APPROVE_ALLOWANCE" }; @@ -1097,6 +1138,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + "https://acpx.virtuals.gg/api/test-memo/1", ); const deliverable = { result: "Job Completed Successfully" }; @@ -1110,8 +1152,8 @@ describe("AcpJob Unit Testing", () => { expect(mockContractClient.createMemo).toHaveBeenCalledWith( 160, - JSON.stringify(deliverable), - MemoType.MESSAGE, + "https://example.com/memo/1", + MemoType.CONTEXT_URL, true, AcpJobPhases.COMPLETED, ); @@ -1124,14 +1166,38 @@ describe("AcpJob Unit Testing", () => { }); it("should successfully deliver regardless of memo nextPhase", async () => { + const txMemo = { + id: 1, + type: MemoType.MESSAGE, + content: "Tx Memo", + nextPhase: AcpJobPhases.EVALUATION, + status: AcpMemoStatus.PENDING, + senderAddress: "0xSender" as Address, + sign: jest.fn(), + } as any; + + const jobInTransaction = new AcpJob( + mockAcpClient, + 123, + "0xClient" as Address, + "0xProvider" as Address, + "0xEvaluator" as Address, + 100, + "0xToken" as Address, + [txMemo as AcpMemo], + AcpJobPhases.TRANSACTION, + { testContext: "data" }, + "0xContract" as Address, + ); + const deliverable = { result: "Done" }; - const result = await acpJob.deliver(deliverable); + const result = await jobInTransaction.deliver(deliverable); expect(mockContractClient.createMemo).toHaveBeenCalledWith( 123, - JSON.stringify(deliverable), - MemoType.MESSAGE, + "https://example.com/memo/1", + MemoType.CONTEXT_URL, true, AcpJobPhases.COMPLETED, ); @@ -1172,6 +1238,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, ); const deliverable = { output: "Final Deliverable" }; @@ -1201,7 +1268,7 @@ describe("AcpJob Unit Testing", () => { expect(mockContractClient.createPayableMemo).toHaveBeenCalledWith( 170, - JSON.stringify(deliverable), + "https://example.com/memo/1", mockFareAmount.amount, "0xClient", BigInt(0), // NO_FEE for fixed pricing @@ -1282,6 +1349,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, ); const deliverable = { data: "result" }; @@ -1299,7 +1367,7 @@ describe("AcpJob Unit Testing", () => { expect(mockContractClient.createPayableMemo).toHaveBeenCalledWith( 180, - JSON.stringify(deliverable), + "https://example.com/memo/1", mockFareAmount.amount, "0xClient", BigInt(75000), @@ -1337,6 +1405,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, ); const deliverable = { output: "work" }; @@ -1354,7 +1423,7 @@ describe("AcpJob Unit Testing", () => { expect(mockContractClient.createPayableMemo).toHaveBeenCalledWith( 190, - JSON.stringify(deliverable), + "https://example.com/memo/1", mockFareAmount.amount, "0xClient", BigInt(0), @@ -1389,6 +1458,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, ); const beforeCall = Date.now(); @@ -1524,6 +1594,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, ); const content = "Percentage Notification"; @@ -1583,6 +1654,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, ); const content = "Notification with skipFee"; @@ -1668,6 +1740,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.REQUEST, {}, "0xContract" as Address, + null, 1, ); @@ -1703,6 +1776,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, 1, ); @@ -1750,6 +1824,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, 1, ); @@ -1795,6 +1870,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, 1, ); @@ -1901,6 +1977,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, 1, ); @@ -1971,6 +2048,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, 1, ); @@ -2047,6 +2125,7 @@ describe("AcpJob Unit Testing", () => { AcpJobPhases.TRANSACTION, {}, "0xContract" as Address, + null, 1, ); From 0778aa147858d8609da73df99a955b6b5952e566 Mon Sep 17 00:00:00 2001 From: johnsonchin Date: Tue, 3 Mar 2026 15:11:04 +0800 Subject: [PATCH 2/3] feat: updated tests to reflect latest acpClient.ts --- test/integration/acpClient.integration.test.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/integration/acpClient.integration.test.ts b/test/integration/acpClient.integration.test.ts index ccbdbea..47cdc79 100644 --- a/test/integration/acpClient.integration.test.ts +++ b/test/integration/acpClient.integration.test.ts @@ -220,14 +220,25 @@ describe("AcpClient Integration Testing", () => { it("should respect top_k parameter", async () => { const keyword = "agent"; - const topK = 2; + const k = 3; const options = { - topK: topK, + top_k: k, }; const result = await acpClient.browseAgents(keyword, options); - expect(result.length).toBeLessThanOrEqual(topK); + expect(result.length).toBeLessThanOrEqual(k); + }, 30000); + + it("should respect topK parameter", async () => { + const keyword = "agent"; + const k = 3; + const options = { + topK: k, + }; + + const result = await acpClient.browseAgents(keyword, options); + expect(result.length).toBeLessThanOrEqual(k); }, 30000); it("should handle search with sort options", async () => { From 689378dd48fa1fd96e8f95d82c0b104c22e8937b Mon Sep 17 00:00:00 2001 From: johnsonchin Date: Wed, 4 Mar 2026 15:13:01 +0800 Subject: [PATCH 3/3] chore: deprecate snake case for top_k test --- test/integration/acpClient.integration.test.ts | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/test/integration/acpClient.integration.test.ts b/test/integration/acpClient.integration.test.ts index 47cdc79..38c441f 100644 --- a/test/integration/acpClient.integration.test.ts +++ b/test/integration/acpClient.integration.test.ts @@ -218,18 +218,6 @@ describe("AcpClient Integration Testing", () => { } }, 30000); - it("should respect top_k parameter", async () => { - const keyword = "agent"; - const k = 3; - const options = { - top_k: k, - }; - - const result = await acpClient.browseAgents(keyword, options); - - expect(result.length).toBeLessThanOrEqual(k); - }, 30000); - it("should respect topK parameter", async () => { const keyword = "agent"; const k = 3; @@ -257,7 +245,7 @@ describe("AcpClient Integration Testing", () => { it("should handle search with graduation status filter", async () => { const keyword = "agent"; const options = { - top_k: 5, + topK: 5, graduationStatus: AcpGraduationStatus.GRADUATED, }; @@ -270,7 +258,7 @@ describe("AcpClient Integration Testing", () => { it("should handle search with online status filter", async () => { const keyword = "agent"; const options = { - top_k: 5, + topK: 5, onlineStatus: AcpOnlineStatus.ONLINE, };