1
1
package tests
2
2
3
3
import (
4
+ "github.com/zigbee-alliance/distributed-compliance-ledger/x/pki/tests/utils"
4
5
"testing"
5
6
6
7
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -15,18 +16,18 @@ import (
15
16
// Main
16
17
17
18
func TestHandler_AddNocIntermediateCert (t * testing.T ) {
18
- setup := Setup (t )
19
+ setup := utils . Setup (t )
19
20
20
21
accAddress := setup .CreateVendorAccount (testconstants .Vid )
21
22
22
23
// add NOC root certificate
23
- addNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
24
+ utils . AddNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
24
25
25
26
// add NOC ICA certificate
26
- addNocIntermediateCertificate (setup , accAddress , testconstants .NocCert1 )
27
+ utils . AddNocIntermediateCertificate (setup , accAddress , testconstants .NocCert1 )
27
28
28
29
// Check: Noc + All + UniqueCertificate
29
- ensureNocIntermediateCertificateExist (
30
+ utils . EnsureNocIntermediateCertificateExist (
30
31
t ,
31
32
setup ,
32
33
testconstants .NocCert1Subject ,
@@ -38,7 +39,7 @@ func TestHandler_AddNocIntermediateCert(t *testing.T) {
38
39
)
39
40
40
41
// ChildCertificates: check that child certificates of issuer contains certificate identifier
41
- ensureChildCertificateExist (
42
+ utils . EnsureChildCertificateExist (
42
43
t ,
43
44
setup ,
44
45
testconstants .NocRootCert1Subject ,
@@ -51,14 +52,14 @@ func TestHandler_AddNocIntermediateCert(t *testing.T) {
51
52
// Extra cases
52
53
53
54
func TestHandler_AddNocX509Cert_Renew (t * testing.T ) {
54
- setup := Setup (t )
55
+ setup := utils . Setup (t )
55
56
56
- accAddress := GenerateAccAddress ()
57
+ accAddress := utils . GenerateAccAddress ()
57
58
vid := testconstants .Vid
58
59
setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, testconstants .Vid )
59
60
60
61
// add NOC root certificate
61
- addNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
62
+ utils . AddNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
62
63
63
64
// Store the NOC certificate
64
65
newNocCertificate := types .NewNocCertificate (
@@ -95,18 +96,18 @@ func TestHandler_AddNocX509Cert_Renew(t *testing.T) {
95
96
require .NoError (t , err )
96
97
97
98
// query noc certificate by Subject and SKID
98
- nocCertificates , err := queryNocCertificates (setup , newNocCertificate .Subject , newNocCertificate .SubjectKeyId )
99
+ nocCertificates , err := utils . QueryNocCertificates (setup , newNocCertificate .Subject , newNocCertificate .SubjectKeyId )
99
100
require .NoError (t , err )
100
101
require .Equal (t , len (nocCertificates .Certs ), 2 )
101
102
require .Equal (t , & newNocCertificate , nocCertificates .Certs [0 ])
102
103
103
104
// query noc certificate by Subject
104
- nocCertificatesBySubject , err := queryNocCertificatesBySubject (setup , newNocCertificate .Subject )
105
+ nocCertificatesBySubject , err := utils . QueryNocCertificatesBySubject (setup , newNocCertificate .Subject )
105
106
require .NoError (t , err )
106
107
require .Equal (t , 1 , len (nocCertificatesBySubject .SubjectKeyIds ))
107
108
108
109
// query noc certificate by SKID
109
- nocCertificatesBySubjectKeyID , err := queryAllNocCertificatesBySubjectKeyID (setup , newNocCertificate .SubjectKeyId )
110
+ nocCertificatesBySubjectKeyID , err := utils . QueryNocCertificatesBySubjectKeyID (setup , newNocCertificate .SubjectKeyId )
110
111
require .NoError (t , err )
111
112
require .Equal (t , 1 , len (nocCertificatesBySubjectKeyID ))
112
113
require .Equal (t , 2 , len (nocCertificatesBySubjectKeyID [0 ].Certs ))
@@ -115,7 +116,7 @@ func TestHandler_AddNocX509Cert_Renew(t *testing.T) {
115
116
require .Equal (t , vid , nocCertificatesBySubjectKeyID [0 ].Certs [0 ].Vid )
116
117
117
118
// query noc certificate by VID
118
- nocCertificatesByVid , err := queryNocIcaCertificatesByVid (setup , testconstants .Vid )
119
+ nocCertificatesByVid , err := utils . QueryNocIcaCertificatesByVid (setup , testconstants .Vid )
119
120
require .NoError (t , err )
120
121
require .Equal (t , len (nocCertificatesByVid .Certs ), 2 )
121
122
require .Equal (t , testconstants .NocCert1Subject , nocCertificatesByVid .Certs [0 ].Subject )
@@ -126,7 +127,7 @@ func TestHandler_AddNocX509Cert_Renew(t *testing.T) {
126
127
// Error cases
127
128
128
129
func TestHandler_AddNocX509Cert_SenderNotVendor (t * testing.T ) {
129
- setup := Setup (t )
130
+ setup := utils . Setup (t )
130
131
131
132
addNocX509Cert := types .NewMsgAddNocX509IcaCert (setup .Trustee1 .String (), testconstants .NocCert1 , testconstants .CertSchemaVersion )
132
133
_ , err := setup .Handler (setup .Ctx , addNocX509Cert )
@@ -135,16 +136,16 @@ func TestHandler_AddNocX509Cert_SenderNotVendor(t *testing.T) {
135
136
}
136
137
137
138
func TestHandler_AddNocX509Cert_Root_VID_Does_Not_Equal_To_AccountVID (t * testing.T ) {
138
- setup := Setup (t )
139
+ setup := utils . Setup (t )
139
140
140
- accAddress := GenerateAccAddress ()
141
+ accAddress := utils . GenerateAccAddress ()
141
142
vid := testconstants .Vid
142
143
setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
143
144
144
145
// add NOC root certificate
145
- addNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
146
+ utils . AddNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
146
147
147
- newAccAddress := GenerateAccAddress ()
148
+ newAccAddress := utils . GenerateAccAddress ()
148
149
setup .AddAccount (newAccAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, 1111 )
149
150
150
151
// try to add NOC certificate
@@ -154,9 +155,9 @@ func TestHandler_AddNocX509Cert_Root_VID_Does_Not_Equal_To_AccountVID(t *testing
154
155
}
155
156
156
157
func TestHandler_AddNocX509Cert_ForInvalidCertificate (t * testing.T ) {
157
- setup := Setup (t )
158
+ setup := utils . Setup (t )
158
159
159
- accAddress := GenerateAccAddress ()
160
+ accAddress := utils . GenerateAccAddress ()
160
161
vid := testconstants .Vid
161
162
setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
162
163
@@ -167,9 +168,9 @@ func TestHandler_AddNocX509Cert_ForInvalidCertificate(t *testing.T) {
167
168
}
168
169
169
170
func TestHandler_AddXNoc509Cert_ForNocRootCertificate (t * testing.T ) {
170
- setup := Setup (t )
171
+ setup := utils . Setup (t )
171
172
172
- accAddress := GenerateAccAddress ()
173
+ accAddress := utils . GenerateAccAddress ()
173
174
vid := testconstants .Vid
174
175
setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
175
176
@@ -180,21 +181,21 @@ func TestHandler_AddXNoc509Cert_ForNocRootCertificate(t *testing.T) {
180
181
}
181
182
182
183
func TestHandler_AddXNoc509Cert_ForRootNonNocCertificate (t * testing.T ) {
183
- setup := Setup (t )
184
+ setup := utils . Setup (t )
184
185
185
- accAddress := GenerateAccAddress ()
186
+ accAddress := utils . GenerateAccAddress ()
186
187
vid := testconstants .Vid
187
188
setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
188
189
189
190
// store root certificate
190
- rootCertOptions := & rootCertOptions {
191
- pemCert : testconstants .RootCertWithVid ,
192
- info : testconstants .Info ,
193
- subject : testconstants .RootCertWithVidSubject ,
194
- subjectKeyID : testconstants .RootCertWithVidSubjectKeyID ,
195
- vid : testconstants .RootCertWithVidVid ,
191
+ rootCertOptions := & utils. RootCertOptions {
192
+ PemCert : testconstants .RootCertWithVid ,
193
+ Info : testconstants .Info ,
194
+ Subject : testconstants .RootCertWithVidSubject ,
195
+ SubjectKeyID : testconstants .RootCertWithVidSubjectKeyID ,
196
+ Vid : testconstants .RootCertWithVidVid ,
196
197
}
197
- proposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCertOptions )
198
+ utils . ProposeAndApproveRootCertificate (setup , setup .Trustee1 , rootCertOptions )
198
199
199
200
// try to add root certificate x509 certificate
200
201
addX509Cert := types .NewMsgAddNocX509IcaCert (accAddress .String (), testconstants .IntermediateCertWithVid1 , testconstants .CertSchemaVersion )
@@ -203,9 +204,9 @@ func TestHandler_AddXNoc509Cert_ForRootNonNocCertificate(t *testing.T) {
203
204
}
204
205
205
206
func TestHandler_AddXNoc509Cert_WhenNocRootCertIsAbsent (t * testing.T ) {
206
- setup := Setup (t )
207
+ setup := utils . Setup (t )
207
208
208
- accAddress := GenerateAccAddress ()
209
+ accAddress := utils . GenerateAccAddress ()
209
210
vid := testconstants .Vid
210
211
setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
211
212
@@ -217,7 +218,7 @@ func TestHandler_AddXNoc509Cert_WhenNocRootCertIsAbsent(t *testing.T) {
217
218
}
218
219
219
220
func TestHandler_AddNocX509Cert_CertificateExist (t * testing.T ) {
220
- accAddress := GenerateAccAddress ()
221
+ accAddress := utils . GenerateAccAddress ()
221
222
222
223
cases := []struct {
223
224
name string
@@ -325,12 +326,12 @@ func TestHandler_AddNocX509Cert_CertificateExist(t *testing.T) {
325
326
326
327
for _ , tc := range cases {
327
328
t .Run (tc .name , func (t * testing.T ) {
328
- setup := Setup (t )
329
+ setup := utils . Setup (t )
329
330
vid := testconstants .Vid
330
331
setup .AddAccount (accAddress , []dclauthtypes.AccountRole {dclauthtypes .Vendor }, vid )
331
332
332
333
// add NOC root certificate
333
- addNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
334
+ utils . AddNocRootCertificate (setup , accAddress , testconstants .NocRootCert1 )
334
335
335
336
// add the existing certificate
336
337
setup .Keeper .AddAllCertificate (setup .Ctx , * tc .existingCert )
0 commit comments