Skip to content

Commit

Permalink
fix: fix a bug in AssembledTransaction.simulate (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Nov 23, 2024
1 parent 23b7fdd commit a30157f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions stellar_sdk/contract/assembled_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def simulate(self, restore: bool = True) -> "AssembledTransaction":
raise RestorationFailureError(
"Failed to restore contract data.", self
) from e
self.simulate()
return self.simulate()

if self.simulation.error is not None:
raise SimulationFailedError(
Expand Down Expand Up @@ -144,6 +144,14 @@ def sign(
self,
)

if self.simulation and self.simulation.restore_preamble:
raise ExpiredStateError(
"You need to restore some contract state before you can invoke this method. "
+ "You can set `restore` to true in order to "
+ "automatically restore the contract state when needed.",
self,
)

transaction_signer = transaction_signer or self.transaction_signer
if not transaction_signer:
raise ValueError(
Expand Down Expand Up @@ -272,7 +280,7 @@ def needs_non_invoker_signing_by(

invoke_host_function_op = self.built_transaction.transaction.operations[0]
if not isinstance(invoke_host_function_op, InvokeHostFunction):
raise ValueError("Unexpected operation type.")
return set()

result = set()
for entry in invoke_host_function_op.auth or []:
Expand Down Expand Up @@ -334,9 +342,9 @@ def restore_footprint(self, restore_preamble: RestorePreamble) -> None:
)
.append_restore_footprint_op()
.set_soroban_data(
SorobanDataBuilder.from_xdr(restore_preamble.transaction_data)
SorobanDataBuilder.from_xdr(restore_preamble.transaction_data).build()
)
.time_bounds(0, 0)
.add_time_bounds(0, 0)
)
restore_assembled: AssembledTransaction = AssembledTransaction(
restore_tx,
Expand All @@ -345,7 +353,7 @@ def restore_footprint(self, restore_preamble: RestorePreamble) -> None:
None,
submit_timeout=self.submit_timeout,
)
restore_assembled.simulate(restore=False).sign()._submit()
restore_assembled.simulate(restore=False).sign(force=True)._submit()

def _simulation_data(
self,
Expand All @@ -358,14 +366,6 @@ def _simulation_data(
if not self.simulation:
raise NotYetSimulatedError("Transaction has not yet been simulated.", self)

if self.simulation.restore_preamble:
raise ExpiredStateError(
"You need to restore some contract state before you can invoke this method. "
+ "You can set `restore` to true in order to "
+ "automatically restore the contract state when needed.",
self,
)

# SimulateHostFunctionResult(auth=[], xdr='AAAAAQ==') for no return function (void)
assert self.simulation.results is not None
assert self.simulation.transaction_data is not None
Expand Down
2 changes: 1 addition & 1 deletion stellar_sdk/contract/assembled_transaction_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def simulate(self, restore: bool = True) -> "AssembledTransactionAsync":
raise RestorationFailureError(
"Failed to restore contract data.", self
) from e
await self.simulate()
return await self.simulate()

if self.simulation.error is not None:
raise SimulationFailedError(
Expand Down

0 comments on commit a30157f

Please sign in to comment.