otomato-sdk 1.3.2 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/examples/create-action.js +6 -6
- package/dist/examples/create-trigger-list.js +5 -10
- package/dist/examples/create-trigger.js +21 -7
- package/dist/examples/create-workflow.js +33 -23
- package/dist/examples/load-workflow.js +1 -1
- package/dist/examples/login.js +32 -0
- package/dist/src/constants/Blocks.js +4 -4
- package/dist/src/constants/chains.js +1 -1
- package/dist/src/constants/tokens.js +13 -3
- package/dist/src/index.js +1 -0
- package/dist/src/models/Action.js +72 -0
- package/dist/src/models/Node.js +46 -57
- package/dist/src/models/Trigger.js +80 -4
- package/dist/src/models/Workflow.js +40 -9
- package/dist/src/services/ApiService.js +27 -5
- package/dist/src/utils/helpers.js +19 -0
- package/dist/src/utils/typeValidator.js +34 -8
- package/dist/test/action.spec.js +80 -11
- package/dist/test/automation.spec.js +9 -8
- package/dist/test/helpers.spec.js +23 -0
- package/dist/test/node.spec.js +13 -19
- package/dist/test/trigger.spec.js +92 -19
- package/dist/types/examples/login.d.ts +1 -0
- package/dist/types/src/constants/tokens.d.ts +2 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/models/Action.d.ts +6 -1
- package/dist/types/src/models/Node.d.ts +13 -2
- package/dist/types/src/models/Trigger.d.ts +8 -2
- package/dist/types/src/models/Workflow.d.ts +14 -1
- package/dist/types/src/services/ApiService.d.ts +6 -1
- package/dist/types/src/utils/helpers.d.ts +2 -0
- package/dist/types/src/utils/typeValidator.d.ts +1 -0
- package/dist/types/test/helpers.spec.d.ts +1 -0
- package/examples/create-action.ts +6 -6
- package/examples/create-trigger-list.ts +5 -10
- package/examples/create-trigger.ts +14 -7
- package/examples/create-workflow.ts +43 -25
- package/examples/load-workflow.ts +1 -1
- package/examples/login.ts +27 -0
- package/package.json +4 -2
- package/src/constants/Blocks.ts +4 -4
- package/src/constants/chains.ts +1 -1
- package/src/constants/tokens.ts +18 -4
- package/src/index.ts +1 -0
- package/src/models/Action.ts +77 -3
- package/src/models/Node.ts +54 -65
- package/src/models/Trigger.ts +84 -6
- package/src/models/Workflow.ts +37 -10
- package/src/services/ApiService.ts +24 -5
- package/src/utils/helpers.ts +9 -0
- package/src/utils/typeValidator.ts +28 -11
- package/test/action.spec.ts +75 -11
- package/test/automation.spec.ts +9 -8
- package/test/helpers.spec.ts +16 -0
- package/test/node.spec.ts +17 -23
- package/test/trigger.spec.ts +89 -19
package/test/action.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import { Action, ACTIONS,
|
|
2
|
+
import { Action, ACTIONS, getTokenFromSymbol, CHAINS } from '../src/index';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
5
5
|
|
|
@@ -10,8 +10,8 @@ describe('Action Class', () => {
|
|
|
10
10
|
const params = transferAction.getParameters();
|
|
11
11
|
|
|
12
12
|
expect(params.chainId).to.be.null;
|
|
13
|
-
expect(params
|
|
14
|
-
expect(params
|
|
13
|
+
expect(params.abi.parameters.value).to.be.null;
|
|
14
|
+
expect(params.abi.parameters.to).to.be.null;
|
|
15
15
|
expect(params.contractAddress).to.be.null;
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -20,13 +20,13 @@ describe('Action Class', () => {
|
|
|
20
20
|
transferAction.setChainId(CHAINS.ETHEREUM);
|
|
21
21
|
transferAction.setParams("value", 1000);
|
|
22
22
|
transferAction.setParams("to", DEFAULT_ADDRESS);
|
|
23
|
-
transferAction.setContractAddress(
|
|
23
|
+
transferAction.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
24
24
|
|
|
25
25
|
const params = transferAction.getParameters();
|
|
26
26
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
27
|
-
expect(params
|
|
28
|
-
expect(params
|
|
29
|
-
expect(params.contractAddress).to.equal(
|
|
27
|
+
expect(params.abi.parameters.value).to.equal(1000);
|
|
28
|
+
expect(params.abi.parameters.to).to.equal(DEFAULT_ADDRESS);
|
|
29
|
+
expect(params.contractAddress).to.equal(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
it('should be able to export an action as json', () => {
|
|
@@ -34,18 +34,23 @@ describe('Action Class', () => {
|
|
|
34
34
|
transferAction.setChainId(CHAINS.ETHEREUM);
|
|
35
35
|
transferAction.setParams("value", 1000);
|
|
36
36
|
transferAction.setParams("to", DEFAULT_ADDRESS);
|
|
37
|
-
transferAction.setContractAddress(
|
|
37
|
+
transferAction.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
38
38
|
|
|
39
39
|
const json = transferAction.toJSON();
|
|
40
40
|
expect(json).to.deep.equal({
|
|
41
41
|
blockId: ACTIONS.TOKENS.ERC20.TRANSFER.blockId,
|
|
42
42
|
ref: transferAction.getRef(),
|
|
43
43
|
type: 'action',
|
|
44
|
+
id: null,
|
|
44
45
|
parameters: {
|
|
45
46
|
chainId: CHAINS.ETHEREUM,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
abi: {
|
|
48
|
+
parameters: {
|
|
49
|
+
to: DEFAULT_ADDRESS,
|
|
50
|
+
value: 1000
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
contractAddress: getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress
|
|
49
54
|
}
|
|
50
55
|
});
|
|
51
56
|
});
|
|
@@ -89,4 +94,63 @@ describe('Action Class', () => {
|
|
|
89
94
|
const smsAction = new Action(ACTIONS.NOTIFICATIONS.SMS);
|
|
90
95
|
expect(() => smsAction.setParams("phoneNumber", "invalid_phone_number")).to.throw('Invalid type for parameter phoneNumber. Expected phone_number.');
|
|
91
96
|
});*/
|
|
97
|
+
|
|
98
|
+
it('should create an action from JSON correctly', async () => {
|
|
99
|
+
const json = {
|
|
100
|
+
"id": "755671a7-adac-4aeb-a759-73c00dd397bc",
|
|
101
|
+
"ref": "n-2",
|
|
102
|
+
"blockId": 100002,
|
|
103
|
+
"type": "action",
|
|
104
|
+
"position": {
|
|
105
|
+
"x": 0,
|
|
106
|
+
"y": -10
|
|
107
|
+
},
|
|
108
|
+
"parameters": {
|
|
109
|
+
"message": "ETH is at 3550 :pepe_joy:",
|
|
110
|
+
"webhook": "https://hooks.slack.com/services/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"
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const action = await Action.fromJSON(json);
|
|
115
|
+
|
|
116
|
+
expect(action.id).to.equal("755671a7-adac-4aeb-a759-73c00dd397bc");
|
|
117
|
+
expect(action.getRef()).to.equal("n-2");
|
|
118
|
+
expect(action.blockId).to.equal(100002);
|
|
119
|
+
expect(action.getParameters().message).to.equal("ETH is at 3550 :pepe_joy:");
|
|
120
|
+
expect(action.getParameters().webhook).to.equal("https://hooks.slack.com/services/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");
|
|
121
|
+
expect(action.getParentInfo()?.name).to.equal("SLACK");
|
|
122
|
+
expect(action.toJSON()).to.deep.equal(json);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should create an action with abi parameters from JSON correctly', async () => {
|
|
126
|
+
const json = {
|
|
127
|
+
"id": "d6e6884f-cd8f-4c96-b36c-e5539b3599fc",
|
|
128
|
+
"ref": "n-3",
|
|
129
|
+
"blockId": 100004,
|
|
130
|
+
"type": "action",
|
|
131
|
+
"parameters": {
|
|
132
|
+
"abi": {
|
|
133
|
+
"parameters": {
|
|
134
|
+
"to": "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6",
|
|
135
|
+
"value": 1000
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
"chainId": 1,
|
|
139
|
+
"contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const action = await Action.fromJSON(json);
|
|
144
|
+
console.log(action)
|
|
145
|
+
|
|
146
|
+
expect(action.id).to.equal("d6e6884f-cd8f-4c96-b36c-e5539b3599fc");
|
|
147
|
+
expect(action.getRef()).to.equal("n-3");
|
|
148
|
+
expect(action.blockId).to.equal(100004);
|
|
149
|
+
expect(action.getParameters().chainId).to.equal(1);
|
|
150
|
+
expect(action.getParameters().contractAddress).to.equal("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48");
|
|
151
|
+
expect(action.getParameters().abi.parameters.to).to.equal("0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
152
|
+
expect(action.getParameters().abi.parameters.value).to.equal(1000);
|
|
153
|
+
expect(action.getParentInfo()?.name).to.equal("ERC20");
|
|
154
|
+
expect(action.toJSON()).to.deep.equal(json);
|
|
155
|
+
});
|
|
92
156
|
});
|
package/test/automation.spec.ts
CHANGED
|
@@ -2,20 +2,20 @@ import { expect } from 'chai';
|
|
|
2
2
|
import { Workflow } from '../src/models/Workflow.js';
|
|
3
3
|
import { Trigger } from '../src/models/Trigger.js';
|
|
4
4
|
import { Action } from '../src/models/Action.js';
|
|
5
|
-
import { TRIGGERS, ACTIONS,
|
|
5
|
+
import { TRIGGERS, ACTIONS, getTokenFromSymbol, CHAINS } from '../src/index.js';
|
|
6
6
|
|
|
7
7
|
describe('Workflow Class', () => {
|
|
8
8
|
it('should create a workflow with a trigger and actions', () => {
|
|
9
9
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
10
10
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
11
|
-
trigger.setContractAddress(
|
|
11
|
+
trigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
12
12
|
trigger.setPosition(0, 0);
|
|
13
13
|
|
|
14
14
|
const action1 = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
15
15
|
action1.setChainId(CHAINS.ETHEREUM);
|
|
16
16
|
action1.setParams("value", 1000);
|
|
17
17
|
action1.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
18
|
-
action1.setContractAddress(
|
|
18
|
+
action1.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
19
19
|
action1.setPosition(1, 0);
|
|
20
20
|
|
|
21
21
|
const action2 = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
@@ -28,6 +28,7 @@ describe('Workflow Class', () => {
|
|
|
28
28
|
const json = workflow.toJSON();
|
|
29
29
|
expect(json).to.deep.equal({
|
|
30
30
|
name: "Test Workflow",
|
|
31
|
+
id: null,
|
|
31
32
|
nodes: [trigger.toJSON(), action1.toJSON(), action2.toJSON()],
|
|
32
33
|
edges: []
|
|
33
34
|
});
|
|
@@ -36,7 +37,7 @@ describe('Workflow Class', () => {
|
|
|
36
37
|
it('should set the name of the workflow', () => {
|
|
37
38
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
38
39
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
39
|
-
trigger.setContractAddress(
|
|
40
|
+
trigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
40
41
|
trigger.setPosition(0, 0);
|
|
41
42
|
|
|
42
43
|
const workflow = new Workflow("Initial Name", [trigger]);
|
|
@@ -48,12 +49,12 @@ describe('Workflow Class', () => {
|
|
|
48
49
|
it('should add a trigger to the workflow', () => {
|
|
49
50
|
const initialTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
50
51
|
initialTrigger.setChainId(CHAINS.ETHEREUM);
|
|
51
|
-
initialTrigger.setContractAddress(
|
|
52
|
+
initialTrigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
52
53
|
initialTrigger.setPosition(0, 0);
|
|
53
54
|
|
|
54
55
|
const newTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
55
56
|
newTrigger.setChainId(CHAINS.ETHEREUM);
|
|
56
|
-
newTrigger.setContractAddress(
|
|
57
|
+
newTrigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
57
58
|
newTrigger.setPosition(1, 0);
|
|
58
59
|
|
|
59
60
|
const workflow = new Workflow("Test Workflow", [initialTrigger]);
|
|
@@ -65,14 +66,14 @@ describe('Workflow Class', () => {
|
|
|
65
66
|
it('should add actions to the workflow', () => {
|
|
66
67
|
const trigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
67
68
|
trigger.setChainId(CHAINS.ETHEREUM);
|
|
68
|
-
trigger.setContractAddress(
|
|
69
|
+
trigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
69
70
|
trigger.setPosition(0, 0);
|
|
70
71
|
|
|
71
72
|
const action1 = new Action(ACTIONS.TOKENS.ERC20.TRANSFER);
|
|
72
73
|
action1.setChainId(CHAINS.ETHEREUM);
|
|
73
74
|
action1.setParams("value", 1000);
|
|
74
75
|
action1.setParams("to", "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
75
|
-
action1.setContractAddress(
|
|
76
|
+
action1.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
76
77
|
action1.setPosition(1, 0);
|
|
77
78
|
|
|
78
79
|
const action2 = new Action(ACTIONS.NOTIFICATIONS.SLACK.SEND_MESSAGE);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { convertToTokenUnits, getTokenFromSymbol, CHAINS } from '../src/index.js';
|
|
3
|
+
|
|
4
|
+
describe('convertToTokenUnits', () => {
|
|
5
|
+
it('should return 10^6 for 1 USDC', async () => {
|
|
6
|
+
const usdcContractAddr = getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress;
|
|
7
|
+
const result = await convertToTokenUnits(1, CHAINS.ETHEREUM, usdcContractAddr);
|
|
8
|
+
expect(result).to.equal(BigInt(10 ** 6));
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should return 10^18 for 1 MODE', async () => {
|
|
12
|
+
const modeContractAddr = getTokenFromSymbol(CHAINS.MODE, 'MODE').contractAddress;
|
|
13
|
+
const result = await convertToTokenUnits(1, CHAINS.MODE, modeContractAddr);
|
|
14
|
+
expect(result).to.equal(BigInt(10 ** 18));
|
|
15
|
+
});
|
|
16
|
+
});
|
package/test/node.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import { Node, Parameter } from '../src/index'; // Adjust the import path according to your project structure
|
|
2
|
+
import { Action, Node, Parameter } from '../src/index'; // Adjust the import path according to your project structure
|
|
3
3
|
|
|
4
4
|
const DEFAULT_PARAMETERS: Parameter[] = [
|
|
5
5
|
{ key: 'chainId', type: 'integer', description: 'Chain ID', value: null },
|
|
@@ -7,14 +7,13 @@ const DEFAULT_PARAMETERS: Parameter[] = [
|
|
|
7
7
|
];
|
|
8
8
|
|
|
9
9
|
describe('Node Class', () => {
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
it('should create a node without coordinates', () => {
|
|
12
|
-
const node = new
|
|
12
|
+
const node = new Action({
|
|
13
13
|
blockId: 1,
|
|
14
14
|
name: 'Test Node',
|
|
15
15
|
description: 'A node for testing',
|
|
16
16
|
parameters: DEFAULT_PARAMETERS,
|
|
17
|
-
class: 'testClass',
|
|
18
17
|
image: 'a',
|
|
19
18
|
});
|
|
20
19
|
|
|
@@ -22,13 +21,12 @@ describe('Node Class', () => {
|
|
|
22
21
|
});
|
|
23
22
|
|
|
24
23
|
it('should create a node with coordinates', () => {
|
|
25
|
-
const node = new
|
|
24
|
+
const node = new Action({
|
|
26
25
|
blockId: 2,
|
|
27
26
|
name: 'Test Node with Coordinates',
|
|
28
27
|
description: 'A node for testing with coordinates',
|
|
29
28
|
parameters: DEFAULT_PARAMETERS,
|
|
30
|
-
|
|
31
|
-
position: {x: 100, y: 200},
|
|
29
|
+
position: { x: 100, y: 200 },
|
|
32
30
|
image: 'a',
|
|
33
31
|
});
|
|
34
32
|
|
|
@@ -37,12 +35,11 @@ describe('Node Class', () => {
|
|
|
37
35
|
});
|
|
38
36
|
|
|
39
37
|
it('should set and get coordinates correctly', () => {
|
|
40
|
-
const node = new
|
|
38
|
+
const node = new Action({
|
|
41
39
|
blockId: 3,
|
|
42
40
|
name: 'Test Node for Coordinates',
|
|
43
41
|
description: 'A node for testing coordinate setting',
|
|
44
42
|
parameters: DEFAULT_PARAMETERS,
|
|
45
|
-
class: 'testClass',
|
|
46
43
|
image: 'a',
|
|
47
44
|
});
|
|
48
45
|
|
|
@@ -52,12 +49,11 @@ describe('Node Class', () => {
|
|
|
52
49
|
});
|
|
53
50
|
|
|
54
51
|
it('should create a node and set parameters correctly', () => {
|
|
55
|
-
const node = new
|
|
52
|
+
const node = new Action({
|
|
56
53
|
blockId: 4,
|
|
57
54
|
name: 'Test Node for Parameters',
|
|
58
55
|
description: 'A node for testing parameter setting',
|
|
59
56
|
parameters: DEFAULT_PARAMETERS,
|
|
60
|
-
class: 'testClass',
|
|
61
57
|
image: 'a',
|
|
62
58
|
});
|
|
63
59
|
|
|
@@ -70,12 +66,11 @@ describe('Node Class', () => {
|
|
|
70
66
|
});
|
|
71
67
|
|
|
72
68
|
it('should be able to export a node as json without coordinates', () => {
|
|
73
|
-
const node = new
|
|
69
|
+
const node = new Action({
|
|
74
70
|
blockId: 5,
|
|
75
71
|
name: 'Test Node for JSON',
|
|
76
72
|
description: 'A node for testing JSON export',
|
|
77
73
|
parameters: DEFAULT_PARAMETERS,
|
|
78
|
-
class: 'testClass',
|
|
79
74
|
image: 'a',
|
|
80
75
|
});
|
|
81
76
|
|
|
@@ -85,8 +80,9 @@ describe('Node Class', () => {
|
|
|
85
80
|
const json = node.toJSON();
|
|
86
81
|
expect(json).to.deep.equal({
|
|
87
82
|
blockId: 5,
|
|
83
|
+
id: null,
|
|
88
84
|
ref: node.getRef(),
|
|
89
|
-
type: '
|
|
85
|
+
type: 'action',
|
|
90
86
|
parameters: {
|
|
91
87
|
chainId: 1,
|
|
92
88
|
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
@@ -95,13 +91,12 @@ describe('Node Class', () => {
|
|
|
95
91
|
});
|
|
96
92
|
|
|
97
93
|
it('should be able to export a node as json with coordinates', () => {
|
|
98
|
-
const node = new
|
|
94
|
+
const node = new Action({
|
|
99
95
|
blockId: 6,
|
|
100
96
|
name: 'Test Node for JSON with Coordinates',
|
|
101
97
|
description: 'A node for testing JSON export with coordinates',
|
|
102
98
|
parameters: DEFAULT_PARAMETERS,
|
|
103
|
-
|
|
104
|
-
position: {x: 1, y: 2},
|
|
99
|
+
position: { x: 1, y: 2 },
|
|
105
100
|
image: 'a',
|
|
106
101
|
});
|
|
107
102
|
|
|
@@ -110,36 +105,35 @@ describe('Node Class', () => {
|
|
|
110
105
|
|
|
111
106
|
const json = node.toJSON();
|
|
112
107
|
expect(json).to.deep.equal({
|
|
113
|
-
type: '
|
|
108
|
+
type: 'action',
|
|
114
109
|
blockId: 6,
|
|
110
|
+
id: null,
|
|
115
111
|
ref: node.getRef(),
|
|
116
112
|
parameters: {
|
|
117
113
|
chainId: 1,
|
|
118
114
|
contractAddress: "0x0000000000000000000000000000000000000000"
|
|
119
115
|
},
|
|
120
|
-
position: {x: 1, y: 2}
|
|
116
|
+
position: { x: 1, y: 2 }
|
|
121
117
|
});
|
|
122
118
|
});
|
|
123
119
|
|
|
124
120
|
it('should throw an error for invalid parameter type', () => {
|
|
125
|
-
const node = new
|
|
121
|
+
const node = new Action({
|
|
126
122
|
blockId: 7,
|
|
127
123
|
name: 'Test Node for Invalid Parameter Type',
|
|
128
124
|
description: 'A node for testing invalid parameter type',
|
|
129
125
|
parameters: DEFAULT_PARAMETERS,
|
|
130
|
-
class: 'testClass',
|
|
131
126
|
image: 'a',
|
|
132
127
|
});
|
|
133
128
|
expect(() => node.setParams("chainId", "invalid")).to.throw('Invalid type for parameter chainId. Expected integer.');
|
|
134
129
|
});
|
|
135
130
|
|
|
136
131
|
it('should throw an error for invalid address', () => {
|
|
137
|
-
const node = new
|
|
132
|
+
const node = new Action({
|
|
138
133
|
blockId: 8,
|
|
139
134
|
name: 'Test Node for Invalid Address',
|
|
140
135
|
description: 'A node for testing invalid address',
|
|
141
136
|
parameters: DEFAULT_PARAMETERS,
|
|
142
|
-
class: 'testClass',
|
|
143
137
|
image: 'a',
|
|
144
138
|
});
|
|
145
139
|
expect(() => node.setParams("contractAddress", "invalid_address")).to.throw('Invalid type for parameter contractAddress. Expected address.');
|
package/test/trigger.spec.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
|
-
import { Trigger, TRIGGERS,
|
|
2
|
+
import { Trigger, TRIGGERS, getTokenFromSymbol, CHAINS } from '../src/index';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
5
5
|
|
|
@@ -10,8 +10,8 @@ describe('Trigger Class', () => {
|
|
|
10
10
|
const params = transferTrigger.getParameters();
|
|
11
11
|
|
|
12
12
|
expect(params.chainId).to.be.null;
|
|
13
|
-
expect(params
|
|
14
|
-
expect(params
|
|
13
|
+
expect(params.abi.parameters.value).to.equal(null);
|
|
14
|
+
expect(params.abi.parameters.to).to.equal(null);
|
|
15
15
|
expect(params.contractAddress).to.be.null;
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -20,13 +20,13 @@ describe('Trigger Class', () => {
|
|
|
20
20
|
transferTrigger.setChainId(CHAINS.ETHEREUM);
|
|
21
21
|
transferTrigger.setParams("value", 1000);
|
|
22
22
|
transferTrigger.setParams("to", DEFAULT_ADDRESS);
|
|
23
|
-
transferTrigger.setContractAddress(
|
|
23
|
+
transferTrigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
24
24
|
|
|
25
25
|
const params = transferTrigger.getParameters();
|
|
26
26
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
27
|
-
expect(params
|
|
28
|
-
expect(params
|
|
29
|
-
expect(params.contractAddress).to.equal(
|
|
27
|
+
expect(params.abi.parameters.value).to.equal(1000);
|
|
28
|
+
expect(params.abi.parameters.to).to.equal(DEFAULT_ADDRESS);
|
|
29
|
+
expect(params.contractAddress).to.equal(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
it('should be able to export a trigger as json', () => {
|
|
@@ -34,20 +34,25 @@ describe('Trigger Class', () => {
|
|
|
34
34
|
transferTrigger.setChainId(CHAINS.ETHEREUM);
|
|
35
35
|
transferTrigger.setParams("value", 1000);
|
|
36
36
|
transferTrigger.setParams("to", DEFAULT_ADDRESS);
|
|
37
|
-
transferTrigger.setContractAddress(
|
|
37
|
+
transferTrigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
38
38
|
|
|
39
39
|
const json = transferTrigger.toJSON();
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
expect(json).to.deep.equal({
|
|
42
42
|
blockId: TRIGGERS.TOKENS.ERC20.TRANSFER.blockId,
|
|
43
43
|
ref: transferTrigger.getRef(),
|
|
44
|
+
id: null,
|
|
44
45
|
type: 'trigger',
|
|
45
46
|
parameters: {
|
|
46
47
|
chainId: CHAINS.ETHEREUM,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
abi: {
|
|
49
|
+
parameters: {
|
|
50
|
+
value: 1000,
|
|
51
|
+
to: DEFAULT_ADDRESS,
|
|
52
|
+
from: null
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
contractAddress: getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress
|
|
51
56
|
}
|
|
52
57
|
});
|
|
53
58
|
});
|
|
@@ -56,16 +61,14 @@ describe('Trigger Class', () => {
|
|
|
56
61
|
const balanceTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.BALANCE);
|
|
57
62
|
balanceTrigger.setChainId(CHAINS.ETHEREUM);
|
|
58
63
|
balanceTrigger.setParams("account", DEFAULT_ADDRESS);
|
|
59
|
-
balanceTrigger.setContractAddress(
|
|
64
|
+
balanceTrigger.setContractAddress(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
60
65
|
balanceTrigger.setCondition("gte");
|
|
61
66
|
balanceTrigger.setComparisonValue(45000);
|
|
62
|
-
balanceTrigger.setInterval(5000);
|
|
63
67
|
|
|
64
68
|
const params = balanceTrigger.getParameters();
|
|
65
69
|
expect(params.chainId).to.equal(CHAINS.ETHEREUM);
|
|
66
|
-
expect(params
|
|
67
|
-
expect(params.contractAddress).to.equal(
|
|
68
|
-
console.log(balanceTrigger.toJSON());
|
|
70
|
+
expect(params.abi.parameters.account).to.equal(DEFAULT_ADDRESS);
|
|
71
|
+
expect(params.contractAddress).to.equal(getTokenFromSymbol(CHAINS.ETHEREUM, 'USDC').contractAddress);
|
|
69
72
|
expect(balanceTrigger.toJSON().parameters.condition).to.equal("gte");
|
|
70
73
|
expect(balanceTrigger.toJSON().parameters.comparisonValue).to.equal(45000);
|
|
71
74
|
expect(balanceTrigger.toJSON().parameters.interval).to.equal(5000);
|
|
@@ -76,7 +79,6 @@ describe('Trigger Class', () => {
|
|
|
76
79
|
|
|
77
80
|
expect(() => transferTrigger.setCondition(">")).to.throw('Condition setting is not applicable for subscription based triggers.');
|
|
78
81
|
expect(() => transferTrigger.setComparisonValue(45000)).to.throw('Comparison value setting is not applicable for subscription based triggers.');
|
|
79
|
-
expect(() => transferTrigger.setInterval(5000)).to.throw('Interval setting is not applicable for subscription based triggers.');
|
|
80
82
|
});
|
|
81
83
|
|
|
82
84
|
it('should throw an error for invalid parameter type', () => {
|
|
@@ -88,4 +90,72 @@ describe('Trigger Class', () => {
|
|
|
88
90
|
const transferTrigger = new Trigger(TRIGGERS.TOKENS.ERC20.TRANSFER);
|
|
89
91
|
expect(() => transferTrigger.setParams("to", "invalid_address")).to.throw('Invalid type for parameter abiParams.to. Expected address.');
|
|
90
92
|
});
|
|
93
|
+
|
|
94
|
+
it('should create a trigger from JSON correctly', async () => {
|
|
95
|
+
const json = {
|
|
96
|
+
"id": "5c87bcd2-8771-417f-aab6-c23998caa9ae",
|
|
97
|
+
"ref": "n-1",
|
|
98
|
+
"blockId": 10,
|
|
99
|
+
"type": "trigger",
|
|
100
|
+
"position": {
|
|
101
|
+
"x": 0,
|
|
102
|
+
"y": 0
|
|
103
|
+
},
|
|
104
|
+
"parameters": {
|
|
105
|
+
"chainId": 34443,
|
|
106
|
+
"currency": "USD",
|
|
107
|
+
"interval": 5000,
|
|
108
|
+
"condition": "gte",
|
|
109
|
+
"comparisonValue": 3550,
|
|
110
|
+
"contractAddress": "0x4200000000000000000000000000000000000006"
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const trigger = await Trigger.fromJSON(json);
|
|
115
|
+
|
|
116
|
+
expect(trigger.id).to.equal("5c87bcd2-8771-417f-aab6-c23998caa9ae");
|
|
117
|
+
expect(trigger.getRef()).to.equal("n-1");
|
|
118
|
+
expect(trigger.blockId).to.equal(10);
|
|
119
|
+
expect(trigger.getParameters().chainId).to.equal(34443);
|
|
120
|
+
expect(trigger.getParameters().currency).to.equal("USD");
|
|
121
|
+
expect(trigger.getParameters().condition).to.equal("gte");
|
|
122
|
+
expect(trigger.getParameters().comparisonValue).to.equal(3550);
|
|
123
|
+
expect(trigger.getParameters().contractAddress).to.equal("0x4200000000000000000000000000000000000006");
|
|
124
|
+
expect(trigger.getParentInfo()?.name).to.equal("ON_CHAIN_PRICE_MOVEMENT");
|
|
125
|
+
expect(trigger.toJSON()).to.deep.equal(json);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('should create a trigger from JSON correctly - 2', async () => {
|
|
129
|
+
const json = {
|
|
130
|
+
"id": null,
|
|
131
|
+
"ref": "n-1",
|
|
132
|
+
"blockId": 1,
|
|
133
|
+
"type": "trigger",
|
|
134
|
+
"parameters": {
|
|
135
|
+
"chainId": 1,
|
|
136
|
+
"abi": {
|
|
137
|
+
"parameters": {
|
|
138
|
+
"from": null,
|
|
139
|
+
"value": "1000000n",
|
|
140
|
+
"to": "0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6"
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
"contractAddress": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const trigger = await Trigger.fromJSON(json);
|
|
148
|
+
|
|
149
|
+
expect(trigger.id).to.be.null;
|
|
150
|
+
expect(trigger.getRef()).to.equal("n-1");
|
|
151
|
+
expect(trigger.blockId).to.equal(1);
|
|
152
|
+
expect(trigger.getParameters().chainId).to.equal(1);
|
|
153
|
+
expect(trigger.getParameters().abi.parameters.from).to.be.null;
|
|
154
|
+
expect(trigger.getParameters().abi.parameters.value).to.equal(BigInt(1000000));
|
|
155
|
+
expect(trigger.getParameters().abi.parameters.to).to.equal("0xe1432599B51d9BE1b5A27E2A2FB8e5dF684749C6");
|
|
156
|
+
expect(trigger.getParameters().contractAddress).to.equal("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48");
|
|
157
|
+
expect(trigger.getParentInfo()?.name).to.equal("ERC20");
|
|
158
|
+
expect(trigger.toJSON()).to.deep.equal(json);
|
|
159
|
+
});
|
|
160
|
+
|
|
91
161
|
});
|