Skip to content

Commit 94b3b50

Browse files
authored
#706 Remove Model/Model-Version dependency while provisioning model version (#712)
* #706 Enable skipping the check for Model Version existence while provisioning Model Version Signed-off-by: Abdulbois <abdulbois.tursunov@dsr-corporation.com>
1 parent bc84713 commit 94b3b50

4 files changed

Lines changed: 43 additions & 11 deletions

File tree

docs/transactions/compliance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ is written on the ledger (`CERTIFY_MODEL` was called), or
141141

142142
Sets provisional state for the Model Version.
143143

144-
The corresponding Model and Model Version is required to be present in the ledger.
144+
The corresponding Model and Model Version are not required to be present in the ledger. It can be added later by Vendors.
145145

146146
Can not be set if there is already a certification record on the ledger (certified or revoked).
147147

integration_tests/cli/compliance-provisioning.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ schema_version_0=0
4444

4545
test_divider
4646

47+
echo "Provision unknown Model with VID: $vid PID: $pid SV: ${sv} with zigbee certification"
48+
result=$(echo "$passphrase" | dcld tx compliance provision-model --vid=$vid --pid=$pid --softwareVersion=$sv --softwareVersionString=$svs --certificationType=$certification_type_zb --provisionalDate="$provision_date" --cdCertificateId="$cd_certificate_id" --cdVersionNumber=1 --from $zb_account --yes)
49+
result=$(get_txn_result "$result")
50+
echo "$result"
51+
check_response "$result" "\"code\": 0"
52+
53+
echo "Get Compliance Info for Model with VID: ${vid} PID: ${pid} SV: ${sv} for ZB"
54+
result=$(dcld query compliance compliance-info --vid=$vid --pid=$pid --softwareVersion=$sv --certificationType=$certification_type_zb)
55+
check_response "$result" "\"vid\": $vid"
56+
check_response "$result" "\"pid\": $pid"
57+
check_response "$result" "\"softwareVersion\": $sv"
58+
check_response "$result" "\"softwareVersionString\": \"$svs\""
59+
check_response "$result" "\"certificationType\": \"$certification_type_zb\""
60+
check_response "$result" "\"date\": \"$provision_date\""
61+
check_response "$result" "\"cDCertificateId\": \"$cd_certificate_id\""
62+
63+
echo "Delete compliance info vid=$vid pid=$pid softwareVersion=$sv certificationType=$certification_type_zb"
64+
result=$(echo "$passphrase" | dcld tx compliance delete-compliance-info --vid=$vid --pid=$pid --softwareVersion=$sv --certificationType=$certification_type_zb --from=$zb_account --yes)
65+
result=$(get_txn_result "$result")
66+
67+
test_divider
68+
4769
echo "Add Model and a New Model Version with VID: $vid PID: $pid SV: $sv"
4870
create_model_and_version $vid $pid $sv $svs $vendor_account
4971

x/compliance/handler_provision_model_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ func TestHandler_ProvisionModel_WithAllOptionalFlagsForAllCertificationTypes(t *
101101
}
102102
}
103103

104+
func TestHandler_ProvisionModelWhenModelVersionDoesNotExist(t *testing.T) {
105+
setup := setup(t)
106+
vid, pid, softwareVersion := testconstants.Vid, testconstants.Pid, testconstants.SoftwareVersion
107+
setup.setNoModelVersionForKey(vid, pid, softwareVersion)
108+
109+
provisionModelMsg, provisionModelErr := setup.provisionModel(vid, pid, softwareVersion, testconstants.SoftwareVersionString, types.ZigbeeCertificationType, setup.CertificationCenter)
110+
require.NoError(t, provisionModelErr)
111+
112+
setup.checkComplianceInfoEqualsProvisionModelMsgData(t, provisionModelMsg)
113+
setup.checkModelProvisioned(t, provisionModelMsg)
114+
}
115+
104116
func TestHandler_ProvisionModel_ByWrongRoles(t *testing.T) {
105117
setup, vid, pid, softwareVersion, softwareVersionString, certificationType := setupProvisionModel(t)
106118

x/compliance/keeper/msg_server_provision_model.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/zigbee-alliance/distributed-compliance-ledger/x/compliance/types"
1111
dclauthtypes "github.com/zigbee-alliance/distributed-compliance-ledger/x/dclauth/types"
12-
modeltypes "github.com/zigbee-alliance/distributed-compliance-ledger/x/model/types"
1312
)
1413

1514
func (k msgServer) ProvisionModel(goCtx context.Context, msg *types.MsgProvisionModel) (*types.MsgProvisionModelResponse, error) {
@@ -46,16 +45,15 @@ func (k msgServer) ProvisionModel(goCtx context.Context, msg *types.MsgProvision
4645

4746
modelVersion, isFound := k.modelKeeper.GetModelVersion(ctx, msg.Vid, msg.Pid, msg.SoftwareVersion)
4847

49-
if !isFound {
50-
return nil, modeltypes.NewErrModelVersionDoesNotExist(msg.Vid, msg.Pid, msg.SoftwareVersion)
51-
}
52-
53-
if modelVersion.SoftwareVersionString != msg.SoftwareVersionString {
54-
return nil, types.NewErrModelVersionStringDoesNotMatch(msg.Vid, msg.Pid, msg.SoftwareVersion, msg.SoftwareVersionString)
55-
}
48+
if isFound {
49+
// check if softwareVersionString matches with what is stored for the given version
50+
if modelVersion.SoftwareVersionString != msg.SoftwareVersionString {
51+
return nil, types.NewErrModelVersionStringDoesNotMatch(msg.Vid, msg.Pid, msg.SoftwareVersion, msg.SoftwareVersionString)
52+
}
5653

57-
if modelVersion.CdVersionNumber != int32(msg.CDVersionNumber) {
58-
return nil, types.NewErrModelVersionCDVersionNumberDoesNotMatch(msg.Vid, msg.Pid, msg.SoftwareVersion, msg.CDVersionNumber)
54+
if modelVersion.CdVersionNumber != int32(msg.CDVersionNumber) {
55+
return nil, types.NewErrModelVersionCDVersionNumberDoesNotMatch(msg.Vid, msg.Pid, msg.SoftwareVersion, msg.CDVersionNumber)
56+
}
5957
}
6058

6159
complianceInfo = types.ComplianceInfo{

0 commit comments

Comments
 (0)