Skip to content

feat: separate build and simulate steps in TransactionBuilder#121

Open
thinktanktom wants to merge 1 commit intoOpenZeppelin:mainfrom
thinktanktom:fix/separate-build-simulation
Open

feat: separate build and simulate steps in TransactionBuilder#121
thinktanktom wants to merge 1 commit intoOpenZeppelin:mainfrom
thinktanktom:fix/separate-build-simulation

Conversation

@thinktanktom
Copy link
Copy Markdown

Description

Fixes #48

This PR separates the building and simulation steps in the TransactionBuilder API to provide more flexibility to users.

Changes

  • New function: simulate_transaction(tx, env, account) - standalone function that simulates an already-built transaction
  • Refactored: simulate_and_build() now internally calls build() then simulate_transaction()
  • Improved efficiency: Removed unnecessary transaction reconstruction - now modifies transaction in-place using mut
  • Backward compatible: Existing simulate_and_build() API continues to work exactly as before
  • New test: Added test_simulate_transaction() to verify the new function works correctly
  • Export: Added simulate_transaction to public API in lib.rs

New API Usage

Option 1: Build and simulate separately (new flexibility)

let tx = TransactionBuilder::new(&account, &env)
    .add_operation(operation)
    .build()
    .await?;

let simulated_tx = simulate_transaction(tx, &env, &account).await?;

Option 2: Build and simulate together (existing convenience)

let tx = TransactionBuilder::new(&account, &env)
    .add_operation(operation)
    .simulate_and_build(&env, &account)
    .await?;

Testing

  • ✅ All existing tests pass
  • ✅ New test test_simulate_transaction() added and passing
  • cargo fmt applied
  • cargo clippy clean

Checklist

  • Code compiles without warnings
  • All tests pass
  • Code is formatted with cargo fmt
  • Code passes cargo clippy
  • Documentation includes examples
  • Backward compatibility maintained

- Extract simulation logic into standalone simulate_transaction() function
- Refactor simulate_and_build() to use the new function internally
- Add test for simulate_transaction()
- Update lib.rs to export simulate_transaction()
- Maintain backward compatibility with existing simulate_and_build() API

Closes OpenZeppelin#48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Separate Building step from Simulation step

1 participant