Skip to content

Commit

Permalink
Merge Model and ModelVersion into single module
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur325 committed Oct 20, 2021
1 parent 6f3ff87 commit 446ed71
Show file tree
Hide file tree
Showing 51 changed files with 1,147 additions and 2,461 deletions.
21 changes: 3 additions & 18 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/zigbee-alliance/distributed-compliance-ledger/x/compliancetest"
"github.com/zigbee-alliance/distributed-compliance-ledger/x/genutil"
"github.com/zigbee-alliance/distributed-compliance-ledger/x/model"
"github.com/zigbee-alliance/distributed-compliance-ledger/x/modelversion"
"github.com/zigbee-alliance/distributed-compliance-ledger/x/pki"
"github.com/zigbee-alliance/distributed-compliance-ledger/x/validator"
"github.com/zigbee-alliance/distributed-compliance-ledger/x/vendorinfo"
Expand All @@ -57,7 +56,6 @@ var ModuleBasics = module.NewBasicManager(
validator.AppModuleBasic{},
genutil.AppModuleBasic{},
model.AppModuleBasic{},
modelversion.AppModuleBasic{},
compliance.AppModuleBasic{},
compliancetest.AppModuleBasic{},
pki.AppModuleBasic{},
Expand Down Expand Up @@ -87,7 +85,6 @@ type dcLedgerApp struct {
authKeeper auth.Keeper
validatorKeeper validator.Keeper
modelKeeper model.Keeper
modelversionKeeper modelversion.Keeper
pkiKeeper pki.Keeper
complianceKeeper compliance.Keeper
compliancetestKeeper compliancetest.Keeper
Expand All @@ -108,7 +105,7 @@ func NewDcLedgerApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
bApp.SetAppVersion(version.Version)

keys := sdk.NewKVStoreKeys(bam.MainStoreKey, auth.StoreKey, validator.StoreKey,
model.StoreKey, modelversion.StoreKey, compliance.StoreKey, compliancetest.StoreKey, pki.StoreKey, vendorinfo.StoreKey)
model.StoreKey, compliance.StoreKey, compliancetest.StoreKey, pki.StoreKey, vendorinfo.StoreKey)

tkeys := sdk.NewTransientStoreKeys(params.TStoreKey)

Expand Down Expand Up @@ -155,9 +152,8 @@ func InitModuleManager(app *dcLedgerApp) {
auth.NewAppModule(app.authKeeper),
validator.NewAppModule(app.validatorKeeper, app.authKeeper),
model.NewAppModule(app.modelKeeper, app.authKeeper),
modelversion.NewAppModule(app.modelversionKeeper, app.authKeeper, app.modelKeeper),
compliance.NewAppModule(app.complianceKeeper, app.modelversionKeeper, app.compliancetestKeeper, app.authKeeper),
compliancetest.NewAppModule(app.compliancetestKeeper, app.authKeeper, app.modelversionKeeper),
compliance.NewAppModule(app.complianceKeeper, app.modelKeeper, app.compliancetestKeeper, app.authKeeper),
compliancetest.NewAppModule(app.compliancetestKeeper, app.authKeeper, app.modelKeeper),
pki.NewAppModule(app.pkiKeeper, app.authKeeper),
vendorinfo.NewAppModule(app.vendorinfoKeeper, app.authKeeper),
)
Expand All @@ -169,7 +165,6 @@ func InitModuleManager(app *dcLedgerApp) {
auth.ModuleName,
validator.ModuleName,
model.ModuleName,
modelversion.ModuleName,
compliance.ModuleName,
compliancetest.ModuleName,
pki.ModuleName,
Expand All @@ -188,9 +183,6 @@ func InitKeepers(app *dcLedgerApp, keys map[string]*sdk.KVStoreKey) {
// The ModelKeeper keeper
app.modelKeeper = MakeModelKeeper(keys, app)

// The ModelversionKeeper keeper
app.modelversionKeeper = MakeModelversionKeeper(keys, app)

// The ComplianceKeeper keeper
app.complianceKeeper = MakeComplianceKeeper(keys, app)

Expand Down Expand Up @@ -221,13 +213,6 @@ func MakeModelKeeper(keys map[string]*sdk.KVStoreKey, app *dcLedgerApp) model.Ke
)
}

func MakeModelversionKeeper(keys map[string]*sdk.KVStoreKey, app *dcLedgerApp) modelversion.Keeper {
return modelversion.NewKeeper(
keys[modelversion.StoreKey],
app.cdc,
)
}

func MakeVendorInfoKeeper(keys map[string]*sdk.KVStoreKey, app *dcLedgerApp) vendorinfo.Keeper {
return vendorinfo.NewKeeper(
keys[vendorinfo.StoreKey],
Expand Down
19 changes: 16 additions & 3 deletions docs/cli-help.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Roles:
- roles: `optional(string)` - comma-separated list of roles (supported roles: Vendor, TestHouse, CertificationCenter, Trustee, NodeAdmin)
- from: `string` - name or address of private key with which to sign

Example: `dclcli tx auth propose-add-account --address=cosmos15ljvz60tfekhstz8lcyy0c9l8dys5qa2nnx4d7 --pubkey=cosmospub1addwnpepqtrnrp93hswlsrzvltc3n8z7hjg9dxuh3n4rkp2w2verwfr8yg27c95l4k3 --roles=Vendor,NodeAdmin --from=jack`
Example: `dclcli tx auth propose-add-account --address=cosmos15ljvz60tfekhstz8lcyy0c9l8dys5qa2nnx4d7 --pubkey=cosmospub1addwnpepqtrnrp93hswlsrzvltc3n8z7hjg9dxuh3n4rkp2w2verwfr8yg27c95l4k3 --roles=Trustee,NodeAdmin --from=jack`

- Approve a proposed account.

Expand Down Expand Up @@ -132,7 +132,20 @@ Roles:

Example: `dclcli tx auth approve-revoke-account --address=cosmos15ljvz60tfekhstz8lcyy0c9l8dys5qa2nnx4d7 --from=jack`

- Propose a new account (Vendor Role). A vendor role is tied to a Vendor ID, hence while proposing a Vendor Role vid is a required field.

Role: `Trustee`

Command: `dclcli tx auth propose-add-account --address=<string> --pubkey=<string> --roles=<roles> --vid=<vendorID> --from=<account>`

Flags:
- address: `string` - bench32 encoded account address
- pubkey: `string` - bench32 encoded public key
- roles: `optional(string)` - comma-separated list of roles (supported roles: Vendor, TestHouse, CertificationCenter, Trustee, NodeAdmin)
- vid: `string` - Vendor ID associated with this account. Required only for Vendor Roles
- from: `string` - name or address of private key with which to sign

Example: `dclcli tx auth propose-add-account --address=cosmos15ljvz60tfekhstz8lcyy0c9l8dys5qa2nnx4d7 --pubkey=cosmospub1addwnpepqtrnrp93hswlsrzvltc3n8z7hjg9dxuh3n4rkp2w2verwfr8yg27c95l4k3 --roles=Vendor,NodeAdmin --vid=123 --from=jack`
##### Queries

- Get a single account. Revoked accounts are not returned.
Expand Down Expand Up @@ -386,10 +399,10 @@ The set of commands that allows you to manage X.509 certificates.

### Model Info

The set of commands that allows you to manage model infos.
The set of commands that allows you to manage model and model versions.

##### Transactions
- Add a new model info.
- Add a new model.

Role: `Vendor`

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/cli/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ create_model_and_version() {
_user_address=$4
result=$(echo 'test1234' | dclcli tx model add-model --vid=$_vid --pid=$_pid --deviceTypeID=1 --productName=TestProduct --productLabel=TestingProductLabel --partNumber=1 --commissioningCustomFlow=0 --from=$_user_address --yes)
check_response "$result" "\"success\": true"
result=$(echo 'test1234' | dclcli tx modelversion add-model-version --cdVersionNumber=1 --maxApplicableSoftwareVersion=10 --minApplicableSoftwareVersion=1 --vid=$_vid --pid=$_pid --softwareVersion=$_softwareVersion --softwareVersionString=1 --from=$_user_address --yes)
result=$(echo 'test1234' | dclcli tx model add-model-version --cdVersionNumber=1 --maxApplicableSoftwareVersion=10 --minApplicableSoftwareVersion=1 --vid=$_vid --pid=$_pid --softwareVersion=$_softwareVersion --softwareVersionString=1 --from=$_user_address --yes)
check_response "$result" "\"success\": true"
}

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/cli/compliance-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test_divider

sv=$RANDOM
echo "Add Model Version with VID: $vid PID: $pid SV: $sv"
result=$(echo 'test1234' | dclcli tx modelversion add-model-version --cdVersionNumber=1 --maxApplicableSoftwareVersion=10 --minApplicableSoftwareVersion=1 --vid=$vid --pid=$pid --softwareVersion=$sv --softwareVersionString=1 --from=$vendor_account --yes)
result=$(echo 'test1234' | dclcli tx model add-model-version --cdVersionNumber=1 --maxApplicableSoftwareVersion=10 --minApplicableSoftwareVersion=1 --vid=$vid --pid=$pid --softwareVersion=$sv --softwareVersionString=1 --from=$vendor_account --yes)
echo $result
check_response "$result" "\"success\": true"

Expand Down
14 changes: 7 additions & 7 deletions integration_tests/cli/modelversion-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ test_divider

sv=$RANDOM
echo "Create a Device Model Version with VID: $vid PID: $pid SV: $sv"
result=$(echo 'test1234' | dclcli tx modelversion add-model-version --cdVersionNumber=1 --maxApplicableSoftwareVersion=10 --minApplicableSoftwareVersion=1 --vid=$vid --pid=$pid --softwareVersion=$sv --softwareVersionString=1 --from=$vendor_account --yes)
result=$(echo 'test1234' | dclcli tx model add-model-version --cdVersionNumber=1 --maxApplicableSoftwareVersion=10 --minApplicableSoftwareVersion=1 --vid=$vid --pid=$pid --softwareVersion=$sv --softwareVersionString=1 --from=$vendor_account --yes)
echo "$result"
check_response "$result" "\"success\": true"

test_divider

# Query the model version
echo "Query Device Model Version with VID: $vid PID: $pid SV: $sv"
result=$(dclcli query modelversion get-model-version --vid=$vid --pid=$pid --softwareVersion=$sv)
result=$(dclcli query model get-model-version --vid=$vid --pid=$pid --softwareVersion=$sv)
echo "$result"

check_response "$result" "\"vid\": $vid"
Expand All @@ -60,21 +60,21 @@ test_divider

# Query non existant model version
echo "Query Device Model Version with VID: $vid PID: $pid SV: 123456"
result=$(dclcli query modelversion get-model-version --vid=$vid --pid=$pid --softwareVersion=123456 2>&1) || true
result=$(dclcli query model get-model-version --vid=$vid --pid=$pid --softwareVersion=123456 2>&1) || true
check_response_and_report "$result" "No model version associated with vid=$vid, pid=$pid and softwareVersion=123456 exist on the ledger"

test_divider

# Update the existing model version
echo "Update Device Model Version with VID: $vid PID: $pid SV: $sv"
result=$(echo 'test1234' | dclcli tx modelversion update-model-version --vid=$vid --pid=$pid --minApplicableSoftwareVersion=2 --softwareVersion=$sv --softwareVersionValid=false --from=$vendor_account --yes)
result=$(echo 'test1234' | dclcli tx model update-model-version --vid=$vid --pid=$pid --minApplicableSoftwareVersion=2 --softwareVersion=$sv --softwareVersionValid=false --from=$vendor_account --yes)
check_response "$result" "\"success\": true"

test_divider

# Query Updated model version
echo "Query updated Device Model Version with VID: $vid PID: $pid SV: $sv"
result=$(dclcli query modelversion get-model-version --vid=$vid --pid=$pid --softwareVersion=$sv)
result=$(dclcli query model get-model-version --vid=$vid --pid=$pid --softwareVersion=$sv)
echo "$result"
check_response "$result" "\"vid\": $vid"
check_response "$result" "\"pid\": $pid"
Expand All @@ -92,15 +92,15 @@ echo "Create a Device Model Version with VID: $vid PID: $pid SV: $sv from a diff
newvid=$RANDOM
different_vendor_account=vendor_account_$newvid
create_new_vendor_account $different_vendor_account $newvid
result=$(echo 'test1234' | dclcli tx modelversion add-model-version --cdVersionNumber=1 --maxApplicableSoftwareVersion=10 --minApplicableSoftwareVersion=1 --vid=$vid --pid=$pid --softwareVersion=$sv --softwareVersionString=1 --from=$different_vendor_account --yes)
result=$(echo 'test1234' | dclcli tx model add-model-version --cdVersionNumber=1 --maxApplicableSoftwareVersion=10 --minApplicableSoftwareVersion=1 --vid=$vid --pid=$pid --softwareVersion=$sv --softwareVersionString=1 --from=$different_vendor_account --yes)
check_response "$result" "\"success\": false"
check_response_and_report "$result" "ModelVersion Add/Update transaction should be signed by an vendor account containing the vendorId $vid"

test_divider

# Update model version with vid belonging to another vendor
echo "Update a Device Model Version with VID: $vid PID: $pid SV: $sv from a different vendor account"
result=$(echo 'test1234' | dclcli tx modelversion update-model-version --vid=$vid --pid=$pid --minApplicableSoftwareVersion=2 --softwareVersion=$sv --softwareVersionValid=false --from=$different_vendor_account --yes)
result=$(echo 'test1234' | dclcli tx model update-model-version --vid=$vid --pid=$pid --minApplicableSoftwareVersion=2 --softwareVersion=$sv --softwareVersionValid=false --from=$different_vendor_account --yes)
check_response "$result" "\"success\": false"
check_response_and_report "$result" "ModelVersion Add/Update transaction should be signed by an vendor account containing the vendorId $vid"

42 changes: 20 additions & 22 deletions integration_tests/utils/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import (
compliancetestRest "github.com/zigbee-alliance/distributed-compliance-ledger/x/compliancetest/client/rest"
"github.com/zigbee-alliance/distributed-compliance-ledger/x/model"
modelRest "github.com/zigbee-alliance/distributed-compliance-ledger/x/model/client/rest"
"github.com/zigbee-alliance/distributed-compliance-ledger/x/modelversion"
modelVersionRest "github.com/zigbee-alliance/distributed-compliance-ledger/x/modelversion/client/rest"
"github.com/zigbee-alliance/distributed-compliance-ledger/x/pki"
pkiRest "github.com/zigbee-alliance/distributed-compliance-ledger/x/pki/client/rest"
)
Expand Down Expand Up @@ -279,7 +277,7 @@ func AddModel(model model.MsgAddModel, sender KeyInfo) (TxnResponse, int) {
return parseWriteTxnResponse(response, code)
}

func AddModelVersion(modelVersion modelversion.MsgAddModelVersion, sender KeyInfo) (TxnResponse, int) {
func AddModelVersion(modelVersion model.MsgAddModelVersion, sender KeyInfo) (TxnResponse, int) {
println("Add Model Version")

response, code := SendAddModelVersionRequest(modelVersion, sender.Name)
Expand All @@ -295,7 +293,7 @@ func PrepareAddModelTransaction(model model.MsgAddModel) (types.StdTx, int) {
return parseStdTxn(response, code)
}

func PrepareAddModelVersionTransaction(modelVersion modelversion.MsgAddModelVersion) (types.StdTx, int) {
func PrepareAddModelVersionTransaction(modelVersion model.MsgAddModelVersion) (types.StdTx, int) {
println("Prepare Add Model Version Transaction")

response, code := SendAddModelVersionRequest(modelVersion, "")
Expand All @@ -319,8 +317,8 @@ func SendAddModelRequest(msgAddModel model.MsgAddModel, account string) ([]byte,
return SendPostRequest(uri, body, account, constants.Passphrase)
}

func SendAddModelVersionRequest(msgAddModelVersion modelversion.MsgAddModelVersion, account string) ([]byte, int) {
request := modelVersionRest.AddModelVersionRequest{
func SendAddModelVersionRequest(msgAddModelVersion model.MsgAddModelVersion, account string) ([]byte, int) {
request := modelRest.AddModelVersionRequest{
ModelVersion: msgAddModelVersion.ModelVersion,
BaseReq: restTypes.BaseReq{
ChainID: constants.ChainID,
Expand All @@ -330,7 +328,7 @@ func SendAddModelVersionRequest(msgAddModelVersion modelversion.MsgAddModelVersi

body, _ := codec.MarshalJSONIndent(app.MakeCodec(), request)

uri := fmt.Sprintf("%s/%s", modelversion.RouterKey, "version")
uri := fmt.Sprintf("%s/%s", model.RouterKey, "version")

return SendPostRequest(uri, body, account, constants.Passphrase)
}
Expand All @@ -343,7 +341,7 @@ func UpdateModel(model model.MsgUpdateModel, sender KeyInfo) (TxnResponse, int)
return parseWriteTxnResponse(response, code)
}

func UpdateModelVersion(modelVersion modelversion.MsgUpdateModelVersion, sender KeyInfo) (TxnResponse, int) {
func UpdateModelVersion(modelVersion model.MsgUpdateModelVersion, sender KeyInfo) (TxnResponse, int) {
println("Update Model Version")

response, code := SendUpdateModelVersionRequest(modelVersion, sender.Name)
Expand All @@ -359,7 +357,7 @@ func PrepareUpdateModelTransaction(model model.MsgUpdateModel) (types.StdTx, int
return parseStdTxn(response, code)
}

func PrepareUpdateModelVersionTransaction(modelVersion modelversion.MsgUpdateModelVersion) (types.StdTx, int) {
func PrepareUpdateModelVersionTransaction(modelVersion model.MsgUpdateModelVersion) (types.StdTx, int) {
println("Prepare Update Model Version Transaction")

response, code := SendUpdateModelVersionRequest(modelVersion, "")
Expand All @@ -383,8 +381,8 @@ func SendUpdateModelRequest(msgUpdateModel model.MsgUpdateModel, account string)
return SendPutRequest(uri, body, account, constants.Passphrase)
}

func SendUpdateModelVersionRequest(msgUpdateModelVersion modelversion.MsgUpdateModelVersion, account string) ([]byte, int) {
request := modelVersionRest.UpdateModelVersionRequest{
func SendUpdateModelVersionRequest(msgUpdateModelVersion model.MsgUpdateModelVersion, account string) ([]byte, int) {
request := modelRest.UpdateModelVersionRequest{
ModelVersion: msgUpdateModelVersion.ModelVersion,
BaseReq: restTypes.BaseReq{
ChainID: constants.ChainID,
Expand All @@ -394,7 +392,7 @@ func SendUpdateModelVersionRequest(msgUpdateModelVersion modelversion.MsgUpdateM

body, _ := codec.MarshalJSONIndent(app.MakeCodec(), request)

uri := fmt.Sprintf("%s/%s", modelversion.RouterKey, "version")
uri := fmt.Sprintf("%s/%s", model.RouterKey, "version")

return SendPutRequest(uri, body, account, constants.Passphrase)
}
Expand All @@ -412,13 +410,13 @@ func GetModel(vid uint16, pid uint16) (model.Model, int) {
return result, code
}

func GetModelVersion(vid uint16, pid uint16, softwareVersion uint32) (modelversion.ModelVersion, int) {
func GetModelVersion(vid uint16, pid uint16, softwareVersion uint32) (model.ModelVersion, int) {
println(fmt.Sprintf("Get Model Version with VID:%v PID:%v SV:%v", vid, pid, softwareVersion))

uri := fmt.Sprintf("%s/%s/%v/%v/%v", modelversion.RouterKey, "version", vid, pid, softwareVersion)
uri := fmt.Sprintf("%s/%s/%v/%v/%v", model.RouterKey, "version", vid, pid, softwareVersion)
response, code := SendGetRequest(uri)

var result modelversion.ModelVersion
var result model.ModelVersion

parseGetReqResponse(removeResponseWrapper(response), &result, code)

Expand Down Expand Up @@ -1030,8 +1028,8 @@ func NewMsgUpdateModel(vid uint16, pid uint16, owner sdk.AccAddress) model.MsgUp
}

func NewMsgAddModelVersion(vid uint16, pid uint16,
softwareVersion uint32, softwareVersionString string, owner sdk.AccAddress) modelversion.MsgAddModelVersion {
newModelVersion := modelversion.ModelVersion{
softwareVersion uint32, softwareVersionString string, owner sdk.AccAddress) model.MsgAddModelVersion {
newModelVersion := model.ModelVersion{

VID: vid,
PID: pid,
Expand All @@ -1048,23 +1046,23 @@ func NewMsgAddModelVersion(vid uint16, pid uint16,
ReleaseNotesURL: constants.ReleaseNotesURL,
}

return modelversion.NewMsgAddModelVersion(
return model.NewMsgAddModelVersion(
newModelVersion,
owner,
)
}

func NewMsgUpdateModelVersion(vid uint16, pid uint16,
softwareVersion uint32, softwareVersionString string, owner sdk.AccAddress) modelversion.MsgUpdateModelVersion {
updateModelVersion := modelversion.ModelVersion{
softwareVersion uint32, softwareVersionString string, owner sdk.AccAddress) model.MsgUpdateModelVersion {
updateModelVersion := model.ModelVersion{
VID: vid,
PID: pid,
SoftwareVersion: softwareVersion,
OtaURL: constants.OtaURL + "/new",
ReleaseNotesURL: constants.ReleaseNotesURL + "/new",
}

return modelversion.NewMsgUpdateModelVersion(
return model.NewMsgUpdateModelVersion(
updateModelVersion,
owner,
)
Expand Down Expand Up @@ -1119,7 +1117,7 @@ func parseGetReqResponse(response []byte, entity interface{}, code int) {
}
}

func InitStartData() (KeyInfo, KeyInfo, model.MsgAddModel, modelversion.MsgAddModelVersion,
func InitStartData() (KeyInfo, KeyInfo, model.MsgAddModel, model.MsgAddModelVersion,
ComplianceInfosHeadersResult, ComplianceInfosHeadersResult) {
// Register new Vendor account
vendor := CreateNewAccount(auth.AccountRoles{auth.Vendor}, constants.VID)
Expand Down
Loading

0 comments on commit 446ed71

Please sign in to comment.