Skip to content

Commit 7e7f701

Browse files
committed
updated tests and errors
Signed-off-by: DenisRybas <denis.rybas@dsr-corporation.com>
1 parent 61f3a2f commit 7e7f701

File tree

2 files changed

+119
-22
lines changed

2 files changed

+119
-22
lines changed

x/model/handler_test.go

+101-5
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ func TestHandler_UpdateModelByVendorWithProductIds(t *testing.T) {
263263
// add new model
264264
msgCreateModel := NewMsgCreateModel(owner)
265265
msgCreateModel.Pid = 200
266+
enhancedSetupFlowTCRevision := msgCreateModel.EnhancedSetupFlowTCRevision
266267
_, err := setup.Handler(setup.Ctx, msgCreateModel)
267268
require.NoError(t, err)
268269

@@ -276,16 +277,20 @@ func TestHandler_UpdateModelByVendorWithProductIds(t *testing.T) {
276277
require.True(t, sdkerrors.ErrUnauthorized.Is(err))
277278

278279
// update existing model by owner
280+
enhancedSetupFlowTCRevision++
279281
msgUpdateModel = NewMsgUpdateModel(owner)
280282
msgUpdateModel.Pid = 200
283+
msgUpdateModel.EnhancedSetupFlowTCRevision = enhancedSetupFlowTCRevision
281284
_, err = setup.Handler(setup.Ctx, msgUpdateModel)
282285
require.NoError(t, err)
283286

284287
vendorWithoutProductIDs := testdata.GenerateAccAddress()
285288
setup.AddAccount(vendorWithoutProductIDs, []dclauthtypes.AccountRole{dclauthtypes.Vendor}, setup.VendorID, testconstants.ProductIDsEmpty)
286289

287290
// update existing model by vendor with the same VendorID as owner's one
291+
enhancedSetupFlowTCRevision++
288292
msgUpdateModel = NewMsgUpdateModel(vendorWithoutProductIDs)
293+
msgUpdateModel.EnhancedSetupFlowTCRevision = enhancedSetupFlowTCRevision
289294
msgUpdateModel.Pid = 200
290295
msgUpdateModel.ProductLabel += "-updated-once-more"
291296
msgUpdateModel.LsfRevision++
@@ -300,6 +305,7 @@ func TestHandler_OnlyOwnerAndVendorWithSameVidCanUpdateModel(t *testing.T) {
300305
msgCreateModel := NewMsgCreateModel(setup.Vendor)
301306
_, err := setup.Handler(setup.Ctx, msgCreateModel)
302307
require.NoError(t, err)
308+
enhancedSetupFlowTCRevision := msgCreateModel.EnhancedSetupFlowTCRevision
303309

304310
for _, role := range []dclauthtypes.AccountRole{
305311
dclauthtypes.CertificationCenter,
@@ -326,15 +332,19 @@ func TestHandler_OnlyOwnerAndVendorWithSameVidCanUpdateModel(t *testing.T) {
326332
require.True(t, sdkerrors.ErrUnauthorized.Is(err))
327333

328334
// update existing model by owner
335+
enhancedSetupFlowTCRevision++
329336
msgUpdateModel = NewMsgUpdateModel(setup.Vendor)
337+
msgUpdateModel.EnhancedSetupFlowTCRevision = enhancedSetupFlowTCRevision
330338
_, err = setup.Handler(setup.Ctx, msgUpdateModel)
331339
require.NoError(t, err)
332340

333341
vendorWithSameVid := testdata.GenerateAccAddress()
334342
setup.AddAccount(vendorWithSameVid, []dclauthtypes.AccountRole{dclauthtypes.Vendor}, setup.VendorID, setup.ProductIDs)
335343

336344
// update existing model by vendor with the same VendorID as owner's one
345+
enhancedSetupFlowTCRevision++
337346
msgUpdateModel = NewMsgUpdateModel(vendorWithSameVid)
347+
msgUpdateModel.EnhancedSetupFlowTCRevision = enhancedSetupFlowTCRevision
338348
msgUpdateModel.ProductLabel += "-updated-once-more"
339349
msgUpdateModel.LsfRevision++
340350
_, err = setup.Handler(setup.Ctx, msgUpdateModel)
@@ -349,6 +359,7 @@ func TestHandler_LsfUpdateValidations(t *testing.T) {
349359
msgCreateModel.LsfUrl = ""
350360
_, err := setup.Handler(setup.Ctx, msgCreateModel)
351361
require.NoError(t, err)
362+
enhancedSetupFlowTCRevision := msgCreateModel.EnhancedSetupFlowTCRevision
352363

353364
// query model
354365
receivedModel, err := queryModel(setup, msgCreateModel.Vid, msgCreateModel.Pid)
@@ -380,7 +391,9 @@ func TestHandler_LsfUpdateValidations(t *testing.T) {
380391
require.True(t, types.ErrLsfRevisionIsNotValid.Is(err))
381392

382393
// Update model with valid LsfUrl and LsfRevision set to 1
394+
enhancedSetupFlowTCRevision++
383395
msgUpdateModel = NewMsgUpdateModel(setup.Vendor)
396+
msgUpdateModel.EnhancedSetupFlowTCRevision = enhancedSetupFlowTCRevision
384397
msgUpdateModel.LsfUrl = "https://example.com/lsf.json"
385398
msgUpdateModel.LsfRevision = testconstants.LsfRevision
386399
_, err = setup.Handler(setup.Ctx, msgUpdateModel)
@@ -394,7 +407,9 @@ func TestHandler_LsfUpdateValidations(t *testing.T) {
394407
require.Equal(t, msgUpdateModel.LsfRevision, receivedModel.LsfRevision)
395408

396409
// Increase LsfRevision by 1
410+
enhancedSetupFlowTCRevision++
397411
msgUpdateModel = NewMsgUpdateModel(setup.Vendor)
412+
msgUpdateModel.EnhancedSetupFlowTCRevision = enhancedSetupFlowTCRevision
398413
msgUpdateModel.LsfUrl = ""
399414
msgUpdateModel.LsfRevision = testconstants.LsfRevision + 1
400415
_, err = setup.Handler(setup.Ctx, msgUpdateModel)
@@ -408,7 +423,9 @@ func TestHandler_LsfUpdateValidations(t *testing.T) {
408423
require.Equal(t, msgUpdateModel.LsfRevision, receivedModel.LsfRevision)
409424

410425
// Increase LsfRevision by more then 1
426+
enhancedSetupFlowTCRevision++
411427
msgUpdateModel = NewMsgUpdateModel(setup.Vendor)
428+
msgUpdateModel.EnhancedSetupFlowTCRevision = enhancedSetupFlowTCRevision
412429
msgUpdateModel.LsfUrl = ""
413430
msgUpdateModel.LsfRevision = testconstants.LsfRevision + 3
414431
_, err = setup.Handler(setup.Ctx, msgUpdateModel)
@@ -543,6 +560,79 @@ func TestHandler_PartiallyUpdateModel(t *testing.T) {
543560
require.Equal(t, msgUpdateModel.ProductLabel, receivedModel.ProductLabel)
544561
}
545562

563+
func TestHandler_UpdateModelEnhancedSetupFlowTCRevisionUnsetIncrement(t *testing.T) {
564+
setup := Setup(t)
565+
566+
// add new model
567+
msgAddModel := NewMsgCreateModel(setup.Vendor)
568+
_, err := setup.Handler(setup.Ctx, msgAddModel)
569+
require.NoError(t, err)
570+
571+
// update EnhancedSetupFlowTCRevision of existing model
572+
msgUpdateModel := NewMsgUpdateModel(setup.Vendor)
573+
574+
_, err = setup.Handler(setup.Ctx, msgUpdateModel)
575+
require.NoError(t, err)
576+
577+
// query model
578+
receivedModel, err := queryModel(setup, msgUpdateModel.Vid, msgUpdateModel.Pid)
579+
require.NoError(t, err)
580+
581+
// check
582+
require.Equal(t, msgUpdateModel.EnhancedSetupFlowTCRevision, receivedModel.EnhancedSetupFlowTCRevision)
583+
}
584+
585+
func TestHandler_UpdateModelEnhancedSetupFlowTCRevisionIncrement(t *testing.T) {
586+
setup := Setup(t)
587+
588+
// add new model
589+
msgAddModel := NewMsgCreateModel(setup.Vendor)
590+
msgAddModel.EnhancedSetupFlowOptions = testconstants.EnhancedSetupFlowOptions
591+
msgAddModel.EnhancedSetupFlowTCUrl = testconstants.EnhancedSetupFlowTCURL
592+
msgAddModel.EnhancedSetupFlowTCRevision = int32(testconstants.EnhancedSetupFlowTCRevision)
593+
msgAddModel.EnhancedSetupFlowTCDigest = testconstants.EnhancedSetupFlowTCDigest
594+
msgAddModel.EnhancedSetupFlowTCFileSize = uint32(testconstants.EnhancedSetupFlowTCFileSize)
595+
msgAddModel.MaintenanceUrl = testconstants.MaintenanceURL
596+
_, err := setup.Handler(setup.Ctx, msgAddModel)
597+
require.NoError(t, err)
598+
599+
// update EnhancedSetupFlowTCRevision of existing model
600+
msgUpdateModel := NewMsgUpdateModel(setup.Vendor)
601+
602+
_, err = setup.Handler(setup.Ctx, msgUpdateModel)
603+
require.NoError(t, err)
604+
605+
// query model
606+
receivedModel, err := queryModel(setup, msgUpdateModel.Vid, msgUpdateModel.Pid)
607+
require.NoError(t, err)
608+
609+
// check
610+
require.Equal(t, msgAddModel.EnhancedSetupFlowTCRevision+1, msgUpdateModel.EnhancedSetupFlowTCRevision)
611+
require.Equal(t, msgUpdateModel.EnhancedSetupFlowTCRevision, receivedModel.EnhancedSetupFlowTCRevision)
612+
}
613+
614+
func TestHandler_UpdateModelEnhancedSetupFlowTCRevisionIncorrectIncrement(t *testing.T) {
615+
setup := Setup(t)
616+
617+
// add new model
618+
msgAddModel := NewMsgCreateModel(setup.Vendor)
619+
msgAddModel.EnhancedSetupFlowOptions = testconstants.EnhancedSetupFlowOptions
620+
msgAddModel.EnhancedSetupFlowTCUrl = testconstants.EnhancedSetupFlowTCURL
621+
msgAddModel.EnhancedSetupFlowTCRevision = int32(testconstants.EnhancedSetupFlowTCRevision)
622+
msgAddModel.EnhancedSetupFlowTCDigest = testconstants.EnhancedSetupFlowTCDigest
623+
msgAddModel.EnhancedSetupFlowTCFileSize = uint32(testconstants.EnhancedSetupFlowTCFileSize)
624+
msgAddModel.MaintenanceUrl = testconstants.MaintenanceURL
625+
_, err := setup.Handler(setup.Ctx, msgAddModel)
626+
require.NoError(t, err)
627+
628+
// update EnhancedSetupFlowTCRevision of existing model
629+
msgUpdateModel := NewMsgUpdateModel(setup.Vendor)
630+
msgUpdateModel.EnhancedSetupFlowTCRevision = msgAddModel.EnhancedSetupFlowTCRevision + 2
631+
_, err = setup.Handler(setup.Ctx, msgUpdateModel)
632+
require.Error(t, err)
633+
require.ErrorIs(t, err, types.ErrEnhancedSetupFlowTCRevisionInvalid)
634+
}
635+
546636
func TestHandler_DeleteModel(t *testing.T) {
547637
setup := Setup(t)
548638

@@ -1635,11 +1725,17 @@ func NewMsgUpdateModel(signer sdk.AccAddress) *types.MsgUpdateModel {
16351725
CommissioningCustomFlowUrl: testconstants.CommissioningCustomFlowURL + "/updated",
16361726
CommissioningModeInitialStepsInstruction: testconstants.CommissioningModeInitialStepsInstruction + "-updated",
16371727
CommissioningModeSecondaryStepsInstruction: testconstants.CommissioningModeSecondaryStepsInstruction + "-updated",
1638-
UserManualUrl: testconstants.UserManualURL + "/updated",
1639-
SupportUrl: testconstants.SupportURL + "/updated",
1640-
ProductUrl: testconstants.ProductURL + "/updated",
1641-
LsfUrl: testconstants.LsfURL + "/updated",
1642-
LsfRevision: testconstants.LsfRevision + 1,
1728+
UserManualUrl: testconstants.UserManualURL + "/updated",
1729+
SupportUrl: testconstants.SupportURL + "/updated",
1730+
ProductUrl: testconstants.ProductURL + "/updated",
1731+
LsfUrl: testconstants.LsfURL + "/updated",
1732+
LsfRevision: testconstants.LsfRevision + 1,
1733+
EnhancedSetupFlowOptions: testconstants.EnhancedSetupFlowOptions + 2,
1734+
EnhancedSetupFlowTCUrl: testconstants.EnhancedSetupFlowTCURL + "/updated",
1735+
EnhancedSetupFlowTCRevision: int32(testconstants.EnhancedSetupFlowTCRevision + 1),
1736+
EnhancedSetupFlowTCDigest: testconstants.EnhancedSetupFlowTCDigest,
1737+
EnhancedSetupFlowTCFileSize: uint32(testconstants.EnhancedSetupFlowTCFileSize + 1),
1738+
MaintenanceUrl: testconstants.MaintenanceURL + "/updated",
16431739
}
16441740
}
16451741

x/model/types/errors.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@ var (
1111
ErrVendorProductsDoNotExist = errors.Register(ModuleName, 504, "vendor products do not exist")
1212

1313
// Model Version Error Codes.
14-
ErrSoftwareVersionStringInvalid = errors.Register(ModuleName, 511, "software version string invalid")
15-
ErrFirmwareInformationInvalid = errors.Register(ModuleName, 512, "firmware digests invalid")
16-
ErrCDVersionNumberInvalid = errors.Register(ModuleName, 513, "CD version number invalid")
17-
ErrOtaURLInvalid = errors.Register(ModuleName, 514, "OTA URL invalid")
18-
ErrOtaMissingInformation = errors.Register(ModuleName, 515, "OTA missing information")
19-
ErrReleaseNotesURLInvalid = errors.Register(ModuleName, 516, "release notes URL invalid")
20-
ErrModelVersionDoesNotExist = errors.Register(ModuleName, 517, "model version does not exist")
21-
ErrNoModelVersionsExist = errors.Register(ModuleName, 518, "no model versions exist")
22-
ErrModelVersionAlreadyExists = errors.Register(ModuleName, 519, "model version already exists")
23-
ErrOtaURLCannotBeSet = errors.Register(ModuleName, 520, "OTA URL cannot be set")
24-
ErrMaxSVLessThanMinSV = errors.Register(ModuleName, 521, "max software version less than min software version")
25-
ErrLsfRevisionIsNotValid = errors.Register(ModuleName, 522, "LsfRevision should monotonically increase by 1")
26-
ErrLsfRevisionIsNotAllowed = errors.Register(ModuleName, 523, "LsfRevision is not allowed if LsfURL is not present")
27-
ErrModelVersionDeletionCertified = errors.Register(ModuleName, 524, "model version has a compliance record and can not be deleted")
28-
ErrModelDeletionCertified = errors.Register(ModuleName, 525, "model has a model version that has a compliance record and correcponding model can not be deleted")
29-
ErrFieldIsNotBase64Encoded = errors.Register(ModuleName, 526, "Field is not base64 encoded string")
14+
ErrSoftwareVersionStringInvalid = errors.Register(ModuleName, 511, "software version string invalid")
15+
ErrFirmwareInformationInvalid = errors.Register(ModuleName, 512, "firmware digests invalid")
16+
ErrCDVersionNumberInvalid = errors.Register(ModuleName, 513, "CD version number invalid")
17+
ErrOtaURLInvalid = errors.Register(ModuleName, 514, "OTA URL invalid")
18+
ErrOtaMissingInformation = errors.Register(ModuleName, 515, "OTA missing information")
19+
ErrReleaseNotesURLInvalid = errors.Register(ModuleName, 516, "release notes URL invalid")
20+
ErrModelVersionDoesNotExist = errors.Register(ModuleName, 517, "model version does not exist")
21+
ErrNoModelVersionsExist = errors.Register(ModuleName, 518, "no model versions exist")
22+
ErrModelVersionAlreadyExists = errors.Register(ModuleName, 519, "model version already exists")
23+
ErrOtaURLCannotBeSet = errors.Register(ModuleName, 520, "OTA URL cannot be set")
24+
ErrMaxSVLessThanMinSV = errors.Register(ModuleName, 521, "max software version less than min software version")
25+
ErrLsfRevisionIsNotValid = errors.Register(ModuleName, 522, "LsfRevision should monotonically increase by 1")
26+
ErrLsfRevisionIsNotAllowed = errors.Register(ModuleName, 523, "LsfRevision is not allowed if LsfURL is not present")
27+
ErrModelVersionDeletionCertified = errors.Register(ModuleName, 524, "model version has a compliance record and can not be deleted")
28+
ErrModelDeletionCertified = errors.Register(ModuleName, 525, "model has a model version that has a compliance record and correcponding model can not be deleted")
29+
ErrFieldIsNotBase64Encoded = errors.Register(ModuleName, 526, "Field is not base64 encoded string")
30+
ErrEnhancedSetupFlowTCRevisionInvalid = errors.Register(ModuleName, 527, "enhanced setup flow TC revision invalid")
3031
)
3132

3233
func NewErrModelAlreadyExists(vid interface{}, pid interface{}) error {
@@ -144,6 +145,6 @@ func NewErrEnhancedSetupFlowTCDigestIsNotBase64Encoded(enhancedSetupFlowTCDigest
144145
}
145146

146147
func NewErrEnhancedSetupFlowTCRevisionInvalidIncrement(newEnhancedSetupFlowTCRevision int32, prevEnhancedSetupFlowTCRevision int32) error {
147-
return errors.Wrapf(ErrFieldIsNotBase64Encoded,
148+
return errors.Wrapf(ErrEnhancedSetupFlowTCRevisionInvalid,
148149
"EnhancedSetupFlowTCRevision %v is not correctly incremented to %v", prevEnhancedSetupFlowTCRevision, newEnhancedSetupFlowTCRevision)
149150
}

0 commit comments

Comments
 (0)