-
Notifications
You must be signed in to change notification settings - Fork 175
/
local.go
54 lines (44 loc) · 1.28 KB
/
local.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
package mocklocal
import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/onflow/flow-go/crypto"
"github.com/onflow/flow-go/crypto/hash"
"github.com/onflow/flow-go/model/flow"
"github.com/onflow/flow-go/model/flow/filter"
)
// MockLocal represents a mock of Local
// We needed to develop a separate mock for Local as we could not mock
// a method with return values with gomock
type MockLocal struct {
sk crypto.PrivateKey
t mock.TestingT
id flow.Identifier
}
func NewMockLocal(sk crypto.PrivateKey, id flow.Identifier, t mock.TestingT) *MockLocal {
return &MockLocal{
sk: sk,
t: t,
id: id,
}
}
func (m *MockLocal) NodeID() flow.Identifier {
return m.id
}
func (m *MockLocal) Address() string {
require.Fail(m.t, "should not call MockLocal Address")
return ""
}
func (m *MockLocal) Sign(msg []byte, hasher hash.Hasher) (crypto.Signature, error) {
return m.sk.Sign(msg, hasher)
}
func (m *MockLocal) MockNodeID(id flow.Identifier) {
m.id = id
}
func (m *MockLocal) NotMeFilter() flow.IdentityFilter {
return filter.Not(filter.HasNodeID(m.id))
}
func (m *MockLocal) SignFunc(data []byte, hasher hash.Hasher, f func(crypto.PrivateKey, []byte, hash.Hasher) (crypto.Signature,
error)) (crypto.Signature, error) {
return f(m.sk, data, hasher)
}