From a58496f0645cd7ca7178c25decca83c4b9cf7b01 Mon Sep 17 00:00:00 2001 From: SCM Date: Wed, 27 Nov 2024 14:32:23 +0000 Subject: [PATCH] black . --- plutus_bench/mock.py | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/plutus_bench/mock.py b/plutus_bench/mock.py index 802a3ec..082c6ac 100644 --- a/plutus_bench/mock.py +++ b/plutus_bench/mock.py @@ -211,16 +211,24 @@ def submit_tx(self, tx: Transaction): self.submit_tx_mock(tx) def submit_tx_mock(self, tx: Transaction): - def is_witnessed(address: Union[bytes, pycardano.Address], witness_set: pycardano.TransactionWitnessSet) -> bool: + def is_witnessed( + address: Union[bytes, pycardano.Address], + witness_set: pycardano.TransactionWitnessSet, + ) -> bool: if isinstance(address, bytes): address = pycardano.Address.from_primitive(address) staking_part = address.staking_part if isinstance(staking_part, pycardano.ScriptHash): - scripts = (witness_set.plutus_v1_script or []) + (witness_set.plutus_v2_script or []) + (witness_set.plutus_v3_script or []) - return staking_part in [pycardano.plutus_script_hash(s) for s in scripts] + scripts = ( + (witness_set.plutus_v1_script or []) + + (witness_set.plutus_v2_script or []) + + (witness_set.plutus_v3_script or []) + ) + return staking_part in [ + pycardano.plutus_script_hash(s) for s in scripts + ] else: raise NotImplementedError() - for input in tx.transaction_body.inputs: utxo = self.get_utxo_from_txid(input.transaction_id, input.index) @@ -265,14 +273,17 @@ def is_witnessed(address: Union[bytes, pycardano.Address], witness_set: pycardan for address in tx.transaction_body.withdraws or {}: value = tx.transaction_body.withdraws[address] stake_address = pycardano.Address.from_primitive(address) - assert is_witnessed(stake_address, tx.transaction_witness_set), f'Withdrawal from address {stake_address} is not witnessed' - assert str(stake_address) in self._reward_account, 'Address {stake_address} not registered' - rewards = self._reward_account[str(stake_address)]['delegation']['rewards'] - assert rewards == value, 'All rewards must be withdrawn. Requested {value} but account contains {rewards}' - self._reward_account[str(stake_address)]['delegation']['rewards'] == 0 - - - + assert is_witnessed( + stake_address, tx.transaction_witness_set + ), f"Withdrawal from address {stake_address} is not witnessed" + assert ( + str(stake_address) in self._reward_account + ), "Address {stake_address} not registered" + rewards = self._reward_account[str(stake_address)]["delegation"]["rewards"] + assert ( + rewards == value + ), "All rewards must be withdrawn. Requested {value} but account contains {rewards}" + self._reward_account[str(stake_address)]["delegation"]["rewards"] == 0 def submit_tx_cbor(self, cbor: Union[bytes, str]): return self.submit_tx(Transaction.from_cbor(cbor))