async def on_account_request(event): counter_cid, counter_cdata = await event.acs_find_one(Counter) return [ ExerciseCommand(event.cid, "CreateAccount", dict(accountId=counter_cdata["value"])), ExerciseCommand(counter_cid, "Increment"), ]
def test_object_atomic_default_true(self): with pytest.warns(DeprecationWarning): builder = CommandBuilder(atomic_default=True) builder.create("Sample:Untyped", {"arg": 1}) builder.exercise(SOME_CONTRACT_ID, "SomeChoice", {"choiceArg": "value"}) expected = [ CommandPayload( party=SOME_PARTY, ledger_id=DEFAULTS.default_ledger_id, workflow_id=DEFAULTS.default_workflow_id, application_id=DEFAULTS.default_application_id, command_id=DEFAULTS.default_command_id, commands=[ CreateCommand(SOME_TEMPLATE_NAME, dict(arg=1)), ExerciseCommand(SOME_CONTRACT_ID, "SomeChoice", {"choiceArg": "value"}), ], ) ] actual = builder.build(DEFAULTS) assert expected == actual
def _create_complicated_notifications(e) -> list: return [ ExerciseCommand(e.cid, "PublishFormula", dict(formula={"Tautology": {}})), ExerciseCommand(e.cid, "PublishFormula", dict(formula={"Contradiction": {}})), ExerciseCommand(e.cid, "PublishFormula", dict(formula={"Proposition": "something"})), ExerciseCommand( e.cid, "PublishFormula", dict(formula={"Conjunction": [{ "Proposition": "something_else" }]}), ), ]
async def async_test_case(client: AIOPartyClient): await client.ready() ensure_future(client.create(OperatorRole, {"operator": client.party})) operator_cid, _ = await client.find_one(OperatorRole) ensure_future(client.exercise(operator_cid, "PublishMany", dict(count=5))) # this should actually be a no-op; we're just making sure that calls to ready() that are # "too late" are not treated strangely await wait_for(client.ready(), timeout=0.1) notifications = await client.find_nonempty(OperatorNotification, {"operator": client.party}, min_count=5) contracts_to_delete = [] for cid, cdata in notifications.items(): if int(cdata["text"]) <= 3: contracts_to_delete.append(cid) ensure_future( client.submit( [ExerciseCommand(cid, "Archive") for cid in contracts_to_delete])) ensure_future(client.exercise(operator_cid, "PublishMany", dict(count=3)))
def on_notification(self, event): if self.evt_count == 25: self.done.set() else: self.evt_count += 1 missing_parties = self.user_parties.difference( event.cdata["theObservers"]) if missing_parties: return ExerciseCommand( event.cid, "Share", {"sharingParty": random.choice(list(missing_parties))})
def test_serialize_exercise(dar_fixture): sut = ProtobufSerializer(dar_fixture.lookup) tref = dar_fixture.lookup.data_type_name("Pending:AccountRequest") cid = ContractId(tref, "#1:0") command = ExerciseCommand(cid, "CreateAccount", dict(accountId=42)) expected = G_Command() expected.exercise.contract_id = "#1:0" expected.exercise.template_id.MergeFrom( dar_fixture.get_identifier("Pending:AccountRequest")) expected.exercise.choice = "CreateAccount" expected.exercise.choice_argument.record.fields.append( G_RecordField(label="accountId", value=G_Value(int64=42))) actual = sut.serialize_command(command) assert expected == actual
def on_one_of_everything(self, event): if event.cdata is not None: self.found_instance = event.cdata return ExerciseCommand(event.cid, "Accept") else: self.archive_done = True
def _create_empty_notification(e) -> list: return [ExerciseCommand(e.cid, "PublishEmpty")]
def on_operator(event): return [ ExerciseCommand(event.cid, "Publish", {"text": n}) for n in range(0, NOTIFICATION_COUNT) ]