Skip to content

Commit 39de66a

Browse files
committed
YAML parsing test
1 parent cd466fd commit 39de66a

3 files changed

Lines changed: 293 additions & 45 deletions

File tree

deployment/cre/jobs/propose_job_spec_test.go

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import (
1111
"github.com/pelletier/go-toml/v2"
1212
"github.com/stretchr/testify/assert"
1313
"github.com/stretchr/testify/require"
14+
"gopkg.in/yaml.v3"
1415

1516
chainsel "github.com/smartcontractkit/chain-selectors"
1617

1718
"github.com/smartcontractkit/chainlink-common/pkg/settings/cresettings"
1819
"github.com/smartcontractkit/chainlink-deployments-framework/datastore"
1920
cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment"
21+
cldpipelineinput "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/pipeline/input"
2022
"github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"
2123
"github.com/smartcontractkit/chainlink-protos/job-distributor/v1/node"
2224
"github.com/smartcontractkit/chainlink/deployment/cre/jobs"
@@ -1753,3 +1755,246 @@ CallLimit = 1_000`, "invalid inputs for CRE settings job spec: invalid wf abcd:
17531755
})
17541756
}
17551757
}
1758+
1759+
func TestProposeJobSpec_GatewayJobYAMLConversion(t *testing.T) {
1760+
t.Parallel()
1761+
1762+
t.Run("don-centric format", func(t *testing.T) {
1763+
t.Parallel()
1764+
1765+
yamlSpec := `
1766+
environment: test
1767+
domain: cre
1768+
changesets:
1769+
- job_propose_arbitrary:
1770+
payload:
1771+
donName: gateway-don
1772+
donFilters:
1773+
- key: don_name
1774+
value: gateway-don
1775+
- key: environment
1776+
value: test
1777+
- key: product
1778+
value: cre
1779+
jobName: test-gateway-job
1780+
template: gateway
1781+
inputs:
1782+
dons:
1783+
- name: workflow-don
1784+
f: 1
1785+
handlers:
1786+
- web-api-capabilities
1787+
- http-capabilities
1788+
gatewayRequestTimeoutSec: 12
1789+
allowedPorts:
1790+
- 443
1791+
- 8080
1792+
allowedSchemes:
1793+
- https
1794+
authGatewayID: my-gateway-id
1795+
`
1796+
var root yaml.Node
1797+
err := yaml.Unmarshal([]byte(yamlSpec), &root)
1798+
require.NoError(t, err)
1799+
1800+
rootMap, ok := cldpipelineinput.YamlNodeToAny(&root).(map[string]any)
1801+
require.True(t, ok)
1802+
1803+
environment, _ := rootMap["environment"].(string)
1804+
domain, _ := rootMap["domain"].(string)
1805+
1806+
changesetData, err := cldpipelineinput.FindChangesetInData(rootMap["changesets"], "job_propose_arbitrary")
1807+
require.NoError(t, err)
1808+
1809+
changesetMap, ok := changesetData.(map[string]any)
1810+
require.True(t, ok)
1811+
1812+
payload, ok := changesetMap["payload"]
1813+
require.True(t, ok)
1814+
1815+
payloadBytes, err := yaml.Marshal(payload)
1816+
require.NoError(t, err)
1817+
1818+
var parsed jobs.ProposeJobSpecInput
1819+
err = yaml.Unmarshal(payloadBytes, &parsed)
1820+
require.NoError(t, err)
1821+
1822+
parsed.Environment = environment
1823+
parsed.Domain = domain
1824+
1825+
assert.Equal(t, "test", parsed.Environment)
1826+
assert.Equal(t, "cre", parsed.Domain)
1827+
assert.Equal(t, "gateway-don", parsed.DONName)
1828+
assert.Equal(t, job_types.Gateway, parsed.Template)
1829+
1830+
var gatewayInput operations.ProposeGatewayJobInput
1831+
err = parsed.Inputs.UnmarshalTo(&gatewayInput)
1832+
require.NoError(t, err)
1833+
1834+
assert.False(t, gatewayInput.ServiceCentricFormatEnabled)
1835+
require.Len(t, gatewayInput.DONs, 1)
1836+
assert.Equal(t, "workflow-don", gatewayInput.DONs[0].Name)
1837+
assert.Equal(t, 1, gatewayInput.DONs[0].F)
1838+
assert.Equal(t, []string{"web-api-capabilities", "http-capabilities"}, gatewayInput.DONs[0].Handlers)
1839+
assert.Equal(t, 12, gatewayInput.GatewayRequestTimeoutSec)
1840+
assert.Equal(t, []int{443, 8080}, gatewayInput.AllowedPorts)
1841+
assert.Equal(t, []string{"https"}, gatewayInput.AllowedSchemes)
1842+
assert.Equal(t, "my-gateway-id", gatewayInput.AuthGatewayID)
1843+
1844+
// Build GatewayJob manually; in production member addresses are resolved via JD.
1845+
gj := pkg.GatewayJob{
1846+
JobName: "CRE Gateway",
1847+
TargetDONs: []pkg.TargetDON{
1848+
{
1849+
ID: gatewayInput.DONs[0].Name,
1850+
F: gatewayInput.DONs[0].F,
1851+
Handlers: gatewayInput.DONs[0].Handlers,
1852+
Members: []pkg.TargetDONMember{
1853+
{Address: "0xabc123", Name: "mock-node-1 (DON workflow-don)"},
1854+
},
1855+
},
1856+
},
1857+
RequestTimeoutSec: gatewayInput.GatewayRequestTimeoutSec,
1858+
AllowedPorts: gatewayInput.AllowedPorts,
1859+
AllowedSchemes: gatewayInput.AllowedSchemes,
1860+
AuthGatewayID: gatewayInput.AuthGatewayID,
1861+
}
1862+
1863+
require.NoError(t, gj.Validate())
1864+
assert.False(t, gj.ServiceCentricFormatEnabled)
1865+
assert.Equal(t, "CRE Gateway", gj.JobName)
1866+
assert.Equal(t, 12, gj.RequestTimeoutSec)
1867+
assert.Equal(t, []int{443, 8080}, gj.AllowedPorts)
1868+
assert.Equal(t, []string{"https"}, gj.AllowedSchemes)
1869+
assert.Equal(t, "my-gateway-id", gj.AuthGatewayID)
1870+
require.Len(t, gj.TargetDONs, 1)
1871+
assert.Equal(t, "workflow-don", gj.TargetDONs[0].ID)
1872+
assert.Equal(t, 1, gj.TargetDONs[0].F)
1873+
assert.Equal(t, []string{"web-api-capabilities", "http-capabilities"}, gj.TargetDONs[0].Handlers)
1874+
})
1875+
1876+
t.Run("service-centric format", func(t *testing.T) {
1877+
t.Parallel()
1878+
1879+
yamlSpec := `
1880+
environment: staging
1881+
domain: cre
1882+
changesets:
1883+
- job_propose_arbitrary:
1884+
payload:
1885+
donName: gateway-don
1886+
donFilters:
1887+
- key: don_name
1888+
value: gateway-don
1889+
- key: environment
1890+
value: staging
1891+
- key: product
1892+
value: cre
1893+
jobName: test-gateway-job-svc
1894+
template: gateway
1895+
inputs:
1896+
serviceCentricFormatEnabled: true
1897+
dons:
1898+
- name: workflow-don
1899+
f: 1
1900+
services:
1901+
- servicename: workflows
1902+
handlers:
1903+
- web-api-capabilities
1904+
- http-capabilities
1905+
dons:
1906+
- workflow-don
1907+
gatewayRequestTimeoutSec: 10
1908+
allowedSchemes:
1909+
- https
1910+
allowedIPsCIDR:
1911+
- 10.0.0.0/8
1912+
`
1913+
var root yaml.Node
1914+
err := yaml.Unmarshal([]byte(yamlSpec), &root)
1915+
require.NoError(t, err)
1916+
1917+
rootMap, ok := cldpipelineinput.YamlNodeToAny(&root).(map[string]any)
1918+
require.True(t, ok)
1919+
1920+
environment, _ := rootMap["environment"].(string)
1921+
domain, _ := rootMap["domain"].(string)
1922+
1923+
changesetData, err := cldpipelineinput.FindChangesetInData(rootMap["changesets"], "job_propose_arbitrary")
1924+
require.NoError(t, err)
1925+
1926+
changesetMap, ok := changesetData.(map[string]any)
1927+
require.True(t, ok)
1928+
1929+
payload, ok := changesetMap["payload"]
1930+
require.True(t, ok)
1931+
1932+
payloadBytes, err := yaml.Marshal(payload)
1933+
require.NoError(t, err)
1934+
1935+
var parsed jobs.ProposeJobSpecInput
1936+
err = yaml.Unmarshal(payloadBytes, &parsed)
1937+
require.NoError(t, err)
1938+
1939+
parsed.Environment = environment
1940+
parsed.Domain = domain
1941+
1942+
assert.Equal(t, "staging", parsed.Environment)
1943+
assert.Equal(t, "cre", parsed.Domain)
1944+
assert.Equal(t, job_types.Gateway, parsed.Template)
1945+
1946+
var gatewayInput operations.ProposeGatewayJobInput
1947+
err = parsed.Inputs.UnmarshalTo(&gatewayInput)
1948+
require.NoError(t, err)
1949+
1950+
assert.True(t, gatewayInput.ServiceCentricFormatEnabled)
1951+
require.Len(t, gatewayInput.DONs, 1)
1952+
assert.Equal(t, "workflow-don", gatewayInput.DONs[0].Name)
1953+
assert.Equal(t, 1, gatewayInput.DONs[0].F)
1954+
require.Len(t, gatewayInput.Services, 1)
1955+
assert.Equal(t, "workflows", gatewayInput.Services[0].ServiceName)
1956+
assert.Equal(t, []string{"web-api-capabilities", "http-capabilities"}, gatewayInput.Services[0].Handlers)
1957+
assert.Equal(t, []string{"workflow-don"}, gatewayInput.Services[0].DONs)
1958+
assert.Equal(t, 10, gatewayInput.GatewayRequestTimeoutSec)
1959+
assert.Equal(t, []string{"https"}, gatewayInput.AllowedSchemes)
1960+
assert.Equal(t, []string{"10.0.0.0/8"}, gatewayInput.AllowedIPsCIDR)
1961+
1962+
// Build GatewayJob manually; in production member addresses are resolved via JD.
1963+
gj := pkg.GatewayJob{
1964+
ServiceCentricFormatEnabled: true,
1965+
JobName: "CRE Gateway",
1966+
DONs: []pkg.TargetDON{
1967+
{
1968+
ID: gatewayInput.DONs[0].Name,
1969+
F: gatewayInput.DONs[0].F,
1970+
Members: []pkg.TargetDONMember{
1971+
{Address: "0xdef456", Name: "mock-node-1 (DON workflow-don)"},
1972+
},
1973+
},
1974+
},
1975+
Services: []pkg.GatewayServiceConfig{
1976+
{
1977+
ServiceName: gatewayInput.Services[0].ServiceName,
1978+
Handlers: gatewayInput.Services[0].Handlers,
1979+
DONs: gatewayInput.Services[0].DONs,
1980+
},
1981+
},
1982+
RequestTimeoutSec: gatewayInput.GatewayRequestTimeoutSec,
1983+
AllowedSchemes: gatewayInput.AllowedSchemes,
1984+
AllowedIPsCIDR: gatewayInput.AllowedIPsCIDR,
1985+
}
1986+
1987+
require.NoError(t, gj.Validate())
1988+
assert.True(t, gj.ServiceCentricFormatEnabled)
1989+
assert.Equal(t, "CRE Gateway", gj.JobName)
1990+
assert.Equal(t, 10, gj.RequestTimeoutSec)
1991+
assert.Equal(t, []string{"https"}, gj.AllowedSchemes)
1992+
assert.Equal(t, []string{"10.0.0.0/8"}, gj.AllowedIPsCIDR)
1993+
require.Len(t, gj.DONs, 1)
1994+
assert.Equal(t, "workflow-don", gj.DONs[0].ID)
1995+
require.Len(t, gj.Services, 1)
1996+
assert.Equal(t, "workflows", gj.Services[0].ServiceName)
1997+
assert.Equal(t, []string{"web-api-capabilities", "http-capabilities"}, gj.Services[0].Handlers)
1998+
assert.Equal(t, []string{"workflow-don"}, gj.Services[0].DONs)
1999+
})
2000+
}

deployment/go.mod

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20260317175207-e9ff89561326
4747
github.com/smartcontractkit/chainlink-common v0.11.1
4848
github.com/smartcontractkit/chainlink-common/keystore v1.0.2
49-
github.com/smartcontractkit/chainlink-deployments-framework v0.86.3
49+
github.com/smartcontractkit/chainlink-deployments-framework v0.90.1
5050
github.com/smartcontractkit/chainlink-evm v0.3.4-0.20260320152158-2191d797b5ce
5151
github.com/smartcontractkit/chainlink-evm/contracts/cre/gobindings v0.0.0-20260107191744-4b93f62cffe3
5252
github.com/smartcontractkit/chainlink-evm/gethwrappers v0.0.0-20260119171452-39c98c3b33cd
@@ -126,21 +126,21 @@ require (
126126
github.com/avast/retry-go v3.0.0+incompatible // indirect
127127
github.com/avast/retry-go/v4 v4.7.0 // indirect
128128
github.com/awalterschulze/gographviz v2.0.3+incompatible // indirect
129-
github.com/aws/aws-sdk-go-v2 v1.41.3 // indirect
130-
github.com/aws/aws-sdk-go-v2/config v1.32.10 // indirect
131-
github.com/aws/aws-sdk-go-v2/credentials v1.19.10 // indirect
132-
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.18 // indirect
133-
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.19 // indirect
134-
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.19 // indirect
135-
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
136-
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.59.1 // indirect
137-
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.5 // indirect
138-
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.18 // indirect
129+
github.com/aws/aws-sdk-go-v2 v1.41.4 // indirect
130+
github.com/aws/aws-sdk-go-v2/config v1.32.12 // indirect
131+
github.com/aws/aws-sdk-go-v2/credentials v1.19.12 // indirect
132+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.20 // indirect
133+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.20 // indirect
134+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.20 // indirect
135+
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.6 // indirect
136+
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.59.2 // indirect
137+
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.7 // indirect
138+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.20 // indirect
139139
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.34.2 // indirect
140-
github.com/aws/aws-sdk-go-v2/service/signin v1.0.6 // indirect
141-
github.com/aws/aws-sdk-go-v2/service/sso v1.30.11 // indirect
142-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.15 // indirect
143-
github.com/aws/aws-sdk-go-v2/service/sts v1.41.7 // indirect
140+
github.com/aws/aws-sdk-go-v2/service/signin v1.0.8 // indirect
141+
github.com/aws/aws-sdk-go-v2/service/sso v1.30.13 // indirect
142+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.17 // indirect
143+
github.com/aws/aws-sdk-go-v2/service/sts v1.41.9 // indirect
144144
github.com/aws/constructs-go/constructs/v10 v10.4.2 // indirect
145145
github.com/aws/jsii-runtime-go v1.104.0 // indirect
146146
github.com/aws/smithy-go v1.24.2 // indirect
@@ -454,6 +454,7 @@ require (
454454
github.com/streamingfast/logging v0.0.0-20230608130331-f22c91403091 // indirect
455455
github.com/stretchr/objx v0.5.2 // indirect
456456
github.com/supranational/blst v0.3.16 // indirect
457+
github.com/suzuki-shunsuke/go-convmap v0.2.1 // indirect
457458
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
458459
github.com/tendermint/go-amino v0.16.0 // indirect
459460
github.com/theodesp/go-heaps v0.0.0-20190520121037-88e35354fe0a // indirect

0 commit comments

Comments
 (0)