def testOnlyTrusteeCanSendPoolUpgradeForceTrue( looper, steward, validUpgradeExpForceTrue): stClient, stWallet = steward _, req = sendUpgrade(stClient, stWallet, validUpgradeExpForceTrue) timeout = plenumWaits.expectedReqNAckQuorumTime() looper.run(eventually(checkNacks, stClient, req.reqId, 'cannot do', retryWait=1, timeout=timeout))
def sendMoney(self, to: str, amount: int, nodes, expected: bool = True): req = self.submit({ TXN_TYPE: CREDIT, TARGET_NYM: to, DATA: { AMOUNT: amount } }) if expected: waitForSufficientRepliesForRequests(self.looper, self.client, requests=[req]) else: timeout = waits.expectedReqNAckQuorumTime() for node in nodes: self.looper.run( eventually(checkReqNack, self.client, node, req.identifier, req.reqId, None, retryWait=1, timeout=timeout)) return req
def testNodeRejectsPoolUpgrade(looper, nodeSet, tdir, trustee, trusteeWallet, invalidUpgrade): _, req = sendUpgrade(trustee, trusteeWallet, invalidUpgrade) timeout = plenumWaits.expectedReqNAckQuorumTime() looper.run(eventually(checkNacks, trustee, req.reqId, 'since time span between upgrades', retryWait=1, timeout=timeout))
def testOnlyUsersTrustAnchorCanAddAttribute( nodeSet, looper, steward, stewardWallet, attributeData, anotherTrustAnchor, userIdA): with whitelistextras("UnauthorizedClientRequest"): client, wallet = anotherTrustAnchor attrib = Attribute(name='test2 attribute', origin=wallet.defaultId, value=attributeData, dest=userIdA, ledgerStore=LedgerStore.RAW) reqs = makeAttribRequest(client, wallet, attrib) timeout = waits.expectedReqNAckQuorumTime() looper.run( eventually( checkRejects, client, reqs[0].reqId, "UnauthorizedClientRequest('Only identity " "owner/guardian can add attribute for that identity'", retryWait=1, timeout=timeout))
def nymsAddedInQuickSuccession(nodeSet, addedTrustAnchor, looper, trustAnchor, trustAnchorWallet): usigner = DidSigner() nym = usigner.verkey idy = Identity(identifier=nym) trustAnchorWallet.addTrustAnchoredIdentity(idy) # Creating a NYM request with same nym again req = idy.ledgerRequest() trustAnchorWallet._pending.appendleft((req, idy.identifier)) reqs = trustAnchorWallet.preparePending() trustAnchor.submitReqs(*reqs) def check(): assert trustAnchorWallet._trustAnchored[nym].seqNo timeout = waits.expectedTransactionExecutionTime(len(nodeSet)) looper.run(eventually(check, timeout=timeout)) timeout = waits.expectedReqNAckQuorumTime() looper.run(eventually(checkNacks, trustAnchor, req.reqId, "is already added", retryWait=1, timeout=timeout)) count = 0 for node in nodeSet: for seq, txn in node.domainLedger.getAllTxn(): if txn[TXN_TYPE] == NYM and txn[TARGET_NYM] == usigner.identifier: count += 1 assert(count == len(nodeSet))
def nymsAddedInQuickSuccession(looper, nodeSet, sdk_added_raw_attribute, trustAnchor, trustAnchorWallet): usigner = DidSigner() nym = usigner.verkey idy = Identity(identifier=nym) trustAnchorWallet.addTrustAnchoredIdentity(idy) # Creating a NYM request with same nym again req = idy.ledgerRequest() trustAnchorWallet._pending.appendleft((req, idy.identifier)) reqs = trustAnchorWallet.preparePending() trustAnchor.submitReqs(*reqs) def check(): assert trustAnchorWallet._trustAnchored[nym].seqNo timeout = waits.expectedTransactionExecutionTime(len(nodeSet)) looper.run(eventually(check, timeout=timeout)) timeout = waits.expectedReqNAckQuorumTime() looper.run( eventually(checkNacks, trustAnchor, req.reqId, "is already added", retryWait=1, timeout=timeout)) count = 0 for node in nodeSet: for seq, txn in node.domainLedger.getAllTxn(): if txn[TXN_TYPE] == NYM and txn[TARGET_NYM] == usigner.identifier: count += 1 assert (count == len(nodeSet))
def submitAndCheckAccepts(looper, client, wallet, op, identifier): reqId = submit(wallet, op, identifier, client) timeout = waits.expectedReqNAckQuorumTime() looper.run(eventually(checkAccpets, client, reqId, retryWait=1, timeout=timeout))
def testOnlyTrusteeCanSendPoolUpgrade(looper, steward, validUpgrade): # A steward sending POOL_UPGRADE but txn fails stClient, stWallet = steward validUpgrade = deepcopy(validUpgrade) validUpgrade[NAME] = 'upgrade-20' validUpgrade[VERSION] = bumpedVersion() _, req = sendUpgrade(stClient, stWallet, validUpgrade) timeout = plenumWaits.expectedReqNAckQuorumTime() looper.run(eventually(checkRejects, stClient, req.reqId, 'cannot do', retryWait=1, timeout=timeout))
def submitAndCheckRejects(looper, client, wallet, op, identifier, contains='UnauthorizedClientRequest', check_func=checkRejects): reqId = submit(wallet, op, identifier, client) timeout = waits.expectedReqNAckQuorumTime() looper.run(eventually(check_func, client, reqId, contains, retryWait=1, timeout=timeout))
def test_accept_then_reject_upgrade(looper, trustee, trusteeWallet, validUpgradeSent, validUpgrade): upgrade_name = validUpgrade[NAME] error_msg = "InvalidClientRequest(\"Upgrade '{}' is already scheduled\"".format(upgrade_name) validUpgrade2 = deepcopy(validUpgrade) _, req = sendUpgrade(trustee, trusteeWallet, validUpgrade2) timeout = plenumWaits.expectedReqNAckQuorumTime() looper.run(eventually(checkRejects, trustee, req.reqId, error_msg, retryWait=1, timeout=timeout))
def submitAndCheckRejects(looper, client, wallet, op, identifier, contains='UnauthorizedClientRequest'): req = wallet.signOp(op, identifier=identifier) wallet.pendRequest(req) reqs = wallet.preparePending() client.submitReqs(*reqs) timeout = waits.expectedReqNAckQuorumTime() looper.run(eventually(checkRejects, client, req.reqId, contains, retryWait=1, timeout=timeout))
def test_accept_then_reject_upgrade( looper, trustee, trusteeWallet, validUpgradeSent, validUpgrade): upgrade_name = validUpgrade[NAME] error_msg = "InvalidClientRequest(\"Upgrade '{}' is already scheduled\"".\ format(upgrade_name) validUpgrade2 = deepcopy(validUpgrade) _, req = sendUpgrade(trustee, trusteeWallet, validUpgrade2) timeout = plenumWaits.expectedReqNAckQuorumTime() looper.run(eventually(checkRejects, trustee, req.reqId, error_msg, retryWait=1, timeout=timeout))
def test_nym_addition_fails_with_empty_verkey(looper, addedTrustAnchor, trustAnchor, trustAnchorWallet): new_wallet = addRole(looper, trustAnchor, trustAnchorWallet, 'userC', useDid=False, addVerkey=False) idy = Identity(identifier=new_wallet.defaultId, verkey='') trustAnchorWallet.updateTrustAnchoredIdentity(idy) reqs = trustAnchorWallet.preparePending() reqs = trustAnchor.submitReqs(*reqs) timeout = waits.expectedReqNAckQuorumTime() looper.run(eventually(checkNacks, trustAnchor, reqs[0].reqId, 'validation error: b58 decoded value length 0 should be one of [32]', retryWait=1, timeout=timeout))
def testStewardCannotAddUsersAttribute(nodeSet, looper, steward, stewardWallet, userIdA, attributeData): with whitelistextras("UnauthorizedClientRequest"): attrib = Attribute(name='test3 attribute', origin=stewardWallet.defaultId, value=attributeData, dest=userIdA, ledgerStore=LedgerStore.RAW) reqs = makeAttribRequest(steward, stewardWallet, attrib) timeout = waits.expectedReqNAckQuorumTime() looper.run(eventually(checkRejects, steward, reqs[0].reqId, "UnauthorizedClientRequest('Only identity owner/guardian can add attribute for that identity'", retryWait=1, timeout=timeout))
def submitAndCheckRejects(looper, client, wallet, op, identifier, contains='UnauthorizedClientRequest', check_func=checkRejects): reqId = submit(wallet, op, identifier, client) timeout = waits.expectedReqNAckQuorumTime() looper.run( eventually(check_func, client, reqId, contains, retryWait=1, timeout=timeout))
def submitAndCheckNacks(looper, client, wallet, op, identifier, contains='UnauthorizedClientRequest'): req = wallet.signOp(op, identifier=identifier) wallet.pendRequest(req) reqs = wallet.preparePending() client.submitReqs(*reqs) timeout = waits.expectedReqNAckQuorumTime() looper.run( eventually(checkNacks, client, req.reqId, contains, retryWait=1, timeout=timeout))
def test_nym_addition_fails_with_empty_verkey(looper, addedTrustAnchor, trustAnchor, trustAnchorWallet): new_wallet = addRole(looper, trustAnchor, trustAnchorWallet, 'userC', useDid=False, addVerkey=False) idy = Identity(identifier=new_wallet.defaultId, verkey='') trustAnchorWallet.updateTrustAnchoredIdentity(idy) reqs = trustAnchorWallet.preparePending() reqs = trustAnchor.submitReqs(*reqs) timeout = waits.expectedReqNAckQuorumTime() looper.run( eventually( checkNacks, trustAnchor, reqs[0].reqId, 'validation error: b58 decoded value length 0 should be one of [32]', retryWait=1, timeout=timeout))
def test_accept_then_reject_upgrade(looper, trustee, trusteeWallet, validUpgradeSent, validUpgrade): validUpgrade2 = deepcopy(validUpgrade) _, req = sendUpgrade(trustee, trusteeWallet, validUpgrade2) timeout = plenumWaits.expectedReqNAckQuorumTime() looper.run(eventually(checkRejects, trustee, req.reqId, 'InvalidClientRequest', retryWait=1, timeout=timeout))
def waitReqNackWithReason(looper, client, reason: str, sender: str): timeout = waits.expectedReqNAckQuorumTime() return wait_negative_resp(looper, client, reason, sender, timeout, checkReqNackWithReason)