11from plenum .common .constants import TXN_TYPE , TARGET_NYM , AUDIT_TXN_LEDGER_ROOT , AUDIT_TXN_STATE_ROOT , TXN_PAYLOAD , \
2- TXN_PAYLOAD_DATA , TXN_METADATA , TXN_METADATA_SEQ_NO , TXN_AUTHOR_AGREEMENT_AML , AML_VERSION , ROLE , DATA , ALIAS
2+ TXN_PAYLOAD_DATA , TXN_METADATA , TXN_METADATA_SEQ_NO , TXN_AUTHOR_AGREEMENT_AML , AML_VERSION , ROLE , DATA , ALIAS , CURRENT_PROTOCOL_VERSION
33from plenum .common .ledger import Ledger
44from plenum .common .transactions import PlenumTransactions
55from plenum .server .batch_handlers .three_pc_batch import ThreePcBatch
6- from plenum .test .helper import sdk_gen_request
6+ from plenum .test .helper import sdk_gen_request , sdk_sign_request_objects
7+ from plenum .common .request import Request as PlenumRequest
8+ import json
79
810
9- def test_audit_ledger_multiple_ledgers_in_one_batch (txnPoolNodeSet ):
11+ def test_audit_ledger_multiple_ledgers_in_one_batch (txnPoolNodeSet , looper , sdk_wallet_trustee , sdk_pool_handle ):
1012 # Checking first case -- first audit txn
1113 node = txnPoolNodeSet [0 ]
1214 audit_batch_handler = node .write_manager .audit_b_handler
15+
16+ # Create a NYM operation
1317 op = {
1418 TXN_TYPE : PlenumTransactions .NYM .value ,
1519 TARGET_NYM : "000000000000000000000000Trustee4"
1620 }
17- nym_req = sdk_gen_request (op , signatures = {"sig1" : "111" })
21+
22+ # Use proper signing instead of hardcoded signatures
23+ req_obj = sdk_gen_request (op , protocol_version = CURRENT_PROTOCOL_VERSION ,
24+ identifier = sdk_wallet_trustee [1 ]) # Use the trustee DID
25+
26+ # Sign the request properly
27+ indy_vdr_req = sdk_sign_request_objects (looper , sdk_wallet_trustee , [req_obj ])[0 ]
28+
29+ # Convert indy-vdr Request to plenum Request
30+ req_dict = json .loads (indy_vdr_req .body )
31+ nym_req = PlenumRequest (
32+ identifier = req_dict .get ('identifier' ),
33+ reqId = req_dict .get ('reqId' ),
34+ operation = req_dict .get ('operation' ),
35+ signature = req_dict .get ('signature' ),
36+ protocolVersion = req_dict .get ('protocolVersion' )
37+ )
38+
39+ # Apply the request
1840 node .write_manager .apply_request (nym_req , 10000 )
19- op2 = {TXN_TYPE : TXN_AUTHOR_AGREEMENT_AML ,
20- AML_VERSION : "version1" }
21- pool_config_req = sdk_gen_request (op2 , signatures = {"sig1" : "111" })
41+
42+ # Similarly for the second request
43+ op2 = {
44+ TXN_TYPE : TXN_AUTHOR_AGREEMENT_AML ,
45+ AML_VERSION : "version1"
46+ }
47+
48+ req_obj2 = sdk_gen_request (op2 , protocol_version = CURRENT_PROTOCOL_VERSION ,
49+ identifier = sdk_wallet_trustee [1 ])
50+ indy_vdr_req2 = sdk_sign_request_objects (looper , sdk_wallet_trustee , [req_obj2 ])[0 ]
51+
52+ # Convert indy-vdr Request to plenum Request
53+ req_dict2 = json .loads (indy_vdr_req2 .body )
54+ pool_config_req = PlenumRequest (
55+ identifier = req_dict2 .get ('identifier' ),
56+ reqId = req_dict2 .get ('reqId' ),
57+ operation = req_dict2 .get ('operation' ),
58+ signature = req_dict2 .get ('signature' ),
59+ protocolVersion = req_dict2 .get ('protocolVersion' )
60+ )
61+
2262 node .write_manager .apply_request (pool_config_req , 10000 )
2363
2464 domain_root_hash = Ledger .hashToStr (node .domainLedger .uncommittedRootHash )
@@ -41,11 +81,42 @@ def test_audit_ledger_multiple_ledgers_in_one_batch(txnPoolNodeSet):
4181 TXN_TYPE : PlenumTransactions .NYM .value ,
4282 TARGET_NYM : "000000000000000000000000Trustee5"
4383 }
44- nym_req = sdk_gen_request (op , signatures = {"sig1" : "111" })
84+
85+ req_obj = sdk_gen_request (op , protocol_version = CURRENT_PROTOCOL_VERSION ,
86+ identifier = sdk_wallet_trustee [1 ])
87+ indy_vdr_req = sdk_sign_request_objects (looper , sdk_wallet_trustee , [req_obj ])[0 ]
88+
89+ # Convert indy-vdr Request to plenum Request
90+ req_dict = json .loads (indy_vdr_req .body )
91+ nym_req = PlenumRequest (
92+ identifier = req_dict .get ('identifier' ),
93+ reqId = req_dict .get ('reqId' ),
94+ operation = req_dict .get ('operation' ),
95+ signature = req_dict .get ('signature' ),
96+ protocolVersion = req_dict .get ('protocolVersion' )
97+ )
98+
4599 node .write_manager .apply_request (nym_req , 10000 )
46- op2 = {TXN_TYPE : TXN_AUTHOR_AGREEMENT_AML ,
47- AML_VERSION : "version2" }
48- pool_config_req = sdk_gen_request (op2 , signatures = {"sig1" : "111" })
100+
101+ op2 = {
102+ TXN_TYPE : TXN_AUTHOR_AGREEMENT_AML ,
103+ AML_VERSION : "version2"
104+ }
105+
106+ req_obj2 = sdk_gen_request (op2 , protocol_version = CURRENT_PROTOCOL_VERSION ,
107+ identifier = sdk_wallet_trustee [1 ])
108+ indy_vdr_req2 = sdk_sign_request_objects (looper , sdk_wallet_trustee , [req_obj2 ])[0 ]
109+
110+ # Convert indy-vdr Request to plenum Request
111+ req_dict2 = json .loads (indy_vdr_req2 .body )
112+ pool_config_req = PlenumRequest (
113+ identifier = req_dict2 .get ('identifier' ),
114+ reqId = req_dict2 .get ('reqId' ),
115+ operation = req_dict2 .get ('operation' ),
116+ signature = req_dict2 .get ('signature' ),
117+ protocolVersion = req_dict2 .get ('protocolVersion' )
118+ )
119+
49120 node .write_manager .apply_request (pool_config_req , 10000 )
50121
51122 # Checking second batch created
@@ -65,7 +136,7 @@ def test_audit_ledger_multiple_ledgers_in_one_batch(txnPoolNodeSet):
65136 assert txn_data [AUDIT_TXN_STATE_ROOT ][2 ] == config_state_root_2
66137
67138
68- def test_multiple_ledgers_in_second_batch_apply_first_time (txnPoolNodeSet ):
139+ def test_multiple_ledgers_in_second_batch_apply_first_time (txnPoolNodeSet , looper , sdk_wallet_trustee , sdk_pool_handle ):
69140 # First txn
70141 node = txnPoolNodeSet [0 ]
71142 audit_batch_handler = node .write_manager .audit_b_handler
@@ -74,11 +145,42 @@ def test_multiple_ledgers_in_second_batch_apply_first_time(txnPoolNodeSet):
74145 TARGET_NYM : "000000000000000000000000Trustee4" ,
75146 ROLE : None
76147 }
77- nym_req = sdk_gen_request (op , signatures = {"sig1" : "111" })
148+
149+ req_obj = sdk_gen_request (op , protocol_version = CURRENT_PROTOCOL_VERSION ,
150+ identifier = sdk_wallet_trustee [1 ])
151+ indy_vdr_req = sdk_sign_request_objects (looper , sdk_wallet_trustee , [req_obj ])[0 ]
152+
153+ # Convert indy-vdr Request to plenum Request
154+ req_dict = json .loads (indy_vdr_req .body )
155+ nym_req = PlenumRequest (
156+ identifier = req_dict .get ('identifier' ),
157+ reqId = req_dict .get ('reqId' ),
158+ operation = req_dict .get ('operation' ),
159+ signature = req_dict .get ('signature' ),
160+ protocolVersion = req_dict .get ('protocolVersion' )
161+ )
162+
78163 node .write_manager .apply_request (nym_req , 10000 )
79- op2 = {TXN_TYPE : TXN_AUTHOR_AGREEMENT_AML ,
80- AML_VERSION : "version2" }
81- pool_config_req = sdk_gen_request (op2 , signatures = {"sig1" : "111" })
164+
165+ op2 = {
166+ TXN_TYPE : TXN_AUTHOR_AGREEMENT_AML ,
167+ AML_VERSION : "version2"
168+ }
169+
170+ req_obj2 = sdk_gen_request (op2 , protocol_version = CURRENT_PROTOCOL_VERSION ,
171+ identifier = sdk_wallet_trustee [1 ])
172+ indy_vdr_req2 = sdk_sign_request_objects (looper , sdk_wallet_trustee , [req_obj2 ])[0 ]
173+
174+ # Convert indy-vdr Request to plenum Request
175+ req_dict2 = json .loads (indy_vdr_req2 .body )
176+ pool_config_req = PlenumRequest (
177+ identifier = req_dict2 .get ('identifier' ),
178+ reqId = req_dict2 .get ('reqId' ),
179+ operation = req_dict2 .get ('operation' ),
180+ signature = req_dict2 .get ('signature' ),
181+ protocolVersion = req_dict2 .get ('protocolVersion' )
182+ )
183+
82184 node .write_manager .apply_request (pool_config_req , 10000 )
83185
84186 domain_root_hash = Ledger .hashToStr (node .domainLedger .uncommittedRootHash )
@@ -94,12 +196,42 @@ def test_multiple_ledgers_in_second_batch_apply_first_time(txnPoolNodeSet):
94196 TARGET_NYM : "000000000000000000000000Trustee1" ,
95197 DATA : {ALIAS : "Node100" }
96198 }
97- node_req = sdk_gen_request (op2 , signatures = {"sig1" : "111" })
199+
200+ req_obj2 = sdk_gen_request (op2 , protocol_version = CURRENT_PROTOCOL_VERSION ,
201+ identifier = sdk_wallet_trustee [1 ])
202+ indy_vdr_req2 = sdk_sign_request_objects (looper , sdk_wallet_trustee , [req_obj2 ])[0 ]
203+
204+ # Convert indy-vdr Request to plenum Request
205+ req_dict2 = json .loads (indy_vdr_req2 .body )
206+ node_req = PlenumRequest (
207+ identifier = req_dict2 .get ('identifier' ),
208+ reqId = req_dict2 .get ('reqId' ),
209+ operation = req_dict2 .get ('operation' ),
210+ signature = req_dict2 .get ('signature' ),
211+ protocolVersion = req_dict2 .get ('protocolVersion' )
212+ )
213+
98214 node .write_manager .apply_request (node_req , 10000 )
99215
100- op2 = {TXN_TYPE : TXN_AUTHOR_AGREEMENT_AML ,
101- AML_VERSION : "version2" }
102- pool_config_req = sdk_gen_request (op2 , signatures = {"sig1" : "111" })
216+ op2 = {
217+ TXN_TYPE : TXN_AUTHOR_AGREEMENT_AML ,
218+ AML_VERSION : "version2"
219+ }
220+
221+ req_obj2 = sdk_gen_request (op2 , protocol_version = CURRENT_PROTOCOL_VERSION ,
222+ identifier = sdk_wallet_trustee [1 ])
223+ indy_vdr_req2 = sdk_sign_request_objects (looper , sdk_wallet_trustee , [req_obj2 ])[0 ]
224+
225+ # Convert indy-vdr Request to plenum Request
226+ req_dict2 = json .loads (indy_vdr_req2 .body )
227+ pool_config_req = PlenumRequest (
228+ identifier = req_dict2 .get ('identifier' ),
229+ reqId = req_dict2 .get ('reqId' ),
230+ operation = req_dict2 .get ('operation' ),
231+ signature = req_dict2 .get ('signature' ),
232+ protocolVersion = req_dict2 .get ('protocolVersion' )
233+ )
234+
103235 node .write_manager .apply_request (pool_config_req , 10000 )
104236
105237 pool_root_hash = Ledger .hashToStr (node .poolLedger .uncommittedRootHash )
0 commit comments