@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,125 +0,0 @@
|
|
|
1
|
-
// src/lib/core/__tests__/graph.spec.ts
|
|
2
|
-
import * as path from 'path'
|
|
3
|
-
import { ProjectLoader } from '../loader'
|
|
4
|
-
import { DependencyGraph } from '../graph'
|
|
5
|
-
import { Job, Template } from '../../types'
|
|
6
|
-
|
|
7
|
-
describe('DependencyGraph', () => {
|
|
8
|
-
let loader: ProjectLoader
|
|
9
|
-
|
|
10
|
-
beforeAll(async () => {
|
|
11
|
-
// Load the real project structure from the examples directory
|
|
12
|
-
const projectRoot = path.resolve(__dirname, '../../../../examples')
|
|
13
|
-
loader = new ProjectLoader(projectRoot)
|
|
14
|
-
await loader.load()
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('should be created without errors for a valid project', () => {
|
|
18
|
-
expect(() => new DependencyGraph(loader.jobs, loader.templates)).not.toThrow()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('should identify direct dependencies from `depends_on` field', () => {
|
|
22
|
-
const graph = new DependencyGraph(loader.jobs, loader.templates)
|
|
23
|
-
// guards-v1.yaml has `depends_on: ["sequence-v1"]`
|
|
24
|
-
const guardsDeps = graph.getDependencies('guards-v1')
|
|
25
|
-
expect(guardsDeps.has('sequence-v1')).toBe(true)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('should identify dependencies from a template setup block (`job-completed`)', () => {
|
|
29
|
-
const jobs = new Map<string, Job>()
|
|
30
|
-
const templates = new Map<string, Template>()
|
|
31
|
-
|
|
32
|
-
templates.set('template-with-setup', {
|
|
33
|
-
name: 'template-with-setup',
|
|
34
|
-
actions: [],
|
|
35
|
-
setup: { skip_condition: [{ type: 'job-completed', arguments: { job: 'dependency-job' } }] },
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
jobs.set('job-A', { name: 'job-A', version: '1', actions: [{ name: 'a1', template: 'template-with-setup', arguments: {} }] })
|
|
39
|
-
jobs.set('dependency-job', { name: 'dependency-job', version: '1', actions: [] })
|
|
40
|
-
|
|
41
|
-
const graph = new DependencyGraph(jobs, templates)
|
|
42
|
-
const jobADeps = graph.getDependencies('job-A')
|
|
43
|
-
expect(jobADeps.has('dependency-job')).toBe(true)
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('should identify nested dependencies from templates calling templates in setup', () => {
|
|
47
|
-
// In our examples:
|
|
48
|
-
// job `sequence-v1` uses `sequence-universal-deployer-2`
|
|
49
|
-
// `sequence-universal-deployer-2`'s setup uses `nano-universal-deployer`
|
|
50
|
-
// `nano-universal-deployer`'s setup uses `min-balance` and `send-signed-transaction` (primitives)
|
|
51
|
-
// This test confirms the graph builder doesn't crash on this complexity.
|
|
52
|
-
// A more specific test would require mocking a deeper chain.
|
|
53
|
-
const graph = new DependencyGraph(loader.jobs, loader.templates);
|
|
54
|
-
const seqV1Deps = graph.getDependencies('sequence-v1');
|
|
55
|
-
|
|
56
|
-
// sequence-v1 itself has no job dependencies defined in its YAMLs, so this should be empty.
|
|
57
|
-
// This confirms our logic correctly distinguishes between template-setup-actions and job dependencies.
|
|
58
|
-
expect(seqV1Deps.size).toBe(0);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should correctly identify transitive dependencies', () => {
|
|
62
|
-
const graph = new DependencyGraph(loader.jobs, loader.templates)
|
|
63
|
-
// "sequence-v1-seq-0001-patch" -> "guards-v1" -> "sequence-v1"
|
|
64
|
-
const patchDeps = graph.getDependencies('sequence-v1-seq-0001-patch')
|
|
65
|
-
expect(patchDeps.has('guards-v1')).toBe(true)
|
|
66
|
-
expect(patchDeps.has('sequence-v1')).toBe(true) // Transitive dependency
|
|
67
|
-
expect(patchDeps.size).toBe(2) // depends on sequence-v1, and guards-v1
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('should produce a valid topological sort order', () => {
|
|
71
|
-
const graph = new DependencyGraph(loader.jobs, loader.templates)
|
|
72
|
-
const order = graph.getExecutionOrder()
|
|
73
|
-
|
|
74
|
-
// We can't know the exact order due to parallel possibilities,
|
|
75
|
-
// but we can verify that dependencies always come before their dependents.
|
|
76
|
-
const patchIndex = order.indexOf('sequence-v1-seq-0001-patch')
|
|
77
|
-
const guardsIndex = order.indexOf('guards-v1')
|
|
78
|
-
const seqV1Index = order.indexOf('sequence-v1')
|
|
79
|
-
|
|
80
|
-
expect(patchIndex).toBeGreaterThan(guardsIndex)
|
|
81
|
-
expect(patchIndex).toBeGreaterThan(seqV1Index)
|
|
82
|
-
expect(guardsIndex).toBeGreaterThan(seqV1Index)
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
describe('Cycle Detection', () => {
|
|
86
|
-
it('should throw an error for a simple (A -> B -> A) cycle', () => {
|
|
87
|
-
const jobs = new Map<string, Job>()
|
|
88
|
-
jobs.set('job-A', { name: 'job-A', version: '1', actions: [], depends_on: ['job-B'] })
|
|
89
|
-
jobs.set('job-B', { name: 'job-B', version: '1', actions: [], depends_on: ['job-A'] })
|
|
90
|
-
|
|
91
|
-
expect(() => new DependencyGraph(jobs, new Map())).toThrow(
|
|
92
|
-
/Circular dependency detected: job-A -> job-B -> job-A/
|
|
93
|
-
)
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('should throw an error for a longer (A -> B -> C -> A) cycle', () => {
|
|
97
|
-
const jobs = new Map<string, Job>()
|
|
98
|
-
jobs.set('job-A', { name: 'job-A', version: '1', actions: [], depends_on: ['job-B'] })
|
|
99
|
-
jobs.set('job-B', { name: 'job-B', version: '1', actions: [], depends_on: ['job-C'] })
|
|
100
|
-
jobs.set('job-C', { name: 'job-C', version: '1', actions: [], depends_on: ['job-A'] })
|
|
101
|
-
|
|
102
|
-
expect(() => new DependencyGraph(jobs, new Map())).toThrow(
|
|
103
|
-
/Circular dependency detected: job-A -> job-B -> job-C -> job-A/
|
|
104
|
-
)
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
it('should throw an error for a self-referencing cycle', () => {
|
|
108
|
-
const jobs = new Map<string, Job>()
|
|
109
|
-
jobs.set('job-A', { name: 'job-A', version: '1', actions: [], depends_on: ['job-A'] })
|
|
110
|
-
|
|
111
|
-
expect(() => new DependencyGraph(jobs, new Map())).toThrow(
|
|
112
|
-
/Circular dependency detected: job-A -> job-A/
|
|
113
|
-
)
|
|
114
|
-
})
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
it('should throw an error for a dependency on a non-existent job', () => {
|
|
118
|
-
const jobs = new Map<string, Job>()
|
|
119
|
-
jobs.set('job-A', { name: 'job-A', version: '1', actions: [], depends_on: ['job-non-existent'] })
|
|
120
|
-
|
|
121
|
-
expect(() => new DependencyGraph(jobs, new Map())).toThrow(
|
|
122
|
-
'Invalid dependency: Job "job-A" depends on "job-non-existent", which does not exist.'
|
|
123
|
-
)
|
|
124
|
-
})
|
|
125
|
-
})
|
|
@@ -1,425 +0,0 @@
|
|
|
1
|
-
import { ExecutionEngine } from '../engine'
|
|
2
|
-
import { ExecutionContext } from '../context'
|
|
3
|
-
import { ValueResolver } from '../resolver'
|
|
4
|
-
import { ContractRepository } from '../../contracts/repository'
|
|
5
|
-
import { Action, Network, ReadJsonValue, SliceBytesValue } from '../../types'
|
|
6
|
-
import { VerificationPlatformRegistry } from '../../verification/etherscan'
|
|
7
|
-
|
|
8
|
-
describe('JSON Integration Tests', () => {
|
|
9
|
-
let engine: ExecutionEngine
|
|
10
|
-
let context: ExecutionContext
|
|
11
|
-
let resolver: ValueResolver
|
|
12
|
-
let mockNetwork: Network
|
|
13
|
-
let mockRegistry: ContractRepository
|
|
14
|
-
let templates: Map<string, any>
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
mockNetwork = { name: 'testnet', chainId: 999, rpcUrl: 'http://localhost:8545' }
|
|
18
|
-
mockRegistry = new ContractRepository()
|
|
19
|
-
|
|
20
|
-
// Create a mock context that doesn't require a real connection
|
|
21
|
-
context = {
|
|
22
|
-
getNetwork: () => mockNetwork,
|
|
23
|
-
setOutput: jest.fn(),
|
|
24
|
-
getOutput: jest.fn(),
|
|
25
|
-
setContextPath: jest.fn(),
|
|
26
|
-
getContextPath: jest.fn(),
|
|
27
|
-
dispose: jest.fn(),
|
|
28
|
-
provider: {} as any,
|
|
29
|
-
contractRepository: mockRegistry
|
|
30
|
-
} as any
|
|
31
|
-
|
|
32
|
-
templates = new Map()
|
|
33
|
-
const verificationRegistry = new VerificationPlatformRegistry()
|
|
34
|
-
engine = new ExecutionEngine(templates, { verificationRegistry })
|
|
35
|
-
resolver = new ValueResolver()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
describe('ReadJsonValue resolver', () => {
|
|
39
|
-
it('should extract nested values from JSON objects', async () => {
|
|
40
|
-
const testJson = {
|
|
41
|
-
txs: {
|
|
42
|
-
to: '0x596aF90CecdBF9A768886E771178fd5561dD27Ab',
|
|
43
|
-
data: '0x1234'
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const value: ReadJsonValue = {
|
|
48
|
-
type: 'read-json',
|
|
49
|
-
arguments: {
|
|
50
|
-
json: testJson,
|
|
51
|
-
path: 'txs.data'
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const result = await resolver.resolve(value, context)
|
|
56
|
-
expect(result).toBe('0x1234')
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('should extract nested address values', async () => {
|
|
60
|
-
const testJson = {
|
|
61
|
-
txs: {
|
|
62
|
-
to: '0x596aF90CecdBF9A768886E771178fd5561dD27Ab',
|
|
63
|
-
data: '0x1234'
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const value: ReadJsonValue = {
|
|
68
|
-
type: 'read-json',
|
|
69
|
-
arguments: {
|
|
70
|
-
json: testJson,
|
|
71
|
-
path: 'txs.to'
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const result = await resolver.resolve(value, context)
|
|
76
|
-
expect(result).toBe('0x596aF90CecdBF9A768886E771178fd5561dD27Ab')
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
it('should handle array access', async () => {
|
|
80
|
-
const testJson = {
|
|
81
|
-
transactions: [
|
|
82
|
-
{ hash: '0xabc123', value: '1000' },
|
|
83
|
-
{ hash: '0xdef456', value: '2000' }
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const value: ReadJsonValue = {
|
|
88
|
-
type: 'read-json',
|
|
89
|
-
arguments: {
|
|
90
|
-
json: testJson,
|
|
91
|
-
path: 'transactions.1.hash'
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const result = await resolver.resolve(value, context)
|
|
96
|
-
expect(result).toBe('0xdef456')
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('should handle deeply nested objects', async () => {
|
|
100
|
-
const testJson = {
|
|
101
|
-
response: {
|
|
102
|
-
data: {
|
|
103
|
-
blockchain: {
|
|
104
|
-
ethereum: {
|
|
105
|
-
contracts: {
|
|
106
|
-
token: {
|
|
107
|
-
address: '0x123456789',
|
|
108
|
-
symbol: 'TEST'
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const value: ReadJsonValue = {
|
|
118
|
-
type: 'read-json',
|
|
119
|
-
arguments: {
|
|
120
|
-
json: testJson,
|
|
121
|
-
path: 'response.data.blockchain.ethereum.contracts.token.symbol'
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const result = await resolver.resolve(value, context)
|
|
126
|
-
expect(result).toBe('TEST')
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('should return entire object when path is empty', async () => {
|
|
130
|
-
const testJson = { name: 'test', value: 42 }
|
|
131
|
-
|
|
132
|
-
const value: ReadJsonValue = {
|
|
133
|
-
type: 'read-json',
|
|
134
|
-
arguments: {
|
|
135
|
-
json: testJson,
|
|
136
|
-
path: ''
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const result = await resolver.resolve(value, context)
|
|
141
|
-
expect(result).toEqual(testJson)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('should throw error for invalid paths', async () => {
|
|
145
|
-
const testJson = { name: 'test' }
|
|
146
|
-
|
|
147
|
-
const value: ReadJsonValue = {
|
|
148
|
-
type: 'read-json',
|
|
149
|
-
arguments: {
|
|
150
|
-
json: testJson,
|
|
151
|
-
path: 'nonexistent.field'
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
await expect(resolver.resolve(value, context)).rejects.toThrow(
|
|
156
|
-
'read-json: Failed to access path "nonexistent.field"'
|
|
157
|
-
)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
it('should handle null and undefined values gracefully', async () => {
|
|
161
|
-
const testJson = {
|
|
162
|
-
data: {
|
|
163
|
-
value: null,
|
|
164
|
-
missing: undefined
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const nullValue: ReadJsonValue = {
|
|
169
|
-
type: 'read-json',
|
|
170
|
-
arguments: {
|
|
171
|
-
json: testJson,
|
|
172
|
-
path: 'data.value'
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const result = await resolver.resolve(nullValue, context)
|
|
177
|
-
expect(result).toBeNull()
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
it('should work with template variables', async () => {
|
|
181
|
-
// Mock context to return a JSON object when resolving a template variable
|
|
182
|
-
const mockJson = {
|
|
183
|
-
api: {
|
|
184
|
-
response: {
|
|
185
|
-
status: 'success',
|
|
186
|
-
data: '0xabcdef'
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Mock the resolver to handle template variable resolution
|
|
192
|
-
const originalResolve = resolver.resolve.bind(resolver)
|
|
193
|
-
jest.spyOn(resolver, 'resolve').mockImplementation(async (value, ctx, scope) => {
|
|
194
|
-
if (value === '{{apiResponse}}') {
|
|
195
|
-
return mockJson
|
|
196
|
-
}
|
|
197
|
-
if (value === '{{extractPath}}') {
|
|
198
|
-
return 'api.response.data'
|
|
199
|
-
}
|
|
200
|
-
return originalResolve(value, ctx, scope)
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
const value: ReadJsonValue = {
|
|
204
|
-
type: 'read-json',
|
|
205
|
-
arguments: {
|
|
206
|
-
json: '{{apiResponse}}',
|
|
207
|
-
path: '{{extractPath}}'
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const result = await resolver.resolve(value, context)
|
|
212
|
-
expect(result).toBe('0xabcdef')
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
it('should allow numeric network chain IDs to index top-level maps', async () => {
|
|
216
|
-
const value: ReadJsonValue = {
|
|
217
|
-
type: 'read-json',
|
|
218
|
-
arguments: {
|
|
219
|
-
json: {
|
|
220
|
-
999: {
|
|
221
|
-
executeCalldata: '0xfeedface'
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
path: '{{Network().chainId}}'
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const result = await resolver.resolve(value, context)
|
|
229
|
-
expect(result).toEqual({ executeCalldata: '0xfeedface' })
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
it('should let value-empty detect missing top-level map entries', async () => {
|
|
233
|
-
const value = {
|
|
234
|
-
type: 'value-empty',
|
|
235
|
-
arguments: {
|
|
236
|
-
value: {
|
|
237
|
-
type: 'read-json',
|
|
238
|
-
arguments: {
|
|
239
|
-
json: {
|
|
240
|
-
999: {
|
|
241
|
-
executeCalldata: '0xfeedface'
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
path: '{{missingChainId}}'
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
} as const
|
|
249
|
-
|
|
250
|
-
const scope = new Map<string, any>([['missingChainId', 10]])
|
|
251
|
-
const result = await resolver.resolve(value, context, scope)
|
|
252
|
-
expect(result).toBe(true)
|
|
253
|
-
})
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
describe('JsonRequestAction integration', () => {
|
|
257
|
-
it('should handle json-request action type validation', () => {
|
|
258
|
-
const action: Action = {
|
|
259
|
-
type: 'json-request',
|
|
260
|
-
name: 'test-request',
|
|
261
|
-
arguments: {
|
|
262
|
-
url: 'https://api.example.com/data',
|
|
263
|
-
method: 'GET'
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
expect(action.type).toBe('json-request')
|
|
268
|
-
expect(action.arguments.url).toBe('https://api.example.com/data')
|
|
269
|
-
expect(action.arguments.method).toBe('GET')
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
it('should validate required url parameter', async () => {
|
|
273
|
-
const action: Action = {
|
|
274
|
-
type: 'json-request',
|
|
275
|
-
name: 'test-request',
|
|
276
|
-
arguments: {
|
|
277
|
-
url: null as any
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Mock the engine's executePrimitive method to test validation
|
|
282
|
-
const mockEngine = {
|
|
283
|
-
resolver: {
|
|
284
|
-
resolve: jest.fn().mockResolvedValue(null)
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// The engine should validate that url is a string
|
|
289
|
-
expect(mockEngine.resolver.resolve).toBeDefined()
|
|
290
|
-
})
|
|
291
|
-
})
|
|
292
|
-
|
|
293
|
-
describe('End-to-end workflow simulation', () => {
|
|
294
|
-
it('should simulate the Guard API example workflow', async () => {
|
|
295
|
-
// Simulate the API response from Guard
|
|
296
|
-
const mockApiResponse = {
|
|
297
|
-
txs: {
|
|
298
|
-
to: '0x596aF90CecdBF9A768886E771178fd5561dD27Ab',
|
|
299
|
-
data: '0x1234'
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// Step 1: Simulate storing the API response in context
|
|
304
|
-
context.setOutput('guard-patch-request.response', mockApiResponse)
|
|
305
|
-
|
|
306
|
-
// Step 2: Extract the data using read-json
|
|
307
|
-
const extractDataValue: ReadJsonValue = {
|
|
308
|
-
type: 'read-json',
|
|
309
|
-
arguments: {
|
|
310
|
-
json: mockApiResponse,
|
|
311
|
-
path: 'txs.data'
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const extractedData = await resolver.resolve(extractDataValue, context)
|
|
316
|
-
expect(extractedData).toBe('0x1234')
|
|
317
|
-
|
|
318
|
-
// Step 3: Extract the to address using read-json
|
|
319
|
-
const extractToValue: ReadJsonValue = {
|
|
320
|
-
type: 'read-json',
|
|
321
|
-
arguments: {
|
|
322
|
-
json: mockApiResponse,
|
|
323
|
-
path: 'txs.to'
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
const extractedTo = await resolver.resolve(extractToValue, context)
|
|
328
|
-
expect(extractedTo).toBe('0x596aF90CecdBF9A768886E771178fd5561dD27Ab')
|
|
329
|
-
|
|
330
|
-
// Verify both values are correctly extracted
|
|
331
|
-
expect(extractedData).toBe('0x1234')
|
|
332
|
-
expect(extractedTo).toBe('0x596aF90CecdBF9A768886E771178fd5561dD27Ab')
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
it('should allow piping read-json output into slice-bytes', async () => {
|
|
336
|
-
const response = {
|
|
337
|
-
txs: {
|
|
338
|
-
data: '0xaabbccddff'
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
const value: SliceBytesValue = {
|
|
343
|
-
type: 'slice-bytes',
|
|
344
|
-
arguments: {
|
|
345
|
-
value: {
|
|
346
|
-
type: 'read-json',
|
|
347
|
-
arguments: {
|
|
348
|
-
json: response,
|
|
349
|
-
path: 'txs.data'
|
|
350
|
-
}
|
|
351
|
-
},
|
|
352
|
-
range: ':-1'
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const trimmed = await resolver.resolve(value, context)
|
|
357
|
-
expect(trimmed).toBe('0xaabbccdd')
|
|
358
|
-
})
|
|
359
|
-
|
|
360
|
-
it('should handle complex nested API responses', async () => {
|
|
361
|
-
const complexApiResponse = {
|
|
362
|
-
status: 'success',
|
|
363
|
-
data: {
|
|
364
|
-
blockchain: 'ethereum',
|
|
365
|
-
network: 'mainnet',
|
|
366
|
-
transactions: [
|
|
367
|
-
{
|
|
368
|
-
hash: '0xabc123',
|
|
369
|
-
to: '0x111111',
|
|
370
|
-
data: '0xfirst'
|
|
371
|
-
},
|
|
372
|
-
{
|
|
373
|
-
hash: '0xdef456',
|
|
374
|
-
to: '0x222222',
|
|
375
|
-
data: '0xsecond'
|
|
376
|
-
}
|
|
377
|
-
],
|
|
378
|
-
metadata: {
|
|
379
|
-
timestamp: 1234567890,
|
|
380
|
-
source: 'guard-api'
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// Extract various nested values
|
|
386
|
-
const statusValue: ReadJsonValue = {
|
|
387
|
-
type: 'read-json',
|
|
388
|
-
arguments: {
|
|
389
|
-
json: complexApiResponse,
|
|
390
|
-
path: 'status'
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
const firstTxData: ReadJsonValue = {
|
|
395
|
-
type: 'read-json',
|
|
396
|
-
arguments: {
|
|
397
|
-
json: complexApiResponse,
|
|
398
|
-
path: 'data.transactions.0.data'
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const secondTxTo: ReadJsonValue = {
|
|
403
|
-
type: 'read-json',
|
|
404
|
-
arguments: {
|
|
405
|
-
json: complexApiResponse,
|
|
406
|
-
path: 'data.transactions.1.to'
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const timestamp: ReadJsonValue = {
|
|
411
|
-
type: 'read-json',
|
|
412
|
-
arguments: {
|
|
413
|
-
json: complexApiResponse,
|
|
414
|
-
path: 'data.metadata.timestamp'
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// Test all extractions
|
|
419
|
-
expect(await resolver.resolve(statusValue, context)).toBe('success')
|
|
420
|
-
expect(await resolver.resolve(firstTxData, context)).toBe('0xfirst')
|
|
421
|
-
expect(await resolver.resolve(secondTxTo, context)).toBe('0x222222')
|
|
422
|
-
expect(await resolver.resolve(timestamp, context)).toBe(1234567890)
|
|
423
|
-
})
|
|
424
|
-
})
|
|
425
|
-
})
|