def testRetrieveChangedVerkey(looper, tconf, nodeSet, sdk_pool_handle, sdk_wallet_trustee, nym_empty_vk): _, did = nym_empty_vk trw, trd = sdk_wallet_trustee new_vk = sdk_rotate_verkey(looper, sdk_pool_handle, trw, trd, did) resp_data = nym_get(looper, sdk_pool_handle, sdk_wallet_trustee, did) assert did == resp_data[0] assert new_vk == resp_data[1]
def testRetrieveChangedVerkey(looper, tconf, nodeSet, sdk_pool_handle, sdk_wallet_trustee, nym_full_vk): wh, did, vk = nym_full_vk new_vk = sdk_rotate_verkey(looper, sdk_pool_handle, wh, did, did) resp_data = nym_get(looper, sdk_pool_handle, sdk_wallet_trustee, did) assert did == resp_data[0] assert vk != resp_data[1] assert new_vk == resp_data[1]
def testVerifySigWithChangedVerkey(looper, tconf, nodeSet, sdk_pool_handle, nym_full_vk): wh, did, vk = nym_full_vk new_vk = sdk_rotate_verkey(looper, sdk_pool_handle, wh, did, did) # check sign by getting nym from ledger - if succ then sign is ok resp_data = nym_get(looper, sdk_pool_handle, (wh, did), did) assert did == resp_data[0] assert vk != resp_data[1] assert new_vk == resp_data[1]
def testVerifySigWithChangedVerkey(looper, tconf, nodeSet, sdk_pool_handle, sdk_wallet_trustee, nym_empty_vk): wh, did = nym_empty_vk trw, trd = sdk_wallet_trustee new_vk = sdk_rotate_verkey(looper, sdk_pool_handle, trw, trd, did) # check sign by getting nym from ledger - if succ then sign is ok resp_data = nym_get(looper, sdk_pool_handle, (wh, did), did) assert did == resp_data[0] assert new_vk == resp_data[1]
def run(self): wh, client_did = self.test_nym _, trustee_did = self.creator_wallet # Step 1. Check default auth rule sdk_rotate_verkey(self.looper, self.sdk_pool_handle, wh, client_did, client_did) verkey = self.sdk_modified_verkey_rotate_failed( self.sdk_pool_handle, wh, trustee_did, client_did) # Step 2. Change auth rule self.send_and_check(self.changed_auth_rule, wallet=self.trustee_wallet) # Step 3. Check, that we cannot add new steward by old way sdk_rotate_verkey(self.looper, self.sdk_pool_handle, wh, trustee_did, client_did, verkey) verkey = self.sdk_modified_verkey_rotate_failed( self.sdk_pool_handle, wh, client_did, client_did) # Step 4. Return default auth rule self.send_and_check(self.default_auth_rule, wallet=self.trustee_wallet) # Step 5. Check, that default auth rule works sdk_rotate_verkey(self.looper, self.sdk_pool_handle, wh, client_did, client_did, verkey) self.sdk_modified_verkey_rotate_failed(self.sdk_pool_handle, wh, trustee_did, client_did)
def testChangeVerkeyToNewVerkey(looper, tconf, nodeSet, sdk_pool_handle, nym_full_vk): wh, did, nvk = nym_full_vk new_verkey = sdk_rotate_verkey(looper, sdk_pool_handle, wh, did, did) assert nvk != new_verkey
def test_successive_batch_do_no_change_state(looper, tconf, nodeSet, sdk_pool_handle, sdk_wallet_trustee, monkeypatch): """ Send 2 NYM txns in different batches such that the second batch does not change state so that state root remains same, but keep the identifier and reqId different. Make sure the first request is not ordered by the primary before PRE-PREPARE for the second is sent. Also check reject and commit :return: """ # Disable view change during this test for n in nodeSet: n.nodeIbStasher.delay(icDelay()) # Delay only first PRE-PREPARE delay_cm_duration = 10 def delay_commits(wrappedMsg): msg, sender = wrappedMsg if isinstance(msg, Commit) and msg.instId == 0: return delay_cm_duration def check_verkey(i, vk): for node in nodeSet: data = node.idrCache.getNym(i, isCommitted=True) assert data[VERKEY] == vk def check_uncommitted(count): for node in nodeSet: assert len(node.idrCache.un_committed) == count for node in nodeSet: for rpl in node.replicas: monkeypatch.setattr(rpl, '_request_missing_three_phase_messages', lambda *x, **y: None) wh, did = sdk_wallet_trustee seed = randomString(32) (new_did, verkey) = looper.loop.run_until_complete( create_and_store_my_did(wh, json.dumps({'seed': seed}))) sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee, dest=new_did, verkey=verkey) for node in nodeSet: node.nodeIbStasher.delay(delay_commits) # Setting the same verkey thrice but in different batches with different # request ids for _ in range(3): verkey = sdk_rotate_verkey(looper, sdk_pool_handle, wh, new_did, new_did, seed) logger.debug('{} rotates his key to {}'.format(new_did, verkey)) # Number of uncommitted entries is 0 looper.run(eventually(check_uncommitted, 0)) check_verkey(new_did, verkey) # Setting the verkey to `x`, then `y` and then back to `x` but in different # batches with different request ids. The idea is to change # state root to `t` then `t'` and then back to `t` and observe that no # errors are encountered seed = randomString(32) (new_client_did, verkey) = looper.loop.run_until_complete( create_and_store_my_did(wh, json.dumps({'seed': seed}))) sdk_add_new_nym(looper, sdk_pool_handle, sdk_wallet_trustee, dest=new_client_did, verkey=verkey) x_seed = randomString(32) verkey = sdk_rotate_verkey(looper, sdk_pool_handle, wh, new_client_did, new_client_did, x_seed) logger.debug('{} rotates his key to {}'.format(new_client_did, verkey)) y_seed = randomString(32) sdk_rotate_verkey(looper, sdk_pool_handle, wh, new_client_did, new_client_did, y_seed) logger.debug('{} rotates his key to {}'.format(new_client_did, verkey)) sdk_rotate_verkey(looper, sdk_pool_handle, wh, new_client_did, new_client_did, x_seed) logger.debug('{} rotates his key to {}'.format(new_client_did, verkey)) # Number of uncommitted entries is 0 looper.run(eventually(check_uncommitted, 0)) check_verkey(new_client_did, verkey) monkeypatch.undo() # Delay COMMITs so that IdrCache can be checked for correct # number of entries uncommitteds = {} methods = {} for node in nodeSet: cache = node.idrCache # type: IdrCache uncommitteds[cache._name] = [] # Since the post batch creation handler is registered (added to a list), # find it and patch it dh = node.get_req_handler(DOMAIN_LEDGER_ID) for i, handler in enumerate(dh.post_batch_creation_handlers): # Find the cache's post create handler, not hardcoding names of # class or functions as they can change with refactoring. if handler.__func__.__qualname__ == '{}.{}'.format( cache.__class__.__name__, cache.currentBatchCreated.__name__): cre = dh.post_batch_creation_handlers[i] break com = cache.onBatchCommitted methods[cache._name] = (cre, com) # Patch methods to record and check roots after commit def patched_cre(self, stateRoot): uncommitteds[self._name].append(stateRoot) return methods[self._name][0](stateRoot) def patched_com(self, stateRoot): assert uncommitteds[self._name][0] == stateRoot rv = methods[self._name][1](stateRoot) uncommitteds[self._name] = uncommitteds[self._name][1:] return rv dh.post_batch_creation_handlers[i] = types.MethodType( patched_cre, cache) cache.onBatchCommitted = types.MethodType(patched_com, cache) # Set verkey of multiple identities more = 5 keys = {} reqs = [] for _ in range(more): seed = randomString(32) nym_request, new_did = looper.loop.run_until_complete( prepare_nym_request(sdk_wallet_trustee, seed, None, None)) keys[new_did] = json.loads(nym_request)['operation']['verkey'] reqs.append( sdk_sign_and_send_prepared_request(looper, sdk_wallet_trustee, sdk_pool_handle, nym_request)) looper.runFor(.01) # Correct number of uncommitted entries looper.run(eventually(check_uncommitted, more, retryWait=1)) sdk_get_and_check_replies(looper, reqs) # Number of uncommitted entries is 0 looper.run(eventually(check_uncommitted, 0)) # The verkeys are correct for i, v in keys.items(): check_verkey(i, v) waitNodeDataEquality(looper, nodeSet[0], *nodeSet[1:]) for _ in range(3): seed = randomString(32) nym_request, new_did = looper.loop.run_until_complete( prepare_nym_request(sdk_wallet_trustee, seed, None, None)) reqs.append( sdk_sign_and_send_prepared_request(looper, sdk_wallet_trustee, sdk_pool_handle, nym_request)) looper.runFor(.01) # Correct number of uncommitted entries looper.run(eventually(check_uncommitted, 3, retryWait=1)) # Check batch reject for node in nodeSet: cache = node.idrCache initial = cache.un_committed cache.batchRejected() # After reject, last entry is removed assert cache.un_committed == initial[:-1] root = cache.un_committed[0][0] cache.onBatchCommitted(root) # Calling commit with same root results in Assertion error with pytest.raises(AssertionError): cache.onBatchCommitted(root)
def testChangeEmptyVerkeyToNewVerkey(looper, tconf, nodeSet, sdk_pool_handle, sdk_wallet_trustee, nym_empty_vk): _, did = nym_empty_vk trw, trd = sdk_wallet_trustee new_vk = sdk_rotate_verkey(looper, sdk_pool_handle, trw, trd, did) assert new_vk