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

[Merged by Bors] - Update tortoise package to use zap directly #5976

Closed
wants to merge 3 commits into from
Closed
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 activation/e2e/nipost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestNIPostBuilderWithClients(t *testing.T) {
goldenATX := types.ATXID{2, 3, 4}
cfg := activation.DefaultPostConfig()
db := sql.InMemory()
cdb := datastore.NewCachedDB(db, log.NewFromLog(logger))
cdb := datastore.NewCachedDB(db, logger)
localDb := localsql.InMemory()

syncer := activation.NewMocksyncer(ctrl)
Expand Down
2 changes: 1 addition & 1 deletion activation/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func newTestHandlerMocks(tb testing.TB, golden types.ATXID) handlerMocks {

func newTestHandler(tb testing.TB, goldenATXID types.ATXID, opts ...HandlerOption) *testHandler {
lg := logtest.New(tb)
cdb := datastore.NewCachedDB(sql.InMemory(), lg)
cdb := datastore.NewCachedDB(sql.InMemory(), lg.Zap())
edVerifier := signing.NewEdVerifier()

mocks := newTestHandlerMocks(tb, goldenATXID)
Expand Down
2 changes: 1 addition & 1 deletion activation/handler_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type v1TestHandler struct {

func newV1TestHandler(tb testing.TB, goldenATXID types.ATXID) *v1TestHandler {
lg := logtest.New(tb)
cdb := datastore.NewCachedDB(sql.InMemory(), lg)
cdb := datastore.NewCachedDB(sql.InMemory(), lg.Zap())
mocks := newTestHandlerMocks(tb, goldenATXID)
return &v1TestHandler{
HandlerV1: &HandlerV1{
Expand Down
6 changes: 3 additions & 3 deletions activation/handler_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"github.com/spacemeshos/post/shared"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"go.uber.org/zap/zaptest"

"github.com/spacemeshos/go-spacemesh/activation/wire"
"github.com/spacemeshos/go-spacemesh/atxsdata"
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/log/logtest"
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql"
)
Expand All @@ -28,7 +28,7 @@ type v2TestHandler struct {
}

func newV2TestHandler(tb testing.TB, golden types.ATXID) *v2TestHandler {
lg := logtest.New(tb)
lg := zaptest.NewLogger(tb)
cdb := datastore.NewCachedDB(sql.InMemory(), lg)
mocks := newTestHandlerMocks(tb, golden)
return &v2TestHandler{
Expand All @@ -41,7 +41,7 @@ func newV2TestHandler(tb testing.TB, golden types.ATXID) *v2TestHandler {
tickSize: 1,
goldenATXID: golden,
nipostValidator: mocks.mValidatorV2,
log: lg.Zap(),
log: lg,
fetcher: mocks.mockFetch,
beacon: mocks.mbeacon,
tortoise: mocks.mtortoise,
Expand Down
3 changes: 1 addition & 2 deletions activation/post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/spacemeshos/go-spacemesh/atxsdata"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/log/logtest"
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql"
"github.com/spacemeshos/go-spacemesh/sql/atxs"
Expand Down Expand Up @@ -365,8 +364,8 @@ func newTestPostManager(tb testing.TB) *testPostManager {
close(synced)
syncer.EXPECT().RegisterForATXSynced().AnyTimes().Return(synced)

cdb := datastore.NewCachedDB(sql.InMemory(), logtest.New(tb))
logger := zaptest.NewLogger(tb)
cdb := datastore.NewCachedDB(sql.InMemory(), logger)
mgr, err := NewPostSetupManager(DefaultPostConfig(), logger, cdb, atxsdata.New(), goldenATXID, syncer, validator)
require.NoError(tb, err)

Expand Down
15 changes: 8 additions & 7 deletions api/grpcserver/grpcserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ func TestMeshService(t *testing.T) {
genesis := time.Unix(genTimeUnix, 0)
genTime.EXPECT().GenesisTime().Return(genesis)
genTime.EXPECT().CurrentLayer().Return(layerCurrent).AnyTimes()
db := datastore.NewCachedDB(sql.InMemory(), logtest.New(t))
db := datastore.NewCachedDB(sql.InMemory(), zaptest.NewLogger(t))
svc := NewMeshService(
db,
meshAPIMock,
Expand Down Expand Up @@ -1676,7 +1676,7 @@ func TestAccountMeshDataStream_comprehensive(t *testing.T) {
ctrl := gomock.NewController(t)
genTime := NewMockgenesisTimeAPI(ctrl)
grpcService := NewMeshService(
datastore.NewCachedDB(sql.InMemory(), logtest.New(t)),
datastore.NewCachedDB(sql.InMemory(), zaptest.NewLogger(t)),
meshAPIMock,
conStateAPI,
genTime,
Expand Down Expand Up @@ -1858,7 +1858,7 @@ func TestLayerStream_comprehensive(t *testing.T) {

ctrl := gomock.NewController(t)
genTime := NewMockgenesisTimeAPI(ctrl)
db := datastore.NewCachedDB(sql.InMemory(), logtest.New(t))
db := datastore.NewCachedDB(sql.InMemory(), zaptest.NewLogger(t))

grpcService := NewMeshService(
db,
Expand Down Expand Up @@ -2004,7 +2004,7 @@ func TestMultiService(t *testing.T) {
genTime.EXPECT().GenesisTime().Return(genesis)
svc1 := NewNodeService(peerCounter, meshAPIMock, genTime, syncer, "v0.0.0", "cafebabe")
svc2 := NewMeshService(
datastore.NewCachedDB(sql.InMemory(), logtest.New(t)),
datastore.NewCachedDB(sql.InMemory(), zaptest.NewLogger(t)),
meshAPIMock,
conStateAPI,
genTime,
Expand Down Expand Up @@ -2274,8 +2274,9 @@ func TestEventsReceived(t *testing.T) {
// Give the server-side time to subscribe to events
time.Sleep(time.Millisecond * 50)

svm := vm.New(sql.InMemory(), vm.WithLogger(logtest.New(t)))
conState := txs.NewConservativeState(svm, sql.InMemory(), txs.WithLogger(zaptest.NewLogger(t).Named("conState")))
lg := logtest.New(t)
svm := vm.New(sql.InMemory(), vm.WithLogger(lg))
conState := txs.NewConservativeState(svm, sql.InMemory(), txs.WithLogger(lg.Zap().Named("conState")))
conState.AddToCache(context.Background(), globalTx, time.Now())

weight := new(big.Rat).SetFloat64(18.7)
Expand Down Expand Up @@ -2476,7 +2477,7 @@ func TestMeshService_EpochStream(t *testing.T) {
genTime := NewMockgenesisTimeAPI(ctrl)
db := sql.InMemory()
srv := NewMeshService(
datastore.NewCachedDB(db, logtest.New(t)),
datastore.NewCachedDB(db, zaptest.NewLogger(t)),
meshAPIMock,
conStateAPI,
genTime,
Expand Down
3 changes: 1 addition & 2 deletions api/grpcserver/http_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/log/logtest"
"github.com/spacemeshos/go-spacemesh/sql"
)

Expand Down Expand Up @@ -66,7 +65,7 @@ func TestJsonApi(t *testing.T) {
conStateAPI := NewMockconservativeState(ctrl)
svc1 := NewNodeService(peerCounter, meshAPIMock, genTime, syncer, version, build)
svc2 := NewMeshService(
datastore.NewCachedDB(sql.InMemory(), logtest.New(t)),
datastore.NewCachedDB(sql.InMemory(), zaptest.NewLogger(t)),
meshAPIMock,
conStateAPI,
genTime,
Expand Down
12 changes: 6 additions & 6 deletions api/grpcserver/mesh_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
pb "github.com/spacemeshos/api/release/go/spacemesh/v1"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
"go.uber.org/zap/zaptest"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/datastore"
"github.com/spacemeshos/go-spacemesh/events"
"github.com/spacemeshos/go-spacemesh/log/logtest"
"github.com/spacemeshos/go-spacemesh/malfeasance/wire"
"github.com/spacemeshos/go-spacemesh/signing"
"github.com/spacemeshos/go-spacemesh/sql"
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestMeshService_MalfeasanceQuery(t *testing.T) {
genTime := NewMockgenesisTimeAPI(ctrl)
db := sql.InMemory()
srv := NewMeshService(
datastore.NewCachedDB(db, logtest.New(t)),
datastore.NewCachedDB(db, zaptest.NewLogger(t)),
meshAPIMock,
conStateAPI,
genTime,
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestMeshService_MalfeasanceStream(t *testing.T) {
genTime := NewMockgenesisTimeAPI(ctrl)
db := sql.InMemory()
srv := NewMeshService(
datastore.NewCachedDB(db, logtest.New(t)),
datastore.NewCachedDB(db, zaptest.NewLogger(t)),
meshAPIMock,
conStateAPI,
genTime,
Expand Down Expand Up @@ -303,7 +303,7 @@ func TestReadLayer(t *testing.T) {
genTime := NewMockgenesisTimeAPI(ctrl)
db := sql.InMemory()
srv := NewMeshService(
datastore.NewCachedDB(db, logtest.New(t)),
datastore.NewCachedDB(db, zaptest.NewLogger(t)),
&MeshAPIMockInstrumented{},
conStateAPI,
genTime,
Expand All @@ -325,7 +325,7 @@ func TestReadLayer(t *testing.T) {
require.NoError(t, err)

srv = NewMeshService(
datastore.NewCachedDB(db, logtest.New(t)),
datastore.NewCachedDB(db, zaptest.NewLogger(t)),
meshAPIMock,
conStateAPI,
genTime,
Expand All @@ -340,7 +340,7 @@ func TestReadLayer(t *testing.T) {

// now instrument conStateAPI to return errors
srv = NewMeshService(
datastore.NewCachedDB(db, logtest.New(t)),
datastore.NewCachedDB(db, zaptest.NewLogger(t)),
meshAPIMock,
&ConStateAPIMockInstrumented{*conStateAPI},
genTime,
Expand Down
34 changes: 20 additions & 14 deletions beacon/beacon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func newTestDriver(tb testing.TB, cfg Config, p pubsub.Publisher, miners int, id

tpd.mVerifier.EXPECT().Verify(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return(true)

tpd.cdb = datastore.NewCachedDB(sql.InMemory(), lg)
tpd.cdb = datastore.NewCachedDB(sql.InMemory(), lg.Zap())
tpd.ProtocolDriver = New(p, signing.NewEdVerifier(), tpd.mVerifier, tpd.cdb, tpd.mClock,
WithConfig(cfg),
WithLogger(lg),
Expand Down Expand Up @@ -490,14 +490,15 @@ func TestBeaconWithMetrics(t *testing.T) {

func TestBeacon_NoRaceOnClose(t *testing.T) {
mclock := NewMocklayerClock(gomock.NewController(t))
lg := logtest.New(t)
pd := &ProtocolDriver{
logger: logtest.New(t).WithName("Beacon"),
logger: lg.WithName("Beacon"),
beacons: make(map[types.EpochID]types.Beacon),
cdb: datastore.NewCachedDB(sql.InMemory(), logtest.New(t)),
cdb: datastore.NewCachedDB(sql.InMemory(), lg.Zap()),
clock: mclock,
closed: make(chan struct{}),
results: make(chan result.Beacon, 100),
metricsCollector: metrics.NewBeaconMetricsCollector(nil, logtest.New(t).WithName("metrics")),
metricsCollector: metrics.NewBeaconMetricsCollector(nil, lg.WithName("metrics")),
}
// check for a race between onResult and Close
var eg errgroup.Group
Expand All @@ -523,11 +524,12 @@ func TestBeacon_NoRaceOnClose(t *testing.T) {
func TestBeacon_BeaconsWithDatabase(t *testing.T) {
t.Parallel()

lg := logtest.New(t)
mclock := NewMocklayerClock(gomock.NewController(t))
pd := &ProtocolDriver{
logger: logtest.New(t).WithName("Beacon"),
logger: lg.WithName("Beacon"),
beacons: make(map[types.EpochID]types.Beacon),
cdb: datastore.NewCachedDB(sql.InMemory(), logtest.New(t)),
cdb: datastore.NewCachedDB(sql.InMemory(), lg.Zap()),
clock: mclock,
}
epoch3 := types.EpochID(3)
Expand Down Expand Up @@ -575,11 +577,12 @@ func TestBeacon_BeaconsWithDatabase(t *testing.T) {
func TestBeacon_BeaconsWithDatabaseFailure(t *testing.T) {
t.Parallel()

lg := logtest.New(t)
mclock := NewMocklayerClock(gomock.NewController(t))
pd := &ProtocolDriver{
logger: logtest.New(t).WithName("Beacon"),
logger: lg.WithName("Beacon"),
beacons: make(map[types.EpochID]types.Beacon),
cdb: datastore.NewCachedDB(sql.InMemory(), logtest.New(t)),
cdb: datastore.NewCachedDB(sql.InMemory(), lg.Zap()),
clock: mclock,
}
epoch := types.EpochID(3)
Expand All @@ -593,10 +596,11 @@ func TestBeacon_BeaconsWithDatabaseFailure(t *testing.T) {
func TestBeacon_BeaconsCleanupOldEpoch(t *testing.T) {
t.Parallel()

lg := logtest.New(t)
mclock := NewMocklayerClock(gomock.NewController(t))
pd := &ProtocolDriver{
logger: logtest.New(t).WithName("Beacon"),
cdb: datastore.NewCachedDB(sql.InMemory(), logtest.New(t)),
logger: lg.WithName("Beacon"),
cdb: datastore.NewCachedDB(sql.InMemory(), lg.Zap()),
beacons: make(map[types.EpochID]types.Beacon),
ballotsBeacons: make(map[types.EpochID]map[types.Beacon]*beaconWeight),
clock: mclock,
Expand Down Expand Up @@ -696,11 +700,12 @@ func TestBeacon_ReportBeaconFromBallot(t *testing.T) {
require.Greater(t, maxWeight.Float(), 0.0)
}

lg := logtest.New(t)
mclock := NewMocklayerClock(gomock.NewController(t))
pd := &ProtocolDriver{
logger: logtest.New(t).WithName("Beacon"),
logger: lg.WithName("Beacon"),
config: UnitTestConfig(),
cdb: datastore.NewCachedDB(sql.InMemory(), logtest.New(t)),
cdb: datastore.NewCachedDB(sql.InMemory(), lg.Zap()),
beacons: make(map[types.EpochID]types.Beacon),
ballotsBeacons: make(map[types.EpochID]map[types.Beacon]*beaconWeight),
clock: mclock,
Expand Down Expand Up @@ -731,11 +736,12 @@ func TestBeacon_ReportBeaconFromBallot(t *testing.T) {
func TestBeacon_ReportBeaconFromBallot_SameBallot(t *testing.T) {
t.Parallel()

lg := logtest.New(t)
mclock := NewMocklayerClock(gomock.NewController(t))
pd := &ProtocolDriver{
logger: logtest.New(t).WithName("Beacon"),
logger: lg.WithName("Beacon"),
config: UnitTestConfig(),
cdb: datastore.NewCachedDB(sql.InMemory(), logtest.New(t)),
cdb: datastore.NewCachedDB(sql.InMemory(), lg.Zap()),
beacons: make(map[types.EpochID]types.Beacon),
ballotsBeacons: make(map[types.EpochID]map[types.Beacon]*beaconWeight),
clock: mclock,
Expand Down
2 changes: 1 addition & 1 deletion checkpoint/recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func validateAndPreserveData(
mvalidator := activation.NewMocknipostValidator(ctrl)
mreceiver := activation.NewMockAtxReceiver(ctrl)
mtrtl := smocks.NewMockTortoise(ctrl)
cdb := datastore.NewCachedDB(db, lg)
cdb := datastore.NewCachedDB(db, lg.Zap())
atxHandler := activation.NewHandler(
"",
cdb,
Expand Down
7 changes: 4 additions & 3 deletions cmd/bootstrapper/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestGenerator_Generate(t *testing.T) {
targetEpoch := types.EpochID(3)
db := sql.InMemory()
createAtxs(t, db, targetEpoch-1, types.RandomActiveSet(activeSetSize))
cfg, cleanup := launchServer(t, datastore.NewCachedDB(db, logtest.New(t)))
cfg, cleanup := launchServer(t, datastore.NewCachedDB(db, zaptest.NewLogger(t)))
t.Cleanup(cleanup)

for _, tc := range []struct {
Expand Down Expand Up @@ -169,15 +169,16 @@ func TestGenerator_Generate(t *testing.T) {
func TestGenerator_CheckAPI(t *testing.T) {
targetEpoch := types.EpochID(3)
db := sql.InMemory()
lg := logtest.New(t)
createAtxs(t, db, targetEpoch-1, types.RandomActiveSet(activeSetSize))
cfg, cleanup := launchServer(t, datastore.NewCachedDB(db, logtest.New(t)))
cfg, cleanup := launchServer(t, datastore.NewCachedDB(db, lg.Zap()))
t.Cleanup(cleanup)

fs := afero.NewMemMapFs()
g := NewGenerator(
"https://api.blockcypher.com/v1/btc/main",
cfg.PublicListener,
WithLogger(logtest.New(t)),
WithLogger(lg),
WithFilesystem(fs),
WithHttpClient(http.DefaultClient),
)
Expand Down
3 changes: 2 additions & 1 deletion cmd/bootstrapper/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/spf13/afero"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"

"github.com/spacemeshos/go-spacemesh/bootstrap"
"github.com/spacemeshos/go-spacemesh/common/types"
Expand Down Expand Up @@ -57,7 +58,7 @@ func updateCheckpoint(t *testing.T, ctx context.Context, data string) {

func TestServer(t *testing.T) {
db := sql.InMemory()
cfg, cleanup := launchServer(t, datastore.NewCachedDB(db, logtest.New(t)))
cfg, cleanup := launchServer(t, datastore.NewCachedDB(db, zaptest.NewLogger(t)))
t.Cleanup(cleanup)

fs := afero.NewMemMapFs()
Expand Down
Loading
Loading