@@ -12,7 +12,7 @@ import (
1212 "github.com/oasisprotocol/oasis-core/go/beacon/api"
1313 memorySigner "github.com/oasisprotocol/oasis-core/go/common/crypto/signature/signers/memory"
1414 "github.com/oasisprotocol/oasis-core/go/common/node"
15- consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
15+ consensusAPI "github.com/oasisprotocol/oasis-core/go/consensus/api"
1616 "github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
1717)
1818
@@ -23,28 +23,28 @@ var TestSigner = memorySigner.NewTestSigner("oasis-core epochtime mock key seed"
2323
2424// BeaconImplementationTests exercises the basic functionality of a
2525// beacon backend.
26- func BeaconImplementationTests (t * testing.T , backend consensus. Backend ) {
26+ func BeaconImplementationTests (t * testing.T , consensus consensusAPI. Service ) {
2727 require := require .New (t )
2828
29- timeSource := backend .Beacon ()
29+ timeSource := consensus .Beacon ()
3030
31- beacon , err := timeSource .GetBeacon (context .Background (), consensus .HeightLatest )
31+ beacon , err := timeSource .GetBeacon (context .Background (), consensusAPI .HeightLatest )
3232 require .NoError (err , "GetBeacon" )
3333 require .Len (beacon , api .BeaconSize , "GetBeacon - length" )
3434
35- _ = MustAdvanceEpoch (t , backend )
35+ _ = MustAdvanceEpoch (t , consensus )
3636
37- newBeacon , err := timeSource .GetBeacon (context .Background (), consensus .HeightLatest )
37+ newBeacon , err := timeSource .GetBeacon (context .Background (), consensusAPI .HeightLatest )
3838 require .NoError (err , "GetBeacon" )
3939 require .Len (newBeacon , api .BeaconSize , "GetBeacon - length" )
4040 require .NotEqual (beacon , newBeacon , "After epoch transition, new beacon should be generated." )
4141
42- latestEpoch , err := timeSource .GetEpoch (context .Background (), consensus .HeightLatest )
42+ latestEpoch , err := timeSource .GetEpoch (context .Background (), consensusAPI .HeightLatest )
4343 require .NoError (err , "GetEpoch" )
4444
4545 // Querying epoch for a non-existing height should fail.
4646 _ , err = timeSource .GetEpoch (context .Background (), 100000000000 )
47- require .ErrorIs (err , consensus .ErrVersionNotFound , "GetEpoch should fail for non-existing height" )
47+ require .ErrorIs (err , consensusAPI .ErrVersionNotFound , "GetEpoch should fail for non-existing height" )
4848
4949 var lastHeight int64
5050 for epoch := api .EpochTime (0 ); epoch <= latestEpoch ; epoch ++ {
@@ -57,16 +57,16 @@ func BeaconImplementationTests(t *testing.T, backend consensus.Backend) {
5757
5858// EpochtimeSetableImplementationTest exercises the basic functionality of
5959// a setable (mock) epochtime backend.
60- func EpochtimeSetableImplementationTest (t * testing.T , backend consensus. Backend ) {
60+ func EpochtimeSetableImplementationTest (t * testing.T , consensus consensusAPI. Service ) {
6161 require := require .New (t )
6262
63- timeSource := backend .Beacon ()
63+ timeSource := consensus .Beacon ()
6464
65- parameters , err := timeSource .ConsensusParameters (context .Background (), consensus .HeightLatest )
65+ parameters , err := timeSource .ConsensusParameters (context .Background (), consensusAPI .HeightLatest )
6666 require .NoError (err , "ConsensusParameters" )
6767 require .True (parameters .DebugMockBackend , "expected debug backend" )
6868
69- epoch , err := timeSource .GetEpoch (context .Background (), consensus .HeightLatest )
69+ epoch , err := timeSource .GetEpoch (context .Background (), consensusAPI .HeightLatest )
7070 require .NoError (err , "GetEpoch" )
7171
7272 var e api.EpochTime
@@ -92,7 +92,7 @@ func EpochtimeSetableImplementationTest(t *testing.T, backend consensus.Backend)
9292 }
9393
9494 epoch ++
95- err = SetEpoch (context .Background (), epoch , backend )
95+ err = SetEpoch (context .Background (), epoch , consensus )
9696 require .NoError (err , "SetEpoch" )
9797
9898 select {
@@ -109,28 +109,28 @@ func EpochtimeSetableImplementationTest(t *testing.T, backend consensus.Backend)
109109 t .Fatalf ("failed to receive latest epoch after transition" )
110110 }
111111
112- e , err = timeSource .GetEpoch (context .Background (), consensus .HeightLatest )
112+ e , err = timeSource .GetEpoch (context .Background (), consensusAPI .HeightLatest )
113113 require .NoError (err , "GetEpoch after set" )
114114 require .Equal (epoch , e , "GetEpoch after set, epoch" )
115115}
116116
117117// MustAdvanceEpoch advances the epoch and returns the new epoch.
118- func MustAdvanceEpoch (t * testing.T , backend consensus. Backend ) api.EpochTime {
118+ func MustAdvanceEpoch (t * testing.T , consensus consensusAPI. Service ) api.EpochTime {
119119 require := require .New (t )
120120
121- timeSource := backend .Beacon ()
121+ timeSource := consensus .Beacon ()
122122
123123 ctx , cancel := context .WithTimeout (context .Background (), recvTimeout )
124124 defer cancel ()
125125
126- epoch , err := timeSource .GetEpoch (ctx , consensus .HeightLatest )
126+ epoch , err := timeSource .GetEpoch (ctx , consensusAPI .HeightLatest )
127127 require .NoError (err , "GetEpoch" )
128128
129129 // While using a timeout here would be nice, the correct timeout value
130130 // depends on the block interval and all the various internal timekeeping
131131 // periods so it's not easy to set one.
132132 epoch ++
133- err = SetEpoch (context .Background (), epoch , backend )
133+ err = SetEpoch (context .Background (), epoch , consensus )
134134 require .NoError (err , "SetEpoch" )
135135
136136 return epoch
@@ -141,16 +141,16 @@ func MustAdvanceEpoch(t *testing.T, backend consensus.Backend) api.EpochTime {
141141// Between each epoch increment the method ensures that the consensus validator is re-registered
142142// so that epochs are not advanced too fast, which could cause a consensus error due to no
143143// validators being registered for the epoch.
144- func MustAdvanceEpochMulti (t * testing.T , backend consensus. Backend , increment uint64 ) api.EpochTime {
144+ func MustAdvanceEpochMulti (t * testing.T , consensus consensusAPI. Service , increment uint64 ) api.EpochTime {
145145 require := require .New (t )
146146
147- timeSource := backend .Beacon ()
148- registry := backend .Registry ()
147+ timeSource := consensus .Beacon ()
148+ registry := consensus .Registry ()
149149
150150 ctx , cancel := context .WithTimeout (context .Background (), recvTimeout )
151151 defer cancel ()
152152
153- epoch , err := timeSource .GetEpoch (ctx , consensus .HeightLatest )
153+ epoch , err := timeSource .GetEpoch (ctx , consensusAPI .HeightLatest )
154154 require .NoError (err , "GetEpoch" )
155155
156156 // While using a timeout here would be nice, the correct timeout value
@@ -167,7 +167,7 @@ func MustAdvanceEpochMulti(t *testing.T, backend consensus.Backend, increment ui
167167 // While using a timeout here would be nice, the correct timeout value
168168 // depends on the block interval and all the various internal timekeeping
169169 // periods so it's not easy to set one.
170- err = SetEpoch (context .Background (), epoch , backend )
170+ err = SetEpoch (context .Background (), epoch , consensus )
171171 require .NoError (err , "SetEpoch" )
172172
173173 // Ensure validator re-registers before transitioning to next epoch.
@@ -194,15 +194,15 @@ func MustAdvanceEpochMulti(t *testing.T, backend consensus.Backend, increment ui
194194}
195195
196196// SetEpoch sets the current epoch.
197- func SetEpoch (ctx context.Context , epoch api.EpochTime , backend consensus. Backend ) error {
198- ch , sub , err := backend .Beacon ().WatchEpochs (ctx )
197+ func SetEpoch (ctx context.Context , epoch api.EpochTime , consensus consensusAPI. Service ) error {
198+ ch , sub , err := consensus .Beacon ().WatchEpochs (ctx )
199199 if err != nil {
200200 return fmt .Errorf ("watch epochs failed: %w" , err )
201201 }
202202 defer sub .Close ()
203203
204204 tx := transaction .NewTransaction (0 , nil , api .MethodSetEpoch , epoch )
205- if err := consensus .SignAndSubmitTx (ctx , backend , TestSigner , tx ); err != nil {
205+ if err := consensusAPI .SignAndSubmitTx (ctx , consensus , TestSigner , tx ); err != nil {
206206 return fmt .Errorf ("set epoch failed: %w" , err )
207207 }
208208
0 commit comments