Skip to content

Commit c035859

Browse files
authored
feat: add option to set NodeIDs for test environment (#512)
Adds a new option to the test environment loader: - `WithNodeIDs` option to set NodeIDs into the test environment This allows for more flexibility in the test environment setup where the user may have existing NodeIDs they want to provide into the environment for testing.
1 parent 8fd65fe commit c035859

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

.changeset/solid-apples-carry.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"chainlink-deployments-framework": minor
3+
---
4+
5+
Adds a new option to test engine environment loading for setting NodeIDs
6+
7+
`WithNodeIDs` - option to set NodeIDs into the test environment

engine/test/environment/components.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type components struct {
1919
AddressBook fdeployment.AddressBook
2020
Datastore fdatastore.DataStore
2121
OffchainClient foffchain.Client
22+
NodeIDs []string
2223
Logger logger.Logger
2324
}
2425

engine/test/environment/environment.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ func (l *Loader) Load(ctx context.Context, opts ...LoadOpt) (*fdeployment.Enviro
5656
ab = fdeployment.NewMemoryAddressBook()
5757
}
5858

59+
nodeIDs := cmps.NodeIDs
60+
if len(nodeIDs) == 0 {
61+
nodeIDs = []string{}
62+
}
63+
5964
// We do not set any default offchain client as it is not required for all tests.
6065
// We may want to set a default memory based offchain client in the future.
6166
oc := cmps.OffchainClient
@@ -66,8 +71,8 @@ func (l *Loader) Load(ctx context.Context, opts ...LoadOpt) (*fdeployment.Enviro
6671
BlockChains: fchain.NewBlockChainsFromSlice(cmps.Chains),
6772
ExistingAddresses: ab,
6873
DataStore: ds,
69-
Catalog: nil, // Unimplemented for now
70-
NodeIDs: []string{}, // Unimplemented for now
74+
Catalog: nil, // Unimplemented for now
75+
NodeIDs: nodeIDs,
7176
Offchain: oc,
7277
GetContext: getCtx,
7378
OCRSecrets: focr.XXXGenerateTestOCRSecrets(),

engine/test/environment/environment_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ func TestLoader_Load_OffchainClientOption(t *testing.T) {
135135
require.Equal(t, oc, env.Offchain)
136136
}
137137

138+
func TestLoader_Load_NodeIDsOption(t *testing.T) {
139+
t.Parallel()
140+
141+
nodeIDs := []string{"1", "2", "3"}
142+
143+
loader := NewLoader()
144+
env, err := loader.Load(t.Context(), WithNodeIDs(nodeIDs))
145+
require.NoError(t, err)
146+
require.NotNil(t, env)
147+
require.Equal(t, nodeIDs, env.NodeIDs)
148+
}
149+
138150
func TestLoader_Load_AddressBookOption(t *testing.T) {
139151
t.Parallel()
140152

engine/test/environment/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ func WithOffchainClient(oc offchain.Client) LoadOpt {
179179
}
180180
}
181181

182+
// WithNodeIDs sets a custom node IDs for the environment.
183+
func WithNodeIDs(nodeIDs []string) LoadOpt {
184+
return func(cmps *components) error {
185+
cmps.NodeIDs = nodeIDs
186+
return nil
187+
}
188+
}
189+
182190
// withChainLoader creates a LoadOpt that loads chains using the provided loader and selectors.
183191
func withChainLoader(t *testing.T, loader *onchain.ChainLoader, selectors []uint64) LoadOpt {
184192
t.Helper()

0 commit comments

Comments
 (0)