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

Add test upgrading Protocol 20 to Protocol 21 #150

Merged
merged 7 commits into from
Apr 22, 2024
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
13 changes: 4 additions & 9 deletions cmd/soroban-rpc/internal/test/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,7 @@ func NewTest(t *testing.T, cfg *TestConfig) *Test {

if i.protocolVersion == 0 {
// Default to the maximum supported protocol version
i.protocolVersion = maxSupportedProtocolVersion
// If the environment tells us that Core only supports up to certain version,
// use that.
maxSupportedCoreProtocolFromEnv := GetCoreMaxSupportedProtocol()
if maxSupportedCoreProtocolFromEnv != 0 && maxSupportedCoreProtocolFromEnv < maxSupportedProtocolVersion {
i.protocolVersion = maxSupportedCoreProtocolFromEnv
}
i.protocolVersion = GetCoreMaxSupportedProtocol()
}

proxy := httputil.NewSingleHostReverseProxy(&url.URL{Scheme: "http", Host: stellarCoreArchiveHost})
Expand Down Expand Up @@ -411,11 +405,12 @@ func findDockerComposePath() string {
func GetCoreMaxSupportedProtocol() uint32 {
str := os.Getenv("SOROBAN_RPC_INTEGRATION_TESTS_CORE_MAX_SUPPORTED_PROTOCOL")
if str == "" {
return 0
return maxSupportedProtocolVersion
}
version, err := strconv.ParseUint(str, 10, 32)
if err != nil {
return 0
return maxSupportedProtocolVersion
}

return uint32(version)
}
125 changes: 125 additions & 0 deletions cmd/soroban-rpc/internal/test/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package test

import (
"context"
"testing"
"time"

"github.com/creachadair/jrpc2"
"github.com/creachadair/jrpc2/jhttp"
"github.com/stellar/go/keypair"
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/xdr"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/db"
)

func TestUpgradeFrom20To21(t *testing.T) {
if GetCoreMaxSupportedProtocol() != 21 {
t.Skip("Only test this for protocol 21")
}
test := NewTest(t, &TestConfig{
ProtocolVersion: 20,
})

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)

// Upgrade to protocol 21 and re-upload the contract, which should cause a caching of the contract
// estimations
test.UpgradeProtocol(21)
// Wait for the ledger to advance, so that the simulation library passes the right protocol number
rpcDB := test.daemon.GetDB()
initialLedgerSequence, err := db.NewLedgerEntryReader(rpcDB).GetLatestLedgerSequence(context.Background())
require.Eventually(t,
func() bool {
newLedgerSequence, err := db.NewLedgerEntryReader(rpcDB).GetLatestLedgerSequence(context.Background())
require.NoError(t, err)
return newLedgerSequence > initialLedgerSequence
},
time.Minute,
time.Second,
)

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)

params = preflightTransactionParams(t, client, txnbuild.TransactionParams{
SourceAccount: &account,
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
createCreateContractOperation(address, helloWorldContract),
},
BaseFee: txnbuild.MinBaseFee,
Preconditions: txnbuild.Preconditions{
TimeBounds: txnbuild.NewInfiniteTimeout(),
},
})

tx, err = txnbuild.NewTransaction(params)
assert.NoError(t, err)
sendSuccessfulTransaction(t, client, sourceAccount, tx)

contractID := getContractID(t, address, testSalt, StandaloneNetworkPassphrase)
contractFnParameterSym := xdr.ScSymbol("world")
params = preflightTransactionParams(t, client, txnbuild.TransactionParams{
SourceAccount: &account,
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{
createInvokeHostOperation(
address,
contractID,
"hello",
xdr.ScVal{
Type: xdr.ScValTypeScvSymbol,
Sym: &contractFnParameterSym,
},
),
},
BaseFee: txnbuild.MinBaseFee,
Preconditions: txnbuild.Preconditions{
TimeBounds: txnbuild.NewInfiniteTimeout(),
},
})
tx, err = txnbuild.NewTransaction(params)
assert.NoError(t, err)

sendSuccessfulTransaction(t, client, sourceAccount, tx)
}
Loading