Skip to content

Commit

Permalink
stellar#5175: added verify in sac tests for empty soroban when disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
sreuland committed Jan 23, 2024
1 parent cd9cf1f commit c01058f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
27 changes: 26 additions & 1 deletion services/horizon/internal/integration/invokehostfunction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/protocols/horizon"
"github.com/stellar/go/protocols/horizon/operations"
"github.com/stellar/go/services/horizon/internal/test/integration"
"github.com/stellar/go/txnbuild"
Expand All @@ -35,7 +36,7 @@ func TestInvokeHostFns(t *testing.T) {
}

func runAllTests(t *testing.T) {
t.Run("Soroabn Processing Enbabled", func(t *testing.T) {
t.Run(fmt.Sprintf("Soroban Processing Disabled = %v", DisabledSoroban), func(t *testing.T) {
CaseContractInvokeHostFunctionInstallContract(t)
CaseContractInvokeHostFunctionCreateContractByAddress(t)
CaseContractInvokeHostFunctionInvokeStatelessContractFn(t)
Expand Down Expand Up @@ -127,6 +128,10 @@ func CaseContractInvokeHostFunctionCreateContractByAddress(t *testing.T) {
clientTx, err := itest.Client().TransactionDetail(tx.Hash)
require.NoError(t, err)

if DisabledSoroban {
verifyEmptySorobanMeta(t, clientTx)
}

assert.Equal(t, tx.Hash, clientTx.Hash)
var txResult xdr.TransactionResult
err = xdr.SafeUnmarshalBase64(clientTx.ResultXdr, &txResult)
Expand Down Expand Up @@ -241,6 +246,8 @@ func CaseContractInvokeHostFunctionInvokeStatelessContractFn(t *testing.T) {
var transactionMeta xdr.TransactionMeta
assert.NoError(t, xdr.SafeUnmarshalBase64(tx.ResultMetaXdr, &transactionMeta))
assert.True(t, expectedScVal.Equals(transactionMeta.V3.SorobanMeta.ReturnValue))
} else {
verifyEmptySorobanMeta(t, clientTx)
}

clientInvokeOp, err := itest.Client().Operations(horizonclient.OperationRequest{
Expand Down Expand Up @@ -341,6 +348,8 @@ func CaseContractInvokeHostFunctionInvokeStatefulContractFn(t *testing.T) {
var transactionMeta xdr.TransactionMeta
assert.NoError(t, xdr.SafeUnmarshalBase64(clientTx.ResultMetaXdr, &transactionMeta))
assert.True(t, expectedScVal.Equals(transactionMeta.V3.SorobanMeta.ReturnValue))
} else {
verifyEmptySorobanMeta(t, clientTx)
}

clientInvokeOp, err := itest.Client().Operations(horizonclient.OperationRequest{
Expand Down Expand Up @@ -415,3 +424,19 @@ func assembleCreateContractOp(t *testing.T, sourceAccount string, wasmFileName s
SourceAccount: sourceAccount,
}
}

func verifyEmptySorobanMeta(t *testing.T, clientTx horizon.Transaction) {
if !DisabledSoroban {
return
}

var txMeta xdr.TransactionMeta
err := xdr.SafeUnmarshalBase64(clientTx.ResultMetaXdr, &txMeta)
require.NoError(t, err)

require.NotNil(t, txMeta.V3)
require.Empty(t, txMeta.V3.Operations)
require.Empty(t, txMeta.V3.TxChangesAfter)
require.Empty(t, txMeta.V3.TxChangesBefore)
require.Nil(t, txMeta.V3.SorobanMeta)
}
12 changes: 7 additions & 5 deletions services/horizon/internal/integration/sac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ var (

func TestSAC(t *testing.T) {
// first test contracts when soroban processing is enabled
DisabledSoroban = true
DisabledSoroban = false
runAllSACTests(t)
// now test same contracts when soroban processing is disabled
DisabledSoroban = true
runAllSACTests(t)
}

func runAllSACTests(t *testing.T) {
t.Run("Soroabn Processing Enbabled", func(t *testing.T) {
t.Run(fmt.Sprintf("Soroban Processing Disabled = %v", DisabledSoroban), func(t *testing.T) {
CaseContractMintToAccount(t)
CaseContractMintToContract(t)
CaseExpirationAndRestoration(t)
Expand Down Expand Up @@ -1514,16 +1514,18 @@ func assertInvokeHostFnSucceeds(itest *integration.Test, signer *keypair.Full, o
assert.True(itest.CurrentTest(), ok)
assert.Equal(itest.CurrentTest(), invokeHostFunctionResult.Code, xdr.InvokeHostFunctionResultCodeInvokeHostFunctionSuccess)

var returnValue xdr.ScVal
var returnValue *xdr.ScVal

if !DisabledSoroban {
var txMetaResult xdr.TransactionMeta
err = xdr.SafeUnmarshalBase64(clientTx.ResultMetaXdr, &txMetaResult)
require.NoError(itest.CurrentTest(), err)
returnValue = txMetaResult.MustV3().SorobanMeta.ReturnValue
returnValue = &txMetaResult.MustV3().SorobanMeta.ReturnValue
} else {
verifyEmptySorobanMeta(itest.CurrentTest(), clientTx)
}

return &returnValue, clientTx.Hash, &preFlightOp
return returnValue, clientTx.Hash, &preFlightOp
}

func stellarAssetContractID(itest *integration.Test, asset xdr.Asset) xdr.Hash {
Expand Down

0 comments on commit c01058f

Please sign in to comment.