Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed test failures caused by disallowing trigger of Completed status and bump up sdk-js version #58

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/sdk-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @avaprotocol/sdk-js

## 1.3.3

### Patch Changes

- update the new auth method and trigger matcher array

## 1.3.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@avaprotocol/sdk-js",
"version": "1.3.2",
"version": "1.3.3",
"description": "A JavaScript/TypeScript SDK designed to simplify integration with Ava Protocol's AVS",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
37 changes: 16 additions & 21 deletions tests/getExecutions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,69 +49,66 @@ describe("getExecutions Tests", () => {
afterAll(async () => await removeCreatedWorkflows(client, createdWorkflows));

test("options.limit returns the correct number of executions", async () => {
const countFirstPage = 1;
const blockInterval = 5;
const limitOneExecution = 1;
const triggerInterval = 5;
const repeatCount = 4;

const wallet = await client.getWallet({ salt });
const blockNumber = await getBlockNumber();
const currentBlockNumber = await getBlockNumber();

const trigger = TriggerFactory.create({
id: defaultTriggerId,
name: "blockTrigger",
type: TriggerType.Block,
data: { interval: blockInterval },
data: { interval: triggerInterval },
});

const workflowId = await client.submitWorkflow(
client.createWorkflow({
...WorkflowTemplate,
trigger,
smartWalletAddress: wallet.address,
maxExecution: 1000, // Set a high maxExecution to ensure the workflow is not completed; otherwise, mannually triggering a completed workflow will fail
})
);
queueForRemoval(createdWorkflows, workflowId);

// Get the first page of executions with limit:1
let executions = await client.getExecutions([workflowId], {
limit: countFirstPage,
limit: limitOneExecution,
});
expect(executions.result.length).toBe(0);
expect(executions.hasMore).toBe(false);

// Manually trigger the workflow with block number + 20
const result = await client.triggerWorkflow({
id: workflowId,
data: {
type: TriggerType.Block,
blockNumber: blockNumber,
blockNumber: currentBlockNumber + triggerInterval,
},
isBlocking: true,
});

// trigger the test {repeatCount} extra time more
for(let i = 0; i < repeatCount; i++){
for(let i = 1; i <= repeatCount; i++){
await client.triggerWorkflow({
id: workflowId,
data: {
type: TriggerType.Block,
blockNumber: blockNumber + repeatCount +1
blockNumber: currentBlockNumber + triggerInterval + repeatCount * triggerInterval,
},
isBlocking: true,
});
}

console.log("triggerWorkflow.result", result);

// Get the first page of executions with limit:1
executions = await client.getExecutions([workflowId], {
limit: countFirstPage,
limit: limitOneExecution,
});

console.log("executions", executions);

expect(Array.isArray(executions.result)).toBe(true);
expect(executions.result.length).toBe(countFirstPage);
expect(executions.result.length).toBe(limitOneExecution);
expect(executions).toHaveProperty("cursor");
expect(executions.hasMore).toBe(true);
const firstCursor = executions.cursor;
Expand All @@ -122,15 +119,12 @@ describe("getExecutions Tests", () => {
cursor: firstCursor,
});

console.log("executions2", executions2);

// Verify that the count of the second return is totalCount - limit
expect(Array.isArray(executions2.result)).toBe(true);
expect(executions2.result.length).toBe(repeatCount);
expect(executions2.hasMore).toBe(false);
const secondCursor = executions2.cursor;

// Make sure there’s no overlap between the two lists

// Make sure there's no overlap between the two lists
expect(
_.intersection(
executions.result.map((item) => item.id),
Expand Down Expand Up @@ -159,6 +153,7 @@ describe("getExecutions Tests", () => {
...WorkflowTemplate,
trigger,
smartWalletAddress: wallet.address,
maxExecution: 1000, // Set a high maxExecution to ensure the workflow is not completed; otherwise, mannually triggering a completed workflow will fail
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the second test: getExecutions Tests › options.cursor works as pagination

Simply adding this line makes the tests pass.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup that what i mean on the chat. the error was

 9 FAILED_PRECONDITION: The workflow is not in a runable status, it has reached the limit execution or the expiration time

so we just need to fix it.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we set it to 0? maxExeuctio = 0 mean unlimited run. the default instead of setting a big enough number like 1000

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right. 0 is better. Let me update this value.

})
);
queueForRemoval(createdWorkflows, workflowId);
Expand Down Expand Up @@ -198,7 +193,7 @@ describe("getExecutions Tests", () => {
expect(Array.isArray(executions2.result)).toBe(true);
expect(executions2.result.length).toBe(repeatCount - limit);

// Make sure theres no overlap between the two lists
// Make sure there's no overlap between the two lists
expect(
_.intersection(
executions.result.map((item) => item.id),
Expand Down
Loading