From 83d4d63fca1ac85e4d7e1ec9d4cc2cec3ce363a8 Mon Sep 17 00:00:00 2001 From: imstar15 Date: Mon, 27 Nov 2023 10:41:56 +0800 Subject: [PATCH 1/3] Add a past time test for dynamic dispatch task --- test/functional/dynamicDispatchTask.test.ts | 2113 ++++++++++--------- 1 file changed, 1074 insertions(+), 1039 deletions(-) diff --git a/test/functional/dynamicDispatchTask.test.ts b/test/functional/dynamicDispatchTask.test.ts index 073e5d0..98c7345 100644 --- a/test/functional/dynamicDispatchTask.test.ts +++ b/test/functional/dynamicDispatchTask.test.ts @@ -27,1055 +27,1090 @@ const initialize = async () => { keyringPair = context.keyringPair; }; -beforeAll(() => initialize(), DEFAULT_TIMEOUT_INITIALIZE); -afterAll(() => polkadotApi?.disconnect()); - -/** - * dynamicDispatchTask.fixed schedule and cancel succeed - */ -test( - "dynamicDispatchTask.fixed schedule and cancel succeed", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - - const { - schedule: { - fixed: { executionTimes }, - }, - } = extrinsicParams; - - const taskID = await scheduleDynamicDispatchTaskAndVerify( - automationTimeApi, - keyringPair, - extrinsicParams, - ); - - // Cancel task and verify - await cancelTaskAndVerify( - automationTimeApi, - keyringPair, - taskID, - executionTimes[0], - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring schedule and cancel succeed - */ -test( - "dynamicDispatchTask.recurring schedule and cancel succeed", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { - schedule: { - recurring: { nextExecutionTime }, - }, - } = extrinsicParams; - - const taskID = await scheduleDynamicDispatchTaskAndVerify( - automationTimeApi, - keyringPair, - extrinsicParams, - ); - - // Cancel task and verify - await cancelTaskAndVerify( - automationTimeApi, - keyringPair, - taskID, - nextExecutionTime, - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600-1) fails - */ -test( - "dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600-1) fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.frequency -= 1; - - // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency - const extrinsicHex = - await automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, +describe("test-dynamic-dispatch-task", () => { + beforeAll(() => initialize(), DEFAULT_TIMEOUT_INITIALIZE); + afterAll(() => polkadotApi?.disconnect()); + + /** + * dynamicDispatchTask.fixed schedule and cancel succeed + */ + it( + "dynamicDispatchTask.fixed schedule and cancel succeed", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", ); - await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( - `${SECTION_NAME}.InvalidTime`, - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency - */ -test( - "dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600*0.5) fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.frequency *= 0.5; - schedule.recurring.frequency = Math.ceil(schedule.recurring.frequency); - - // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency - const extrinsicHex = - await automationTimeApi.buildScheduleDynamicDispatchTask( + + const { + schedule: { + fixed: { executionTimes }, + }, + } = extrinsicParams; + + const taskID = await scheduleDynamicDispatchTaskAndVerify( + automationTimeApi, keyringPair, - schedule, - call, + extrinsicParams, ); - await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( - `${SECTION_NAME}.InvalidTime`, - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600*3.3) fails - */ -test( - "dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600*3.3) fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.frequency *= 1.3; - schedule.recurring.frequency = Math.ceil(schedule.recurring.frequency); - - // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency - const extrinsicHex = - await automationTimeApi.buildScheduleDynamicDispatchTask( + + expect(typeof taskID).toBe("string"); + + // Cancel task and verify + await cancelTaskAndVerify( + automationTimeApi, keyringPair, - schedule, - call, + taskID, + executionTimes[0], ); - await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( - `${SECTION_NAME}.InvalidTime`, - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with frequency that is 0 fails - */ -test( - "dynamicDispatchTask.recurring with frequency that is 0 fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.frequency = 0; - - // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency - // const extrinsicHex = await scheduler.buildScheduleDynamicDispatchTask(keyringPair, schedule, call); - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with frequency that is negtive integer fails - */ -test( - "dynamicDispatchTask.recurring with frequency that is negtive integer fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.frequency = -1; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with frequency that is larger than Number.MAX_SAFE_INTEGER fails - */ -test( - "dynamicDispatchTask.recurring with frequency that is larger than Number.MAX_SAFE_INTEGER fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.frequency = Number.MAX_SAFE_INTEGER + 1; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with frequency that is string fails - */ -test( - "dynamicDispatchTask.recurring with frequency that is string fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.frequency = "123123"; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with frequency that is object fails - */ -test( - "dynamicDispatchTask.recurring with frequency that is object fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.frequency = {}; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with frequency that is null fails - */ -test( - "dynamicDispatchTask.recurring with frequency that is null fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.frequency = null; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with frequency that is undefined fails - */ -test( - "dynamicDispatchTask.recurring with frequency that is undefined fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.frequency = undefined; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+5min) fails. - */ -test( - "dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+5min) fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime += 5 * 60; - - // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency - const extrinsicHex = - await automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring schedule and cancel succeed + */ + it( + "dynamicDispatchTask.recurring schedule and cancel succeed", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", ); - await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( - `${SECTION_NAME}.InvalidTime`, - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+30min) fails. - */ -test( - "dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+30min) fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime += 30 * 60; - - // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency - const extrinsicHex = - await automationTimeApi.buildScheduleDynamicDispatchTask( + const { + schedule: { + recurring: { nextExecutionTime }, + }, + } = extrinsicParams; + + const taskID = await scheduleDynamicDispatchTaskAndVerify( + automationTimeApi, keyringPair, - schedule, - call, + extrinsicParams, ); - await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( - `${SECTION_NAME}.InvalidTime`, - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+45min) fails. - */ -test( - "dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+45min) fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime += 30 * 60; - - // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency - const extrinsicHex = - await automationTimeApi.buildScheduleDynamicDispatchTask( + + expect(typeof taskID).toBe("string"); + + // Cancel task and verify + await cancelTaskAndVerify( + automationTimeApi, keyringPair, - schedule, - call, + taskID, + nextExecutionTime, ); - await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( - `${SECTION_NAME}.InvalidTime`, - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with nextExecutionTime that is 0 fails - */ -test( - "dynamicDispatchTask.recurring with nextExecutionTime that is 0 fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime = 0; - - // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with nextExecutionTime that is negtive integer fails - */ -test( - "dynamicDispatchTask.recurring with nextExecutionTime that is negtive integer fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime = -1; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with nextExecutionTime that is larger than Number.MAX_SAFE_INTEGER fails - */ -test( - "dynamicDispatchTask.recurring with nextExecutionTime that is larger than Number.MAX_SAFE_INTEGER fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime = Number.MAX_SAFE_INTEGER + 1; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with nextExecutionTime that is string fails - */ -test( - "dynamicDispatchTask.recurring with nextExecutionTime that is string fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime = "123123"; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with frequency that is object fails - */ -test( - "dynamicDispatchTask.recurring with nextExecutionTime that is object fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime = {}; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with nextExecutionTime that is null fails - */ -test( - "dynamicDispatchTask.recurring with nextExecutionTime that is null fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime = null; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with nextExecutionTime that is undefined fails - */ -test( - "dynamicDispatchTask.recurring with nextExecutionTime that is undefined fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime = undefined; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+5min) fails - */ -test( - "dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+5min) fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes[0] += 60 * 5; - - // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency - const extrinsicHex = - await automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with nextExecutionTime that is is a past time fails + */ + it( + "dynamicDispatchTask.recurring with nextExecutionTime that is a past time fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", ); - await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( - `${SECTION_NAME}.InvalidTime`, - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+30min) fails - */ -test( - "dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+30min) fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes[0] += 60 * 30; - - // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency - const extrinsicHex = - await automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime = Math.floor( + new Date().valueOf() / 1000 - 1, ); - await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( - `${SECTION_NAME}.InvalidTime`, - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+45min) fails - */ -test( - "dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+45min) fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes[0] += 60 * 30; - - const extrinsicHex = - await automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, + + // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency + const extrinsicHex = + await automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ); + await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( + `${SECTION_NAME}.InvalidTime`, ); - await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( - `${SECTION_NAME}.InvalidTime`, - ); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution time that is string fails - */ -test( - "dynamicDispatchTask.fixed schedule with filling execution time string fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes = "abc"; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution time that is object fails - */ -test( - "dynamicDispatchTask.fixed schedule with filling execution time object fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes = {}; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution time that is null fails - */ -test( - "dynamicDispatchTask.fixed schedule with filling execution time null fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes = null; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution time that is undefined fails - */ -test( - "dynamicDispatchTask.fixed schedule with filling execution time undefined fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes = undefined; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with empty execution times array fails - */ -test( - "dynamicDispatchTask.fixed schedule with empty execution times array fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes = []; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution times array that is string fails - */ -test( - "dynamicDispatchTask.fixed schedule with execution times array that is string fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes = "abc"; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution times array that is object fails - */ -test( - "dynamicDispatchTask.fixed schedule with execution times array that is object fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes = {}; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution times array that is null fails - */ -test( - "dynamicDispatchTask.fixed schedule with execution times array that is null fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes = null; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed schedule with execution times array that is undefined fails - */ -test( - "dynamicDispatchTask.fixed schedule with execution times array that is undefined fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes = undefined; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed with null call fails - */ -test( - "dynamicDispatchTask.fixed with null call fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule } = extrinsicParams; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - null, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed with undefined call fails - */ -test( - "dynamicDispatchTask.fixed with undefined call fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { schedule } = extrinsicParams; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - undefined, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with null call fails - */ -test( - "dynamicDispatchTask.recurring with null call fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule } = extrinsicParams; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - null, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with undefined call fails - */ -test( - "dynamicDispatchTask.recurring with undefined call fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { schedule } = extrinsicParams; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - schedule, - undefined, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed with null schedule fails - */ -test( - "dynamicDispatchTask.fixed with null schedule fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { call } = extrinsicParams; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - null, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.fixed with undefined schedule fails - */ -test( - "dynamicDispatchTask.fixed with undefined schedule fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "fixed", - ); - const { call } = extrinsicParams; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - undefined, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with null schedule fails - */ -test( - "dynamicDispatchTask.recurring with null schedule fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { call } = extrinsicParams; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - null, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); - -/** - * dynamicDispatchTask.recurring with undefined schedule fails - */ -test( - "dynamicDispatchTask.recurring with undefined schedule fails", - async () => { - const extrinsicParams = await getDynamicDispatchExtrinsicParams( - polkadotApi, - "recurring", - ); - const { call } = extrinsicParams; - - await expect( - automationTimeApi.buildScheduleDynamicDispatchTask( - keyringPair, - undefined, - call, - ), - ).rejects.toThrow(); - }, - DEFAULT_TIMEOUT_PER_TEST, -); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600-1) fails + */ + it( + "dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600-1) fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.frequency -= 1; + + // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency + const extrinsicHex = + await automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ); + await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( + `${SECTION_NAME}.InvalidTime`, + ); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency + */ + it( + "dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600*0.5) fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.frequency *= 0.5; + schedule.recurring.frequency = Math.ceil(schedule.recurring.frequency); + + // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency + const extrinsicHex = + await automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ); + await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( + `${SECTION_NAME}.InvalidTime`, + ); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600*3.3) fails + */ + it( + "dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600*3.3) fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.frequency *= 1.3; + schedule.recurring.frequency = Math.ceil(schedule.recurring.frequency); + + // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency + const extrinsicHex = + await automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ); + await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( + `${SECTION_NAME}.InvalidTime`, + ); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with frequency that is 0 fails + */ + it( + "dynamicDispatchTask.recurring with frequency that is 0 fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.frequency = 0; + + // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency + // const extrinsicHex = await scheduler.buildScheduleDynamicDispatchTask(keyringPair, schedule, call); + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with frequency that is negtive integer fails + */ + it( + "dynamicDispatchTask.recurring with frequency that is negtive integer fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.frequency = -1; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with frequency that is larger than Number.MAX_SAFE_INTEGER fails + */ + it( + "dynamicDispatchTask.recurring with frequency that is larger than Number.MAX_SAFE_INTEGER fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.frequency = Number.MAX_SAFE_INTEGER + 1; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with frequency that is string fails + */ + it( + "dynamicDispatchTask.recurring with frequency that is string fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.frequency = "123123"; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with frequency that is object fails + */ + it( + "dynamicDispatchTask.recurring with frequency that is object fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.frequency = {}; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with frequency that is null fails + */ + it( + "dynamicDispatchTask.recurring with frequency that is null fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.frequency = null; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with frequency that is undefined fails + */ + it( + "dynamicDispatchTask.recurring with frequency that is undefined fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.frequency = undefined; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+5min) fails. + */ + it( + "dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+5min) fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime += 5 * 60; + + // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency + const extrinsicHex = + await automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ); + await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( + `${SECTION_NAME}.InvalidTime`, + ); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+30min) fails. + */ + it( + "dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+30min) fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime += 30 * 60; + + // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency + const extrinsicHex = + await automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ); + await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( + `${SECTION_NAME}.InvalidTime`, + ); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+45min) fails. + */ + it( + "dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+45min) fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime += 30 * 60; + + // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency + const extrinsicHex = + await automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ); + await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( + `${SECTION_NAME}.InvalidTime`, + ); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with nextExecutionTime that is 0 fails + */ + it( + "dynamicDispatchTask.recurring with nextExecutionTime that is 0 fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime = 0; + + // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with nextExecutionTime that is negtive integer fails + */ + it( + "dynamicDispatchTask.recurring with nextExecutionTime that is negtive integer fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime = -1; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with nextExecutionTime that is larger than Number.MAX_SAFE_INTEGER fails + */ + it( + "dynamicDispatchTask.recurring with nextExecutionTime that is larger than Number.MAX_SAFE_INTEGER fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime = Number.MAX_SAFE_INTEGER + 1; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with nextExecutionTime that is string fails + */ + it( + "dynamicDispatchTask.recurring with nextExecutionTime that is string fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime = "123123"; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with frequency that is object fails + */ + it( + "dynamicDispatchTask.recurring with nextExecutionTime that is object fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime = {}; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with nextExecutionTime that is null fails + */ + it( + "dynamicDispatchTask.recurring with nextExecutionTime that is null fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime = null; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with nextExecutionTime that is undefined fails + */ + it( + "dynamicDispatchTask.recurring with nextExecutionTime that is undefined fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule, call } = extrinsicParams; + schedule.recurring.nextExecutionTime = undefined; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+5min) fails + */ + it( + "dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+5min) fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes[0] += 60 * 5; + + // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency + const extrinsicHex = + await automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ); + await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( + `${SECTION_NAME}.InvalidTime`, + ); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+30min) fails + */ + it( + "dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+30min) fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes[0] += 60 * 30; + + // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency + const extrinsicHex = + await automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ); + await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( + `${SECTION_NAME}.InvalidTime`, + ); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+45min) fails + */ + it( + "dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+45min) fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes[0] += 60 * 30; + + const extrinsicHex = + await automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ); + await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( + `${SECTION_NAME}.InvalidTime`, + ); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution time that is string fails + */ + it( + "dynamicDispatchTask.fixed schedule with filling execution time string fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes = "abc"; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution time that is object fails + */ + it( + "dynamicDispatchTask.fixed schedule with filling execution time object fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes = {}; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution time that is null fails + */ + it( + "dynamicDispatchTask.fixed schedule with filling execution time null fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes = null; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution time that is undefined fails + */ + it( + "dynamicDispatchTask.fixed schedule with filling execution time undefined fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes = undefined; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with empty execution times array fails + */ + it( + "dynamicDispatchTask.fixed schedule with empty execution times array fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes = []; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution times array that is string fails + */ + it( + "dynamicDispatchTask.fixed schedule with execution times array that is string fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes = "abc"; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution times array that is object fails + */ + it( + "dynamicDispatchTask.fixed schedule with execution times array that is object fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes = {}; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution times array that is null fails + */ + it( + "dynamicDispatchTask.fixed schedule with execution times array that is null fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes = null; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed schedule with execution times array that is undefined fails + */ + it( + "dynamicDispatchTask.fixed schedule with execution times array that is undefined fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule, call } = extrinsicParams; + schedule.fixed.executionTimes = undefined; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed with null call fails + */ + it( + "dynamicDispatchTask.fixed with null call fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule } = extrinsicParams; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + null, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed with undefined call fails + */ + it( + "dynamicDispatchTask.fixed with undefined call fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { schedule } = extrinsicParams; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + undefined, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with null call fails + */ + it( + "dynamicDispatchTask.recurring with null call fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule } = extrinsicParams; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + null, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with undefined call fails + */ + it( + "dynamicDispatchTask.recurring with undefined call fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { schedule } = extrinsicParams; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + schedule, + undefined, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed with null schedule fails + */ + it( + "dynamicDispatchTask.fixed with null schedule fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { call } = extrinsicParams; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + null, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.fixed with undefined schedule fails + */ + it( + "dynamicDispatchTask.fixed with undefined schedule fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "fixed", + ); + const { call } = extrinsicParams; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + undefined, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with null schedule fails + */ + it( + "dynamicDispatchTask.recurring with null schedule fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { call } = extrinsicParams; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + null, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); + + /** + * dynamicDispatchTask.recurring with undefined schedule fails + */ + it( + "dynamicDispatchTask.recurring with undefined schedule fails", + async () => { + const extrinsicParams = await getDynamicDispatchExtrinsicParams( + polkadotApi, + "recurring", + ); + const { call } = extrinsicParams; + + await expect( + automationTimeApi.buildScheduleDynamicDispatchTask( + keyringPair, + undefined, + call, + ), + ).rejects.toThrow(undefined); + }, + DEFAULT_TIMEOUT_PER_TEST, + ); +}); From 38f9f5c6612f5c2a4adc87cc6a7aa24addf31cca Mon Sep 17 00:00:00 2001 From: imstar15 Date: Mon, 27 Nov 2023 20:39:09 +0800 Subject: [PATCH 2/3] Specific errors were thrown during testing --- test/functional/dynamicDispatchTask.test.ts | 234 ++++----- test/package.json | 18 + test/utils/helpFn.ts | 235 ++++----- test/yarn.lock | 518 ++++++++++++++++++++ 4 files changed, 779 insertions(+), 226 deletions(-) create mode 100644 test/package.json create mode 100644 test/yarn.lock diff --git a/test/functional/dynamicDispatchTask.test.ts b/test/functional/dynamicDispatchTask.test.ts index 98c7345..a9f0474 100644 --- a/test/functional/dynamicDispatchTask.test.ts +++ b/test/functional/dynamicDispatchTask.test.ts @@ -162,7 +162,7 @@ describe("test-dynamic-dispatch-task", () => { * scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency */ it( - "dynamicDispatchTask.recurring with frequency that is not a multiply of 3600(3600*0.5) fails", + "dynamicDispatchTask.recurring with frequency that is not a multiply of a timeslot fails", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -215,10 +215,10 @@ describe("test-dynamic-dispatch-task", () => { ); /** - * dynamicDispatchTask.recurring with frequency that is 0 fails + * Build dynamicDispatchTask.recurring task with frequency that is 0 fails will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with frequency that is 0 fails", + "build dynamicDispatchTask.recurring task with frequency that is 0 fails will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -235,16 +235,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("frequency must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with frequency that is negtive integer fails + * Build dynamicDispatchTask.recurring task with frequency that is negtive integer will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with frequency that is negtive integer fails", + "build dynamicDispatchTask.recurring task with frequency that is negtive integer will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -259,16 +259,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("frequency must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with frequency that is larger than Number.MAX_SAFE_INTEGER fails + * Build dynamicDispatchTask.recurring task with frequency that is larger than Number.MAX_SAFE_INTEGER will throw too large error */ it( - "dynamicDispatchTask.recurring with frequency that is larger than Number.MAX_SAFE_INTEGER fails", + "build dynamicDispatchTask.recurring task with frequency that is larger than Number.MAX_SAFE_INTEGER will throw too large error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -283,16 +283,18 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow( + 'createType(Call):: Call: failed decoding automationTime.scheduleDynamicDispatchTask:: Struct: failed on args: {"schedule":"{\\"_enum\\":{\\"Fixed\\":\\"{\\\\\\"executionTimes\\\\\\":\\\\\\"Vec\\\\\\"}\\",\\"Recurring\\":\\"{\\\\\\"nextExecutionTime\\\\\\":\\\\\\"u64\\\\\\",\\\\\\"frequency\\\\\\":\\\\\\"u64\\\\\\"}\\"}}","call":"Call"}:: Struct: failed on schedule: {"_enum":{"Fixed":"{\\"executionTimes\\":\\"Vec\\"}","Recurring":"{\\"nextExecutionTime\\":\\"u64\\",\\"frequency\\":\\"u64\\"}"}}:: Enum(recurring):: Struct: failed on frequency: u64:: Number needs to be an integer <= Number.MAX_SAFE_INTEGER, i.e. 2 ^ 53 - 1', + ); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with frequency that is string fails + * dynamicDispatchTask.recurring with frequency that is string will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with frequency that is string fails", + "dynamicDispatchTask.recurring with frequency that is string will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -307,16 +309,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("frequency must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with frequency that is object fails + * Build dynamicDispatchTask.recurring task with frequency that is object will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with frequency that is object fails", + "build dynamicDispatchTask.recurring task with frequency that is object will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -331,16 +333,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("frequency must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with frequency that is null fails + * Build dynamicDispatchTask.recurring with frequency that is null will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with frequency that is null fails", + "build dynamicDispatchTask.recurring with frequency that is null will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -355,16 +357,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("frequency must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with frequency that is undefined fails + * Build dynamicDispatchTask.recurring task with frequency that is undefined will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with frequency that is undefined fails", + "build dynamicDispatchTask.recurring task with frequency that is undefined will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -379,23 +381,23 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("frequency must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+5min) fails. + * build dynamicDispatchTask.recurring task with nextExecutionTime not on 10 minutes time slot(+5min) will throw automationTime.InvalidTime error. */ it( - "dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+5min) fails", + "build dynamicDispatchTask.recurring task with nextExecutionTime not on 10 minutes time slot(+1min) will throw automationTime.InvalidTime error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, "recurring", ); const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime += 5 * 60; + schedule.recurring.nextExecutionTime += 60 * 1; // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency const extrinsicHex = @@ -412,17 +414,17 @@ describe("test-dynamic-dispatch-task", () => { ); /** - * dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+30min) fails. + * Build dynamicDispatchTask.recurring task with nextExecutionTime not on non-o’clock(+7) will throw automationTime.InvalidTime error. */ it( - "dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+30min) fails", + "build dynamicDispatchTask.recurring task with nextExecutionTime not on 10 minutes time slot(+5min) will throw automationTime.InvalidTime error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, "recurring", ); const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime += 30 * 60; + schedule.recurring.nextExecutionTime += 30 * 5; // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency const extrinsicHex = @@ -439,17 +441,17 @@ describe("test-dynamic-dispatch-task", () => { ); /** - * dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+45min) fails. + * build dynamicDispatchTask.recurring task nextExecutionTime not on 10 minutes time slot(+5min) will throw automationTime.InvalidTime error. */ it( - "dynamicDispatchTask.recurring nextExecutionTime on non-o’clock(+45min) fails", + "build dynamicDispatchTask.recurring task with nextExecutionTime not on 10 minutes time slot(+7min) will throw automationTime.InvalidTime error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, "recurring", ); const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime += 30 * 60; + schedule.recurring.nextExecutionTime += 30 * 7; // automationTimeApi.buildScheduleDynamicDispatchTask will fail with invalid frequency const extrinsicHex = @@ -466,10 +468,10 @@ describe("test-dynamic-dispatch-task", () => { ); /** - * dynamicDispatchTask.recurring with nextExecutionTime that is 0 fails + * Build dynamicDispatchTask.recurring task with nextExecutionTime that is 0 will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with nextExecutionTime that is 0 fails", + "build dynamicDispatchTask.recurring task with nextExecutionTime that is 0 will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -485,16 +487,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("nextExecutionTime must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with nextExecutionTime that is negtive integer fails + * Build dynamicDispatchTask.recurring task with nextExecutionTime that is negtive integer fails */ it( - "dynamicDispatchTask.recurring with nextExecutionTime that is negtive integer fails", + "build dynamicDispatchTask.recurring task with nextExecutionTime that is negtive integer will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -509,7 +511,7 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("nextExecutionTime must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); @@ -518,7 +520,7 @@ describe("test-dynamic-dispatch-task", () => { * dynamicDispatchTask.recurring with nextExecutionTime that is larger than Number.MAX_SAFE_INTEGER fails */ it( - "dynamicDispatchTask.recurring with nextExecutionTime that is larger than Number.MAX_SAFE_INTEGER fails", + "dynamicDispatchTask.recurring with nextExecutionTime that is larger than Number.MAX_SAFE_INTEGER will throw too large error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -533,16 +535,18 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow( + 'createType(Call):: Call: failed decoding automationTime.scheduleDynamicDispatchTask:: Struct: failed on args: {"schedule":"{\\"_enum\\":{\\"Fixed\\":\\"{\\\\\\"executionTimes\\\\\\":\\\\\\"Vec\\\\\\"}\\",\\"Recurring\\":\\"{\\\\\\"nextExecutionTime\\\\\\":\\\\\\"u64\\\\\\",\\\\\\"frequency\\\\\\":\\\\\\"u64\\\\\\"}\\"}}","call":"Call"}:: Struct: failed on schedule: {"_enum":{"Fixed":"{\\"executionTimes\\":\\"Vec\\"}","Recurring":"{\\"nextExecutionTime\\":\\"u64\\",\\"frequency\\":\\"u64\\"}"}}:: Enum(recurring):: Struct: failed on nextExecutionTime: u64:: Number needs to be an integer <= Number.MAX_SAFE_INTEGER, i.e. 2 ^ 53 - 1', + ); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with nextExecutionTime that is string fails + * Build dynamicDispatchTask.recurring task with nextExecutionTime that is string will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with nextExecutionTime that is string fails", + "build dynamicDispatchTask.recurring task with nextExecutionTime that is string will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -557,16 +561,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("nextExecutionTime must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with frequency that is object fails + * Build dynamicDispatchTask.recurring task with nextExecutionTime that is object will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with nextExecutionTime that is object fails", + "build dynamicDispatchTask.recurring task with nextExecutionTime that is object will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -581,16 +585,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("nextExecutionTime must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with nextExecutionTime that is null fails + * Build dynamicDispatchTask.recurring task with nextExecutionTime that is null will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with nextExecutionTime that is null fails", + "build dynamicDispatchTask.recurring task with nextExecutionTime that is null will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -605,16 +609,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("nextExecutionTime must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with nextExecutionTime that is undefined fails + * Build dynamicDispatchTask.recurring task with nextExecutionTime that is undefined will throw not a positive integer error */ it( - "dynamicDispatchTask.recurring with nextExecutionTime that is undefined fails", + "build dynamicDispatchTask.recurring task with nextExecutionTime that is undefined will throw not a positive integer error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -629,23 +633,23 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("nextExecutionTime must be a positive integer"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+5min) fails + * Send dynamicDispatchTask.fixed task with execution time not on 10 minutes time slot(+5min) will throw automationTime.InvalidTime error */ it( - "dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+5min) fails", + "send dynamicDispatchTask.fixed task with execution time not on 10 minutes time slot(+1min) will throw automationTime.InvalidTime error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, "fixed", ); const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes[0] += 60 * 5; + schedule.fixed.executionTimes[0] += 60 * 1; // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency const extrinsicHex = @@ -662,17 +666,17 @@ describe("test-dynamic-dispatch-task", () => { ); /** - * dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+30min) fails + * Send dynamicDispatchTask.fixed task with execution time not on 10 minutes time slot(+5min) will throw automationTime.InvalidTime error */ it( - "dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+30min) fails", + "send dynamicDispatchTask.fixed task with execution time not on 10 minutes time slot(+5min) will throw automationTime.InvalidTime error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, "fixed", ); const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes[0] += 60 * 30; + schedule.fixed.executionTimes[0] += 60 * 5; // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency const extrinsicHex = @@ -689,17 +693,17 @@ describe("test-dynamic-dispatch-task", () => { ); /** - * dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+45min) fails + * Send dynamicDispatchTask.fixed task with execution time not on 10 minutes time slot(+7min) will throw automationTime.InvalidTime error */ it( - "dynamicDispatchTask.fixed schedule with execution time on non-o’clock(+45min) fails", + "send dynamicDispatchTask.fixed task with execution time not on 10 minutes time slot(+7min) will throw automationTime.InvalidTime error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, "fixed", ); const { schedule, call } = extrinsicParams; - schedule.fixed.executionTimes[0] += 60 * 30; + schedule.fixed.executionTimes[0] += 60 * 7; const extrinsicHex = await automationTimeApi.buildScheduleDynamicDispatchTask( @@ -715,10 +719,10 @@ describe("test-dynamic-dispatch-task", () => { ); /** - * dynamicDispatchTask.fixed schedule with execution time that is string fails + * Build dynamicDispatchTask.fixed task with execution time that is string will throw not an array error */ it( - "dynamicDispatchTask.fixed schedule with filling execution time string fails", + "build dynamicDispatchTask.fixed task with filling execution time string will throw not an array error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -733,16 +737,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("executionTimes is not an array"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed schedule with execution time that is object fails + * Build dynamicDispatchTask.fixed task schedule with execution time that is object will throw not an array error */ it( - "dynamicDispatchTask.fixed schedule with filling execution time object fails", + "build dynamicDispatchTask.fixed task with filling execution time object will throw not an array error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -757,16 +761,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("executionTimes is not an array"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed schedule with execution time that is null fails + * Build dynamicDispatchTask.fixed task with execution time that is null will throw not an array error */ it( - "dynamicDispatchTask.fixed schedule with filling execution time null fails", + "build dynamicDispatchTask.fixed task with filling execution time null will throw not an array error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -781,16 +785,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("executionTimes is not an array"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed schedule with execution time that is undefined fails + * Build dynamicDispatchTask.fixed task with execution time that is undefined will throw not an array error */ it( - "dynamicDispatchTask.fixed schedule with filling execution time undefined fails", + "build dynamicDispatchTask.fixed task with filling execution time undefined will throw not an array error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -805,16 +809,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("executionTimes is not an array"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed schedule with empty execution times array fails + * Build dynamicDispatchTask.fixed task with empty execution times array will throw empty array error */ it( - "dynamicDispatchTask.fixed schedule with empty execution times array fails", + "build dynamicDispatchTask.fixed task schedule with empty execution times array will throw empty array error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -829,16 +833,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("executionTimes is empty"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed schedule with execution times array that is string fails + * Build dynamicDispatchTask.fixed task with execution times array that is string will throw not an array error */ it( - "dynamicDispatchTask.fixed schedule with execution times array that is string fails", + "build dynamicDispatchTask.fixed task schedule with execution times array that is string will throw not an array error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -853,16 +857,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("executionTimes is not an array"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed schedule with execution times array that is object fails + * Build dynamicDispatchTask.fixed task schedule with execution times array that is object fails */ it( - "dynamicDispatchTask.fixed schedule with execution times array that is object fails", + "build dynamicDispatchTask.fixed task schedule with execution times array that is object will throw not an array", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -877,16 +881,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("executionTimes is not an array"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed schedule with execution times array that is null fails + * Build dynamicDispatchTask.fixed task with execution times array that is null will throw not an array task error */ it( - "dynamicDispatchTask.fixed schedule with execution times array that is null fails", + "build dynamicDispatchTask.fixed task with execution times array that is null will throw not an array task error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -901,16 +905,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("executionTimes is not an array"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed schedule with execution times array that is undefined fails + * Build dynamicDispatchTask.fixed task with execution times array that is undefined will throw not an array error */ it( - "dynamicDispatchTask.fixed schedule with execution times array that is undefined fails", + "build dynamicDispatchTask.fixed task with execution times array that is undefined will throw not an array error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -925,16 +929,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("executionTimes is not an array"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed with null call fails + * Build dynamicDispatchTask.fixed task with null call will throw null call error */ it( - "dynamicDispatchTask.fixed with null call fails", + "build dynamicDispatchTask.fixed task with null call will throw null call error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -948,16 +952,18 @@ describe("test-dynamic-dispatch-task", () => { schedule, null, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow( + 'createType(Call):: Call: failed decoding automationTime.scheduleDynamicDispatchTask:: Struct: failed on args: {"schedule":"{\\"_enum\\":{\\"Fixed\\":\\"{\\\\\\"executionTimes\\\\\\":\\\\\\"Vec\\\\\\"}\\",\\"Recurring\\":\\"{\\\\\\"nextExecutionTime\\\\\\":\\\\\\"u64\\\\\\",\\\\\\"frequency\\\\\\":\\\\\\"u64\\\\\\"}\\"}}","call":"Call"}:: Struct: failed on call: Call:: Call: Cannot decode value \'null\' of type object', + ); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed with undefined call fails + * Build dynamicDispatchTask.fixed task with undefined call will throw undefined call error */ it( - "dynamicDispatchTask.fixed with undefined call fails", + "build dynamicDispatchTask.fixed task with undefined call will throw undefined call error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -971,16 +977,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, undefined, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("call is null or undefined"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with null call fails + * Build dynamicDispatchTask.recurring task with null call will throw null call error */ it( - "dynamicDispatchTask.recurring with null call fails", + "build dynamicDispatchTask.recurring task with null call will throw null call error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -994,16 +1000,18 @@ describe("test-dynamic-dispatch-task", () => { schedule, null, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow( + 'createType(Call):: Call: failed decoding automationTime.scheduleDynamicDispatchTask:: Struct: failed on args: {"schedule":"{\\"_enum\\":{\\"Fixed\\":\\"{\\\\\\"executionTimes\\\\\\":\\\\\\"Vec\\\\\\"}\\",\\"Recurring\\":\\"{\\\\\\"nextExecutionTime\\\\\\":\\\\\\"u64\\\\\\",\\\\\\"frequency\\\\\\":\\\\\\"u64\\\\\\"}\\"}}","call":"Call"}:: Struct: failed on call: Call:: Call: Cannot decode value \'null\' of type object', + ); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with undefined call fails + * Build dynamicDispatchTask.recurring task with undefined call fails */ it( - "dynamicDispatchTask.recurring with undefined call fails", + "build dynamicDispatchTask.recurrin task with undefined call will throw undefined call error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -1017,16 +1025,16 @@ describe("test-dynamic-dispatch-task", () => { schedule, undefined, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("call is null or undefined"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed with null schedule fails + * Build dynamicDispatchTask.fixed task with null schedule will throw null object error */ it( - "dynamicDispatchTask.fixed with null schedule fails", + "build dynamicDispatchTask.fixed with null schedule will throw null object error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -1040,16 +1048,16 @@ describe("test-dynamic-dispatch-task", () => { null, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("Cannot read properties of null (reading 'recurring')"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.fixed with undefined schedule fails + * Build dynamicDispatchTask.fixed task with undefined schedule will throw undefined object error */ it( - "dynamicDispatchTask.fixed with undefined schedule fails", + "build dynamicDispatchTask.fixed task with undefined schedule will throw undefined object error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -1063,16 +1071,18 @@ describe("test-dynamic-dispatch-task", () => { undefined, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow( + "Cannot read properties of undefined (reading 'recurring')", + ); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with null schedule fails + * Build dynamicDispatchTask.recurring task with null schedule fails will throw null object error */ it( - "dynamicDispatchTask.recurring with null schedule fails", + "build dynamicDispatchTask.recurring task with null schedule fails will throw null object error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -1086,16 +1096,16 @@ describe("test-dynamic-dispatch-task", () => { null, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow("Cannot read properties of null (reading 'recurring')"); }, DEFAULT_TIMEOUT_PER_TEST, ); /** - * dynamicDispatchTask.recurring with undefined schedule fails + * Build dynamicDispatchTask.recurring task with undefined schedule will throw undefind object error */ it( - "dynamicDispatchTask.recurring with undefined schedule fails", + "build dynamicDispatchTask.recurring task with undefined schedule will throw undefind object error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, @@ -1109,7 +1119,9 @@ describe("test-dynamic-dispatch-task", () => { undefined, call, ), - ).rejects.toThrow(undefined); + ).rejects.toThrow( + "Cannot read properties of undefined (reading 'recurring')", + ); }, DEFAULT_TIMEOUT_PER_TEST, ); diff --git a/test/package.json b/test/package.json new file mode 100644 index 0000000..afcfc3b --- /dev/null +++ b/test/package.json @@ -0,0 +1,18 @@ +{ + "name": "demo", + "version": "1.0.0", + "description": "", + "main": "index.js", + "author": "", + "license": "ISC", + "dependencies": { + "@oak-network/api-augment": "file:../packages/api-augment/build", + "@oak-network/types": "file:../packages/types/build", + "@polkadot/api": "^10.11.1", + "@polkadot/types": "^10.11.1", + "@polkadot/util": "^12.6.1", + "@polkadot/wasm-crypto": "^7.3.1", + "bn.js": "^5.2.1", + "lodash": "^4.17.21" + } +} diff --git a/test/utils/helpFn.ts b/test/utils/helpFn.ts index a5f6097..86a41ac 100644 --- a/test/utils/helpFn.ts +++ b/test/utils/helpFn.ts @@ -12,7 +12,7 @@ import BN from "bn.js"; import { rpc, types, runtime } from "@oak-network/types"; import "@oak-network/api-augment"; -import { AutomationTimeApi, Recurrer, oakConstants, config } from "./"; +import { AutomationTimeApi, Recurrer, oakConstants, config } from "."; const { SS58_PREFIX } = oakConstants; @@ -21,7 +21,8 @@ export const MIN_RUNNING_TEST_BALANCE = 20000000000; export const TRANSFER_AMOUNT = 1000000000; export const RECEIVER_ADDRESS = "66fhJwYLiK87UDXYDQP9TfYdHpeEyMvQ3MK8Z6GgWAdyyCL3"; -const RECURRING_FREQUENCY = 3600; +export const TIME_SLOT_IN_SECONDS = 600; +const RECURRING_FREQUENCY = TIME_SLOT_IN_SECONDS; // This is a Moonbeam test account private key. Please do not use it for any other purpose. // https://github.com/moonbeam-foundation/moonbeam/blob/2ea0db7c18d907ddeda1a5f4d3f68262e10560e7/README.md?plain=1#L65 const ALITH_PRIVATE_KEY = @@ -34,14 +35,34 @@ export const createPolkadotApi = async (endpoint: string) => { const polkadotApi = await ApiPromise.create({ provider: wsProvider, rpc, - types, runtime, + types, }); return polkadotApi; }; export const getPolkadotApi = async () => createPolkadotApi(config.endpoint); +/** + * Get keyring pair for testing + * @returns keyring pair + */ +export const getKeyringPair = async (): Promise => { + const { mnemonic } = config; + if (_.isEmpty(mnemonic)) { + throw new Error("The MNEMONIC environment variable is not set."); + } + + await waitReady(); + + // Generate sender keyring pair from mnemonic + const keyring = new Keyring({ ss58Format: SS58_PREFIX, type: "sr25519" }); + const keyringPair = _.startsWith(mnemonic, "//") + ? keyring.addFromUri(mnemonic) + : keyring.addFromMnemonic(mnemonic); + return keyringPair; +}; + /** * getContext: Get test context * @returns context object: { scheduler, observer, keyringPair } @@ -51,6 +72,64 @@ export const getContext = async (polkadotApi: ApiPromise) => ({ keyringPair: await getKeyringPair(), }); +/** + * Default error handler for websockets updates for extrinsic + * @param result + * @returns null + */ +const defaultErrorHandler = async ( + polkadotApi: ApiPromise, + result: ISubmittableResult, +): Promise => { + console.log(`Tx status: ${result.status.type}`); + if (result.status.isFinalized) { + if (!_.isUndefined(result.dispatchError)) { + if (result.dispatchError.isModule) { + const metaError = polkadotApi.registry.findMetaError( + result.dispatchError.asModule, + ); + const { docs, name, section } = metaError; + const dispatchErrorMessage = JSON.stringify({ docs, name, section }); + const errMsg = `Transaction finalized with error by blockchain ${dispatchErrorMessage}`; + console.log(errMsg); + } else { + const errMsg = `Transaction finalized with error by blockchain ${result.dispatchError.toString()}`; + console.log(errMsg); + } + } + } +}; + +/** + * SendExtrinsic: sends built and signed extrinsic to the chain. + * Accepts pre-built extrinsic hex string. You may provide your own error handler. + * If none provided, a default error handler is provided, seen below. + * A transaction hash should be returned as a result of the extrinsic. + * @param extrinsic + * @param handleDispatch + * @returns transaction hash + */ +const sendExtrinsicToChain = async ( + polkadotApi: ApiPromise, + extrinsicHex: HexString, + /* eslint-disable @typescript-eslint/no-explicit-any */ + handleDispatch: (result: ISubmittableResult) => any, +): Promise => { + const txObject = polkadotApi.tx(extrinsicHex); + const unsub = await txObject.send(async (result) => { + const { status } = result; + if (_.isUndefined(handleDispatch)) { + await defaultErrorHandler(polkadotApi, result); + } else { + await handleDispatch(result); + } + if (status.isFinalized) { + unsub(); + } + }); + return txObject.hash.toString(); +}; + /** * sendExtrinsic: Send extrinsic to chain * @param scheduler @@ -67,29 +146,37 @@ export const sendExtrinsic = async ( polkadotApi, extrinsicHex, ({ status, events, dispatchError }) => { - if (status?.isFinalized) { - if (!_.isUndefined(dispatchError)) { - if (dispatchError.isModule) { - const metaError = polkadotApi.registry.findMetaError(dispatchError.asModule); + if (status?.isFinalized) { + if (!_.isUndefined(dispatchError)) { + if (dispatchError.isModule) { + const metaError = polkadotApi.registry.findMetaError( + dispatchError.asModule, + ); const { name, section } = metaError; reject(new Error(`${section}.${name}`)); return; - } - reject(new Error(dispatchError.toString())); - return; - + } + reject(new Error(dispatchError.toString())); + return; + } + + const event = _.find(events, ({ event: eventItem }) => + polkadotApi.events.system.ExtrinsicSuccess.is(eventItem), + ); + // We pass the event array out so the caller can access and fetch relevant data in extrinsic such as the task id. Recall that task id is emit from the TaskScheduled { who, taskId } event + // if the event is empty that mean the extrinsic failed the test resolve to error + if (event) { + resolve({ + blockHash: status?.asFinalized?.toString(), + events, + extrinsicHash: extrinsic.hash.toString(), + }); + } else { + reject(new Error("The event.ExtrinsicSuccess is not found")); + } } - - const event = _.find(events, ({ event }) => polkadotApi.events.system.ExtrinsicSuccess.is(event)); - // We pass the event array out so the caller can access and fetch relevant data in extrinsic such as the task id. Recall that task id is emit from the TaskScheduled { who, taskId } event - // if the event is empty that mean the extrinsic failed the test resolve to error - if (event) { - resolve({ extrinsicHash: extrinsic.hash.toString(), blockHash: status?.asFinalized?.toString(), events }); - } else { - reject(new Error('The event.ExtrinsicSuccess is not found')); - } - } - }).catch((reason) => reject(reason)); + }, + ).catch((reason) => reject(reason)); }); export const hexToAscii = (hexStr: string, hasPrefix = false) => { @@ -117,26 +204,6 @@ export const checkBalance = async ( ).toEqual(true); }; -/** - * Get keyring pair for testing - * @returns keyring pair - */ -export const getKeyringPair = async (): Promise => { - const { mnemonic } = config; - if (_.isEmpty(mnemonic)) { - throw new Error("The MNEMONIC environment variable is not set."); - } - - await waitReady(); - - // Generate sender keyring pair from mnemonic - const keyring = new Keyring({ type: "sr25519", ss58Format: SS58_PREFIX }); - const keyringPair = _.startsWith(mnemonic, "//") - ? keyring.addFromUri(mnemonic) - : keyring.addFromMnemonic(mnemonic); - return keyringPair; -}; - /** * Get keyring pair for moonbeam testing * @returns keyring pair @@ -159,7 +226,6 @@ export const getMoonbeamKeyringPair = async (): Promise => { const ethDerPath = `m/44'/60'/0'/0/${index}`; await waitReady(); - const keyringECDSA = new Keyring({ type: "ethereum" }); moonbeamKeyringPair = keyringECDSA.addFromUri( `${process.env.MNEMONIC}/${ethDerPath}`, ); @@ -186,7 +252,7 @@ export const findExtrinsicFromChain = async ( } = signedBlock; const extrinsic = _.find( extrinsics, - (extrinsic) => extrinsic.hash.toHex() === extrinsicHash, + (extrinsicItem) => extrinsicItem.hash.toHex() === extrinsicHash, ); return extrinsic; }; @@ -227,7 +293,7 @@ export const cancelTaskAndVerify = async ( expect(section).toEqual(SECTION_NAME); expect(method).toEqual("cancelTask"); - expect(new Buffer(taskIdOnChain).toString()).toEqual(taskID); + expect(Buffer.from(taskIdOnChain.toU8a(true)).toString()).toEqual(taskID); // Make sure the task has been canceled. const tasks = @@ -235,7 +301,8 @@ export const cancelTaskAndVerify = async ( expect( _.find( tasks, - (task) => !_.isUndefined(_.find(task, (task) => task[1] === taskID)), + (task) => + !_.isUndefined(_.find(task, (taskItem) => taskItem[1] === taskID)), ), ).toBeUndefined(); }; @@ -291,13 +358,15 @@ export const scheduleDynamicDispatchTaskAndVerify = async ( firstExecutionTime = nextExecutionTime; } else { const { executionTimes } = fixed; - firstExecutionTime = executionTimes[0]; + [firstExecutionTime] = executionTimes; } // Make use the task has been scheduled const taskScheduledEvent = events.find((record) => { const { event } = record; - return event.method == "TaskScheduled" && event.section == "automationTime"; + return ( + event.method === "TaskScheduled" && event.section === "automationTime" + ); }); const taskID = Buffer.from(taskScheduledEvent.event.data.taskId).toString(); @@ -309,10 +378,7 @@ export const scheduleDynamicDispatchTaskAndVerify = async ( tasks, (task) => !_.isUndefined( - _.find( - task, - ([_account, scheduledTaskId]) => scheduledTaskId === taskID, - ), + _.find(task, ([, scheduledTaskId]) => scheduledTaskId === taskID), ), ), ).toBeUndefined(); @@ -337,8 +403,8 @@ export const getDynamicDispatchExtrinsicParams = async ( ); schedule = { recurring: { - nextExecutionTime, frequency: RECURRING_FREQUENCY, + nextExecutionTime, }, }; } else { @@ -350,68 +416,7 @@ export const getDynamicDispatchExtrinsicParams = async ( } return { + call: polkadotApi.tx.balances.transfer(RECEIVER_ADDRESS, TRANSFER_AMOUNT), schedule, - call: polkadotApi.tx.balances["transfer"]( - RECEIVER_ADDRESS, - TRANSFER_AMOUNT, - ), }; }; - -/** - * Default error handler for websockets updates for extrinsic - * @param result - * @returns null - */ -const defaultErrorHandler = async ( - polkadotApi: ApiPromise, - result: ISubmittableResult, -): Promise => { - console.log(`Tx status: ${result.status.type}`); - if (result.status.isFinalized) { - if (!_.isUndefined(result.dispatchError)) { - if (result.dispatchError.isModule) { - const metaError = polkadotApi.registry.findMetaError( - result.dispatchError.asModule, - ); - const { docs, name, section } = metaError; - const dispatchErrorMessage = JSON.stringify({ docs, name, section }); - const errMsg = `Transaction finalized with error by blockchain ${dispatchErrorMessage}`; - console.log(errMsg); - } else { - const errMsg = `Transaction finalized with error by blockchain ${result.dispatchError.toString()}`; - console.log(errMsg); - } - } - } -}; - -/** - * SendExtrinsic: sends built and signed extrinsic to the chain. - * Accepts pre-built extrinsic hex string. You may provide your own error handler. - * If none provided, a default error handler is provided, seen below. - * A transaction hash should be returned as a result of the extrinsic. - * @param extrinsic - * @param handleDispatch - * @returns transaction hash - */ -const sendExtrinsicToChain = async ( - polkadotApi: ApiPromise, - extrinsicHex: HexString, - /* eslint-disable @typescript-eslint/no-explicit-any */ - handleDispatch: (result: ISubmittableResult) => any, -): Promise => { - const txObject = polkadotApi.tx(extrinsicHex); - const unsub = await txObject.send(async (result) => { - const { status } = result; - if (_.isUndefined(handleDispatch)) { - await defaultErrorHandler(polkadotApi, result); - } else { - await handleDispatch(result); - } - if (status.isFinalized) { - unsub(); - } - }); - return txObject.hash.toString(); -}; diff --git a/test/yarn.lock b/test/yarn.lock new file mode 100644 index 0000000..153f2d3 --- /dev/null +++ b/test/yarn.lock @@ -0,0 +1,518 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@noble/curves@^1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35" + integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw== + dependencies: + "@noble/hashes" "1.3.2" + +"@noble/hashes@1.3.2", "@noble/hashes@^1.3.2": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" + integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== + +"@oak-network/api-augment@file:../packages/api-augment/build": + version "2.0.7" + dependencies: + "@polkadot/types" "^10.9.1" + +"@oak-network/types@file:../packages/types/build": + version "2.0.7" + dependencies: + "@open-web3/orml-type-definitions" "^2.0.1" + +"@open-web3/orml-type-definitions@^2.0.1": + version "2.0.1" + resolved "https://registry.yarnpkg.com/@open-web3/orml-type-definitions/-/orml-type-definitions-2.0.1.tgz#b3db4fb5777dc05c55fa5184c34f4ec91030f012" + integrity sha512-wqeSBOKk8UU9CBqYhK2yQh9YqwaS7vai71WuOGFNJnzRT+6WnzY0leaLTionuzfE3M4Y/jTrc8BTL6+PVFCr6Q== + dependencies: + lodash.merge "^4.6.2" + +"@polkadot/api-augment@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/api-augment/-/api-augment-10.11.1.tgz#63a5ccc3b33c18fa71263d5e58e0a4c6041a8504" + integrity sha512-9Sk7fi6wzvxAoxvGJPcMt0hU4WzuIAlBy4Rng6WPiS6Ed0HJLr1dkZaqFFmV5my2pb3tu//1JGYkt+MUVB0Kqw== + dependencies: + "@polkadot/api-base" "10.11.1" + "@polkadot/rpc-augment" "10.11.1" + "@polkadot/types" "10.11.1" + "@polkadot/types-augment" "10.11.1" + "@polkadot/types-codec" "10.11.1" + "@polkadot/util" "^12.6.1" + tslib "^2.6.2" + +"@polkadot/api-base@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/api-base/-/api-base-10.11.1.tgz#843fec74989b466278c42516a86fba65778b69bf" + integrity sha512-A645Hj9bGtq0EOEWcwTaGoD40vp8/ih1suwinl5il8Psg+bdDmzodnVH5Jhuwe1dNKOuXuvxZvOmbYUPWyIqyg== + dependencies: + "@polkadot/rpc-core" "10.11.1" + "@polkadot/types" "10.11.1" + "@polkadot/util" "^12.6.1" + rxjs "^7.8.1" + tslib "^2.6.2" + +"@polkadot/api-derive@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-10.11.1.tgz#528f90e33577258997cb998c0b597ba54bc9c683" + integrity sha512-i48okJr0l1IrFTPa9KVkoJnDL2EHKExR6XC0Z7I9+kW9noxYWqo0tIoi5s1bNVD475xWK/rUjT7qHxiDbPaCUQ== + dependencies: + "@polkadot/api" "10.11.1" + "@polkadot/api-augment" "10.11.1" + "@polkadot/api-base" "10.11.1" + "@polkadot/rpc-core" "10.11.1" + "@polkadot/types" "10.11.1" + "@polkadot/types-codec" "10.11.1" + "@polkadot/util" "^12.6.1" + "@polkadot/util-crypto" "^12.6.1" + rxjs "^7.8.1" + tslib "^2.6.2" + +"@polkadot/api@10.11.1", "@polkadot/api@^10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-10.11.1.tgz#3667ae1cf2f9c1955e138438c313efdba081314d" + integrity sha512-WEgUYvY90AHX9drmsvWQ4DDuqlE7h4x3f28K5eOoJF4dQ5AkWsFogxwJ4TH57POWLfyi8AIn6/f1vsqPtReDhA== + dependencies: + "@polkadot/api-augment" "10.11.1" + "@polkadot/api-base" "10.11.1" + "@polkadot/api-derive" "10.11.1" + "@polkadot/keyring" "^12.6.1" + "@polkadot/rpc-augment" "10.11.1" + "@polkadot/rpc-core" "10.11.1" + "@polkadot/rpc-provider" "10.11.1" + "@polkadot/types" "10.11.1" + "@polkadot/types-augment" "10.11.1" + "@polkadot/types-codec" "10.11.1" + "@polkadot/types-create" "10.11.1" + "@polkadot/types-known" "10.11.1" + "@polkadot/util" "^12.6.1" + "@polkadot/util-crypto" "^12.6.1" + eventemitter3 "^5.0.1" + rxjs "^7.8.1" + tslib "^2.6.2" + +"@polkadot/keyring@^12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-12.6.1.tgz#0984dd625edd582750d8975f1898a4acb14bda8b" + integrity sha512-cicTctZr5Jy5vgNT2FsNiKoTZnz6zQkgDoIYv79NI+p1Fhwc9C+DN/iMCnk3Cm9vR2gSAd2fSV+Y5iKVDhAmUw== + dependencies: + "@polkadot/util" "12.6.1" + "@polkadot/util-crypto" "12.6.1" + tslib "^2.6.2" + +"@polkadot/networks@12.6.1", "@polkadot/networks@^12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/networks/-/networks-12.6.1.tgz#eb0b1fb9e04fbaba066d44df4ff18b0567ca5fcc" + integrity sha512-pzyirxTYAnsx+6kyLYcUk26e4TLz3cX6p2KhTgAVW77YnpGX5VTKTbYykyXC8fXFd/migeQsLaa2raFN47mwoA== + dependencies: + "@polkadot/util" "12.6.1" + "@substrate/ss58-registry" "^1.44.0" + tslib "^2.6.2" + +"@polkadot/rpc-augment@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/rpc-augment/-/rpc-augment-10.11.1.tgz#f100165e60777a58583ea97cb672692a31a185f2" + integrity sha512-wrtxHnEwqS3b1GuZ3sA1pzLuUjjLnW4FPawOklONRcIuKbGmFuvu7QvEIHmxBV1FAS/fs8gbvp8ImKWUPnT93Q== + dependencies: + "@polkadot/rpc-core" "10.11.1" + "@polkadot/types" "10.11.1" + "@polkadot/types-codec" "10.11.1" + "@polkadot/util" "^12.6.1" + tslib "^2.6.2" + +"@polkadot/rpc-core@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-10.11.1.tgz#557958e57514d93fd3270a99910bf0d9f066df82" + integrity sha512-3l4l+zL7MDWzQx3WnaieXXUKsbeA1Miu4wsje5trYJEE+hm+nMW8h7fiFKfYzXBi7ty/wMS+S7BfQPTrDkYHxA== + dependencies: + "@polkadot/rpc-augment" "10.11.1" + "@polkadot/rpc-provider" "10.11.1" + "@polkadot/types" "10.11.1" + "@polkadot/util" "^12.6.1" + rxjs "^7.8.1" + tslib "^2.6.2" + +"@polkadot/rpc-provider@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-10.11.1.tgz#8d94e96bba71ee8bbce9baf407b411c523fc2f28" + integrity sha512-86aDUOnaG42si0jSOAgn6Fs3F3rz57x+iNBK1JpM0PLL2XvmPuoMZL5dZwzqSIey3nVdGJqRYfnFquWuyQpnOQ== + dependencies: + "@polkadot/keyring" "^12.6.1" + "@polkadot/types" "10.11.1" + "@polkadot/types-support" "10.11.1" + "@polkadot/util" "^12.6.1" + "@polkadot/util-crypto" "^12.6.1" + "@polkadot/x-fetch" "^12.6.1" + "@polkadot/x-global" "^12.6.1" + "@polkadot/x-ws" "^12.6.1" + eventemitter3 "^5.0.1" + mock-socket "^9.3.1" + nock "^13.3.8" + tslib "^2.6.2" + optionalDependencies: + "@substrate/connect" "0.7.35" + +"@polkadot/types-augment@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/types-augment/-/types-augment-10.11.1.tgz#273762db2e0dd932378860555e0d24672c583c7f" + integrity sha512-Exd5mMCuSOXXz73iWqy8ocScWTrwAPqHz0Kxpz5OWlAu+5usipMuhjoeaZA803FHQntZh9lHUN31fuc50Exhew== + dependencies: + "@polkadot/types" "10.11.1" + "@polkadot/types-codec" "10.11.1" + "@polkadot/util" "^12.6.1" + tslib "^2.6.2" + +"@polkadot/types-codec@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/types-codec/-/types-codec-10.11.1.tgz#063afd17c1648279de2f9add42b23792026a402f" + integrity sha512-B9Fu2hq3cRpJpGPcgfZ8Qi1OSX9u82J46adlbIG95ktoA+70eZ83VS3Zvtt9ACsdLVGETCJfDjSO25XptjhZKQ== + dependencies: + "@polkadot/util" "^12.6.1" + "@polkadot/x-bigint" "^12.6.1" + tslib "^2.6.2" + +"@polkadot/types-create@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/types-create/-/types-create-10.11.1.tgz#3f850e9f5e5b4f04da3ea4def5240d9d4e2789d3" + integrity sha512-oeaI185F3XeWSz9/fe//qZ0KsQyE6C6c13WuOa+5cX/Yuz7cSAXawrhl58HRaU+fueaE/ijEHLcuK1sdM6e1JQ== + dependencies: + "@polkadot/types-codec" "10.11.1" + "@polkadot/util" "^12.6.1" + tslib "^2.6.2" + +"@polkadot/types-known@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/types-known/-/types-known-10.11.1.tgz#6159b13c81660fd2db1c797e28356aee4691b0c0" + integrity sha512-BPHI7EbdRaznZR4RVVrQC5epyxL6caJ5dkluZP6rRwx7VmQK0FTGIwgh3UP724mzQhM8rT77MD3h2ftnq1cteg== + dependencies: + "@polkadot/networks" "^12.6.1" + "@polkadot/types" "10.11.1" + "@polkadot/types-codec" "10.11.1" + "@polkadot/types-create" "10.11.1" + "@polkadot/util" "^12.6.1" + tslib "^2.6.2" + +"@polkadot/types-support@10.11.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/types-support/-/types-support-10.11.1.tgz#227c702526f9702a5b6882ecf55bc264f9d3beaf" + integrity sha512-eCvWjdpELsHvXiTq201DdbIeOIaEr53zTD7HqC2wR/Z1bkQuw79Z+CyIU4sp79GL1vZ1PxS7vUH9M3FKNaTl1Q== + dependencies: + "@polkadot/util" "^12.6.1" + tslib "^2.6.2" + +"@polkadot/types@10.11.1", "@polkadot/types@^10.11.1", "@polkadot/types@^10.9.1": + version "10.11.1" + resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-10.11.1.tgz#d2b8c747c103b0a5f725090980d4be10037ddef0" + integrity sha512-4uKnzW2GZqNA5qRZpTPJ7z+G/ARTvXI89etv9xXXVttUdfTaYZsMf4rMuMThOAE/mAUn70LoH0JKthZLwzVgNQ== + dependencies: + "@polkadot/keyring" "^12.6.1" + "@polkadot/types-augment" "10.11.1" + "@polkadot/types-codec" "10.11.1" + "@polkadot/types-create" "10.11.1" + "@polkadot/util" "^12.6.1" + "@polkadot/util-crypto" "^12.6.1" + rxjs "^7.8.1" + tslib "^2.6.2" + +"@polkadot/util-crypto@12.6.1", "@polkadot/util-crypto@^12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-12.6.1.tgz#f1e354569fb039822db5e57297296e22af575af8" + integrity sha512-2ezWFLmdgeDXqB9NAUdgpp3s2rQztNrZLY+y0SJYNOG4ch+PyodTW/qSksnOrVGVdRhZ5OESRE9xvo9LYV5UAw== + dependencies: + "@noble/curves" "^1.2.0" + "@noble/hashes" "^1.3.2" + "@polkadot/networks" "12.6.1" + "@polkadot/util" "12.6.1" + "@polkadot/wasm-crypto" "^7.3.1" + "@polkadot/wasm-util" "^7.3.1" + "@polkadot/x-bigint" "12.6.1" + "@polkadot/x-randomvalues" "12.6.1" + "@scure/base" "^1.1.3" + tslib "^2.6.2" + +"@polkadot/util@12.6.1", "@polkadot/util@^12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-12.6.1.tgz#477b8e2c601e8aae0662670ed33da46f1b335e5a" + integrity sha512-10ra3VfXtK8ZSnWI7zjhvRrhupg3rd4iFC3zCaXmRpOU+AmfIoCFVEmuUuC66gyXiz2/g6k5E6j0lWQCOProSQ== + dependencies: + "@polkadot/x-bigint" "12.6.1" + "@polkadot/x-global" "12.6.1" + "@polkadot/x-textdecoder" "12.6.1" + "@polkadot/x-textencoder" "12.6.1" + "@types/bn.js" "^5.1.5" + bn.js "^5.2.1" + tslib "^2.6.2" + +"@polkadot/wasm-bridge@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@polkadot/wasm-bridge/-/wasm-bridge-7.3.1.tgz#8438363aa98296f8be949321ca1d3a4cbcc4fc49" + integrity sha512-wPtDkGaOQx5BUIYP+kJv5aV3BnCQ+HXr36khGKYrRQAMBrG+ybCNPOTVXDQnSbraPQRSw7fSIJmiQpEmFsIz0w== + dependencies: + "@polkadot/wasm-util" "7.3.1" + tslib "^2.6.2" + +"@polkadot/wasm-crypto-asmjs@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@polkadot/wasm-crypto-asmjs/-/wasm-crypto-asmjs-7.3.1.tgz#8322a554635bcc689eb3a944c87ea64061b6ba81" + integrity sha512-pTUOCIP0nUc4tjzdG1vtEBztKEWde4DBEZm7NaxBLvwNUxsbYhLKYvuhASEyEIz0ZyE4rOBWEmRF4Buic8oO+g== + dependencies: + tslib "^2.6.2" + +"@polkadot/wasm-crypto-init@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@polkadot/wasm-crypto-init/-/wasm-crypto-init-7.3.1.tgz#5a140f9e2746ce3009dbcc4d05827e0703fd344d" + integrity sha512-Fx15ItLcxCe7uJCWZVXhFbsrXqHUKAp9KGYQFKBRK7r1C2va4Y7qnirjwkxoMHQcunusLe2KdbrD+YJuzh4wlA== + dependencies: + "@polkadot/wasm-bridge" "7.3.1" + "@polkadot/wasm-crypto-asmjs" "7.3.1" + "@polkadot/wasm-crypto-wasm" "7.3.1" + "@polkadot/wasm-util" "7.3.1" + tslib "^2.6.2" + +"@polkadot/wasm-crypto-wasm@7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@polkadot/wasm-crypto-wasm/-/wasm-crypto-wasm-7.3.1.tgz#8f0906ab5dd11fa706db4c3547304b0e1d99f671" + integrity sha512-hBMRwrBLCfVsFHSdnwwIxEPshoZdW/dHehYRxMSpUdmqOxtD1gnjocXGE1KZUYGX675+EFuR+Ch6OoTKFJxwTA== + dependencies: + "@polkadot/wasm-util" "7.3.1" + tslib "^2.6.2" + +"@polkadot/wasm-crypto@^7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@polkadot/wasm-crypto/-/wasm-crypto-7.3.1.tgz#178e43ab68385c90d40f53590d3fdb59ee1aa5f4" + integrity sha512-BSK0YyCN4ohjtwbiHG71fgf+7ufgfLrHxjn7pKsvXhyeiEVuDhbDreNcpUf3eGOJ5tNk75aSbKGF4a3EJGIiNA== + dependencies: + "@polkadot/wasm-bridge" "7.3.1" + "@polkadot/wasm-crypto-asmjs" "7.3.1" + "@polkadot/wasm-crypto-init" "7.3.1" + "@polkadot/wasm-crypto-wasm" "7.3.1" + "@polkadot/wasm-util" "7.3.1" + tslib "^2.6.2" + +"@polkadot/wasm-util@7.3.1", "@polkadot/wasm-util@^7.3.1": + version "7.3.1" + resolved "https://registry.yarnpkg.com/@polkadot/wasm-util/-/wasm-util-7.3.1.tgz#047fbce91e9bdd944d46bea8f636d2fdc268fba2" + integrity sha512-0m6ozYwBrJgnGl6QvS37ZiGRu4FFPPEtMYEVssfo1Tz4skHJlByWaHWhRNoNCVFAKiGEBu+rfx5HAQMAhoPkvg== + dependencies: + tslib "^2.6.2" + +"@polkadot/x-bigint@12.6.1", "@polkadot/x-bigint@^12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/x-bigint/-/x-bigint-12.6.1.tgz#82b6a3639e1bc1195b2858482f0421b403641b80" + integrity sha512-YlABeVIlgYQZJ4ZpW/+akFGGxw5jMGt4g5vaP7EumlORGneJHzzWJYDmI5v2y7j1zvC9ofOle7z4tRmtN/QDew== + dependencies: + "@polkadot/x-global" "12.6.1" + tslib "^2.6.2" + +"@polkadot/x-fetch@^12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/x-fetch/-/x-fetch-12.6.1.tgz#6cd3023177f842ef51f05324c971671cbe010eca" + integrity sha512-iyBv0ecfCsqGSv26CPJk9vSoKtry/Fn7x549ysA4hlc9KboraMHxOHTpcNZYC/OdgvbFZl40zIXCY0SA1ai8aw== + dependencies: + "@polkadot/x-global" "12.6.1" + node-fetch "^3.3.2" + tslib "^2.6.2" + +"@polkadot/x-global@12.6.1", "@polkadot/x-global@^12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/x-global/-/x-global-12.6.1.tgz#1a00ae466e344539bdee57eb7b1dd4e4d5b1dc95" + integrity sha512-w5t19HIdBPuyu7X/AiCyH2DsKqxBF0KpF4Ymolnx8PfcSIgnq9ZOmgs74McPR6FgEmeEkr9uNKujZrsfURi1ug== + dependencies: + tslib "^2.6.2" + +"@polkadot/x-randomvalues@12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/x-randomvalues/-/x-randomvalues-12.6.1.tgz#f0ad7afa5b0bac123b634ac19d6625cd301a9307" + integrity sha512-1uVKlfYYbgIgGV5v1Dgn960cGovenWm5pmg+aTMeUGXVYiJwRD2zOpLyC1i/tP454iA74j74pmWb8Nkn0tJZUQ== + dependencies: + "@polkadot/x-global" "12.6.1" + tslib "^2.6.2" + +"@polkadot/x-textdecoder@12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/x-textdecoder/-/x-textdecoder-12.6.1.tgz#ee6e9a0f1819204aa60e0ef5a576e8b222501123" + integrity sha512-IasodJeV1f2Nr/VtA207+LXCQEqYcG8y9qB/EQcRsrEP58NbwwxM5Z2obV0lSjJOxRTJ4/OlhUwnLHwcbIp6+g== + dependencies: + "@polkadot/x-global" "12.6.1" + tslib "^2.6.2" + +"@polkadot/x-textencoder@12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/x-textencoder/-/x-textencoder-12.6.1.tgz#b39d4afb50c8bc2ff6add9f20cfc2338abff90d4" + integrity sha512-sTq/+tXqBhGe01a1rjieSHFh3y935vuRgtahVgVJZnfqh5SmLPgSN5tTPxZWzyx7gHIfotle8laTJbJarv7V1A== + dependencies: + "@polkadot/x-global" "12.6.1" + tslib "^2.6.2" + +"@polkadot/x-ws@^12.6.1": + version "12.6.1" + resolved "https://registry.yarnpkg.com/@polkadot/x-ws/-/x-ws-12.6.1.tgz#340830d4500bbb301c63a9c5b289da85a5cc898c" + integrity sha512-fs9V+XekjJLpVLLwxnqq3llqSZu2T/b9brvld8anvzS/htDLPbi7+c5W3VGJ9Po8fS67IsU3HCt0Gu6F6mGrMA== + dependencies: + "@polkadot/x-global" "12.6.1" + tslib "^2.6.2" + ws "^8.14.2" + +"@scure/base@^1.1.3": + version "1.1.3" + resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.3.tgz#8584115565228290a6c6c4961973e0903bb3df2f" + integrity sha512-/+SgoRjLq7Xlf0CWuLHq2LUZeL/w65kfzAPG5NH9pcmBhs+nunQTn4gvdwgMTIXnt9b2C/1SeL2XiysZEyIC9Q== + +"@substrate/connect-extension-protocol@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@substrate/connect-extension-protocol/-/connect-extension-protocol-1.0.1.tgz#fa5738039586c648013caa6a0c95c43265dbe77d" + integrity sha512-161JhCC1csjH3GE5mPLEd7HbWtwNSPJBg3p1Ksz9SFlTzj/bgEwudiRN2y5i0MoLGCIJRYKyKGMxVnd29PzNjg== + +"@substrate/connect@0.7.35": + version "0.7.35" + resolved "https://registry.yarnpkg.com/@substrate/connect/-/connect-0.7.35.tgz#853d8ff50717a8c9ee8f219d11a86e61a54b88b8" + integrity sha512-Io8vkalbwaye+7yXfG1Nj52tOOoJln2bMlc7Q9Yy3vEWqZEVkgKmcPVzbwV0CWL3QD+KMPDA2Dnw/X7EdwgoLw== + dependencies: + "@substrate/connect-extension-protocol" "^1.0.1" + smoldot "2.0.7" + +"@substrate/ss58-registry@^1.44.0": + version "1.44.0" + resolved "https://registry.yarnpkg.com/@substrate/ss58-registry/-/ss58-registry-1.44.0.tgz#54f214e2a44f450b7bbc9252891c1879a54e0606" + integrity sha512-7lQ/7mMCzVNSEfDS4BCqnRnKCFKpcOaPrxMeGTXHX1YQzM/m2BBHjbK2C3dJvjv7GYxMiaTq/HdWQj1xS6ss+A== + +"@types/bn.js@^5.1.5": + version "5.1.5" + resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.5.tgz#2e0dacdcce2c0f16b905d20ff87aedbc6f7b4bf0" + integrity sha512-V46N0zwKRF5Q00AZ6hWtN0T8gGmDUaUzLWQvHFo5yThtVwK/VCenFY3wXVbOvNfajEpsTfQM4IN9k/d6gUVX3A== + dependencies: + "@types/node" "*" + +"@types/node@*": + version "20.10.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.10.0.tgz#16ddf9c0a72b832ec4fcce35b8249cf149214617" + integrity sha512-D0WfRmU9TQ8I9PFx9Yc+EBHw+vSpIub4IDvQivcp26PtPrdMGAq5SDcpXEo/epqa/DXotVpekHiLNTg3iaKXBQ== + dependencies: + undici-types "~5.26.4" + +bn.js@^5.2.1: + version "5.2.1" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70" + integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ== + +data-uri-to-buffer@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz#d8feb2b2881e6a4f58c2e08acfd0e2834e26222e" + integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A== + +debug@^4.1.0: + version "4.3.4" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" + integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== + dependencies: + ms "2.1.2" + +eventemitter3@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4" + integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA== + +fetch-blob@^3.1.2, fetch-blob@^3.1.4: + version "3.2.0" + resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.2.0.tgz#f09b8d4bbd45adc6f0c20b7e787e793e309dcce9" + integrity sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ== + dependencies: + node-domexception "^1.0.0" + web-streams-polyfill "^3.0.3" + +formdata-polyfill@^4.0.10: + version "4.0.10" + resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423" + integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g== + dependencies: + fetch-blob "^3.1.2" + +json-stringify-safe@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" + integrity sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA== + +lodash.merge@^4.6.2: + version "4.6.2" + resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" + integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== + +lodash@^4.17.21: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== + +mock-socket@^9.3.1: + version "9.3.1" + resolved "https://registry.yarnpkg.com/mock-socket/-/mock-socket-9.3.1.tgz#24fb00c2f573c84812aa4a24181bb025de80cc8e" + integrity sha512-qxBgB7Qa2sEQgHFjj0dSigq7fX4k6Saisd5Nelwp2q8mlbAFh5dHV9JTTlF8viYJLSSWgMCZFUom8PJcMNBoJw== + +ms@2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + +nock@^13.3.8: + version "13.3.8" + resolved "https://registry.yarnpkg.com/nock/-/nock-13.3.8.tgz#7adf3c66f678b02ef0a78d5697ae8bc2ebde0142" + integrity sha512-96yVFal0c/W1lG7mmfRe7eO+hovrhJYd2obzzOZ90f6fjpeU/XNvd9cYHZKZAQJumDfhXgoTpkpJ9pvMj+hqHw== + dependencies: + debug "^4.1.0" + json-stringify-safe "^5.0.1" + propagate "^2.0.0" + +node-domexception@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" + integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== + +node-fetch@^3.3.2: + version "3.3.2" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.2.tgz#d1e889bacdf733b4ff3b2b243eb7a12866a0b78b" + integrity sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA== + dependencies: + data-uri-to-buffer "^4.0.0" + fetch-blob "^3.1.4" + formdata-polyfill "^4.0.10" + +propagate@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/propagate/-/propagate-2.0.1.tgz#40cdedab18085c792334e64f0ac17256d38f9a45" + integrity sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag== + +rxjs@^7.8.1: + version "7.8.1" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.1.tgz#6f6f3d99ea8044291efd92e7c7fcf562c4057543" + integrity sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg== + dependencies: + tslib "^2.1.0" + +smoldot@2.0.7: + version "2.0.7" + resolved "https://registry.yarnpkg.com/smoldot/-/smoldot-2.0.7.tgz#407efd6bbb82a074612db4d056d631d8d615f442" + integrity sha512-VAOBqEen6vises36/zgrmAT1GWk2qE3X8AGnO7lmQFdskbKx8EovnwS22rtPAG+Y1Rk23/S22kDJUdPANyPkBA== + dependencies: + ws "^8.8.1" + +tslib@^2.1.0, tslib@^2.6.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae" + integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q== + +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + +web-streams-polyfill@^3.0.3: + version "3.2.1" + resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6" + integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q== + +ws@^8.14.2, ws@^8.8.1: + version "8.14.2" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.14.2.tgz#6c249a806eb2db7a20d26d51e7709eab7b2e6c7f" + integrity sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g== From f99d0c2a54c8624c5e7029309981a7ae410e0da5 Mon Sep 17 00:00:00 2001 From: imstar15 Date: Mon, 27 Nov 2023 20:43:31 +0800 Subject: [PATCH 3/3] Fix past time test with time slot --- test/functional/dynamicDispatchTask.test.ts | 11 +++++------ test/utils/helpFn.ts | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/test/functional/dynamicDispatchTask.test.ts b/test/functional/dynamicDispatchTask.test.ts index a9f0474..5642f17 100644 --- a/test/functional/dynamicDispatchTask.test.ts +++ b/test/functional/dynamicDispatchTask.test.ts @@ -9,6 +9,7 @@ import { getDynamicDispatchExtrinsicParams, SECTION_NAME, sendExtrinsic, + getPastTime, } from "../utils/helpFn"; import { AutomationTimeApi } from "../utils"; import { @@ -103,19 +104,17 @@ describe("test-dynamic-dispatch-task", () => { ); /** - * dynamicDispatchTask.recurring with nextExecutionTime that is is a past time fails + * Call dynamicDispatchTask.recurring task with nextExecutionTime that is is a past time will throw automationTime.PastTime error */ it( - "dynamicDispatchTask.recurring with nextExecutionTime that is a past time fails", + "call dynamicDispatchTask.recurring task with nextExecutionTime that is a past time will throw automationTime.PastTime error", async () => { const extrinsicParams = await getDynamicDispatchExtrinsicParams( polkadotApi, "recurring", ); const { schedule, call } = extrinsicParams; - schedule.recurring.nextExecutionTime = Math.floor( - new Date().valueOf() / 1000 - 1, - ); + schedule.recurring.nextExecutionTime = getPastTime(); // scheduler.buildScheduleDynamicDispatchTask will fail with invalid frequency const extrinsicHex = @@ -125,7 +124,7 @@ describe("test-dynamic-dispatch-task", () => { call, ); await expect(sendExtrinsic(polkadotApi, extrinsicHex)).rejects.toThrow( - `${SECTION_NAME}.InvalidTime`, + `${SECTION_NAME}.PastTime`, ); }, DEFAULT_TIMEOUT_PER_TEST, diff --git a/test/utils/helpFn.ts b/test/utils/helpFn.ts index 86a41ac..caf80b0 100644 --- a/test/utils/helpFn.ts +++ b/test/utils/helpFn.ts @@ -420,3 +420,18 @@ export const getDynamicDispatchExtrinsicParams = async ( schedule, }; }; + +/** + * Get a past time and ensure it's a multiple of the timeslot. + * @returns past time + */ +export const getPastTime = () => { + // Get the current timestamp + const currentTimeStampInSeconds = Math.floor(Date.now() / 1000); + // Adjust the current timestamp to be a multiple of the timeslot + const adjustedTime = + currentTimeStampInSeconds - + (currentTimeStampInSeconds % TIME_SLOT_IN_SECONDS); + // Adjust the time to a past moment + return adjustedTime - TIME_SLOT_IN_SECONDS; +};