Skip to content

Commit

Permalink
Try #6696:
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemesh-bors[bot] authored Feb 6, 2025
2 parents 106070f + ea45a03 commit 3b994c6
Show file tree
Hide file tree
Showing 66 changed files with 569 additions and 679 deletions.
4 changes: 2 additions & 2 deletions activation/e2e/activation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/spacemeshos/go-spacemesh/activation"
"github.com/spacemeshos/go-spacemesh/activation/wire"
"github.com/spacemeshos/go-spacemesh/api/grpcserver"
v1 "github.com/spacemeshos/go-spacemesh/api/grpcserver/v1"
"github.com/spacemeshos/go-spacemesh/atxsdata"
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
Expand Down Expand Up @@ -64,7 +64,7 @@ func Test_BuilderWithMultipleClients(t *testing.T) {
db := statesql.InMemoryTest(t)
localDB := localsql.InMemoryTest(t)

svc := grpcserver.NewPostService(logger, grpcserver.PostServiceQueryInterval(100*time.Millisecond))
svc := v1.NewPostService(logger, v1.PostServiceQueryInterval(100*time.Millisecond))
svc.AllowConnections(true)

grpcCfg, cleanup := launchServer(t, svc)
Expand Down
4 changes: 2 additions & 2 deletions activation/e2e/atx_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/spacemeshos/go-spacemesh/activation"
ae2e "github.com/spacemeshos/go-spacemesh/activation/e2e"
"github.com/spacemeshos/go-spacemesh/activation/wire"
"github.com/spacemeshos/go-spacemesh/api/grpcserver"
v1 "github.com/spacemeshos/go-spacemesh/api/grpcserver/v1"
"github.com/spacemeshos/go-spacemesh/atxsdata"
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
Expand Down Expand Up @@ -214,7 +214,7 @@ func Test_MarryAndMerge(t *testing.T) {
t.Cleanup(func() { assert.NoError(t, cdb.Close()) })
localDB := localsql.InMemoryTest(t)

svc := grpcserver.NewPostService(logger, grpcserver.PostServiceQueryInterval(100*time.Millisecond))
svc := v1.NewPostService(logger, v1.PostServiceQueryInterval(100*time.Millisecond))
svc.AllowConnections(true)

grpcCfg, cleanup := launchServer(t, svc)
Expand Down
4 changes: 2 additions & 2 deletions activation/e2e/builds_atx_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/spacemeshos/go-spacemesh/activation"
ae2e "github.com/spacemeshos/go-spacemesh/activation/e2e"
"github.com/spacemeshos/go-spacemesh/activation/wire"
"github.com/spacemeshos/go-spacemesh/api/grpcserver"
v1 "github.com/spacemeshos/go-spacemesh/api/grpcserver/v1"
"github.com/spacemeshos/go-spacemesh/atxsdata"
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestBuilder_SwitchesToBuildV2(t *testing.T) {
t.Cleanup(func() { assert.NoError(t, cdb.Close()) })

opts := testPostSetupOpts(t)
svc := grpcserver.NewPostService(logger, grpcserver.PostServiceQueryInterval(100*time.Millisecond))
svc := v1.NewPostService(logger, v1.PostServiceQueryInterval(100*time.Millisecond))
svc.AllowConnections(true)

grpcCfg, cleanup := launchServer(t, svc)
Expand Down
4 changes: 2 additions & 2 deletions activation/e2e/certifier_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"golang.org/x/sync/errgroup"

"github.com/spacemeshos/go-spacemesh/activation"
"github.com/spacemeshos/go-spacemesh/api/grpcserver"
v1 "github.com/spacemeshos/go-spacemesh/api/grpcserver/v1"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql/localsql"
Expand All @@ -39,7 +39,7 @@ func TestCertification(t *testing.T) {

opts := testPostSetupOpts(t)
logger := zaptest.NewLogger(t)
svc := grpcserver.NewPostService(logger, grpcserver.PostServiceQueryInterval(100*time.Millisecond))
svc := v1.NewPostService(logger, v1.PostServiceQueryInterval(100*time.Millisecond))
svc.AllowConnections(true)

grpcCfg, cleanup := launchServer(t, svc)
Expand Down
4 changes: 2 additions & 2 deletions activation/e2e/checkpoint_merged_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/spacemeshos/go-spacemesh/activation"
ae2e "github.com/spacemeshos/go-spacemesh/activation/e2e"
"github.com/spacemeshos/go-spacemesh/activation/wire"
"github.com/spacemeshos/go-spacemesh/api/grpcserver"
v1 "github.com/spacemeshos/go-spacemesh/api/grpcserver/v1"
"github.com/spacemeshos/go-spacemesh/atxsdata"
"github.com/spacemeshos/go-spacemesh/checkpoint"
"github.com/spacemeshos/go-spacemesh/codec"
Expand Down Expand Up @@ -48,7 +48,7 @@ func Test_CheckpointAfterMerge(t *testing.T) {
t.Cleanup(func() { assert.NoError(t, cdb.Close()) })
localDB := localsql.InMemoryTest(t)

svc := grpcserver.NewPostService(logger, grpcserver.PostServiceQueryInterval(100*time.Millisecond))
svc := v1.NewPostService(logger, v1.PostServiceQueryInterval(100*time.Millisecond))
svc.AllowConnections(true)
grpcCfg, cleanup := launchServer(t, svc)
t.Cleanup(cleanup)
Expand Down
4 changes: 2 additions & 2 deletions activation/e2e/checkpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/spacemeshos/go-spacemesh/activation"
ae2e "github.com/spacemeshos/go-spacemesh/activation/e2e"
"github.com/spacemeshos/go-spacemesh/activation/wire"
"github.com/spacemeshos/go-spacemesh/api/grpcserver"
v1 "github.com/spacemeshos/go-spacemesh/api/grpcserver/v1"
"github.com/spacemeshos/go-spacemesh/atxsdata"
"github.com/spacemeshos/go-spacemesh/checkpoint"
"github.com/spacemeshos/go-spacemesh/codec"
Expand Down Expand Up @@ -51,7 +51,7 @@ func TestCheckpoint_PublishingSoloATXs(t *testing.T) {
t.Cleanup(func() { assert.NoError(t, cdb.Close()) })

opts := testPostSetupOpts(t)
svc := grpcserver.NewPostService(logger, grpcserver.PostServiceQueryInterval(100*time.Millisecond))
svc := v1.NewPostService(logger, v1.PostServiceQueryInterval(100*time.Millisecond))
svc.AllowConnections(true)
grpcCfg, cleanup := launchServer(t, svc)
t.Cleanup(cleanup)
Expand Down
11 changes: 6 additions & 5 deletions activation/e2e/nipost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/spacemeshos/go-spacemesh/activation"
ae2e "github.com/spacemeshos/go-spacemesh/activation/e2e"
"github.com/spacemeshos/go-spacemesh/api/grpcserver"
v1 "github.com/spacemeshos/go-spacemesh/api/grpcserver/v1"
"github.com/spacemeshos/go-spacemesh/atxsdata"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/signing"
Expand Down Expand Up @@ -92,7 +93,7 @@ func launchPostSupervisor(
postCfg activation.PostConfig,
postOpts activation.PostSetupOpts,
) func() {
cmdCfg := activation.DefaultTestPostServiceConfig()
cmdCfg := activation.DefaultTestPostServiceConfig(tb)
cmdCfg.NodeAddress = fmt.Sprintf("http://%s", cfg.PublicListener)
provingOpts := activation.DefaultPostProvingOpts()
provingOpts.RandomXMode = activation.PostRandomXModeLight
Expand All @@ -105,7 +106,7 @@ func launchPostSupervisor(
}

func launchServer(tb testing.TB, services ...grpcserver.ServiceAPI) (grpcserver.Config, func()) {
cfg := grpcserver.DefaultTestConfig()
cfg := grpcserver.DefaultTestConfig(tb)

// run on random ports
server := grpcserver.New("127.0.0.1:0", zaptest.NewLogger(tb).Named("grpc"), cfg)
Expand All @@ -130,7 +131,7 @@ func initPost(
sig *signing.EdSigner,
golden types.ATXID,
grpcCfg grpcserver.Config,
svc *grpcserver.PostService,
svc *v1.PostService,
) {
tb.Helper()

Expand Down Expand Up @@ -161,7 +162,7 @@ func TestNIPostBuilderWithClients(t *testing.T) {
localDb := localsql.InMemoryTest(t)

opts := testPostSetupOpts(t)
svc := grpcserver.NewPostService(logger, grpcserver.PostServiceQueryInterval(100*time.Millisecond))
svc := v1.NewPostService(logger, v1.PostServiceQueryInterval(100*time.Millisecond))
svc.AllowConnections(true)
grpcCfg, cleanup := launchServer(t, svc)
t.Cleanup(cleanup)
Expand Down Expand Up @@ -247,7 +248,7 @@ func Test_NIPostBuilderWithMultipleClients(t *testing.T) {
db := statesql.InMemoryTest(t)

opts := testPostSetupOpts(t)
svc := grpcserver.NewPostService(logger, grpcserver.PostServiceQueryInterval(100*time.Millisecond))
svc := v1.NewPostService(logger, v1.PostServiceQueryInterval(100*time.Millisecond))
svc.AllowConnections(true)
grpcCfg, cleanup := launchServer(t, svc)
t.Cleanup(cleanup)
Expand Down
4 changes: 2 additions & 2 deletions activation/e2e/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/spacemeshos/go-spacemesh/activation"
ae2e "github.com/spacemeshos/go-spacemesh/activation/e2e"
"github.com/spacemeshos/go-spacemesh/api/grpcserver"
v1 "github.com/spacemeshos/go-spacemesh/api/grpcserver/v1"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql/localsql"
Expand All @@ -34,7 +34,7 @@ func TestValidator_Validate(t *testing.T) {
validator := activation.NewMocknipostValidator(gomock.NewController(t))

opts := testPostSetupOpts(t)
svc := grpcserver.NewPostService(logger, grpcserver.PostServiceQueryInterval(100*time.Millisecond))
svc := v1.NewPostService(logger, v1.PostServiceQueryInterval(100*time.Millisecond))
svc.AllowConnections(true)
grpcCfg, cleanup := launchServer(t, svc)
t.Cleanup(cleanup)
Expand Down
8 changes: 4 additions & 4 deletions activation/post_supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"strings"
"sync"
"sync/atomic"
"testing"

"github.com/spacemeshos/post/initialization"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"

Expand All @@ -39,11 +41,9 @@ func DefaultPostServiceConfig() PostSupervisorConfig {
}

// DefaultTestPostServiceConfig returns the default config for post service in tests.
func DefaultTestPostServiceConfig() PostSupervisorConfig {
func DefaultTestPostServiceConfig(tb testing.TB) PostSupervisorConfig {
path, err := exec.Command("go", "env", "GOMOD").Output()
if err != nil {
panic(err)
}
require.NoError(tb, err)

return PostSupervisorConfig{
PostServiceCmd: filepath.Join(filepath.Dir(string(path)), "build", DefaultPostServiceName),
Expand Down
16 changes: 8 additions & 8 deletions activation/post_supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func newPostManager(tb testing.TB, cfg PostConfig, opts PostSetupOpts) *PostSetu
func Test_PostSupervisor_ErrorOnMissingBinary(t *testing.T) {
log := zaptest.NewLogger(t)

cmdCfg := DefaultTestPostServiceConfig()
cmdCfg := DefaultTestPostServiceConfig(t)
cmdCfg.PostServiceCmd = "missing"
postCfg := DefaultPostConfig()
postOpts := DefaultPostSetupOpts()
Expand All @@ -93,7 +93,7 @@ func Test_PostSupervisor_StopWithoutStart(t *testing.T) {
func Test_PostSupervisor_Start_FailPrepare(t *testing.T) {
log := zaptest.NewLogger(t).WithOptions(zap.WithFatalHook(calledFatal(t)))

cmdCfg := DefaultTestPostServiceConfig()
cmdCfg := DefaultTestPostServiceConfig(t)
postCfg := DefaultPostConfig()
postOpts := DefaultPostSetupOpts()
postOpts.DataDir = t.TempDir()
Expand Down Expand Up @@ -129,7 +129,7 @@ func calledFatal(tb testing.TB) zapcore.CheckWriteHook {
func Test_PostSupervisor_Start_FailStartSession(t *testing.T) {
log := zaptest.NewLogger(t, zaptest.WrapOptions(zap.WithFatalHook(calledFatal(t))))

cmdCfg := DefaultTestPostServiceConfig()
cmdCfg := DefaultTestPostServiceConfig(t)
postCfg := DefaultPostConfig()
postOpts := DefaultPostSetupOpts()
postOpts.DataDir = t.TempDir()
Expand All @@ -151,7 +151,7 @@ func Test_PostSupervisor_Start_FailStartSession(t *testing.T) {
func Test_PostSupervisor_StartsServiceCmd(t *testing.T) {
log := zaptest.NewLogger(t)

cmdCfg := DefaultTestPostServiceConfig()
cmdCfg := DefaultTestPostServiceConfig(t)
postCfg := DefaultPostConfig()
postOpts := testSetupOpts(t)
provingOpts := DefaultPostProvingOpts()
Expand Down Expand Up @@ -188,7 +188,7 @@ func Test_PostSupervisor_StartsServiceCmd(t *testing.T) {
func Test_PostSupervisor_Restart_Possible(t *testing.T) {
log := zaptest.NewLogger(t)

cmdCfg := DefaultTestPostServiceConfig()
cmdCfg := DefaultTestPostServiceConfig(t)
postCfg := DefaultPostConfig()
postOpts := testSetupOpts(t)
provingOpts := DefaultPostProvingOpts()
Expand Down Expand Up @@ -219,7 +219,7 @@ func Test_PostSupervisor_Restart_Possible(t *testing.T) {
func Test_PostSupervisor_LogFatalOnCrash(t *testing.T) {
log := zaptest.NewLogger(t, zaptest.WrapOptions(zap.WithFatalHook(calledFatal(t))))

cmdCfg := DefaultTestPostServiceConfig()
cmdCfg := DefaultTestPostServiceConfig(t)
postCfg := DefaultPostConfig()
postOpts := testSetupOpts(t)
provingOpts := DefaultPostProvingOpts()
Expand Down Expand Up @@ -250,7 +250,7 @@ func Test_PostSupervisor_LogFatalOnCrash(t *testing.T) {
func Test_PostSupervisor_LogFatalOnInvalidConfig(t *testing.T) {
log := zaptest.NewLogger(t, zaptest.WrapOptions(zap.WithFatalHook(calledFatal(t))))

cmdCfg := DefaultTestPostServiceConfig()
cmdCfg := DefaultTestPostServiceConfig(t)
cmdCfg.NodeAddress = "http://127.0.0.1:9099" // wrong port
cmdCfg.MaxRetries = 1 // speedup test, will fail on 2nd retry (~ 5s)
postCfg := DefaultPostConfig()
Expand Down Expand Up @@ -282,7 +282,7 @@ func Test_PostSupervisor_LogFatalOnInvalidConfig(t *testing.T) {
func Test_PostSupervisor_StopOnError(t *testing.T) {
log := zaptest.NewLogger(t)

cmdCfg := DefaultTestPostServiceConfig()
cmdCfg := DefaultTestPostServiceConfig(t)
postCfg := DefaultPostConfig()
postOpts := testSetupOpts(t)
provingOpts := DefaultPostProvingOpts()
Expand Down
21 changes: 14 additions & 7 deletions api/grpcserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package grpcserver

import (
"testing"
"time"
)

Expand Down Expand Up @@ -74,19 +75,25 @@ const (
func DefaultConfig() Config {
return Config{
PublicServices: []Service{
GlobalState, Mesh, Transaction, Node, Activation, ActivationV2Alpha1,
RewardV2Alpha1, NetworkV2Alpha1, NodeV2Alpha1, LayerV2Alpha1, TransactionV2Alpha1,
AccountV2Alpha1, MalfeasanceV2Alpha1,
// v1
GlobalState, Mesh, Transaction, Node, Activation,

// v2alpha1
ActivationV2Alpha1, RewardV2Alpha1, NetworkV2Alpha1, NodeV2Alpha1,
LayerV2Alpha1, TransactionV2Alpha1, AccountV2Alpha1, MalfeasanceV2Alpha1,

// v2beta1
ActivationV2Beta1, RewardV2Beta1, NetworkV2Beta1, NodeV2Beta1,
LayerV2Beta1, TransactionV2Beta1, AccountV2Beta1, MalfeasanceV2Beta1,
},
PublicListener: "0.0.0.0:9092",
PrivateServices: []Service{
Admin, Smesher, Debug, ActivationStreamV2Alpha1,
RewardStreamV2Alpha1, LayerStreamV2Alpha1, TransactionStreamV2Alpha1,
MalfeasanceStreamV2Alpha1,
// v1
Admin, Smesher, Debug,

// v2alpha1
ActivationStreamV2Alpha1, RewardStreamV2Alpha1, LayerStreamV2Alpha1,
TransactionStreamV2Alpha1, MalfeasanceStreamV2Alpha1,

// v2beta1
ActivationStreamV2Beta1, RewardStreamV2Beta1, LayerStreamV2Beta1,
Expand All @@ -107,7 +114,7 @@ func DefaultConfig() Config {
}

// DefaultTestConfig returns the default config for tests.
func DefaultTestConfig() Config {
func DefaultTestConfig(tb testing.TB) Config {
conf := DefaultConfig()
conf.PublicListener = "127.0.0.1:0"
conf.PrivateListener = "127.0.0.1:0"
Expand Down
17 changes: 9 additions & 8 deletions api/grpcserver/http_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import (
"go.uber.org/zap/zaptest"
"google.golang.org/protobuf/encoding/protojson"

v1 "github.com/spacemeshos/go-spacemesh/api/grpcserver/v1"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/sql/statesql"
)

func launchJsonServer(tb testing.TB, services ...ServiceAPI) (Config, func()) {
cfg := DefaultTestConfig()
cfg := DefaultTestConfig(tb)

// run on random port
jsonService := NewJSONHTTPServer(zaptest.NewLogger(tb).Named("grpc.JSON"), "127.0.0.1:0",
Expand Down Expand Up @@ -59,16 +60,16 @@ func TestJsonApi(t *testing.T) {
const build = "cafebabe"

ctrl, ctx := gomock.WithContext(context.Background(), t)
peerCounter := NewMockpeerCounter(ctrl)
meshAPIMock := NewMockmeshAPI(ctrl)
genTime := NewMockgenesisTimeAPI(ctrl)
syncer := NewMocksyncer(ctrl)
conStateAPI := NewMockconservativeState(ctrl)
peerCounter := v1.NewMockpeerCounter(ctrl)
meshAPIMock := v1.NewMockmeshAPI(ctrl)
genTime := v1.NewMockgenesisTimeAPI(ctrl)
syncer := v1.NewMocksyncer(ctrl)
conStateAPI := v1.NewMockconservativeState(ctrl)

cdb := datastore.NewCachedDB(statesql.InMemoryTest(t), zaptest.NewLogger(t))
t.Cleanup(func() { assert.NoError(t, cdb.Close()) })
svc1 := NewNodeService(peerCounter, meshAPIMock, genTime, syncer, version, build)
svc2 := NewMeshService(
svc1 := v1.NewNodeService(peerCounter, meshAPIMock, genTime, syncer, version, build)
svc2 := v1.NewMeshService(
cdb,
meshAPIMock,
conStateAPI,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package grpcserver
package v1

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package grpcserver
package v1

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package grpcserver
package v1

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package grpcserver
package v1

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package grpcserver
package v1

import (
"context"
Expand Down
Loading

0 comments on commit 3b994c6

Please sign in to comment.