/
mux_mock.go
47 lines (39 loc) · 1.37 KB
/
mux_mock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package abci
import (
"context"
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
"github.com/oasisprotocol/oasis-core/go/consensus/tendermint/api"
upgrade "github.com/oasisprotocol/oasis-core/go/upgrade/api"
)
// MockABCIMux exports some of the muxer's internal methods for testing use.
type MockABCIMux struct {
*abciMux
}
// MockRegisterApp is used to register apps with this muxer during testing.
func (mux *MockABCIMux) MockRegisterApp(app api.Application) error {
return mux.doRegister(app)
}
// MockSetEpochtime sets the timesource used by this muxer when testing.
func (mux *MockABCIMux) MockSetEpochtime(epochTime beacon.Backend) {
mux.state.timeSource = epochTime
}
// MockSetTransactionAuthHandler sets the transaction auth hander used by
// this muxer when testing.
func (mux *MockABCIMux) MockSetTransactionAuthHandler(handler api.TransactionAuthHandler) {
mux.state.txAuthHandler = handler
}
// MockClose cleans up the muxer's state; it must be called once the muxer is no longer needed.
func (mux *MockABCIMux) MockClose() {
mux.doCleanup()
}
// NewMockMux creates a new ABCI mux suitable for testing.
func NewMockMux(ctx context.Context, upgrader upgrade.Backend, cfg *ApplicationConfig) (*MockABCIMux, error) {
mux, err := newABCIMux(ctx, upgrader, cfg)
if err != nil {
return nil, err
}
mockMux := &MockABCIMux{
abciMux: mux,
}
return mockMux, nil
}