diff --git a/cmd/soroban-rpc/internal/test/integration.go b/cmd/soroban-rpc/internal/test/integration.go index 669bcc33..e24d8539 100644 --- a/cmd/soroban-rpc/internal/test/integration.go +++ b/cmd/soroban-rpc/internal/test/integration.go @@ -53,8 +53,9 @@ const ( type TestConfig struct { historyArchiveProxyCallback func(*http.Request) ProtocolVersion uint32 - UseRealRPCVersion string - UseSQLitePath string + // Run a previously released version of RPC (in a container) instead of the current version + UseReleasedRPCVersion string + UseSQLitePath string } type Test struct { @@ -64,9 +65,9 @@ type Test struct { protocolVersion uint32 - rpcContainerVersion string - rpcConfigMountDir string - rpcSQLiteMountDir string + rpcContainerVersion string + rpcContainerConfigMountDir string + rpcContainerSQLiteMountDir string daemon *daemon.Daemon @@ -96,7 +97,7 @@ func NewTest(t *testing.T, cfg *TestConfig) *Test { sqlLitePath := "" if cfg != nil { - i.rpcContainerVersion = cfg.UseRealRPCVersion + i.rpcContainerVersion = cfg.UseReleasedRPCVersion i.historyArchiveProxyCallback = cfg.historyArchiveProxyCallback i.protocolVersion = cfg.ProtocolVersion sqlLitePath = cfg.UseSQLitePath @@ -118,7 +119,7 @@ func NewTest(t *testing.T, cfg *TestConfig) *Test { rpcCfg := i.getRPConfig(sqlLitePath) if i.rpcContainerVersion != "" { - i.rpcConfigMountDir = i.createRPCContainerMountDir(rpcCfg) + i.rpcContainerConfigMountDir = i.createRPCContainerMountDir(rpcCfg) } i.runComposeCommand("up", "--detach", "--quiet-pull", "--no-color") i.prepareShutdownHandlers() @@ -203,7 +204,7 @@ func (i *Test) getRPConfig(sqlitePath string) map[string]string { // The container needs to listen on all interfaces, not just localhost bindHost = "0.0.0.0" // The container needs to use the sqlite mount point - i.rpcSQLiteMountDir = filepath.Dir(sqlitePath) + i.rpcContainerSQLiteMountDir = filepath.Dir(sqlitePath) sqlitePath = "/db/" + filepath.Base(sqlitePath) stellarCoreURL = fmt.Sprintf("http://core:%d", stellarCorePort) } @@ -315,8 +316,8 @@ func (i *Test) runComposeCommand(args ...string) { cmd.Env = append( cmd.Env, "RPC_IMAGE_TAG="+i.rpcContainerVersion, - "RPC_CONFIG_MOUNT_DIR="+i.rpcConfigMountDir, - "RPC_SQLITE_MOUNT_DIR="+i.rpcSQLiteMountDir, + "RPC_CONFIG_MOUNT_DIR="+i.rpcContainerConfigMountDir, + "RPC_SQLITE_MOUNT_DIR="+i.rpcContainerSQLiteMountDir, ) } if len(cmd.Env) > 0 { @@ -338,9 +339,7 @@ func (i *Test) runComposeCommand(args ...string) { func (i *Test) prepareShutdownHandlers() { i.shutdownCalls = append(i.shutdownCalls, func() { - if i.daemon != nil { - i.daemon.Close() - } + i.StopRPC() if i.historyArchiveProxy != nil { i.historyArchiveProxy.Close() } @@ -435,6 +434,16 @@ func (i *Test) UpgradeProtocol(version uint32) { i.t.Fatalf("could not upgrade protocol in 10s") } +func (i *Test) StopRPC() { + if i.daemon != nil { + i.daemon.Close() + i.daemon = nil + } + if i.rpcContainerVersion != "" { + i.runComposeCommand("down", "rpc", "-v") + } +} + // Cluttering code with if err != nil is absolute nonsense. func panicIf(err error) { if err != nil { diff --git a/cmd/soroban-rpc/internal/test/migrate_test.go b/cmd/soroban-rpc/internal/test/migrate_test.go index 10d37fa1..d7d565cf 100644 --- a/cmd/soroban-rpc/internal/test/migrate_test.go +++ b/cmd/soroban-rpc/internal/test/migrate_test.go @@ -23,11 +23,12 @@ import ( // Test that every Soroban RPC version (within the current protocol) can migrate cleanly to the current version // We cannot test prior protocol versions since the Transaction XDR used for the test could be incompatible +// TODO: find a way to test migrations between protocols func TestMigrate(t *testing.T) { if GetCoreMaxSupportedProtocol() != MaxSupportedProtocolVersion { t.Skip("Only test this for the latest protocol: ", MaxSupportedProtocolVersion) } - for _, originVersion := range getCurrentProtocolReleaseVersions(t) { + for _, originVersion := range getCurrentProtocolReleasedVersions(t) { if originVersion == "21.1.0" { // This version of the RPC container fails to even start with its captive core companion file // (it fails Invalid configuration: DEPRECATED_SQL_LEDGER_STATE not set.) @@ -47,8 +48,8 @@ func TestMigrate(t *testing.T) { func testMigrateFromVersion(t *testing.T, version string) { sqliteFile := filepath.Join(t.TempDir(), "soroban-rpc.db") it := NewTest(t, &TestConfig{ - UseRealRPCVersion: version, - UseSQLitePath: sqliteFile, + UseReleasedRPCVersion: version, + UseSQLitePath: sqliteFile, }) ch := jhttp.NewChannel(it.sorobanRPCURL(), nil) @@ -75,18 +76,11 @@ func testMigrateFromVersion(t *testing.T, version string) { assert.NoError(t, err) submitTransactionResponse := sendSuccessfulTransaction(t, client, kp, tx) - // Check the transaction with current RPC, but the previous network and sql database (causing a data migration) - // TODO: create a dedicated method - it.runComposeCommand("down", "rpc", "-v") + // Run the current RPC version, but the previous network and sql database (causing a data migration if needed) + it.StopRPC() it = NewTest(t, &TestConfig{UseSQLitePath: sqliteFile}) - // make sure that the instance is healthy - var healthResult methods.HealthCheckResult - err = client.CallResult(context.Background(), "getHealth", nil, &healthResult) - require.NoError(t, err) - require.Equal(t, "healthy", healthResult.Status) - - // make sure that the transaction submitted before and its events exist + // make sure that the transaction submitted before and its events exist in current RPC var transactionsResult methods.GetTransactionsResponse getTransactions := methods.GetTransactionsRequest{ StartLedger: submitTransactionResponse.Ledger, @@ -112,7 +106,7 @@ func testMigrateFromVersion(t *testing.T, version string) { require.Equal(t, submitTransactionResponse.Ledger, uint32(eventsResult.Events[0].Ledger)) } -func getCurrentProtocolReleaseVersions(t *testing.T) []string { +func getCurrentProtocolReleasedVersions(t *testing.T) []string { protocolStr := strconv.Itoa(MaxSupportedProtocolVersion) _, currentFilename, _, _ := runtime.Caller(0) currentDir := filepath.Dir(currentFilename)