Skip to content

Commit 68086ac

Browse files
committed
adding helper function
1 parent 6c680e4 commit 68086ac

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

helpers/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
WHITELISTED_WALLET_PRIVATE_KEY=
2+
WHITELISTED_WALLET_ENTITY_ID=
3+
BUYER_WALLET_ADDRESS=

helpers/acpHelperFunctions.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import * as path from 'path';
2+
import AcpClient from "../src/acpClient";
3+
import AcpContractClient from "../src/acpContractClient";
4+
import { baseSepoliaAcpConfig } from "../src/configs";
5+
import * as dotenv from "dotenv";
6+
import { Address } from "viem";
7+
8+
// Load environment variables
9+
dotenv.config({ override: true });
10+
11+
async function testHelperFunctions() {
12+
console.log("Testing ACP helper functions...");
13+
14+
// Initialize AcpClient
15+
const acpClient = new AcpClient({
16+
acpContractClient: await AcpContractClient.build(
17+
process.env.WHITELISTED_WALLET_PRIVATE_KEY as `0x${string}`,
18+
Number(process.env.WHITELISTED_WALLET_ENTITY_ID),
19+
process.env.BUYER_WALLET_ADDRESS as Address,
20+
baseSepoliaAcpConfig
21+
)
22+
});
23+
24+
// Get active jobs
25+
const activeJobs = await acpClient.getActiveJobs(1, 10);
26+
console.log("\n🔵 Active Jobs:");
27+
console.log(activeJobs.data.length > 0 ? activeJobs.data : "No active jobs found.");
28+
29+
// Get completed jobs
30+
const completedJobs = await acpClient.getCompletedJobs(1, 10);
31+
console.log("\n✅ Completed Jobs:");
32+
console.log(completedJobs.data.length > 0 ? completedJobs.data : "No completed jobs found.");
33+
34+
// Get cancelled jobs
35+
const cancelledJobs = await acpClient.getCancelledJobs(1, 10);
36+
console.log("\n❌ Cancelled Jobs:");
37+
console.log(cancelledJobs.data.length > 0 ? cancelledJobs.data : "No cancelled jobs found.");
38+
39+
if (completedJobs.data.length > 0) {
40+
const onChainJobId = completedJobs.data[0].onChainJobId;
41+
if (onChainJobId) {
42+
const job = await acpClient.getJobByOnChainJobId(onChainJobId);
43+
console.log(`\n📄 Job Details (Job ID: ${onChainJobId}):`);
44+
console.log(job.data);
45+
46+
const memos = completedJobs.data[0].memos;
47+
if (memos && memos.length > 0) {
48+
const memoId = memos[0].memoId;
49+
const memo = await acpClient.getMemoById(onChainJobId, memoId);
50+
console.log(`\n📝 Memo Details (Job ID: ${onChainJobId}, Memo ID: ${memoId}):`);
51+
console.log(memo.data);
52+
} else {
53+
console.log("\n⚠️ No memos found for the completed job.");
54+
}
55+
}
56+
} else {
57+
console.log("\n⚠️ No completed jobs available for detailed inspection.");
58+
}
59+
}
60+
61+
// Run the test
62+
testHelperFunctions().catch(error => {
63+
console.error("Error in helper functions test:", error);
64+
process.exit(1);
65+
});

0 commit comments

Comments
 (0)