Skip to content

Commit

Permalink
black .
Browse files Browse the repository at this point in the history
  • Loading branch information
SCMusson committed Nov 27, 2024
1 parent 22062d9 commit a58496f
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions plutus_bench/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit a58496f

Please sign in to comment.