Skip to content
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
817 changes: 361 additions & 456 deletions internal/jsonrpc/jsonrpc_test.go

Large diffs are not rendered by default.

61 changes: 44 additions & 17 deletions internal/jsonrpc/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (
"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/model"
"github.com/cartesi/rollups-node/internal/repository/factory"
"github.com/cartesi/rollups-node/internal/repository/repotest"
"github.com/cartesi/rollups-node/pkg/service"
"github.com/cartesi/rollups-node/test/tooling/db"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// histogram to gather statistics for each method
Expand Down Expand Up @@ -73,16 +74,16 @@ func newTestService(t *testing.T, name string) *Service {
ctx := context.Background()

dbTestEndpoint, err := db.GetTestDatabaseEndpoint()
assert.Nil(t, err)
require.NoError(t, err)

err = db.SetupTestPostgres(dbTestEndpoint)
assert.Nil(t, err)
require.NoError(t, err)

repo, err := factory.NewRepositoryFromConnectionString(ctx, dbTestEndpoint)
assert.Nil(t, err)
require.NoError(t, err)

logLevel, err := config.GetLogLevel()
assert.Nil(t, err)
require.NoError(t, err)

ci := CreateInfo{
CreateInfo: service.CreateInfo{
Expand All @@ -93,7 +94,7 @@ func newTestService(t *testing.T, name string) *Service {
Repository: repo,
}
s, err := Create(ctx, &ci)
assert.Nil(t, err, "on new test service")
require.NoError(t, err, "on new test service")

return s
}
Expand All @@ -108,17 +109,14 @@ func numberToName(x uint64) string {
}

// create an application with mostly stub values.
func (s *Service) newTestApplication(ctx context.Context, t *testing.T, test, i uint64) int64 {
func (s *Service) newTestApplication(ctx context.Context, t *testing.T, i uint64) int64 {
hex := numberToName(i)
id, err := s.repository.CreateApplication(ctx, &model.Application{
Name: hex,
IApplicationAddress: common.HexToAddress(hex),
DataAvailability: []byte{0x00, 0x00, 0x00, 0x00},
State: model.ApplicationState_Enabled,
ConsensusType: model.Consensus_Authority,
}, false)
assert.Nil(t, err, "on test case: %v, when creating application: %v", test, i)
return id
app := repotest.NewApplicationBuilder().
WithName(hex).
WithAddress(common.HexToAddress(hex)).
WithDataAvailability([]byte{0x00, 0x00, 0x00, 0x00}).
Create(ctx, t, s.repository)
return app.ID
}

func (s *Service) doRequest(t *testing.T, i uint64, reqData []byte) []byte {
Expand All @@ -134,7 +132,7 @@ func (s *Service) doRequest(t *testing.T, i uint64, reqData []byte) []byte {

body := new(strings.Builder)
_, err := io.Copy(body, w.Result().Body)
assert.Nil(t, err, "on test case: %v", i)
require.NoError(t, err, "on test case: %v", i)

return []byte(body.String())
}
Expand All @@ -151,6 +149,35 @@ func emptyVoucher() []byte {
return raw
}

// createTestEpoch creates an epoch using production CreateEpochsAndInputs.
func (s *Service) createTestEpoch(ctx context.Context, t *testing.T, appName string, epoch *model.Epoch) {
t.Helper()
err := s.repository.CreateEpochsAndInputs(ctx, appName,
map[*model.Epoch][]*model.Input{epoch: {}}, 10)
require.NoError(t, err)
}

// createTestEpochWithInput creates an epoch with one input using production CreateEpochsAndInputs.
func (s *Service) createTestEpochWithInput(
ctx context.Context, t *testing.T, appName string,
epoch *model.Epoch, input *model.Input,
) {
t.Helper()
err := s.repository.CreateEpochsAndInputs(ctx, appName,
map[*model.Epoch][]*model.Input{epoch: {input}}, 10)
require.NoError(t, err)
}

// advanceInput stores an advance result (outputs/reports) for an input using production StoreAdvanceResult.
func (s *Service) advanceInput(
ctx context.Context, t *testing.T, appID int64,
epochIndex, inputIndex uint64, outputs [][]byte, reports [][]byte,
) {
t.Helper()
repotest.StoreAdvanceResult(ctx, t, s.repository, appID, epochIndex, inputIndex,
model.InputCompletionStatus_Accepted, outputs, reports)
}

type listTournamentsResult struct {
EpochIndex hex64 `json:"epoch_index"`
Address common.Address `json:"address"`
Expand Down
135 changes: 0 additions & 135 deletions internal/repository/postgres/test_only.go

This file was deleted.

7 changes: 0 additions & 7 deletions internal/repository/postgres/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ func hashToBytes(h *common.Hash) any {
return (*h)[:]
}

func addressToBytes(a *common.Address) any {
if a == nil {
return nil
}
return (*a)[:]
}

// SubstrBytea returns a SUBSTR expression properly typed as ByteaExpression.
func SubstrBytea(col postgres.ColumnBytea, from, count int64) postgres.ByteaExpression {
qualified := pgx.Identifier{col.TableName(), col.Name()}.Sanitize()
Expand Down
8 changes: 0 additions & 8 deletions internal/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,6 @@ type ClaimerRepository interface {
) error
}

type TestRepository interface {
CreateEpoch(ctx context.Context, e *Epoch) error
CreateInput(ctx context.Context, inp *Input) error
CreateOutput(ctx context.Context, out *Output) error
CreateReport(ctx context.Context, report *Report) error
}

type Repository interface {
ApplicationRepository
EpochRepository
Expand All @@ -231,7 +224,6 @@ type Repository interface {
BulkOperationsRepository
NodeConfigRepository
ClaimerRepository
TestRepository
Close()
}

Expand Down
Loading
Loading