@0xsequence/catapult 1.4.0 → 1.5.0
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 +27 -0
- package/dist/lib/__tests__/network-loader.spec.js.map +1 -1
- package/dist/lib/core/__tests__/resolver.spec.js +22 -0
- package/dist/lib/core/__tests__/resolver.spec.js.map +1 -1
- package/dist/lib/core/__tests__/sign-actions.spec.d.ts +2 -0
- package/dist/lib/core/__tests__/sign-actions.spec.d.ts.map +1 -0
- package/dist/lib/core/__tests__/sign-actions.spec.js +128 -0
- package/dist/lib/core/__tests__/sign-actions.spec.js.map +1 -0
- package/dist/lib/core/__tests__/signer.spec.d.ts +2 -0
- package/dist/lib/core/__tests__/signer.spec.d.ts.map +1 -0
- package/dist/lib/core/__tests__/signer.spec.js +40 -0
- package/dist/lib/core/__tests__/signer.spec.js.map +1 -0
- package/dist/lib/core/context.d.ts +3 -2
- package/dist/lib/core/context.d.ts.map +1 -1
- package/dist/lib/core/context.js +3 -2
- package/dist/lib/core/context.js.map +1 -1
- package/dist/lib/core/engine.d.ts +4 -0
- package/dist/lib/core/engine.d.ts.map +1 -1
- package/dist/lib/core/engine.js +173 -0
- package/dist/lib/core/engine.js.map +1 -1
- package/dist/lib/core/signer.d.ts +7 -0
- package/dist/lib/core/signer.d.ts.map +1 -0
- package/dist/lib/core/signer.js +60 -0
- package/dist/lib/core/signer.js.map +1 -0
- package/dist/lib/parsers/__tests__/source.spec.js +37 -0
- package/dist/lib/parsers/__tests__/source.spec.js.map +1 -1
- package/dist/lib/parsers/source.js +1 -1
- package/dist/lib/parsers/source.js.map +1 -1
- package/dist/lib/provenance.js +51 -2
- package/dist/lib/provenance.js.map +1 -1
- package/dist/lib/types/actions.d.ts +26 -2
- package/dist/lib/types/actions.d.ts.map +1 -1
- package/dist/lib/types/actions.js +3 -0
- package/dist/lib/types/actions.js.map +1 -1
- package/dist/lib/types/source.d.ts +2 -0
- package/dist/lib/types/source.d.ts.map +1 -1
- package/package.json +4 -1
- package/.eslintrc.json +0 -29
- package/.github/workflows/ci.yml +0 -181
- package/CONCEPT.md +0 -24
- package/contracts/checked-call.huff +0 -65
- package/eslint.config.js +0 -48
- package/examples/jobs/guards-v1.yaml +0 -17
- package/examples/jobs/sequence-seq-0001-patch.yaml +0 -59
- package/examples/jobs/sequence-v1.yaml +0 -59
- package/examples/templates/sequence-factory-v1.yaml +0 -56
- package/jest.config.js +0 -25
- package/src/cli.ts +0 -18
- package/src/commands/common.ts +0 -61
- package/src/commands/dry.ts +0 -209
- package/src/commands/etherscan.ts +0 -360
- package/src/commands/index.ts +0 -6
- package/src/commands/list.ts +0 -262
- package/src/commands/provenance.ts +0 -120
- package/src/commands/run.ts +0 -146
- package/src/commands/utils.ts +0 -215
- package/src/index.ts +0 -67
- package/src/lib/__tests__/deployer-events.spec.ts +0 -338
- package/src/lib/__tests__/deployer.spec.ts +0 -2269
- package/src/lib/__tests__/network-loader.spec.ts +0 -150
- package/src/lib/__tests__/network-selection.spec.ts +0 -41
- package/src/lib/__tests__/network-utils.spec.ts +0 -230
- package/src/lib/__tests__/provenance.spec.ts +0 -208
- package/src/lib/artifacts/__tests__/fixtures/contract1.json +0 -19
- package/src/lib/artifacts/__tests__/fixtures/contract2.json +0 -19
- package/src/lib/artifacts/__tests__/fixtures/duplicate-name.json +0 -19
- package/src/lib/artifacts/__tests__/fixtures/nested/nested-contract.json +0 -18
- package/src/lib/artifacts/__tests__/fixtures/not-an-artifact.json +0 -8
- package/src/lib/artifacts/__tests__/fixtures/readme.txt +0 -2
- package/src/lib/contracts/__tests__/repository.spec.ts +0 -612
- package/src/lib/contracts/repository.ts +0 -411
- package/src/lib/core/__tests__/assert-action.spec.ts +0 -474
- package/src/lib/core/__tests__/context.spec.ts +0 -37
- package/src/lib/core/__tests__/engine.spec.ts +0 -2005
- package/src/lib/core/__tests__/graph.spec.ts +0 -125
- package/src/lib/core/__tests__/json-integration.spec.ts +0 -425
- package/src/lib/core/__tests__/loader.spec.ts +0 -367
- package/src/lib/core/__tests__/multi-platform-verification.spec.ts +0 -406
- package/src/lib/core/__tests__/resolver.spec.ts +0 -2496
- package/src/lib/core/__tests__/static-action.spec.ts +0 -172
- package/src/lib/core/context.ts +0 -127
- package/src/lib/core/engine.ts +0 -1834
- package/src/lib/core/graph.ts +0 -252
- package/src/lib/core/loader.ts +0 -253
- package/src/lib/core/resolver.ts +0 -873
- package/src/lib/deployer.ts +0 -1005
- package/src/lib/events/__tests__/event-system.spec.ts +0 -392
- package/src/lib/events/cli-adapter.ts +0 -369
- package/src/lib/events/emitter.ts +0 -62
- package/src/lib/events/index.ts +0 -3
- package/src/lib/events/types.ts +0 -520
- package/src/lib/index.ts +0 -17
- package/src/lib/network-loader.ts +0 -90
- package/src/lib/network-selection.ts +0 -73
- package/src/lib/network-utils.ts +0 -64
- package/src/lib/parsers/__tests__/buildinfo.spec.ts +0 -122
- package/src/lib/parsers/__tests__/fixtures/buildinfo/invalid-bytecode-buildinfo.json +0 -62
- package/src/lib/parsers/__tests__/fixtures/buildinfo/invalid-json.txt +0 -2
- package/src/lib/parsers/__tests__/fixtures/buildinfo/multi-contract-buildinfo.json +0 -89
- package/src/lib/parsers/__tests__/fixtures/buildinfo/no-contracts-buildinfo.json +0 -17
- package/src/lib/parsers/__tests__/fixtures/buildinfo/simple-buildinfo.json +0 -63
- package/src/lib/parsers/__tests__/fixtures/buildinfo/wrong-format.json +0 -4
- package/src/lib/parsers/__tests__/job.spec.ts +0 -439
- package/src/lib/parsers/__tests__/source.spec.ts +0 -134
- package/src/lib/parsers/__tests__/template.spec.ts +0 -111
- package/src/lib/parsers/artifact/__tests__/artifact.spec.ts +0 -117
- package/src/lib/parsers/artifact/__tests__/fixtures/empty-bytecode.json +0 -5
- package/src/lib/parsers/artifact/__tests__/fixtures/hardhat-artifact.json +0 -67
- package/src/lib/parsers/artifact/__tests__/fixtures/invalid-bytecode.json +0 -5
- package/src/lib/parsers/artifact/__tests__/fixtures/invalid-json.txt +0 -11
- package/src/lib/parsers/artifact/__tests__/fixtures/minimal-artifact.json +0 -5
- package/src/lib/parsers/artifact/__tests__/fixtures/missing-abi.json +0 -4
- package/src/lib/parsers/artifact/__tests__/fixtures/missing-bytecode.json +0 -11
- package/src/lib/parsers/artifact/__tests__/fixtures/missing-contract-name.json +0 -11
- package/src/lib/parsers/artifact/__tests__/fixtures/simple-artifact.json +0 -40
- package/src/lib/parsers/artifact/__tests__/fixtures/wrong-types.json +0 -7
- package/src/lib/parsers/artifact/foundry-1.2.ts +0 -72
- package/src/lib/parsers/artifact/index.ts +0 -27
- package/src/lib/parsers/artifact/types.ts +0 -9
- package/src/lib/parsers/buildinfo.ts +0 -127
- package/src/lib/parsers/constants.ts +0 -56
- package/src/lib/parsers/index.ts +0 -6
- package/src/lib/parsers/job.ts +0 -160
- package/src/lib/parsers/source.ts +0 -129
- package/src/lib/parsers/template.ts +0 -135
- package/src/lib/provenance.ts +0 -785
- package/src/lib/std/templates/arachnid-deterministic-deployment-proxy.yaml +0 -68
- package/src/lib/std/templates/assured-deployment.yaml +0 -46
- package/src/lib/std/templates/era-evm-predeploy.yaml +0 -35
- package/src/lib/std/templates/erc-2470.yaml +0 -70
- package/src/lib/std/templates/min-balance.yaml +0 -35
- package/src/lib/std/templates/nano-universal-deployer.yaml +0 -61
- package/src/lib/std/templates/raw-erc-2470.yaml +0 -62
- package/src/lib/std/templates/raw-nano-universal-deployer.yaml +0 -54
- package/src/lib/std/templates/raw-sequence-universal-deployer-2.yaml +0 -52
- package/src/lib/std/templates/sequence-universal-deployer-2.yaml +0 -61
- package/src/lib/types/__tests__/json-request-action.spec.ts +0 -243
- package/src/lib/types/__tests__/read-json-value.spec.ts +0 -278
- package/src/lib/types/__tests__/resolve-json-value.spec.ts +0 -769
- package/src/lib/types/actions.ts +0 -148
- package/src/lib/types/artifacts.ts +0 -21
- package/src/lib/types/buildinfo.ts +0 -116
- package/src/lib/types/conditions.ts +0 -50
- package/src/lib/types/contracts.ts +0 -26
- package/src/lib/types/definitions.ts +0 -77
- package/src/lib/types/index.ts +0 -9
- package/src/lib/types/network.ts +0 -33
- package/src/lib/types/project.ts +0 -9
- package/src/lib/types/source.ts +0 -26
- package/src/lib/types/task.ts +0 -9
- package/src/lib/types/values.ts +0 -221
- package/src/lib/utils/assertion.ts +0 -24
- package/src/lib/utils/validation.ts +0 -116
- package/src/lib/validation/contract-references.ts +0 -210
- package/src/lib/validation/index.ts +0 -1
- package/src/lib/verification/__tests__/etherscan.spec.ts +0 -710
- package/src/lib/verification/__tests__/sourcify.spec.ts +0 -288
- package/src/lib/verification/etherscan.ts +0 -547
- package/src/lib/verification/sourcify.ts +0 -248
- package/test_validation/artifacts/TestContract.json +0 -9
- package/test_validation/jobs/test-missing.yaml +0 -16
- package/test_validation/networks.yaml +0 -3
- package/tsconfig.json +0 -36
|
@@ -1,474 +0,0 @@
|
|
|
1
|
-
import { ExecutionEngine } from '../engine'
|
|
2
|
-
import { ExecutionContext } from '../context'
|
|
3
|
-
import { ContractRepository } from '../../contracts/repository'
|
|
4
|
-
import { Action, Network } from '../../types'
|
|
5
|
-
import { VerificationPlatformRegistry } from '../../verification/etherscan'
|
|
6
|
-
|
|
7
|
-
describe('Assert Action', () => {
|
|
8
|
-
let engine: ExecutionEngine
|
|
9
|
-
let context: ExecutionContext
|
|
10
|
-
let mockNetwork: Network
|
|
11
|
-
let mockRegistry: ContractRepository
|
|
12
|
-
let templates: Map<string, any>
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
mockNetwork = { name: 'testnet', chainId: 999, rpcUrl: 'http://localhost:8545' }
|
|
16
|
-
mockRegistry = new ContractRepository()
|
|
17
|
-
|
|
18
|
-
// Create a mock context that doesn't require a real connection
|
|
19
|
-
context = {
|
|
20
|
-
getNetwork: () => mockNetwork,
|
|
21
|
-
setOutput: jest.fn(),
|
|
22
|
-
getOutput: jest.fn(),
|
|
23
|
-
setContextPath: jest.fn(),
|
|
24
|
-
getContextPath: jest.fn(),
|
|
25
|
-
dispose: jest.fn()
|
|
26
|
-
} as any
|
|
27
|
-
|
|
28
|
-
templates = new Map()
|
|
29
|
-
const verificationRegistry = new VerificationPlatformRegistry()
|
|
30
|
-
engine = new ExecutionEngine(templates, { verificationRegistry })
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
describe('assert primitive action', () => {
|
|
34
|
-
it('should pass when eq comparison is true', async () => {
|
|
35
|
-
const action: Action = {
|
|
36
|
-
type: 'assert',
|
|
37
|
-
name: 'test-assert-eq',
|
|
38
|
-
arguments: {
|
|
39
|
-
actual: '42',
|
|
40
|
-
eq: '42'
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
45
|
-
|
|
46
|
-
expect(context.setOutput).toHaveBeenCalledWith('test-assert-eq.actual', '42')
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('should fail when eq comparison is false', async () => {
|
|
50
|
-
const action: Action = {
|
|
51
|
-
type: 'assert',
|
|
52
|
-
name: 'test-assert-fail',
|
|
53
|
-
arguments: {
|
|
54
|
-
actual: '42',
|
|
55
|
-
eq: '99'
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
await expect(
|
|
60
|
-
(engine as any).executePrimitive(action, context, new Map())
|
|
61
|
-
).rejects.toThrow(/assert failed.*actual=42.*expected=99.*op=eq/)
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
it('should include custom message on failure', async () => {
|
|
65
|
-
const action: Action = {
|
|
66
|
-
type: 'assert',
|
|
67
|
-
name: 'test-assert-msg',
|
|
68
|
-
arguments: {
|
|
69
|
-
actual: '10',
|
|
70
|
-
eq: '20',
|
|
71
|
-
message: 'balance mismatch'
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
await expect(
|
|
76
|
-
(engine as any).executePrimitive(action, context, new Map())
|
|
77
|
-
).rejects.toThrow(/assert failed: balance mismatch.*actual=10.*expected=20.*op=eq/)
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it('should pass neq comparison', async () => {
|
|
81
|
-
const action: Action = {
|
|
82
|
-
type: 'assert',
|
|
83
|
-
name: 'test-assert-neq',
|
|
84
|
-
arguments: {
|
|
85
|
-
actual: '10',
|
|
86
|
-
neq: '20'
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
91
|
-
expect(context.setOutput).toHaveBeenCalledWith('test-assert-neq.actual', '10')
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('should fail neq comparison when values are equal', async () => {
|
|
95
|
-
const action: Action = {
|
|
96
|
-
type: 'assert',
|
|
97
|
-
name: 'test-assert-neq-fail',
|
|
98
|
-
arguments: {
|
|
99
|
-
actual: '10',
|
|
100
|
-
neq: '10'
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
await expect(
|
|
105
|
-
(engine as any).executePrimitive(action, context, new Map())
|
|
106
|
-
).rejects.toThrow(/assert failed.*op=neq/)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('should pass gte comparison', async () => {
|
|
110
|
-
const action: Action = {
|
|
111
|
-
type: 'assert',
|
|
112
|
-
name: 'test-assert-gte',
|
|
113
|
-
arguments: {
|
|
114
|
-
actual: '100',
|
|
115
|
-
gte: '50'
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
120
|
-
expect(context.setOutput).toHaveBeenCalledWith('test-assert-gte.actual', '100')
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('should pass gte when equal', async () => {
|
|
124
|
-
const action: Action = {
|
|
125
|
-
type: 'assert',
|
|
126
|
-
name: 'test-assert-gte-equal',
|
|
127
|
-
arguments: {
|
|
128
|
-
actual: '50',
|
|
129
|
-
gte: '50'
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
it('should fail gte when less', async () => {
|
|
137
|
-
const action: Action = {
|
|
138
|
-
type: 'assert',
|
|
139
|
-
name: 'test-assert-gte-fail',
|
|
140
|
-
arguments: {
|
|
141
|
-
actual: '10',
|
|
142
|
-
gte: '100'
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
await expect(
|
|
147
|
-
(engine as any).executePrimitive(action, context, new Map())
|
|
148
|
-
).rejects.toThrow(/assert failed.*op=gte/)
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('should pass lt comparison', async () => {
|
|
152
|
-
const action: Action = {
|
|
153
|
-
type: 'assert',
|
|
154
|
-
name: 'test-assert-lt',
|
|
155
|
-
arguments: {
|
|
156
|
-
actual: '10',
|
|
157
|
-
lt: '100'
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('should fail lt when greater', async () => {
|
|
165
|
-
const action: Action = {
|
|
166
|
-
type: 'assert',
|
|
167
|
-
name: 'test-assert-lt-fail',
|
|
168
|
-
arguments: {
|
|
169
|
-
actual: '100',
|
|
170
|
-
lt: '10'
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
await expect(
|
|
175
|
-
(engine as any).executePrimitive(action, context, new Map())
|
|
176
|
-
).rejects.toThrow(/assert failed.*op=lt/)
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('should pass lte comparison', async () => {
|
|
180
|
-
const action: Action = {
|
|
181
|
-
type: 'assert',
|
|
182
|
-
name: 'test-assert-lte',
|
|
183
|
-
arguments: {
|
|
184
|
-
actual: '10',
|
|
185
|
-
lte: '100'
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
it('should pass lte when equal', async () => {
|
|
193
|
-
const action: Action = {
|
|
194
|
-
type: 'assert',
|
|
195
|
-
name: 'test-assert-lte-equal',
|
|
196
|
-
arguments: {
|
|
197
|
-
actual: '100',
|
|
198
|
-
lte: '100'
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
203
|
-
})
|
|
204
|
-
|
|
205
|
-
it('should fail lte when greater', async () => {
|
|
206
|
-
const action: Action = {
|
|
207
|
-
type: 'assert',
|
|
208
|
-
name: 'test-assert-lte-fail',
|
|
209
|
-
arguments: {
|
|
210
|
-
actual: '100',
|
|
211
|
-
lte: '10'
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
await expect(
|
|
216
|
-
(engine as any).executePrimitive(action, context, new Map())
|
|
217
|
-
).rejects.toThrow(/assert failed.*op=lte/)
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
it('should pass gt comparison', async () => {
|
|
221
|
-
const action: Action = {
|
|
222
|
-
type: 'assert',
|
|
223
|
-
name: 'test-assert-gt',
|
|
224
|
-
arguments: {
|
|
225
|
-
actual: '100',
|
|
226
|
-
gt: '10'
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
it('should fail gt when less', async () => {
|
|
234
|
-
const action: Action = {
|
|
235
|
-
type: 'assert',
|
|
236
|
-
name: 'test-assert-gt-fail',
|
|
237
|
-
arguments: {
|
|
238
|
-
actual: '10',
|
|
239
|
-
gt: '100'
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
await expect(
|
|
244
|
-
(engine as any).executePrimitive(action, context, new Map())
|
|
245
|
-
).rejects.toThrow(/assert failed.*op=gt/)
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
it('should use `to` + `signature` form (call resolver)', async () => {
|
|
249
|
-
// Mock the resolver to simulate a call returning a value
|
|
250
|
-
const mockResolver = {
|
|
251
|
-
resolve: jest.fn(async (value: any, ctx: any, scope: any) => {
|
|
252
|
-
if (value.type === 'call') {
|
|
253
|
-
return '0xDepositManagerAddress'
|
|
254
|
-
}
|
|
255
|
-
if (value.type === 'basic-arithmetic') {
|
|
256
|
-
const [a, b] = value.arguments.values
|
|
257
|
-
if (value.arguments.operation === 'eq') {
|
|
258
|
-
return a === b
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
return value
|
|
262
|
-
})
|
|
263
|
-
}
|
|
264
|
-
;(engine as any).resolver = mockResolver
|
|
265
|
-
|
|
266
|
-
const action: Action = {
|
|
267
|
-
type: 'assert',
|
|
268
|
-
name: 'test-assert-call',
|
|
269
|
-
arguments: {
|
|
270
|
-
to: '0xSomeProxyAddress',
|
|
271
|
-
signature: 'depositManager() returns (address)',
|
|
272
|
-
eq: '0xDepositManagerAddress'
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
277
|
-
|
|
278
|
-
expect(mockResolver.resolve).toHaveBeenCalledWith(
|
|
279
|
-
{ type: 'call', arguments: { to: '0xSomeProxyAddress', signature: 'depositManager() returns (address)', values: [] } },
|
|
280
|
-
context,
|
|
281
|
-
new Map()
|
|
282
|
-
)
|
|
283
|
-
expect(context.setOutput).toHaveBeenCalledWith('test-assert-call.actual', '0xDepositManagerAddress')
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
it('should use `actual` form with read-balance resolver', async () => {
|
|
287
|
-
// Mock the resolver to simulate a read-balance returning a value
|
|
288
|
-
const mockResolver = {
|
|
289
|
-
resolve: jest.fn(async (value: any, ctx: any, scope: any) => {
|
|
290
|
-
if (value.type === 'read-balance') {
|
|
291
|
-
return '1000000000000000000' // 1 ETH
|
|
292
|
-
}
|
|
293
|
-
if (value.type === 'basic-arithmetic') {
|
|
294
|
-
const [a, b] = value.arguments.values
|
|
295
|
-
if (value.arguments.operation === 'gte') {
|
|
296
|
-
return BigInt(a) >= BigInt(b)
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return value
|
|
300
|
-
})
|
|
301
|
-
}
|
|
302
|
-
;(engine as any).resolver = mockResolver
|
|
303
|
-
|
|
304
|
-
const action: Action = {
|
|
305
|
-
type: 'assert',
|
|
306
|
-
name: 'test-assert-read-balance',
|
|
307
|
-
arguments: {
|
|
308
|
-
actual: { type: 'read-balance', arguments: { address: '0xDeployer' } },
|
|
309
|
-
gte: '1000000000000000000',
|
|
310
|
-
message: 'deployer underfunded'
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
315
|
-
|
|
316
|
-
expect(mockResolver.resolve).toHaveBeenCalledWith(
|
|
317
|
-
{ type: 'read-balance', arguments: { address: '0xDeployer' } },
|
|
318
|
-
context,
|
|
319
|
-
new Map()
|
|
320
|
-
)
|
|
321
|
-
expect(context.setOutput).toHaveBeenCalledWith('test-assert-read-balance.actual', '1000000000000000000')
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
it('should not store outputs when action has no name', async () => {
|
|
325
|
-
const action: Action = {
|
|
326
|
-
type: 'assert',
|
|
327
|
-
arguments: {
|
|
328
|
-
actual: '42',
|
|
329
|
-
eq: '42'
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
334
|
-
|
|
335
|
-
expect(context.setOutput).not.toHaveBeenCalled()
|
|
336
|
-
})
|
|
337
|
-
|
|
338
|
-
it('should not store outputs when action has custom output', async () => {
|
|
339
|
-
const action: Action = {
|
|
340
|
-
type: 'assert',
|
|
341
|
-
name: 'test-assert-custom',
|
|
342
|
-
arguments: {
|
|
343
|
-
actual: '42',
|
|
344
|
-
eq: '42'
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
await (engine as any).executePrimitive(action, context, new Map(), true)
|
|
349
|
-
|
|
350
|
-
// With hasCustomOutput=true, the .actual output should not be stored by the assert case
|
|
351
|
-
// (the custom output handling is done elsewhere in executeAction)
|
|
352
|
-
const setOutputCalls = (context.setOutput as jest.Mock).mock.calls
|
|
353
|
-
const actualOutputs = setOutputCalls.filter((c: any[]) => c[0].includes('.actual'))
|
|
354
|
-
expect(actualOutputs.length).toBe(0)
|
|
355
|
-
})
|
|
356
|
-
|
|
357
|
-
it('should fail when no comparator key is provided', async () => {
|
|
358
|
-
const action: Action = {
|
|
359
|
-
type: 'assert',
|
|
360
|
-
name: 'test-assert-no-comparator',
|
|
361
|
-
arguments: {
|
|
362
|
-
actual: '42'
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
await expect(
|
|
367
|
-
(engine as any).executePrimitive(action, context, new Map())
|
|
368
|
-
).rejects.toThrow(/assert must have exactly one of/)
|
|
369
|
-
})
|
|
370
|
-
|
|
371
|
-
it('should fail when more than one comparator key is provided', async () => {
|
|
372
|
-
const action: Action = {
|
|
373
|
-
type: 'assert',
|
|
374
|
-
name: 'test-assert-multi-comparator',
|
|
375
|
-
arguments: {
|
|
376
|
-
actual: '42',
|
|
377
|
-
eq: '42',
|
|
378
|
-
gte: '1'
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
await expect(
|
|
383
|
-
(engine as any).executePrimitive(action, context, new Map())
|
|
384
|
-
).rejects.toThrow(/assert must have exactly one comparator, but got: eq, gte/)
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
it('should resolve values from context variables', async () => {
|
|
388
|
-
// Mock the resolver to simulate template variable resolution
|
|
389
|
-
// returning the same value for both actual and expected
|
|
390
|
-
const mockResolver = {
|
|
391
|
-
resolve: jest.fn(async (value: any, ctx: any, scope: any) => {
|
|
392
|
-
if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {
|
|
393
|
-
return 'resolved-value'
|
|
394
|
-
}
|
|
395
|
-
if (value.type === 'basic-arithmetic') {
|
|
396
|
-
const [a, b] = value.arguments.values
|
|
397
|
-
if (value.arguments.operation === 'eq') {
|
|
398
|
-
return a === b
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
return value
|
|
402
|
-
})
|
|
403
|
-
}
|
|
404
|
-
;(engine as any).resolver = mockResolver
|
|
405
|
-
|
|
406
|
-
const action: Action = {
|
|
407
|
-
type: 'assert',
|
|
408
|
-
name: 'test-assert-context',
|
|
409
|
-
arguments: {
|
|
410
|
-
actual: '{{myValue}}',
|
|
411
|
-
eq: '{{myExpected}}'
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
416
|
-
|
|
417
|
-
// Both {{myValue}} and {{myExpected}} resolve to 'resolved-value', so eq returns true
|
|
418
|
-
expect(context.setOutput).toHaveBeenCalledWith('test-assert-context.actual', 'resolved-value')
|
|
419
|
-
})
|
|
420
|
-
|
|
421
|
-
it('should handle boolean values in eq comparison', async () => {
|
|
422
|
-
const action: Action = {
|
|
423
|
-
type: 'assert',
|
|
424
|
-
name: 'test-assert-bool',
|
|
425
|
-
arguments: {
|
|
426
|
-
actual: true,
|
|
427
|
-
eq: true
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
432
|
-
expect(context.setOutput).toHaveBeenCalledWith('test-assert-bool.actual', true)
|
|
433
|
-
})
|
|
434
|
-
|
|
435
|
-
it('should handle large number comparisons', async () => {
|
|
436
|
-
const action: Action = {
|
|
437
|
-
type: 'assert',
|
|
438
|
-
name: 'test-assert-large',
|
|
439
|
-
arguments: {
|
|
440
|
-
actual: '115792089237316195423570985008687907853269984665640564039457584007913129639935',
|
|
441
|
-
gte: '10000000000000000000000000000000000000000000000000000000000000000000000000000'
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
await (engine as any).executePrimitive(action, context, new Map())
|
|
446
|
-
expect(context.setOutput).toHaveBeenCalledWith('test-assert-large.actual', '115792089237316195423570985008687907853269984665640564039457584007913129639935')
|
|
447
|
-
})
|
|
448
|
-
|
|
449
|
-
it('should describe call form as signature in error message', async () => {
|
|
450
|
-
const mockResolver = {
|
|
451
|
-
resolve: jest.fn(async (value: any, ctx: any, scope: any) => {
|
|
452
|
-
if (value.type === 'call') return 'wrong-address'
|
|
453
|
-
if (value.type === 'basic-arithmetic') return false
|
|
454
|
-
return value
|
|
455
|
-
})
|
|
456
|
-
}
|
|
457
|
-
;(engine as any).resolver = mockResolver
|
|
458
|
-
|
|
459
|
-
const action: Action = {
|
|
460
|
-
type: 'assert',
|
|
461
|
-
name: 'test-assert-call-desc',
|
|
462
|
-
arguments: {
|
|
463
|
-
to: '0xProxy',
|
|
464
|
-
signature: 'getOwner() returns (address)',
|
|
465
|
-
eq: '0xCorrectOwner'
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
await expect(
|
|
470
|
-
(engine as any).executePrimitive(action, context, new Map())
|
|
471
|
-
).rejects.toThrow(/assert failed.*getOwner\(\) returns \(address\)/)
|
|
472
|
-
})
|
|
473
|
-
})
|
|
474
|
-
})
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers'
|
|
2
|
-
import { ExecutionContext } from '../context'
|
|
3
|
-
import { Network } from '../../types'
|
|
4
|
-
|
|
5
|
-
describe('ExecutionContext', () => {
|
|
6
|
-
const network: Network = {
|
|
7
|
-
name: 'test',
|
|
8
|
-
chainId: 31337,
|
|
9
|
-
rpcUrl: 'http://127.0.0.1:8545'
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const contractRepository = {} as any
|
|
13
|
-
|
|
14
|
-
it('wraps private-key signers in a NonceManager', async () => {
|
|
15
|
-
const context = new ExecutionContext(
|
|
16
|
-
network,
|
|
17
|
-
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
|
|
18
|
-
contractRepository
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
const signer = await context.getResolvedSigner()
|
|
22
|
-
expect(signer).toBeInstanceOf(ethers.NonceManager)
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('wraps promised signers in a NonceManager when first resolved', async () => {
|
|
26
|
-
const getSignerSpy = jest.spyOn(ethers.JsonRpcProvider.prototype, 'getSigner')
|
|
27
|
-
getSignerSpy.mockResolvedValue(
|
|
28
|
-
ethers.Wallet.createRandom().connect(new ethers.JsonRpcProvider(network.rpcUrl)) as any
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
const context = new ExecutionContext(network, undefined, contractRepository)
|
|
32
|
-
|
|
33
|
-
await expect(context.getResolvedSigner()).resolves.toBeInstanceOf(ethers.NonceManager)
|
|
34
|
-
|
|
35
|
-
getSignerSpy.mockRestore()
|
|
36
|
-
})
|
|
37
|
-
})
|