Skip to content

Commit 168cfa1

Browse files
committed
CR: remove KmdJSONOverride, add LibGoalFixture override
1 parent a27b0ef commit 168cfa1

File tree

8 files changed

+35
-55
lines changed

8 files changed

+35
-55
lines changed

netdeploy/network.go

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ func OverrideConsensusVersion(ver protocol.ConsensusVersion) TemplateOverride {
7878
}
7979
}
8080

81+
// OverrideKmdConfig changes the KMD config.
82+
func OverrideKmdConfig(kmdConfig TemplateKMDConfig) TemplateOverride {
83+
return func(template *NetworkTemplate) {
84+
template.kmdConfig = kmdConfig
85+
}
86+
}
87+
8188
// CreateNetworkFromTemplate uses the specified template to deploy a new private network
8289
// under the specified root directory.
8390
func CreateNetworkFromTemplate(name, rootDir string, templateReader io.Reader, binDir string, importKeys bool, nodeExitCallback nodecontrol.AlgodExitErrorCallback, consensus config.ConsensusProtocols, overrides ...TemplateOverride) (Network, error) {

netdeploy/networkTemplate.go

+13-17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ type NetworkTemplate struct {
4343
Genesis gen.GenesisData
4444
Nodes []remote.NodeConfigGoal
4545
Consensus config.ConsensusProtocols
46+
kmdConfig TemplateKMDConfig
47+
}
48+
49+
// TemplateKMDConfig is a subset of the kmd configuration that can be overridden in the network template
50+
// by using OverrideKmdConfig TemplateOverride opts.
51+
// The reason why config.KMDConfig cannot be used directly is that it contains DataDir field which is
52+
// is not known until the template instantiation.
53+
type TemplateKMDConfig struct {
54+
SessionLifetimeSecs uint64
4655
}
4756

4857
var defaultNetworkTemplate = NetworkTemplate{
@@ -133,13 +142,13 @@ func (t NetworkTemplate) createNodeDirectories(targetFolder string, binDir strin
133142
}
134143

135144
var kmdDir string
136-
if len(cfg.KmdJSONOverride) > 0 {
145+
if (t.kmdConfig != TemplateKMDConfig{}) {
137146
kmdDir = filepath.Join(nodeDir, libgoal.DefaultKMDDataDir)
138147
err = os.MkdirAll(kmdDir, 0700) // kmd requires 700 permissions
139148
if err != nil {
140149
return
141150
}
142-
err = createKMDConfigFile(cfg, kmdDir)
151+
err = createKMDConfigFile(t.kmdConfig, kmdDir)
143152
if err != nil {
144153
return
145154
}
@@ -268,15 +277,6 @@ func (t NetworkTemplate) Validate() error {
268277
}
269278
}
270279

271-
// Validate KmdJSONOverride decoding
272-
for _, cfg := range t.Nodes {
273-
kmdconf := kmdconfig.KMDConfig{}
274-
err := decodeJSONOverride(cfg.KmdJSONOverride, &kmdconf)
275-
if err != nil {
276-
return fmt.Errorf("invalid template: unable to decode KmdJSONOverride: %w", err)
277-
}
278-
}
279-
280280
// Follow nodes cannot be relays
281281
// Relays cannot have peer list
282282
for _, cfg := range t.Nodes {
@@ -368,12 +368,8 @@ func createConfigFile(node remote.NodeConfigGoal, configFile string, numNodes in
368368
return cfg, cfg.SaveToFile(configFile)
369369
}
370370

371-
func createKMDConfigFile(node remote.NodeConfigGoal, kmdDir string) error {
371+
func createKMDConfigFile(kmdConfig TemplateKMDConfig, kmdDir string) error {
372372
cfg := kmdconfig.DefaultConfig(kmdDir)
373-
err := decodeJSONOverride(node.KmdJSONOverride, &cfg)
374-
if err != nil {
375-
return err
376-
}
377-
373+
cfg.SessionLifetimeSecs = kmdConfig.SessionLifetimeSecs
378374
return kmdconfig.SaveKMDConfig(kmdDir, cfg)
379375
}

netdeploy/networkTemplates_test.go

-28
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,6 @@ func TestDevModeValidate(t *testing.T) {
238238
require.ErrorContains(t, tmpl.Validate(), "unable to decode ConfigJSONOverride")
239239
})
240240

241-
t.Run("KmdJSONOverride does not parse", func(t *testing.T) {
242-
t.Parallel()
243-
tmpl := NetworkTemplate{
244-
Genesis: devmodeGenesis,
245-
Nodes: []remote.NodeConfigGoal{
246-
{
247-
IsRelay: false,
248-
KmdJSONOverride: "DOES NOT PARSE",
249-
},
250-
},
251-
}
252-
require.ErrorContains(t, tmpl.Validate(), "unable to decode KmdJSONOverride")
253-
})
254-
255241
t.Run("ConfigJSONOverride unknown key", func(t *testing.T) {
256242
t.Parallel()
257243
tmpl := NetworkTemplate{
@@ -266,20 +252,6 @@ func TestDevModeValidate(t *testing.T) {
266252
require.ErrorContains(t, tmpl.Validate(), "json: unknown field \"Unknown Key\"")
267253
})
268254

269-
t.Run("KmdJSONOverride unknown key", func(t *testing.T) {
270-
t.Parallel()
271-
tmpl := NetworkTemplate{
272-
Genesis: devmodeGenesis,
273-
Nodes: []remote.NodeConfigGoal{
274-
{
275-
IsRelay: false,
276-
KmdJSONOverride: "{\"Unknown Key\": \"Valid JSON\"}",
277-
},
278-
},
279-
}
280-
require.ErrorContains(t, tmpl.Validate(), "json: unknown field \"Unknown Key\"")
281-
})
282-
283255
t.Run("Valid multi-node DevMode", func(t *testing.T) {
284256
t.Parallel()
285257
tmpl := NetworkTemplate{

netdeploy/remote/nodeConfig.go

-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,5 @@ type NodeConfigGoal struct {
6363
P2PPeerID string `json:",omitempty"`
6464
DeadlockDetection int `json:"-"`
6565
ConfigJSONOverride string `json:",omitempty"` // Raw json to merge into config.json after other modifications are complete
66-
KmdJSONOverride string `json:",omitempty"` // Raw json to merge into default kmd-config.json
6766
PeerList string `json:",omitempty"` // Semicolon separated list of peers to connect to. Only applicable for non-relays
6867
}

test/e2e-go/features/transactions/asset_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ func TestAssetGroupCreateSendDestroy(t *testing.T) {
682682
txSend, err = client1.MakeUnsignedAssetSendTx(assetID3, 0, account1, "", "")
683683
_, err = helperFillSignBroadcast(client1, wh1, account1, txSend, err)
684684
a.Error(err)
685+
686+
a.FailNow("test")
685687
}
686688

687689
func TestAssetSend(t *testing.T) {

test/framework/fixtures/libgoalFixture.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ func (f *LibGoalFixture) setup(test TestingTB, testName string, templateFile str
127127
importKeys := false // Don't automatically import root keys when creating folders, we'll import on-demand
128128
file, err := os.Open(templateFile)
129129
f.failOnError(err, "Template file could not be opened: %v")
130-
network, err := netdeploy.CreateNetworkFromTemplate("test", f.rootDir, file, f.binDir, importKeys, f.nodeExitWithError, f.consensus, overrides...)
130+
defer file.Close()
131+
132+
// Override the kmd session lifetime to 5 minutes to prevent kmd wallet handles from expiring
133+
kmdConfOverride := netdeploy.OverrideKmdConfig(netdeploy.TemplateKMDConfig{SessionLifetimeSecs: 300})
134+
// copy overrides to prevent caller's data from being modified
135+
extraOverrides := append([]netdeploy.TemplateOverride(nil), overrides...)
136+
extraOverrides = append(extraOverrides, kmdConfOverride)
137+
138+
network, err := netdeploy.CreateNetworkFromTemplate("test", f.rootDir, file, f.binDir, importKeys, f.nodeExitWithError, f.consensus, extraOverrides...)
131139
f.failOnError(err, "CreateNetworkFromTemplate failed: %v")
132140
f.network = network
133141

test/testdata/nettemplates/TwoNodes50Each.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@
2222
"Wallets": [
2323
{ "Name": "Wallet1",
2424
"ParticipationOnly": false }
25-
],
26-
"KmdJSONOverride": "{\"session_lifetime_secs\": 300}"
25+
]
2726
},
2827
{
2928
"Name": "Node",
3029
"Wallets": [
3130
{ "Name": "Wallet2",
3231
"ParticipationOnly": false }
33-
],
34-
"KmdJSONOverride": "{\"session_lifetime_secs\": 300}"
32+
]
3533
}
3634
]
3735
}

test/testdata/nettemplates/TwoNodes50EachFuture.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@
2323
"Wallets": [
2424
{ "Name": "Wallet1",
2525
"ParticipationOnly": false }
26-
],
27-
"KmdJSONOverride": "{\"session_lifetime_secs\": 300}"
26+
]
2827
},
2928
{
3029
"Name": "Node",
3130
"Wallets": [
3231
{ "Name": "Wallet2",
3332
"ParticipationOnly": false }
34-
],
35-
"KmdJSONOverride": "{\"session_lifetime_secs\": 300}"
33+
]
3634
}
3735
]
3836
}

0 commit comments

Comments
 (0)