Skip to content

Commit a4064d8

Browse files
committed
Adding more functional and unit test cases
1 parent 3d14596 commit a4064d8

File tree

9 files changed

+779
-94
lines changed

9 files changed

+779
-94
lines changed

integration_tests/cli/model-validation-cases.sh

+448
Large diffs are not rendered by default.

x/model/client/cli/flags.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929
FlagCommissioningModeInitialStepsHint = "commissioningModeInitialStepsHint"
3030
FlagCommissioningModeInitialStepsInstruction = "commissioningModeInitialStepsInstruction"
3131
FlagCommissioningModeSecondaryStepsHint = "commissioningModeSecondaryStepsHint"
32-
FlagCommissioningModeSecondaryStepsInstruction = "commissioningModeSecondaryStepInstruction"
32+
FlagCommissioningModeSecondaryStepsInstruction = "commissioningModeSecondaryStepsInstruction"
3333
FlagUserManualURL = "userManualURL"
3434
FlagSupportURL = "supportURL"
3535
FlagProductURL = "productURL"
@@ -42,7 +42,7 @@ const (
4242
FlagFirmwareDigests = "firmwareDigests"
4343
FlagSoftwareVersionValid = "softwareVersionValid"
4444
FlagOtaURL = "otaURL"
45-
FlagOtaFileSize = "OtaFileSize"
45+
FlagOtaFileSize = "otaFileSize"
4646
FlagOtaChecksum = "otaChecksum"
4747
FlagOtaChecksumType = "otaChecksumType"
4848
FlagMinApplicableSoftwareVersion = "minApplicableSoftwareVersion"

x/model/client/cli/tx.go

+48-34
Original file line numberDiff line numberDiff line change
@@ -159,34 +159,34 @@ func GetCmdAddModel(cdc *codec.Codec) *cobra.Command {
159159
"Model Part Number (or sku)")
160160
cmd.Flags().String(FlagCommissioningCustomFlow, "",
161161
`A value of 1 indicates that user interaction with the device (pressing a button, for example) is
162-
required before commissioning can take place. When CommissioningCustomflow is set to a value of 2,
163-
the commissioner SHOULD attempt to obtain a URL which MAY be used to provide an end-user with
164-
the necessary details for how to configure the product for initial commissioning.`)
162+
required before commissioning can take place. When CommissioningCustomflow is set to a value of 2,
163+
the commissioner SHOULD attempt to obtain a URL which MAY be used to provide an end-user with
164+
the necessary details for how to configure the product for initial commissioning.`)
165165
cmd.Flags().String(FlagCommissioningCustomFlowURL, "",
166166
`commissioningCustomFlowURL SHALL identify a vendor specific commissioning URL for the
167-
device model when the commissioningCustomFlow field is set to '2'`)
167+
device model when the commissioningCustomFlow field is set to '2'`)
168168
cmd.Flags().String(FlagCommissioningModeInitialStepsHint, "",
169169
`commissioningModeInitialStepsHint SHALL
170-
identify a hint for the steps that can be used to put into commissioning mode a device that
171-
has not yet been commissioned. This field is a bitmap with values defined in the Pairing Hint Table.
172-
For example, a value of 1 (bit 0 is set) indicates
173-
that a device that has not yet been commissioned will enter Commissioning Mode upon a power cycle.`)
170+
identify a hint for the steps that can be used to put into commissioning mode a device that
171+
has not yet been commissioned. This field is a bitmap with values defined in the Pairing Hint Table.
172+
For example, a value of 1 (bit 0 is set) indicates
173+
that a device that has not yet been commissioned will enter Commissioning Mode upon a power cycle.`)
174174
cmd.Flags().String(FlagCommissioningModeInitialStepsInstruction, "",
175175
`commissioningModeInitialStepsInstruction SHALL contain text which relates to specific
176-
values of commissioningModeSecondaryStepsHint. Certain values of CommissioningModeInitialStepsHint,
177-
as defined in the Pairing Hint Table, indicate a Pairing Instruction (PI) dependency, and for these
178-
values the commissioningModeInitialStepsInstruction SHALL be set`)
176+
values of commissioningModeSecondaryStepsHint. Certain values of CommissioningModeInitialStepsHint,
177+
as defined in the Pairing Hint Table, indicate a Pairing Instruction (PI) dependency, and for these
178+
values the commissioningModeInitialStepsInstruction SHALL be set`)
179179
cmd.Flags().String(FlagCommissioningModeSecondaryStepsHint, "",
180180
`commissioningModeSecondaryStepsHint SHALL identify a hint for steps that can
181-
be used to put into commissioning mode a device that has already been commissioned.
182-
This field is a bitmap with values defined in the Pairing Hint Table. For example, a value of 4 (bit 2 is set)
183-
indicates that a device that has already been commissioned will require the user to visit a
184-
current CHIP Administrator to put the device into commissioning mode.`)
181+
be used to put into commissioning mode a device that has already been commissioned.
182+
This field is a bitmap with values defined in the Pairing Hint Table. For example, a value of 4 (bit 2 is set)
183+
indicates that a device that has already been commissioned will require the user to visit a
184+
current CHIP Administrator to put the device into commissioning mode.`)
185185
cmd.Flags().String(FlagCommissioningModeSecondaryStepsInstruction, "",
186186
`commissioningModeSecondaryStepInstruction SHALL contain text which relates to specific values
187-
of commissioningModeSecondaryStepsHint. Certain values of commissioningModeSecondaryStepsHint,
188-
as defined in the Pairing Hint Table, indicate a Pairing Instruction (PI) dependency,
189-
and for these values the commissioningModeSecondaryStepInstruction SHALL be set`)
187+
of commissioningModeSecondaryStepsHint. Certain values of commissioningModeSecondaryStepsHint,
188+
as defined in the Pairing Hint Table, indicate a Pairing Instruction (PI) dependency,
189+
and for these values the commissioningModeSecondaryStepInstruction SHALL be set`)
190190
cmd.Flags().String(FlagUserManualURL, "",
191191
"URL that contains product specific web page that contains user manual for the device model.")
192192
cmd.Flags().String(FlagSupportURL, "",
@@ -233,21 +233,25 @@ func GetCmdUpdateModel(cdc *codec.Codec) *cobra.Command {
233233
partNumber := viper.GetString(FlagPartNumber)
234234

235235
commissioningCustomFlowURL := viper.GetString(FlagCommissioningCustomFlowURL)
236+
commissioningModeInitialStepsInstruction := viper.GetString(FlagCommissioningModeInitialStepsInstruction)
237+
commissioningModeSecondaryStepsInstruction := viper.GetString(FlagCommissioningModeSecondaryStepsInstruction)
236238

237239
userManualURL := viper.GetString(FlagUserManualURL)
238240
supportURL := viper.GetString(FlagSupportURL)
239241
productURL := viper.GetString(FlagProductURL)
240242

241243
model := types.Model{
242-
VID: vid,
243-
PID: pid,
244-
ProductName: productName,
245-
ProductLabel: productLabel,
246-
PartNumber: partNumber,
247-
CommissioningCustomFlowURL: commissioningCustomFlowURL,
248-
UserManualURL: userManualURL,
249-
SupportURL: supportURL,
250-
ProductURL: productURL,
244+
VID: vid,
245+
PID: pid,
246+
ProductName: productName,
247+
ProductLabel: productLabel,
248+
PartNumber: partNumber,
249+
CommissioningCustomFlowURL: commissioningCustomFlowURL,
250+
CommissioningModeInitialStepsInstruction: commissioningModeInitialStepsInstruction,
251+
CommissioningModeSecondaryStepsInstruction: commissioningModeSecondaryStepsInstruction,
252+
UserManualURL: userManualURL,
253+
SupportURL: supportURL,
254+
ProductURL: productURL,
251255
}
252256
msg := types.NewMsgUpdateModel(model, cliCtx.FromAddress())
253257

@@ -266,7 +270,17 @@ func GetCmdUpdateModel(cdc *codec.Codec) *cobra.Command {
266270
"Model Part Number (or sku)")
267271
cmd.Flags().String(FlagCommissioningCustomFlowURL, "",
268272
`commissioningCustomFlowURL SHALL identify a vendor specific commissioning URL for the
269-
device model when the commissioningCustomFlow field is set to '2'`)
273+
device model when the commissioningCustomFlow field is set to '2'`)
274+
cmd.Flags().String(FlagCommissioningModeInitialStepsInstruction, "",
275+
`commissioningModeInitialStepsInstruction SHALL contain text which relates to specific
276+
values of commissioningModeSecondaryStepsHint. Certain values of CommissioningModeInitialStepsHint,
277+
as defined in the Pairing Hint Table, indicate a Pairing Instruction (PI) dependency, and for these
278+
values the commissioningModeInitialStepsInstruction SHALL be set`)
279+
cmd.Flags().String(FlagCommissioningModeSecondaryStepsInstruction, "",
280+
`commissioningModeSecondaryStepInstruction SHALL contain text which relates to specific values
281+
of commissioningModeSecondaryStepsHint. Certain values of commissioningModeSecondaryStepsHint,
282+
as defined in the Pairing Hint Table, indicate a Pairing Instruction (PI) dependency,
283+
and for these values the commissioningModeSecondaryStepInstruction SHALL be set`)
270284
cmd.Flags().String(FlagUserManualURL, "",
271285
"URL that contains product specific web page that contains user manual for the device model.")
272286
cmd.Flags().String(FlagSupportURL, "",
@@ -462,18 +476,18 @@ func GetCmdAddModelVersion(cdc *codec.Codec) *cobra.Command {
462476
encoded in base64 string representation. The digest SHALL have been computed using
463477
the algorithm specified in OtaChecksumType`)
464478
cmd.Flags().String(FlagOtaChecksumType, "", `Numberic identifier as defined in
465-
IANA Named Information Hash Algorithm Registry for the type of otaChecksum.
466-
For example, a value of 1 would match the sha-256 identifier,
467-
which maps to the SHA-256 digest algorithm`)
479+
IANA Named Information Hash Algorithm Registry for the type of otaChecksum.
480+
For example, a value of 1 would match the sha-256 identifier,
481+
which maps to the SHA-256 digest algorithm`)
468482
cmd.Flags().String(FlagMinApplicableSoftwareVersion, "",
469483
`MinApplicableSoftwareVersion should specify the lowest
470-
SoftwareVersion for which this image can be applied`)
484+
SoftwareVersion for which this image can be applied`)
471485
cmd.Flags().String(FlagMaxApplicableSoftwareVersion, "",
472486
`MaxApplicableSoftwareVersion should specify the highest
473-
SoftwareVersion for which this image can be applied`)
487+
SoftwareVersion for which this image can be applied`)
474488
cmd.Flags().String(FlagReleaseNotesURL, "",
475489
`URL that contains product specific web page that contains
476-
release notes for the device model.`)
490+
release notes for the device model.`)
477491

478492
_ = cmd.MarkFlagRequired(FlagVID)
479493
_ = cmd.MarkFlagRequired(FlagPID)

x/model/handler.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,30 @@ func handleMsgUpdateModel(ctx sdk.Context, keeper keeper.Keeper, authKeeper auth
101101

102102
// updates existing model value only if corresponding value in MsgUpdate is not empty
103103

104-
if msg.DeviceTypeID != 0 {
105-
model.DeviceTypeID = msg.DeviceTypeID
104+
if msg.ProductName != "" {
105+
model.ProductName = msg.ProductName
106106
}
107107

108108
if msg.ProductLabel != "" {
109109
model.ProductLabel = msg.ProductLabel
110110
}
111111

112+
if msg.PartNumber != "" {
113+
model.PartNumber = msg.PartNumber
114+
}
115+
112116
if msg.CommissioningCustomFlowURL != "" {
113117
model.CommissioningCustomFlowURL = msg.CommissioningCustomFlowURL
114118
}
115119

120+
if msg.CommissioningModeInitialStepsInstruction != "" {
121+
model.CommissioningModeInitialStepsInstruction = msg.CommissioningModeInitialStepsInstruction
122+
}
123+
124+
if msg.CommissioningModeSecondaryStepsInstruction != "" {
125+
model.CommissioningModeSecondaryStepsInstruction = msg.CommissioningModeSecondaryStepsInstruction
126+
}
127+
116128
if msg.UserManualURL != "" {
117129
model.UserManualURL = msg.UserManualURL
118130
}
@@ -225,6 +237,8 @@ func handleMsgUpdateModelVersion(ctx sdk.Context, keeper keeper.Keeper, authKeep
225237
return err.Result()
226238
}
227239

240+
// Only OtaURL is modifiable field per specs. This can only be modified if this was set initially
241+
// as otaFileSize, otaChecksum and otaChecksumType are non mutable fields
228242
if msg.OtaURL != "" && modelVersion.OtaURL == "" {
229243
return types.ErrOtaURLCannotBeSet(msg.VID, msg.PID, msg.SoftwareVersion).Result()
230244
}
@@ -245,7 +259,7 @@ func handleMsgUpdateModelVersion(ctx sdk.Context, keeper keeper.Keeper, authKeep
245259
}
246260

247261
if msg.MaxApplicableSoftwareVersion != 0 {
248-
modelVersion.MinApplicableSoftwareVersion = msg.MaxApplicableSoftwareVersion
262+
modelVersion.MaxApplicableSoftwareVersion = msg.MaxApplicableSoftwareVersion
249263
}
250264

251265
if msg.ReleaseNotesURL != "" {

0 commit comments

Comments
 (0)