-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathvendorinfo-demo.sh
executable file
·161 lines (132 loc) · 6.04 KB
/
vendorinfo-demo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# Copyright 2020 DSR Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -euo pipefail
source integration_tests/cli/common.sh
# Preparation of Actors
vid=$RANDOM
vid2=$RANDOM
vendor_account=vendor_account_$vid
second_vendor_account=vendor_account_$vid2
vendor_admin_account=vendor_admin_account
echo "Create First Vendor Account - $vendor_account"
create_new_vendor_account $vendor_account $vid
echo "Create Second Vendor Account - $second_vendor_account"
create_new_vendor_account $second_vendor_account $vid2
echo "Create A VendorAdmin Account - $vendor_admin_account"
create_new_account $vendor_admin_account "VendorAdmin"
test_divider
# Query non existent
echo "Query non existent vendorinfo"
result=$(dcld query vendorinfo vendor --vid=$vid)
check_response "$result" "Not Found"
echo "$result"
test_divider
echo "Request all vendor info must be empty"
result=$(dcld query vendorinfo all-vendors)
check_response "$result" "\[\]"
echo "$result"
test_divider
# Create a vendor info record
echo "Create VendorInfo Record for VID: $vid"
companyLegalName="XYZ IOT Devices Inc"
vendorName="XYZ Devices"
schema_version_2=2
result=$(echo "test1234" | dcld tx vendorinfo add-vendor --vid=$vid --companyLegalName="$companyLegalName" --vendorName="$vendorName" --schemaVersion=$schema_version_2 --from=$vendor_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$result"
test_divider
# Query vendor info record
echo "Verify if VendorInfo Record for VID: $vid is present or not"
result=$(dcld query vendorinfo vendor --vid=$vid)
check_response "$result" "\"vendorID\": $vid"
check_response "$result" "\"companyLegalName\": \"$companyLegalName\""
check_response "$result" "\"vendorName\": \"$vendorName\""
check_response "$result" "\"schemaVersion\": $schema_version_2"
echo "$result"
test_divider
echo "Request all vendor info"
result=$(dcld query vendorinfo all-vendors)
check_response "$result" "\"vendorID\": $vid"
check_response "$result" "\"companyLegalName\": \"$companyLegalName\""
check_response "$result" "\"vendorName\": \"$vendorName\""
echo "$result"
test_divider
# Update vendor info with empty optional fields
echo "Update vendor info record for VID: $vid (with required fields only)"
result=$(dcld tx vendorinfo update-vendor --vid=$vid --from=$vendor_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$result"
test_divider
# Query updated vendor info record
echo "Verify that omitted fields in update object are not set to empty string"
result=$(dcld query vendorinfo vendor --vid=$vid)
check_response "$result" "\"vendorID\": $vid"
check_response "$result" "\"companyLegalName\": \"$companyLegalName\""
check_response "$result" "\"vendorName\": \"$vendorName\""
echo "$result"
test_divider
# Update vendor info record
echo "Update vendor info record for VID: $vid"
companyLegalName="ABC Subsidiary Corporation"
vendorLandingPageURL="https://www.w3.org/"
schema_version_3=3
result=$(echo "test1234" | dcld tx vendorinfo update-vendor --vid=$vid --companyLegalName="$companyLegalName" --vendorLandingPageURL=$vendorLandingPageURL --vendorName="$vendorName" --schemaVersion=$schema_version_3 --from=$vendor_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$result"
test_divider
# Query updated vendor info record
echo "Verify if VendorInfo Record for VID: $vid is updated or not"
result=$(dcld query vendorinfo vendor --vid=$vid)
check_response "$result" "\"vendorID\": $vid"
check_response "$result" "\"companyLegalName\": \"$companyLegalName\""
check_response "$result" "\"vendorName\": \"$vendorName\""
check_response "$result" "\"vendorLandingPageURL\": \"$vendorLandingPageURL\""
check_response "$result" "\"schemaVersion\": $schema_version_3"
echo "$result"
test_divider
# Create a vendor info record from a vendor account belonging to another vendor_account
vid1=$RANDOM
result=$(echo "test1234" | dcld tx vendorinfo add-vendor --vid=$vid1 --companyLegalName="$companyLegalName" --vendorName="$vendorName" --from=$vendor_account --yes 2>&1) || true
result=$(get_txn_result "$result")
echo "$result"
check_response_and_report "$result" "transaction should be signed by a vendor account associated with the vendorID $vid1"
test_divider
# Update a vendor info record from a vendor account belonging to another vendor_account
result=$(echo "test1234" | dcld tx vendorinfo update-vendor --vid=$vid --companyLegalName="$companyLegalName" --vendorName="$vendorName" --from=$second_vendor_account --yes 2>&1) || true
result=$(get_txn_result "$result")
echo "$result"
check_response_and_report "$result" "transaction should be signed by a vendor account associated with the vendorID $vid"
test_divider
# Create a vendor info reacord from a vendor admin account
echo "Create a vendor info reacord from a vendor admin account"
vid=$RANDOM
result=$(echo "test1234" | dcld tx vendorinfo add-vendor --vid=$vid --companyLegalName="$companyLegalName" --vendorName="$vendorName" --from=$vendor_admin_account --yes 2>&1) || true
result=$(get_txn_result "$result")
echo "$result"
check_response "$result" "\"code\": 0"
echo "$result"
test_divider
# Update the vendor info record by a vendor admin account
echo "Update the vendor info record by a vendor admin account"
companyLegalName1="New Corp"
vendorName1="New Vendor Name"
result=$(echo "test1234" | dcld tx vendorinfo update-vendor --vid=$vid --companyLegalName="$companyLegalName1" --vendorName="$vendorName1" --from=$vendor_admin_account --yes)
result=$(get_txn_result "$result")
check_response "$result" "\"code\": 0"
echo "$result"
test_divider