|
| 1 | +from random import random |
1 | 2 | import pytest
|
2 | 3 |
|
3 | 4 | from indy_common.constants import REVOC_REG_ENTRY, REVOC_REG_DEF_ID, ISSUANCE_BY_DEFAULT, \
|
4 |
| - VALUE, ISSUANCE_TYPE, ISSUED, REVOKED, ACCUM |
| 5 | + VALUE, ISSUANCE_TYPE, ISSUED, REVOKED, ACCUM, REVOC_REG_DEF, CRED_DEF_ID, REVOC_TYPE, TAG |
| 6 | +from indy_common.config_util import getConfig |
5 | 7 | from indy_node.server.request_handlers.domain_req_handlers.revoc_reg_def_handler import RevocRegDefHandler
|
6 | 8 | from indy_node.server.request_handlers.domain_req_handlers.revoc_reg_entry_handler import RevocRegEntryHandler
|
| 9 | +from indy_node.test.request_handlers.conftest import revoc_reg_def_request |
7 | 10 | from indy_node.test.request_handlers.helper import add_to_idr
|
8 | 11 | from plenum.common.constants import TXN_TIME, TRUSTEE
|
9 | 12 |
|
@@ -124,3 +127,74 @@ def test_update_state(revoc_reg_entry_handler, revoc_reg_entry_request,
|
124 | 127 | txn_data[VALUE] = {ACCUM: txn_data[VALUE][ACCUM]}
|
125 | 128 | path, _ = RevocRegEntryHandler.prepare_revoc_reg_entry_accum_for_state(txn)
|
126 | 129 | assert revoc_reg_entry_handler.get_from_state(path) == (txn_data, seq_no, txn_time)
|
| 130 | + |
| 131 | + |
| 132 | +def test_legacy_switch_by_default_new(revoc_reg_entry_handler, revoc_reg_entry_request, |
| 133 | + revoc_reg_def_handler): |
| 134 | + # Default case -> False |
| 135 | + config = getConfig() |
| 136 | + assert config.REV_STRATEGY_USE_COMPAT_ORDERING is False |
| 137 | + |
| 138 | + state = _test_ordering(revoc_reg_entry_handler, revoc_reg_entry_request, |
| 139 | + revoc_reg_def_handler) |
| 140 | + assert state[VALUE][REVOKED] == [5, 6, 12, 13] |
| 141 | + |
| 142 | + |
| 143 | +def test_legacy_switch_by_default_old(revoc_reg_entry_handler, revoc_reg_entry_request, |
| 144 | + revoc_reg_def_handler): |
| 145 | + # Set to true -> enables Usage of CompatSet |
| 146 | + config = getConfig() |
| 147 | + config.REV_STRATEGY_USE_COMPAT_ORDERING = True |
| 148 | + |
| 149 | + state = _test_ordering(revoc_reg_entry_handler, revoc_reg_entry_request, |
| 150 | + revoc_reg_def_handler) |
| 151 | + assert state[VALUE][REVOKED] == [12, 13, 5, 6] |
| 152 | + |
| 153 | + |
| 154 | +def _test_ordering(revoc_reg_entry_handler, revoc_reg_entry_request, |
| 155 | + revoc_reg_def_handler): |
| 156 | + # create revoc_req_def |
| 157 | + seq_no = 1 |
| 158 | + txn_time = 1560241030 |
| 159 | + # Force a new rev reg def for these tests |
| 160 | + revoc_reg_def_request = Request(identifier=randomString(), |
| 161 | + reqId=5, |
| 162 | + signature="sig", |
| 163 | + operation={'type': REVOC_REG_DEF, |
| 164 | + CRED_DEF_ID: "credDefId", |
| 165 | + REVOC_TYPE: randomString(), |
| 166 | + TAG: randomString(), |
| 167 | + }) |
| 168 | + |
| 169 | + revoc_reg_def_request.operation[VALUE] = {} |
| 170 | + revoc_reg_def_request.operation[VALUE][ISSUANCE_TYPE] = ISSUANCE_BY_DEFAULT |
| 171 | + # New random string to create new registry |
| 172 | + txn = reqToTxn(revoc_reg_def_request) |
| 173 | + append_txn_metadata(txn, seq_no, txn_time) |
| 174 | + path = RevocRegDefHandler.prepare_revoc_def_for_state(txn, |
| 175 | + path_only=True) |
| 176 | + revoc_reg_def_handler.update_state(txn, None, revoc_reg_def_request) |
| 177 | + |
| 178 | + # create first revoc_req_entry |
| 179 | + seq_no = 2 |
| 180 | + txn_time = 1560241033 |
| 181 | + revoc_reg_entry_request.operation[REVOC_REG_DEF_ID] = path.decode() |
| 182 | + revoc_reg_entry_request.operation[VALUE][ISSUED] = [] |
| 183 | + revoc_reg_entry_request.operation[VALUE][REVOKED] = [4, 5, 6, 12] |
| 184 | + txn = reqToTxn(revoc_reg_entry_request) |
| 185 | + append_txn_metadata(txn, seq_no, txn_time) |
| 186 | + revoc_reg_entry_handler.update_state(txn, None, revoc_reg_entry_request) |
| 187 | + |
| 188 | + # create second revoc_req_entry |
| 189 | + seq_no = 3 |
| 190 | + txn_time = 1560241042 |
| 191 | + revoc_reg_entry_request.operation[REVOC_REG_DEF_ID] = path.decode() |
| 192 | + revoc_reg_entry_request.operation[VALUE][ISSUED] = [4] |
| 193 | + revoc_reg_entry_request.operation[VALUE][REVOKED] = [13] |
| 194 | + txn = reqToTxn(revoc_reg_entry_request) |
| 195 | + append_txn_metadata(txn, seq_no, txn_time) |
| 196 | + revoc_reg_entry_handler.update_state(txn, None, revoc_reg_entry_request) |
| 197 | + state = revoc_reg_entry_handler.get_from_state( |
| 198 | + RevocRegEntryHandler.prepare_revoc_reg_entry_for_state(txn, |
| 199 | + path_only=True)) |
| 200 | + return state[0] |
0 commit comments