Skip to content

Commit

Permalink
fix all test
Browse files Browse the repository at this point in the history
  • Loading branch information
v9n committed Nov 20, 2024
1 parent 7db6649 commit 906793f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 63 deletions.
25 changes: 12 additions & 13 deletions tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe("Client E2E Tests", () => {
const result = await client.createWallet({salt: "123"}, { authKey });
expect(result?.address).toHaveLength(42);
expect(result?.salt).toEqual("123");
expect(result?.factoryAddress).toEqual("0x29adA1b5217242DEaBB142BC3b1bCfFdd56008e7");
expect(result?.factory).toEqual("0x29adA1b5217242DEaBB142BC3b1bCfFdd56008e7");
});

test("listSmartWallets", async () => {
Expand All @@ -139,15 +139,14 @@ describe("Client E2E Tests", () => {
const result = await client.createTask(sampleTask1, { authKey });

expect(result).toBeDefined();
expect(result).toHaveProperty("id");
expect(result.id).toHaveLength(26);
expect(result).toHaveLength(26);
});

test("getTask", async () => {
const result = await client.createTask(sampleTask1, { authKey });
expect(result?.id).toHaveLength(26);
expect(result).toHaveLength(26);

const task = await client.getTask(result.id, { authKey });
const task = await client.getTask(result, { authKey });
expect(task.status).toEqual(avs_pb.TaskStatus.ACTIVE);
expect(task.nodes).toHaveLength(1);
expect(task.nodes[0].contractWrite.contractAddress).toEqual(sampleTask1.nodes[0].contractWrite.contractAddress);
Expand All @@ -169,20 +168,20 @@ describe("Client E2E Tests", () => {
expect(tasks1.length).toBeGreaterThanOrEqual(1);
expect(tasks2.length).toBeGreaterThanOrEqual(1);

const task1 = tasks1.find(t => t.id == result1.id);
expect(tasks1.find(t => t.id == result2.id)).toBe(undefined);
expect(task1?.id).toEqual(result1.id);
const task1 = tasks1.find(t => t.id == result1);
expect(tasks1.find(t => t.id == result2)).toBe(undefined);
expect(task1?.id).toEqual(result1);
expect(task1?.memo).toEqual('task1 test');

const task2 = tasks2.find(t => t.id == result2.id);
expect(tasks2.find(t => t.id == result1.id)).toBe(undefined);
expect(task2?.id).toEqual(result2.id);
const task2 = tasks2.find(t => t.id == result2);
expect(tasks2.find(t => t.id == result1)).toBe(undefined);
expect(task2?.id).toEqual(result2);
expect(task2?.memo).toEqual('default wallet test');
});

test("cancelTask", async () => {
const result = await client.createTask(sampleTask1, { authKey });
const task = await client.getTask(result.id, { authKey });
const task = await client.getTask(result, { authKey });
expect(task.status).toEqual( avs_pb.TaskStatus.ACTIVE);

const cancelResult = await client.cancelTask(task.id, { authKey });
Expand All @@ -193,7 +192,7 @@ describe("Client E2E Tests", () => {

test("deleteTask", async () => {
const result = await client.createTask(sampleTask1, { authKey });
const task = await client.getTask(result.id, { authKey });
const task = await client.getTask(result, { authKey });
expect(task.status).toEqual(avs_pb.TaskStatus.ACTIVE);
expect(task.id).toHaveLength(26);

Expand Down
12 changes: 3 additions & 9 deletions tests/cancelTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ describe("cancelTask Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{ ...sampleTask1, smartWalletAddress },
{ authKey }
);

createdTaskId = createTaskRes.id;
});

test("should cancel task when authenticated with signature", async () => {
Expand Down Expand Up @@ -101,12 +99,10 @@ describe("cancelTask Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{ ...sampleTask1, smartWalletAddress },
{ authKey }
);

createdTaskId = createTaskRes.id;
});

test("should cancel task when authenticated with API key", async () => {
Expand Down Expand Up @@ -145,15 +141,13 @@ describe("cancelTask Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{
...sampleTask1,
smartWalletAddress
},
{ authKey }
);

createdTaskId = createTaskRes.id;
});

test("should throw error when canceling a task without authentication", async () => {
Expand Down
34 changes: 17 additions & 17 deletions tests/createTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("createTask Tests", () => {
);
console.log("Create task result:", result);
expect(result).toBeDefined();
expect(result).toHaveProperty("id");
expect(result).toHaveLength(26);
});

test("should throw error when creating a task with owner address using signature", async () => {
Expand All @@ -89,14 +89,14 @@ describe("createTask Tests", () => {
{ authKey }
);

const task = await client.getTask(result.id, { authKey });
expect(task.id).toEqual(result.id);
const task = await client.getTask(result, { authKey });
expect(task.id).toEqual(result);
expect(task.status).toEqual(avs_pb.TaskStatus.ACTIVE);
expect(task.nodes).toHaveLength(1);
expect(task.nodes[0].contractWrite.contractAddress).toEqual(sampleTask1.nodes[0].contractWrite.contractAddress);
expect(task.nodes[0].contractWrite.callData).toEqual(sampleTask1.nodes[0].contractWrite.callData);

expect(task.trigger.trigger_type).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.CRON);
expect(task.trigger.triggerType).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.CRON);
expect(task.trigger.cron.schedule[0]).toEqual("5 4 * * *");
expect(task.trigger.cron.schedule[1]).toEqual("5 0 * 8 *");
});
Expand All @@ -114,14 +114,14 @@ describe("createTask Tests", () => {
{ authKey }
);

const task = await client.getTask(result.id, { authKey });
expect(task.id).toEqual(result.id);
const task = await client.getTask(result, { authKey });
expect(task.id).toEqual(result);
expect(task.status).toEqual(avs_pb.TaskStatus.ACTIVE);
expect(task.nodes).toHaveLength(1);
expect(task.nodes[0].contractWrite.contractAddress).toEqual(sampleTask1.nodes[0].contractWrite.contractAddress);
expect(task.nodes[0].contractWrite.callData).toEqual(sampleTask1.nodes[0].contractWrite.callData);

expect(task.trigger.trigger_type).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.FIXED_TIME);
expect(task.trigger.triggerType).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.FIXED_TIME);
expect(task.trigger.fixedTime.epochs).toEqual([10, 20, 30]);
});

Expand All @@ -138,14 +138,14 @@ describe("createTask Tests", () => {
{ authKey }
);

const task = await client.getTask(result.id, { authKey });
expect(task.id).toEqual(result.id);
const task = await client.getTask(result, { authKey });
expect(task.id).toEqual(result);
expect(task.status).toEqual(avs_pb.TaskStatus.ACTIVE);
expect(task.nodes).toHaveLength(1);
expect(task.nodes[0].contractWrite.contractAddress).toEqual(sampleTask1.nodes[0].contractWrite.contractAddress);
expect(task.nodes[0].contractWrite.callData).toEqual(sampleTask1.nodes[0].contractWrite.callData);

expect(task.trigger.trigger_type).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.EVENT);
expect(task.trigger.triggerType).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.EVENT);
expect(task.trigger.event.expression).toEqual(`topic0 == "0x123" && topic2 == "0xdef"` );
});

Expand All @@ -162,14 +162,14 @@ describe("createTask Tests", () => {
{ authKey }
);

const task = await client.getTask(result.id, { authKey });
expect(task.id).toEqual(result.id);
const task = await client.getTask(result, { authKey });
expect(task.id).toEqual(result);
expect(task.status).toEqual(avs_pb.TaskStatus.ACTIVE);
expect(task.nodes).toHaveLength(1);
expect(task.nodes[0].contractWrite.contractAddress).toEqual(sampleTask1.nodes[0].contractWrite.contractAddress);
expect(task.nodes[0].contractWrite.callData).toEqual(sampleTask1.nodes[0].contractWrite.callData);

expect(task.trigger.trigger_type).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.MANUAL);
expect(task.trigger.triggerType).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.MANUAL);
expect(task.trigger.manual).toBe(true);
});

Expand All @@ -188,14 +188,14 @@ describe("createTask Tests", () => {
{ authKey }
);

const task = await client.getTask(result.id, { authKey });
expect(task.id).toEqual(result.id);
const task = await client.getTask(result, { authKey });
expect(task.id).toEqual(result);
expect(task.status).toEqual(avs_pb.TaskStatus.ACTIVE);
expect(task.nodes).toHaveLength(1);
expect(task.nodes[0].contractWrite.contractAddress).toEqual(sampleTask1.nodes[0].contractWrite.contractAddress);
expect(task.nodes[0].contractWrite.callData).toEqual(sampleTask1.nodes[0].contractWrite.callData);

expect(task.trigger.trigger_type).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.BLOCK);
expect(task.trigger.triggerType).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.BLOCK);
expect(task.trigger.block.interval).toEqual(102);
});

Expand Down Expand Up @@ -223,7 +223,7 @@ describe("createTask Tests", () => {
);
console.log("Create task result:", result);
expect(result).toBeDefined();
expect(result).toHaveProperty("id");
expect(result).toHaveLength(26);
});

test("should throw error when creating a task with owner address using API key", async () => {
Expand Down
11 changes: 3 additions & 8 deletions tests/deleteTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ describe("deleteTask Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{ ...sampleTask1, smartWalletAddress },
{ authKey }
);

createdTaskId = createTaskRes.id;
});

test("should delete task when authenticated with signature", async () => {
Expand Down Expand Up @@ -103,12 +101,11 @@ describe("deleteTask Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{ ...sampleTask1, smartWalletAddress },
{ authKey }
);

createdTaskId = createTaskRes.id;
console.log("crate task", createdTaskId);
});

Expand Down Expand Up @@ -152,12 +149,10 @@ describe("deleteTask Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{ ...sampleTask1, smartWalletAddress },
{ authKey }
);

createdTaskId = createTaskRes.id;
});

test("should throw error when deleting a task without authentication", async () => {
Expand Down
16 changes: 6 additions & 10 deletions tests/getTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ describe("getTask Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{
...sampleTask1, smartWalletAddress
},
{ authKey }
);

createdTaskId = createTaskRes.id;
});

test("should get task when authenticated with signature", async () => {
Expand Down Expand Up @@ -106,23 +104,23 @@ describe("getTask Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{ ...sampleTask1, smartWalletAddress },
{ authKey }
);

createdTaskId = createTaskRes.id;
});

test("should get task when authenticated with API key", async () => {
const result = await client.getTask(createdTaskId, { authKey });

console.log("trask is ", result);
// Check if the result is an object and has the expected properties
expect(result).toBeDefined();
expect(result.status).toBe(avs_pb.TaskStatus.ACTIVE);
expect(result.id).toBe(createdTaskId);
expect(result.smartWalletAddress).toEqual(smartWalletAddress);
//expect(result.trigger).toBeDefined();
expect(result.trigger).toBeDefined();
expect(result.trigger.triggerType).toEqual(avs_pb.TaskTrigger.TriggerTypeCase.BLOCK);
expect(result.nodes).toHaveLength(1);
expect(result.expiredAt).toEqual(sampleTask1.expiredAt);
expect(result.memo).toEqual(sampleTask1.memo);
Expand Down Expand Up @@ -154,12 +152,10 @@ describe("getTask Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{ ...sampleTask1, smartWalletAddress },
{ authKey }
);

createdTaskId = createTaskRes.id;
});

test("should throw error when getting a task without authentication", async () => {
Expand Down
8 changes: 2 additions & 6 deletions tests/listTasks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,10 @@ describe("listTasks Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{ ...sampleTask1, smartWalletAddress },
{ authKey }
);

createdTaskId = createTaskRes.id;
});

test("should list tasks when authenticated with signature", async () => {
Expand Down Expand Up @@ -102,12 +100,10 @@ describe("listTasks Tests", () => {
console.log(`Smart wallet created: ${smartWalletAddress}`);

console.log("Creating a task to use for the following tests");
const createTaskRes = await client.createTask(
createdTaskId = await client.createTask(
{ ...sampleTask1, smartWalletAddress },
{ authKey }
);

createdTaskId = createTaskRes.id;
});

test("should list tasks when authenticated with API key", async () => {
Expand Down

0 comments on commit 906793f

Please sign in to comment.