Skip to content

Commit

Permalink
stellar#5175: updated sac tests for disabled soroban config
Browse files Browse the repository at this point in the history
  • Loading branch information
sreuland committed Jan 23, 2024
1 parent a8b5c8e commit d9ca9dc
Show file tree
Hide file tree
Showing 2 changed files with 579 additions and 421 deletions.
79 changes: 63 additions & 16 deletions services/horizon/internal/integration/invokehostfunction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package integration
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"os"
"path/filepath"
"testing"
Expand All @@ -24,13 +25,33 @@ const increment_contract = "soroban_increment_contract.wasm"
// Refer to ./services/horizon/internal/integration/contracts/README.md on how to recompile
// contract code if needed to new wasm.

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

func runAllTests(t *testing.T) {
t.Run("Soroabn Processing Enbabled", func(t *testing.T) {
CaseContractInvokeHostFunctionInstallContract(t)
CaseContractInvokeHostFunctionCreateContractByAddress(t)
CaseContractInvokeHostFunctionInvokeStatelessContractFn(t)
CaseContractInvokeHostFunctionInvokeStatefulContractFn(t)
})
}

func CaseContractInvokeHostFunctionInstallContract(t *testing.T) {
if integration.GetCoreMaxSupportedProtocol() < 20 {
t.Skip("This test run does not support less than Protocol 20")
}

itest := integration.NewTest(t, integration.Config{
ProtocolVersion: 20,
HorizonEnvironment: map[string]string{
"DISABLE_SOROBAN_INGEST_PROCESSORS": fmt.Sprint(DisabledSoroban)},
EnableSorobanRPC: true,
})

Expand Down Expand Up @@ -74,13 +95,15 @@ func TestContractInvokeHostFunctionInstallContract(t *testing.T) {

}

func TestContractInvokeHostFunctionCreateContractByAddress(t *testing.T) {
func CaseContractInvokeHostFunctionCreateContractByAddress(t *testing.T) {
if integration.GetCoreMaxSupportedProtocol() < 20 {
t.Skip("This test run does not support less than Protocol 20")
}

itest := integration.NewTest(t, integration.Config{
ProtocolVersion: 20,
HorizonEnvironment: map[string]string{
"DISABLE_SOROBAN_INGEST_PROCESSORS": fmt.Sprint(DisabledSoroban)},
EnableSorobanRPC: true,
})

Expand Down Expand Up @@ -128,13 +151,15 @@ func TestContractInvokeHostFunctionCreateContractByAddress(t *testing.T) {
assert.Equal(t, invokeHostFunctionOpJson.Salt, "110986164698320180327942133831752629430491002266485370052238869825166557303060")
}

func TestContractInvokeHostFunctionInvokeStatelessContractFn(t *testing.T) {
func CaseContractInvokeHostFunctionInvokeStatelessContractFn(t *testing.T) {
if integration.GetCoreMaxSupportedProtocol() < 20 {
t.Skip("This test run does not support less than Protocol 20")
}

itest := integration.NewTest(t, integration.Config{
ProtocolVersion: 20,
HorizonEnvironment: map[string]string{
"DISABLE_SOROBAN_INGEST_PROCESSORS": fmt.Sprint(DisabledSoroban)},
EnableSorobanRPC: true,
})

Expand Down Expand Up @@ -209,12 +234,14 @@ func TestContractInvokeHostFunctionInvokeStatelessContractFn(t *testing.T) {
assert.True(t, ok)
assert.Equal(t, invokeHostFunctionResult.Code, xdr.InvokeHostFunctionResultCodeInvokeHostFunctionSuccess)

// check the function response, should have summed the two input numbers
invokeResult := xdr.Uint64(9)
expectedScVal := xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &invokeResult}
var transactionMeta xdr.TransactionMeta
assert.NoError(t, xdr.SafeUnmarshalBase64(tx.ResultMetaXdr, &transactionMeta))
assert.True(t, expectedScVal.Equals(transactionMeta.V3.SorobanMeta.ReturnValue))
if !DisabledSoroban {
// check the function response, should have summed the two input numbers
invokeResult := xdr.Uint64(9)
expectedScVal := xdr.ScVal{Type: xdr.ScValTypeScvU64, U64: &invokeResult}
var transactionMeta xdr.TransactionMeta
assert.NoError(t, xdr.SafeUnmarshalBase64(tx.ResultMetaXdr, &transactionMeta))
assert.True(t, expectedScVal.Equals(transactionMeta.V3.SorobanMeta.ReturnValue))
}

clientInvokeOp, err := itest.Client().Operations(horizonclient.OperationRequest{
ForTransaction: tx.Hash,
Expand All @@ -237,13 +264,15 @@ func TestContractInvokeHostFunctionInvokeStatelessContractFn(t *testing.T) {
assert.Equal(t, invokeHostFunctionOpJson.Parameters[3].Type, "U64")
}

func TestContractInvokeHostFunctionInvokeStatefulContractFn(t *testing.T) {
func CaseContractInvokeHostFunctionInvokeStatefulContractFn(t *testing.T) {
if integration.GetCoreMaxSupportedProtocol() < 20 {
t.Skip("This test run does not support less than Protocol 20")
}

itest := integration.NewTest(t, integration.Config{
ProtocolVersion: 20,
HorizonEnvironment: map[string]string{
"DISABLE_SOROBAN_INGEST_PROCESSORS": fmt.Sprint(DisabledSoroban)},
EnableSorobanRPC: true,
})

Expand Down Expand Up @@ -305,12 +334,14 @@ func TestContractInvokeHostFunctionInvokeStatefulContractFn(t *testing.T) {
assert.True(t, ok)
assert.Equal(t, invokeHostFunctionResult.Code, xdr.InvokeHostFunctionResultCodeInvokeHostFunctionSuccess)

// check the function response, should have incremented state from 0 to 1
invokeResult := xdr.Uint32(1)
expectedScVal := xdr.ScVal{Type: xdr.ScValTypeScvU32, U32: &invokeResult}
var transactionMeta xdr.TransactionMeta
assert.NoError(t, xdr.SafeUnmarshalBase64(clientTx.ResultMetaXdr, &transactionMeta))
assert.True(t, expectedScVal.Equals(transactionMeta.V3.SorobanMeta.ReturnValue))
if !DisabledSoroban {
// check the function response, should have incremented state from 0 to 1
invokeResult := xdr.Uint32(1)
expectedScVal := xdr.ScVal{Type: xdr.ScValTypeScvU32, U32: &invokeResult}
var transactionMeta xdr.TransactionMeta
assert.NoError(t, xdr.SafeUnmarshalBase64(clientTx.ResultMetaXdr, &transactionMeta))
assert.True(t, expectedScVal.Equals(transactionMeta.V3.SorobanMeta.ReturnValue))
}

clientInvokeOp, err := itest.Client().Operations(horizonclient.OperationRequest{
ForTransaction: tx.Hash,
Expand Down Expand Up @@ -346,6 +377,22 @@ func assembleInstallContractCodeOp(t *testing.T, sourceAccount string, wasmFileN
}
}

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)
}

func assembleCreateContractOp(t *testing.T, sourceAccount string, wasmFileName string, contractSalt string, passPhrase string) *txnbuild.InvokeHostFunction {
// Assemble the InvokeHostFunction CreateContract operation:
// CAP-0047 - https://github.com/stellar/stellar-protocol/blob/master/core/cap-0047.md#creating-a-contract-using-invokehostfunctionop
Expand Down
Loading

0 comments on commit d9ca9dc

Please sign in to comment.