diff --git a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go index b9af738bb..e2df22533 100644 --- a/cmd/soroban-rpc/internal/test/simulate_transaction_test.go +++ b/cmd/soroban-rpc/internal/test/simulate_transaction_test.go @@ -306,6 +306,64 @@ func TestSimulateTransactionSucceeds(t *testing.T) { assert.Equal(t, result, resultForRequestWithDifferentTxSource) } +func TestSimulateTransactionWithAuth(t *testing.T) { + test := NewTest(t) + + ch := jhttp.NewChannel(test.sorobanRPCURL(), nil) + client := jrpc2.NewClient(ch, nil) + + sourceAccount := keypair.Root(StandaloneNetworkPassphrase) + address := sourceAccount.Address() + account := txnbuild.NewSimpleAccount(address, 0) + + helloWorldContract := getHelloWorldContract(t) + + params := preflightTransactionParams(t, client, txnbuild.TransactionParams{ + SourceAccount: &account, + IncrementSequenceNum: true, + Operations: []txnbuild.Operation{ + createInstallContractCodeOperation(account.AccountID, helloWorldContract), + }, + BaseFee: txnbuild.MinBaseFee, + Preconditions: txnbuild.Preconditions{ + TimeBounds: txnbuild.NewInfiniteTimeout(), + }, + }) + + tx, err := txnbuild.NewTransaction(params) + assert.NoError(t, err) + sendSuccessfulTransaction(t, client, sourceAccount, tx) + + deployContractOp := createCreateContractOperation(t, address, helloWorldContract, StandaloneNetworkPassphrase) + deployContractParams := txnbuild.TransactionParams{ + SourceAccount: &account, + IncrementSequenceNum: true, + Operations: []txnbuild.Operation{ + deployContractOp, + }, + BaseFee: txnbuild.MinBaseFee, + Preconditions: txnbuild.Preconditions{ + TimeBounds: txnbuild.NewInfiniteTimeout(), + }, + } + response := simulateTransactionFromTxParams(t, client, deployContractParams) + require.NotEmpty(t, response.Results) + require.Len(t, response.Results[0].Auth, 1) + require.Empty(t, deployContractOp.Auth) + + var auth xdr.SorobanAuthorizationEntry + assert.NoError(t, xdr.SafeUnmarshalBase64(response.Results[0].Auth[0], &auth)) + require.Equal(t, auth.Credentials.Type, xdr.SorobanCredentialsTypeSorobanCredentialsSourceAccount) + deployContractOp.Auth = append(deployContractOp.Auth, auth) + deployContractParams.Operations = []txnbuild.Operation{deployContractOp} + + // preflight deployContractOp with auth + deployContractParams = preflightTransactionParams(t, client, deployContractParams) + tx, err = txnbuild.NewTransaction(deployContractParams) + assert.NoError(t, err) + sendSuccessfulTransaction(t, client, sourceAccount, tx) +} + func TestSimulateInvokeContractTransactionSucceeds(t *testing.T) { test := NewTest(t) diff --git a/cmd/soroban-rpc/lib/preflight/src/preflight.rs b/cmd/soroban-rpc/lib/preflight/src/preflight.rs index 7b007400f..d9f7d787f 100644 --- a/cmd/soroban-rpc/lib/preflight/src/preflight.rs +++ b/cmd/soroban-rpc/lib/preflight/src/preflight.rs @@ -46,6 +46,12 @@ pub(crate) fn preflight_invoke_hf_op( .context("cannot create budget")?; let storage = Storage::with_recording_footprint(ledger_storage_rc.clone()); let host = Host::with_storage_and_budget(storage, budget); + host.set_source_account(source_account.clone()) + .context("cannot set source account")?; + host.set_diagnostic_level(DiagnosticLevel::Debug) + .context("cannot set debug diagnostic level")?; + host.set_ledger_info(ledger_info.clone()) + .context("cannot set ledger info")?; // We make an assumption here: // - if a transaction doesn't include any soroban authorization entries the client either @@ -63,13 +69,6 @@ pub(crate) fn preflight_invoke_hf_op( .context("cannot set authorization entries")?; } - host.set_diagnostic_level(DiagnosticLevel::Debug) - .context("cannot set debug diagnostic level")?; - host.set_source_account(source_account.clone()) - .context("cannot set source account")?; - host.set_ledger_info(ledger_info.clone()) - .context("cannot set ledger info")?; - // Run the preflight. let maybe_result = host .invoke_function(invoke_hf_op.host_function.clone())