Skip to content

Commit

Permalink
Merge pull request #433 from zigbee-alliance/issue-429-optional-fields
Browse files Browse the repository at this point in the history
Issue 429 optional fields
  • Loading branch information
ashcherbakov committed Mar 2, 2023
2 parents 6d35b52 + 80ffc7f commit 65e0fc5
Show file tree
Hide file tree
Showing 40 changed files with 587 additions and 612 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ jobs:
integration-tests:
if: needs.changes.outputs.src == 'true'
name: Integration tests
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
needs:
- changes
steps:
Expand Down
14 changes: 13 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
# limitations under the License.

linters:
enable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
disable:
- golint # The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner. Replaced by revive.
- gochecknoinits
Expand Down Expand Up @@ -49,3 +56,8 @@ linters:
- execinquery
- nonamedreturns
- exhaustruct
- nosnakecase
- dupword
- nolintlint
- gofmt
- gofumpt
3 changes: 1 addition & 2 deletions docs/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ dcld tx vendorinfo add-vendor --vid=<uint16> --vendorName=<string> --companyLega
Minimal command:

```bash
dcld tx model add-model --vid=<uint16> --pid=<uint16> --deviceTypeID=<uint16> --productName=<string> --productLabel=<string or path> --partNumber=<string>
--from=<account>
dcld tx model add-model --vid=<uint16> --pid=<uint16> --deviceTypeID=<uint16> --productName=<string> --from=<account>
```

Full command:
Expand Down
4 changes: 2 additions & 2 deletions docs/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ Not all fields can be edited (see `EDIT_MODEL`).
- pid: `uint16` - model product ID (positive non-zero)
- deviceTypeID: `uint16` - DeviceTypeID is the device type identifier. For example, DeviceTypeID 10 (0x000a), is the device type identifier for a Door Lock.
- productName: `string` - model name
- productLabel: `string` - model description (string or path to file containing data)
- partNumber: `string` - stock keeping unit
- productLabel: `optional(string)` - model description (string or path to file containing data)
- partNumber: `optional(string)` - stock keeping unit
- commissioningCustomFlow: `optional(uint8)` - A value of 1 indicates that user interaction with the device (pressing a button, for example) is required before commissioning can take place. When CommissioningCustomflow is set to a value of 2, the commissioner SHOULD attempt to obtain a URL which MAY be used to provide an end user with the necessary details for how to configure the product for initial commissioning
- commissioningCustomFlowURL: `optional(string)` - commissioningCustomFlowURL SHALL identify a vendor specific commissioning URL for the device model when the commissioningCustomFlow field is set to '2'
- commissioningModeInitialStepsHint: `optional(uint32)` - commissioningModeInitialStepsHint SHALL identify a hint for the steps that can be used to put into commissioning mode a device that has not yet been commissioned. This field is a bitmap with values defined in the Pairing Hint Table. For example, a value of 1 (bit 0 is set) indicates that a device that has not yet been commissioned will enter Commissioning Mode upon a power cycle.
Expand Down
18 changes: 0 additions & 18 deletions integration_tests/cli/model-negative-cases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,6 @@ check_response_and_report "$result" "ProductName is a required field" raw

test_divider

echo "Add model with empty description"
result=$(echo "test1234" | dcld tx model add-model --vid=$vid --pid=$pid --deviceTypeID=1 --productName=TestProduct --productLabel="" --partNumber=1 --commissioningCustomFlow=0 --from $vendor_account --yes 2>&1) || true
check_response_and_report "$result" "ProductLabel is a required field" raw

test_divider

echo "Add model with empty partNumber"
result=$(echo "test1234" | dcld tx model add-model --vid=$vid --pid=$pid --deviceTypeID=1 --productName=TestProduct --productLabel="Test Label" --partNumber="" --commissioningCustomFlow=0 --from $vendor_account --yes 2>&1) || true
check_response_and_report "$result" "PartNumber is a required field" raw

test_divider

echo "Add model with empty --from flag"
result=$(dcld tx model add-model --vid=$vid --pid=$pid --deviceTypeID=1 --productName=TestProduct --productLabel=TestingProductLabel --partNumber=1 --commissioningCustomFlow=0 --from "" --yes 2>&1) || true
check_response_and_report "$result" "invalid creator address (empty address string is not allowed)" raw
Expand All @@ -124,12 +112,6 @@ check_response_and_report "$result" "required flag(s) \"from\" not set" raw

test_divider

echo "Add model without enough parameters"
result=$(echo "test1234" | dcld tx model add-model --vid=$vid --pid=$pid --deviceTypeID=1 --productName=TestProduct --partNumber="1" --commissioningCustomFlow=0 --from $vendor_account --yes 2>&1) || true
check_response_and_report "$result" "required flag(s) \"productLabel\" not set" raw

test_divider

echo "Update model with Non Mutable fields"
pid=$RANDOM
sv=$RANDOM
Expand Down
6 changes: 4 additions & 2 deletions integration_tests/deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ version: '3.2'

services:
test_deploy_gvn:
privileged: true
image: dcledger_deploy
build: .
container_name: test_deploy_gvn
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
- /tmp

test_deploy_vn:
privileged: true
image: dcledger_deploy
build: .
container_name: test_deploy_vn
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
Expand Down
6 changes: 3 additions & 3 deletions proto/model/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ option go_package = "github.com/zigbee-alliance/distributed-compliance-ledger/x/

// Msg defines the Msg service.
service Msg {
rpc CreateModel(MsgCreateModel) returns (MsgCreateModelResponse);
rpc CreateModel(MsgCreateModel) returns (MsgCreateModelResponse);
rpc UpdateModel(MsgUpdateModel) returns (MsgUpdateModelResponse);
rpc DeleteModel(MsgDeleteModel) returns (MsgDeleteModelResponse);
rpc CreateModelVersion(MsgCreateModelVersion) returns (MsgCreateModelVersionResponse);
Expand All @@ -27,8 +27,8 @@ message MsgCreateModel {

int32 deviceTypeId = 4 [(gogoproto.moretags) = "validate:\"gte=0,lte=65535\""];
string productName = 5 [(gogoproto.moretags) = "validate:\"required,max=128\""];
string productLabel = 6 [(gogoproto.moretags) = "validate:\"required,max=256\""];
string partNumber = 7 [(gogoproto.moretags) = "validate:\"required,max=32\""];
string productLabel = 6 [(gogoproto.moretags) = "validate:\"max=256\""];
string partNumber = 7 [(gogoproto.moretags) = "validate:\"max=32\""];
int32 commissioningCustomFlow = 8 [(gogoproto.moretags) = "validate:\"gte=0,lte=2\""];
string commissioningCustomFlowUrl = 9 [(gogoproto.moretags) = "validate:\"required_if=CommissioningCustomFlow 2,omitempty,url,startsnotwith=http:,max=256\""];
uint32 commissioningModeInitialStepsHint = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,37 +353,37 @@ export default {
}
}
},
async sendMsgCertifyModel({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgProvisionModel({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgCertifyModel(value);
const msg = await txClient.msgProvisionModel(value);
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee,
gas: "200000" }, memo });
return result;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgCertifyModel:Init', 'Could not initialize signing client. Wallet is required.');
throw new SpVuexError('TxClient:MsgProvisionModel:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgCertifyModel:Send', 'Could not broadcast Tx: ' + e.message);
throw new SpVuexError('TxClient:MsgProvisionModel:Send', 'Could not broadcast Tx: ' + e.message);
}
}
},
async sendMsgProvisionModel({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgCertifyModel({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgProvisionModel(value);
const msg = await txClient.msgCertifyModel(value);
const result = await txClient.signAndBroadcast([msg], { fee: { amount: fee,
gas: "200000" }, memo });
return result;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProvisionModel:Init', 'Could not initialize signing client. Wallet is required.');
throw new SpVuexError('TxClient:MsgCertifyModel:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgProvisionModel:Send', 'Could not broadcast Tx: ' + e.message);
throw new SpVuexError('TxClient:MsgCertifyModel:Send', 'Could not broadcast Tx: ' + e.message);
}
}
},
Expand All @@ -402,33 +402,33 @@ export default {
}
}
},
async MsgCertifyModel({ rootGetters }, { value }) {
async MsgProvisionModel({ rootGetters }, { value }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgCertifyModel(value);
const msg = await txClient.msgProvisionModel(value);
return msg;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgCertifyModel:Init', 'Could not initialize signing client. Wallet is required.');
throw new SpVuexError('TxClient:MsgProvisionModel:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgCertifyModel:Create', 'Could not create message: ' + e.message);
throw new SpVuexError('TxClient:MsgProvisionModel:Create', 'Could not create message: ' + e.message);
}
}
},
async MsgProvisionModel({ rootGetters }, { value }) {
async MsgCertifyModel({ rootGetters }, { value }) {
try {
const txClient = await initTxClient(rootGetters);
const msg = await txClient.msgProvisionModel(value);
const msg = await txClient.msgCertifyModel(value);
return msg;
}
catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProvisionModel:Init', 'Could not initialize signing client. Wallet is required.');
throw new SpVuexError('TxClient:MsgCertifyModel:Init', 'Could not initialize signing client. Wallet is required.');
}
else {
throw new SpVuexError('TxClient:MsgProvisionModel:Create', 'Could not create message: ' + e.message);
throw new SpVuexError('TxClient:MsgCertifyModel:Create', 'Could not create message: ' + e.message);
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,33 +443,33 @@ export default {
}
}
},
async sendMsgCertifyModel({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgProvisionModel({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgCertifyModel(value)
const msg = await txClient.msgProvisionModel(value)
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgCertifyModel:Init', 'Could not initialize signing client. Wallet is required.')
throw new SpVuexError('TxClient:MsgProvisionModel:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgCertifyModel:Send', 'Could not broadcast Tx: '+ e.message)
throw new SpVuexError('TxClient:MsgProvisionModel:Send', 'Could not broadcast Tx: '+ e.message)
}
}
},
async sendMsgProvisionModel({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgCertifyModel({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgProvisionModel(value)
const msg = await txClient.msgCertifyModel(value)
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProvisionModel:Init', 'Could not initialize signing client. Wallet is required.')
throw new SpVuexError('TxClient:MsgCertifyModel:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgProvisionModel:Send', 'Could not broadcast Tx: '+ e.message)
throw new SpVuexError('TxClient:MsgCertifyModel:Send', 'Could not broadcast Tx: '+ e.message)
}
}
},
Expand All @@ -488,30 +488,30 @@ export default {
}
}
},
async MsgCertifyModel({ rootGetters }, { value }) {
async MsgProvisionModel({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgCertifyModel(value)
const msg = await txClient.msgProvisionModel(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgCertifyModel:Init', 'Could not initialize signing client. Wallet is required.')
throw new SpVuexError('TxClient:MsgProvisionModel:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgCertifyModel:Create', 'Could not create message: ' + e.message)
throw new SpVuexError('TxClient:MsgProvisionModel:Create', 'Could not create message: ' + e.message)

}
}
},
async MsgProvisionModel({ rootGetters }, { value }) {
async MsgCertifyModel({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgProvisionModel(value)
const msg = await txClient.msgCertifyModel(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new SpVuexError('TxClient:MsgProvisionModel:Init', 'Could not initialize signing client. Wallet is required.')
throw new SpVuexError('TxClient:MsgCertifyModel:Init', 'Could not initialize signing client. Wallet is required.')
}else{
throw new SpVuexError('TxClient:MsgProvisionModel:Create', 'Could not create message: ' + e.message)
throw new SpVuexError('TxClient:MsgCertifyModel:Create', 'Could not create message: ' + e.message)

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { StdFee } from "@cosmjs/launchpad";
import { Registry, OfflineSigner, EncodeObject } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgRevokeModel } from "./types/compliance/tx";
import { MsgCertifyModel } from "./types/compliance/tx";
import { MsgProvisionModel } from "./types/compliance/tx";
import { MsgCertifyModel } from "./types/compliance/tx";
export declare const MissingWalletError: Error;
export declare const registry: Registry;
interface TxClientOptions {
Expand All @@ -16,8 +16,8 @@ interface SignAndBroadcastOptions {
declare const txClient: (wallet: OfflineSigner, { addr: addr }?: TxClientOptions) => Promise<{
signAndBroadcast: (msgs: EncodeObject[], { fee, memo }?: SignAndBroadcastOptions) => any;
msgRevokeModel: (data: MsgRevokeModel) => EncodeObject;
msgCertifyModel: (data: MsgCertifyModel) => EncodeObject;
msgProvisionModel: (data: MsgProvisionModel) => EncodeObject;
msgCertifyModel: (data: MsgCertifyModel) => EncodeObject;
}>;
interface QueryClientOptions {
addr: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { SigningStargateClient } from "@cosmjs/stargate";
import { Registry } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgRevokeModel } from "./types/compliance/tx";
import { MsgCertifyModel } from "./types/compliance/tx";
import { MsgProvisionModel } from "./types/compliance/tx";
import { MsgCertifyModel } from "./types/compliance/tx";
const types = [
["/zigbeealliance.distributedcomplianceledger.compliance.MsgRevokeModel", MsgRevokeModel],
["/zigbeealliance.distributedcomplianceledger.compliance.MsgCertifyModel", MsgCertifyModel],
["/zigbeealliance.distributedcomplianceledger.compliance.MsgProvisionModel", MsgProvisionModel],
["/zigbeealliance.distributedcomplianceledger.compliance.MsgCertifyModel", MsgCertifyModel],
];
export const MissingWalletError = new Error("wallet is required");
export const registry = new Registry(types);
Expand All @@ -30,8 +30,8 @@ const txClient = async (wallet, { addr: addr } = { addr: "http://localhost:26657
return {
signAndBroadcast: (msgs, { fee, memo } = { fee: defaultFee, memo: "" }) => client.signAndBroadcast(address, msgs, fee, memo),
msgRevokeModel: (data) => ({ typeUrl: "/zigbeealliance.distributedcomplianceledger.compliance.MsgRevokeModel", value: MsgRevokeModel.fromPartial(data) }),
msgCertifyModel: (data) => ({ typeUrl: "/zigbeealliance.distributedcomplianceledger.compliance.MsgCertifyModel", value: MsgCertifyModel.fromPartial(data) }),
msgProvisionModel: (data) => ({ typeUrl: "/zigbeealliance.distributedcomplianceledger.compliance.MsgProvisionModel", value: MsgProvisionModel.fromPartial(data) }),
msgCertifyModel: (data) => ({ typeUrl: "/zigbeealliance.distributedcomplianceledger.compliance.MsgCertifyModel", value: MsgCertifyModel.fromPartial(data) }),
};
};
const queryClient = async ({ addr: addr } = { addr: "http://localhost:1317" }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { SigningStargateClient } from "@cosmjs/stargate";
import { Registry, OfflineSigner, EncodeObject, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgRevokeModel } from "./types/compliance/tx";
import { MsgCertifyModel } from "./types/compliance/tx";
import { MsgProvisionModel } from "./types/compliance/tx";
import { MsgCertifyModel } from "./types/compliance/tx";


const types = [
["/zigbeealliance.distributedcomplianceledger.compliance.MsgRevokeModel", MsgRevokeModel],
["/zigbeealliance.distributedcomplianceledger.compliance.MsgCertifyModel", MsgCertifyModel],
["/zigbeealliance.distributedcomplianceledger.compliance.MsgProvisionModel", MsgProvisionModel],
["/zigbeealliance.distributedcomplianceledger.compliance.MsgCertifyModel", MsgCertifyModel],

];
export const MissingWalletError = new Error("wallet is required");
Expand Down Expand Up @@ -46,8 +46,8 @@ const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions =
return {
signAndBroadcast: (msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions = {fee: defaultFee, memo: ""}) => client.signAndBroadcast(address, msgs, fee,memo),
msgRevokeModel: (data: MsgRevokeModel): EncodeObject => ({ typeUrl: "/zigbeealliance.distributedcomplianceledger.compliance.MsgRevokeModel", value: MsgRevokeModel.fromPartial( data ) }),
msgCertifyModel: (data: MsgCertifyModel): EncodeObject => ({ typeUrl: "/zigbeealliance.distributedcomplianceledger.compliance.MsgCertifyModel", value: MsgCertifyModel.fromPartial( data ) }),
msgProvisionModel: (data: MsgProvisionModel): EncodeObject => ({ typeUrl: "/zigbeealliance.distributedcomplianceledger.compliance.MsgProvisionModel", value: MsgProvisionModel.fromPartial( data ) }),
msgCertifyModel: (data: MsgCertifyModel): EncodeObject => ({ typeUrl: "/zigbeealliance.distributedcomplianceledger.compliance.MsgCertifyModel", value: MsgCertifyModel.fromPartial( data ) }),

};
};
Expand Down
Loading

0 comments on commit 65e0fc5

Please sign in to comment.