@@ -18,15 +18,21 @@ import (
18
18
19
19
// Main
20
20
21
- func TestHandler_ProposeAddX509RootCert_ByTrustee (t * testing.T ) {
21
+ func TestHandler_ProposeAddDaRootCert (t * testing.T ) {
22
22
setup := Setup (t )
23
23
24
- // propose x509 root certificate
25
- proposeAddX509RootCert := types .NewMsgProposeAddX509RootCert (setup .Trustee1 .String (), testconstants .RootCertPem , testconstants .Info , testconstants .Vid , testconstants .CertSchemaVersion )
24
+ // propose DA root certificate
25
+ proposeAddX509RootCert := types .NewMsgProposeAddX509RootCert (
26
+ setup .Trustee1 .String (),
27
+ testconstants .RootCertPem ,
28
+ testconstants .Info ,
29
+ testconstants .Vid ,
30
+ testconstants .CertSchemaVersion ,
31
+ )
26
32
_ , err := setup .Handler (setup .Ctx , proposeAddX509RootCert )
27
33
require .NoError (t , err )
28
34
29
- // query proposed certificate
35
+ // Check: ProposedCertificate - present
30
36
proposedCertificate , _ := queryProposedCertificate (setup , testconstants .RootSubject , testconstants .RootSubjectKeyID )
31
37
require .Equal (t , proposeAddX509RootCert .Cert , proposedCertificate .PemCert )
32
38
require .Equal (t , proposeAddX509RootCert .Signer , proposedCertificate .Owner )
@@ -35,43 +41,68 @@ func TestHandler_ProposeAddX509RootCert_ByTrustee(t *testing.T) {
35
41
require .Equal (t , testconstants .RootSerialNumber , proposedCertificate .SerialNumber )
36
42
require .True (t , proposedCertificate .HasApprovalFrom (proposeAddX509RootCert .Signer ))
37
43
38
- // check that unique certificate key is registered
44
+ // Check: UniqueCertificate - present
39
45
require .True (t , setup .Keeper .IsUniqueCertificatePresent (
40
46
setup .Ctx , testconstants .RootIssuer , testconstants .RootSerialNumber ))
41
47
42
- // query approved certificate
43
- _ , err = querySingleApprovedCertificate (setup , testconstants .RootSubject , testconstants .RootSubjectKeyID )
44
- require .Error (t , err )
45
- require .Equal (t , codes .NotFound , status .Code (err ))
48
+ // Check: RejectedCertificate - empty
49
+ require .False (t , setup .Keeper .IsRejectedCertificatePresent (
50
+ setup .Ctx , testconstants .RootSubject , testconstants .RootSubjectKeyID ))
46
51
47
- // query approved certificate
48
- _ , err = querySingleCertificateFromAllCertificatesIndex (setup , testconstants .RootSubject , testconstants .RootSubjectKeyID )
49
- require .Error (t , err )
50
- require .Equal (t , codes .NotFound , status .Code (err ))
52
+ // Check: Approved DA - empty
53
+ ensureCertificateNotPresentInDaCertificateIndexes (
54
+ t ,
55
+ setup ,
56
+ testconstants .RootSubject ,
57
+ testconstants .RootSubjectKeyID ,
58
+ true ,
59
+ false ,
60
+ )
61
+
62
+ // Check: Global - empty
63
+ ensureGlobalCertificateNotExist (
64
+ t ,
65
+ setup ,
66
+ testconstants .RootSubject ,
67
+ testconstants .RootSubjectKeyID ,
68
+ false ,
69
+ )
51
70
}
52
71
53
- func TestHandler_ApproveAddX509RootCert_ForEnoughApprovals (t * testing.T ) {
72
+ func TestHandler_AddDaRootCert (t * testing.T ) {
54
73
setup := Setup (t )
55
74
56
75
// propose add x509 root certificate by trustee
57
- proposeAddX509RootCert := types .NewMsgProposeAddX509RootCert (setup .Trustee1 .String (), testconstants .RootCertPem , testconstants .Info , testconstants .Vid , testconstants .CertSchemaVersion )
76
+ proposeAddX509RootCert := types .NewMsgProposeAddX509RootCert (
77
+ setup .Trustee1 .String (),
78
+ testconstants .RootCertPem ,
79
+ testconstants .Info ,
80
+ testconstants .Vid ,
81
+ testconstants .CertSchemaVersion ,
82
+ )
58
83
_ , err := setup .Handler (setup .Ctx , proposeAddX509RootCert )
59
84
require .NoError (t , err )
60
85
61
86
// approve by second trustee
62
87
approveAddX509RootCert := types .NewMsgApproveAddX509RootCert (
63
- setup .Trustee2 .String (), testconstants .RootSubject , testconstants .RootSubjectKeyID , testconstants .Info )
88
+ setup .Trustee2 .String (),
89
+ testconstants .RootSubject ,
90
+ testconstants .RootSubjectKeyID ,
91
+ testconstants .Info ,
92
+ )
64
93
_ , err = setup .Handler (setup .Ctx , approveAddX509RootCert )
65
94
require .NoError (t , err )
66
95
67
- // DA proposed certificates indexes checks
68
- // query proposed certificate must be empty
69
- _ , err = queryProposedCertificate (setup , testconstants .RootSubject , testconstants .RootSubjectKeyID )
70
- require .Error (t , err )
71
- require .Equal (t , codes .NotFound , status .Code (err ))
96
+ // Check: ProposedCertificate - empty
97
+ require .False (t , setup .Keeper .IsProposedCertificatePresent (
98
+ setup .Ctx , testconstants .RootSubject , testconstants .RootSubjectKeyID ))
99
+
100
+ // Check: UniqueCertificate - present
101
+ require .True (t , setup .Keeper .IsUniqueCertificatePresent (
102
+ setup .Ctx , testconstants .RootIssuer , testconstants .RootSerialNumber ))
72
103
73
- // Check that root certificate exists
74
- ensureDaPaaCertificateExist (
104
+ // Check: DA + All + UniqueCertificate
105
+ ensureDaRootCertificateExist (
75
106
t ,
76
107
setup ,
77
108
testconstants .RootSubject ,
@@ -80,11 +111,17 @@ func TestHandler_ApproveAddX509RootCert_ForEnoughApprovals(t *testing.T) {
80
111
testconstants .RootSerialNumber )
81
112
}
82
113
83
- func TestHandler_TwoThirdApprovalsNeededForAddingRootCertification (t * testing.T ) {
114
+ func TestHandler_AddDaRootCert_TwoThirdApprovalsNeeded (t * testing.T ) {
84
115
setup := Setup (t )
85
116
86
117
// propose x509 root certificate by account without trustee role
87
- proposeAddX509RootCert := types .NewMsgProposeAddX509RootCert (setup .Trustee1 .String (), testconstants .RootCertPem , testconstants .Info , testconstants .Vid , testconstants .CertSchemaVersion )
118
+ proposeAddX509RootCert := types .NewMsgProposeAddX509RootCert (
119
+ setup .Trustee1 .String (),
120
+ testconstants .RootCertPem ,
121
+ testconstants .Info ,
122
+ testconstants .Vid ,
123
+ testconstants .CertSchemaVersion ,
124
+ )
88
125
_ , err := setup .Handler (setup .Ctx , proposeAddX509RootCert )
89
126
require .NoError (t , err )
90
127
@@ -105,7 +142,11 @@ func TestHandler_TwoThirdApprovalsNeededForAddingRootCertification(t *testing.T)
105
142
// Until we hit 2/3 of the total number of Trustees, we should not be able to approve the certificate
106
143
for i := 1 ; i < twoThirds - 1 ; i ++ {
107
144
approveAddX509RootCert := types .NewMsgApproveAddX509RootCert (
108
- trusteeAccounts [i ].String (), testconstants .RootSubject , testconstants .RootSubjectKeyID , testconstants .Info )
145
+ trusteeAccounts [i ].String (),
146
+ testconstants .RootSubject ,
147
+ testconstants .RootSubjectKeyID ,
148
+ testconstants .Info ,
149
+ )
109
150
_ , err = setup .Handler (setup .Ctx , approveAddX509RootCert )
110
151
require .NoError (t , err )
111
152
@@ -120,16 +161,25 @@ func TestHandler_TwoThirdApprovalsNeededForAddingRootCertification(t *testing.T)
120
161
_ , err = setup .Handler (setup .Ctx , approveAddX509RootCert )
121
162
require .NoError (t , err )
122
163
123
- // Check that root certificate exists
124
- ensureDaPaaCertificateExist (
164
+ // Check: ProposedCertificate - empty
165
+ require .False (t , setup .Keeper .IsProposedCertificatePresent (
166
+ setup .Ctx , testconstants .RootSubject , testconstants .RootSubjectKeyID ))
167
+
168
+ // Check: UniqueCertificate - present
169
+ require .True (t , setup .Keeper .IsUniqueCertificatePresent (
170
+ setup .Ctx , testconstants .RootIssuer , testconstants .RootSerialNumber ))
171
+
172
+ // Check: DA + All + UniqueCertificate
173
+ ensureDaRootCertificateExist (
125
174
t ,
126
175
setup ,
127
176
testconstants .RootSubject ,
128
177
testconstants .RootSubjectKeyID ,
129
178
testconstants .RootIssuer ,
130
- testconstants .RootSerialNumber )
179
+ testconstants .RootSerialNumber ,
180
+ )
131
181
132
- // query approved certificate and we should get one back
182
+ // Check: Approvals
133
183
approvedCertificate , _ := querySingleApprovedCertificate (setup , testconstants .RootSubject , testconstants .RootSubjectKeyID )
134
184
require .Equal (t , testconstants .RootIssuer , approvedCertificate .Subject )
135
185
require .Equal (t , testconstants .RootSerialNumber , approvedCertificate .SerialNumber )
@@ -142,7 +192,7 @@ func TestHandler_TwoThirdApprovalsNeededForAddingRootCertification(t *testing.T)
142
192
require .Equal (t , approvedCertificate .HasApprovalFrom (setup .Trustee2 .String ()), true )
143
193
}
144
194
145
- func TestHandler_ApproveX509RootCert_FourApprovalsAreNeeded_FiveTrustees (t * testing.T ) {
195
+ func TestHandler_AddDaRootCert_FourApprovalsAreNeeded_FiveTrustees (t * testing.T ) {
146
196
setup := Setup (t )
147
197
148
198
// we have 5 trustees: 1 approval comes from propose => we need 3 more approvals
@@ -156,43 +206,70 @@ func TestHandler_ApproveX509RootCert_FourApprovalsAreNeeded_FiveTrustees(t *test
156
206
setup .AddAccount (fifthTrustee , []dclauthtypes.AccountRole {dclauthtypes .Trustee }, 1 )
157
207
158
208
// propose x509 root certificate by account Trustee1
159
- proposeAddX509RootCert := types .NewMsgProposeAddX509RootCert (setup .Trustee1 .String (), testconstants .RootCertPem , testconstants .Info , testconstants .Vid , testconstants .CertSchemaVersion )
209
+ proposeAddX509RootCert := types .NewMsgProposeAddX509RootCert (
210
+ setup .Trustee1 .String (),
211
+ testconstants .RootCertPem ,
212
+ testconstants .Info ,
213
+ testconstants .Vid ,
214
+ testconstants .CertSchemaVersion ,
215
+ )
160
216
_ , err := setup .Handler (setup .Ctx , proposeAddX509RootCert )
161
217
require .NoError (t , err )
162
218
163
219
// approve x509 root certificate by account Trustee2
164
- approveAddX509RootCert := types .NewMsgApproveAddX509RootCert (setup .Trustee2 .String (), testconstants .RootSubject , testconstants .RootSubjectKeyID , testconstants .Info )
220
+ approveAddX509RootCert := types .NewMsgApproveAddX509RootCert (
221
+ setup .Trustee2 .String (),
222
+ testconstants .RootSubject ,
223
+ testconstants .RootSubjectKeyID ,
224
+ testconstants .Info ,
225
+ )
165
226
_ , err = setup .Handler (setup .Ctx , approveAddX509RootCert )
166
227
require .NoError (t , err )
167
228
168
229
// approve x509 root certificate by account Trustee3
169
- approveAddX509RootCert = types .NewMsgApproveAddX509RootCert (setup .Trustee3 .String (), testconstants .RootSubject , testconstants .RootSubjectKeyID , testconstants .Info )
230
+ approveAddX509RootCert = types .NewMsgApproveAddX509RootCert (
231
+ setup .Trustee3 .String (),
232
+ testconstants .RootSubject ,
233
+ testconstants .RootSubjectKeyID ,
234
+ testconstants .Info ,
235
+ )
170
236
_ , err = setup .Handler (setup .Ctx , approveAddX509RootCert )
171
237
require .NoError (t , err )
172
238
173
239
// reject x509 root certificate by account Trustee4
174
- rejectAddX509RootCert := types .NewMsgRejectAddX509RootCert (fourthTrustee .String (), testconstants .RootSubject , testconstants .RootSubjectKeyID , testconstants .Info )
240
+ rejectAddX509RootCert := types .NewMsgRejectAddX509RootCert (
241
+ fourthTrustee .String (),
242
+ testconstants .RootSubject ,
243
+ testconstants .RootSubjectKeyID ,
244
+ testconstants .Info ,
245
+ )
175
246
_ , err = setup .Handler (setup .Ctx , rejectAddX509RootCert )
176
247
require .NoError (t , err )
177
248
178
- // certificate should be in the entity <Proposed X509 Root Certificate>, because we haven't enough approvals
179
- proposedCertificate , err := queryProposedCertificate (setup , testconstants .RootSubject , testconstants .RootSubjectKeyID )
180
- require .NoError (t , err )
181
-
182
- // check proposed certificate
183
- require .Equal (t , proposeAddX509RootCert .Cert , proposedCertificate .PemCert )
184
- require .Equal (t , proposeAddX509RootCert .Signer , proposedCertificate .Owner )
185
- require .Equal (t , testconstants .RootSubject , proposedCertificate .Subject )
186
- require .Equal (t , testconstants .RootSubjectKeyID , proposedCertificate .SubjectKeyId )
187
- require .Equal (t , testconstants .RootSerialNumber , proposedCertificate .SerialNumber )
249
+ // Check: ProposedCertificate - present because we haven't enough approvals
250
+ require .True (t , setup .Keeper .IsProposedCertificatePresent (
251
+ setup .Ctx , testconstants .RootSubject , testconstants .RootSubjectKeyID ))
188
252
189
253
// approve x509 root certificate by account Trustee5
190
- approveAddX509RootCert = types .NewMsgApproveAddX509RootCert (fifthTrustee .String (), testconstants .RootSubject , testconstants .RootSubjectKeyID , testconstants .Info )
254
+ approveAddX509RootCert = types .NewMsgApproveAddX509RootCert (
255
+ fifthTrustee .String (),
256
+ testconstants .RootSubject ,
257
+ testconstants .RootSubjectKeyID ,
258
+ testconstants .Info ,
259
+ )
191
260
_ , err = setup .Handler (setup .Ctx , approveAddX509RootCert )
192
261
require .NoError (t , err )
193
262
194
- // certificate should be in the entity <X509 Root Certificate>, because we have enough approvals
195
- ensureDaPaaCertificateExist (
263
+ // Check: ProposedCertificate - empty
264
+ require .False (t , setup .Keeper .IsProposedCertificatePresent (
265
+ setup .Ctx , testconstants .RootSubject , testconstants .RootSubjectKeyID ))
266
+
267
+ // Check: UniqueCertificate - present
268
+ require .True (t , setup .Keeper .IsUniqueCertificatePresent (
269
+ setup .Ctx , testconstants .RootIssuer , testconstants .RootSerialNumber ))
270
+
271
+ // Check: DA + All + UniqueCertificate
272
+ ensureDaRootCertificateExist (
196
273
t ,
197
274
setup ,
198
275
testconstants .RootSubject ,
0 commit comments