-
Notifications
You must be signed in to change notification settings - Fork 105
/
broadcast.go
83 lines (76 loc) · 2.23 KB
/
broadcast.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package mock
import (
"context"
"github.com/axelarnetwork/axelar-core/sdk-utils/broadcast"
sdk "github.com/cosmos/cosmos-sdk/types"
"sync"
)
// Ensure, that BroadcasterMock does implement broadcast.Broadcaster.
// If this is not the case, regenerate this file with moq.
var _ broadcast.Broadcaster = &BroadcasterMock{}
// BroadcasterMock is a mock implementation of broadcast.Broadcaster.
//
// func TestSomethingThatUsesBroadcaster(t *testing.T) {
//
// // make and configure a mocked broadcast.Broadcaster
// mockedBroadcaster := &BroadcasterMock{
// BroadcastFunc: func(ctx context.Context, msgs ...sdk.Msg) (*sdk.TxResponse, error) {
// panic("mock out the Broadcast method")
// },
// }
//
// // use mockedBroadcaster in code that requires broadcast.Broadcaster
// // and then make assertions.
//
// }
type BroadcasterMock struct {
// BroadcastFunc mocks the Broadcast method.
BroadcastFunc func(ctx context.Context, msgs ...sdk.Msg) (*sdk.TxResponse, error)
// calls tracks calls to the methods.
calls struct {
// Broadcast holds details about calls to the Broadcast method.
Broadcast []struct {
// Ctx is the ctx argument value.
Ctx context.Context
// Msgs is the msgs argument value.
Msgs []sdk.Msg
}
}
lockBroadcast sync.RWMutex
}
// Broadcast calls BroadcastFunc.
func (mock *BroadcasterMock) Broadcast(ctx context.Context, msgs ...sdk.Msg) (*sdk.TxResponse, error) {
if mock.BroadcastFunc == nil {
panic("BroadcasterMock.BroadcastFunc: method is nil but Broadcaster.Broadcast was just called")
}
callInfo := struct {
Ctx context.Context
Msgs []sdk.Msg
}{
Ctx: ctx,
Msgs: msgs,
}
mock.lockBroadcast.Lock()
mock.calls.Broadcast = append(mock.calls.Broadcast, callInfo)
mock.lockBroadcast.Unlock()
return mock.BroadcastFunc(ctx, msgs...)
}
// BroadcastCalls gets all the calls that were made to Broadcast.
// Check the length with:
//
// len(mockedBroadcaster.BroadcastCalls())
func (mock *BroadcasterMock) BroadcastCalls() []struct {
Ctx context.Context
Msgs []sdk.Msg
} {
var calls []struct {
Ctx context.Context
Msgs []sdk.Msg
}
mock.lockBroadcast.RLock()
calls = mock.calls.Broadcast
mock.lockBroadcast.RUnlock()
return calls
}