@@ -19,11 +19,12 @@ import (
1919 "github.com/cartesi/rollups-node/internal/config"
2020 "github.com/cartesi/rollups-node/internal/model"
2121 "github.com/cartesi/rollups-node/internal/repository/factory"
22+ "github.com/cartesi/rollups-node/internal/repository/repotest"
2223 "github.com/cartesi/rollups-node/pkg/service"
2324 "github.com/cartesi/rollups-node/test/tooling/db"
2425 "github.com/ethereum/go-ethereum/common"
2526 "github.com/ethereum/go-ethereum/common/hexutil"
26- "github.com/stretchr/testify/assert "
27+ "github.com/stretchr/testify/require "
2728)
2829
2930// histogram to gather statistics for each method
@@ -73,16 +74,16 @@ func newTestService(t *testing.T, name string) *Service {
7374 ctx := context .Background ()
7475
7576 dbTestEndpoint , err := db .GetTestDatabaseEndpoint ()
76- assert . Nil (t , err )
77+ require . NoError (t , err )
7778
7879 err = db .SetupTestPostgres (dbTestEndpoint )
79- assert . Nil (t , err )
80+ require . NoError (t , err )
8081
8182 repo , err := factory .NewRepositoryFromConnectionString (ctx , dbTestEndpoint )
82- assert . Nil (t , err )
83+ require . NoError (t , err )
8384
8485 logLevel , err := config .GetLogLevel ()
85- assert . Nil (t , err )
86+ require . NoError (t , err )
8687
8788 ci := CreateInfo {
8889 CreateInfo : service.CreateInfo {
@@ -93,7 +94,7 @@ func newTestService(t *testing.T, name string) *Service {
9394 Repository : repo ,
9495 }
9596 s , err := Create (ctx , & ci )
96- assert . Nil (t , err , "on new test service" )
97+ require . NoError (t , err , "on new test service" )
9798
9899 return s
99100}
@@ -108,17 +109,14 @@ func numberToName(x uint64) string {
108109}
109110
110111// create an application with mostly stub values.
111- func (s * Service ) newTestApplication (ctx context.Context , t * testing.T , test , i uint64 ) int64 {
112+ func (s * Service ) newTestApplication (ctx context.Context , t * testing.T , i uint64 ) int64 {
112113 hex := numberToName (i )
113- id , err := s .repository .CreateApplication (ctx , & model.Application {
114- Name : hex ,
115- IApplicationAddress : common .HexToAddress (hex ),
116- DataAvailability : []byte {0x00 , 0x00 , 0x00 , 0x00 },
117- State : model .ApplicationState_Enabled ,
118- ConsensusType : model .Consensus_Authority ,
119- }, false )
120- assert .Nil (t , err , "on test case: %v, when creating application: %v" , test , i )
121- return id
114+ app := repotest .NewApplicationBuilder ().
115+ WithName (hex ).
116+ WithAddress (common .HexToAddress (hex )).
117+ WithDataAvailability ([]byte {0x00 , 0x00 , 0x00 , 0x00 }).
118+ Create (ctx , t , s .repository )
119+ return app .ID
122120}
123121
124122func (s * Service ) doRequest (t * testing.T , i uint64 , reqData []byte ) []byte {
@@ -134,7 +132,7 @@ func (s *Service) doRequest(t *testing.T, i uint64, reqData []byte) []byte {
134132
135133 body := new (strings.Builder )
136134 _ , err := io .Copy (body , w .Result ().Body )
137- assert . Nil (t , err , "on test case: %v" , i )
135+ require . NoError (t , err , "on test case: %v" , i )
138136
139137 return []byte (body .String ())
140138}
@@ -151,6 +149,35 @@ func emptyVoucher() []byte {
151149 return raw
152150}
153151
152+ // createTestEpoch creates an epoch using production CreateEpochsAndInputs.
153+ func (s * Service ) createTestEpoch (ctx context.Context , t * testing.T , appName string , epoch * model.Epoch ) {
154+ t .Helper ()
155+ err := s .repository .CreateEpochsAndInputs (ctx , appName ,
156+ map [* model.Epoch ][]* model.Input {epoch : {}}, 10 )
157+ require .NoError (t , err )
158+ }
159+
160+ // createTestEpochWithInput creates an epoch with one input using production CreateEpochsAndInputs.
161+ func (s * Service ) createTestEpochWithInput (
162+ ctx context.Context , t * testing.T , appName string ,
163+ epoch * model.Epoch , input * model.Input ,
164+ ) {
165+ t .Helper ()
166+ err := s .repository .CreateEpochsAndInputs (ctx , appName ,
167+ map [* model.Epoch ][]* model.Input {epoch : {input }}, 10 )
168+ require .NoError (t , err )
169+ }
170+
171+ // advanceInput stores an advance result (outputs/reports) for an input using production StoreAdvanceResult.
172+ func (s * Service ) advanceInput (
173+ ctx context.Context , t * testing.T , appID int64 ,
174+ epochIndex , inputIndex uint64 , outputs [][]byte , reports [][]byte ,
175+ ) {
176+ t .Helper ()
177+ repotest .StoreAdvanceResult (ctx , t , s .repository , appID , epochIndex , inputIndex ,
178+ model .InputCompletionStatus_Accepted , outputs , reports )
179+ }
180+
154181type listTournamentsResult struct {
155182 EpochIndex hex64 `json:"epoch_index"`
156183 Address common.Address `json:"address"`
0 commit comments