Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update soroban tests for disabled config #3

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func NewSystem(config Config) (System, error) {
CacheConfig: historyarchive.CacheOptions{
Cache: true,
Path: path.Join(config.CaptiveCoreStoragePath, "bucket-cache"),
MaxFiles: 50,
MaxFiles: 150,
},
},
)
Expand Down
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) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this no longer used anywhere?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call out, I meant to still use this when DisabledSoroban=true in the test cases, I'll push that up to your branch directly in a bit, as i'm stepping through that per our huddle.

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
Loading