github.com/koko1123/flow-go-1@v0.29.6/engine/testutil/mocklocal/local.go (about)

     1  package mocklocal
     2  
     3  import (
     4  	"github.com/stretchr/testify/mock"
     5  	"github.com/stretchr/testify/require"
     6  
     7  	"github.com/onflow/flow-go/crypto"
     8  	"github.com/onflow/flow-go/crypto/hash"
     9  	"github.com/koko1123/flow-go-1/model/flow"
    10  	"github.com/koko1123/flow-go-1/model/flow/filter"
    11  )
    12  
    13  // MockLocal represents a mock of Local
    14  // We needed to develop a separate mock for Local as we could not mock
    15  // a method with return values with gomock
    16  type MockLocal struct {
    17  	sk crypto.PrivateKey
    18  	t  mock.TestingT
    19  	id flow.Identifier
    20  }
    21  
    22  func NewMockLocal(sk crypto.PrivateKey, id flow.Identifier, t mock.TestingT) *MockLocal {
    23  	return &MockLocal{
    24  		sk: sk,
    25  		t:  t,
    26  		id: id,
    27  	}
    28  }
    29  
    30  func (m *MockLocal) NodeID() flow.Identifier {
    31  	return m.id
    32  }
    33  
    34  func (m *MockLocal) Address() string {
    35  	require.Fail(m.t, "should not call MockLocal Address")
    36  	return ""
    37  }
    38  
    39  func (m *MockLocal) Sign(msg []byte, hasher hash.Hasher) (crypto.Signature, error) {
    40  	return m.sk.Sign(msg, hasher)
    41  }
    42  
    43  func (m *MockLocal) MockNodeID(id flow.Identifier) {
    44  	m.id = id
    45  }
    46  
    47  func (m *MockLocal) NotMeFilter() flow.IdentityFilter {
    48  	return filter.Not(filter.HasNodeID(m.id))
    49  }
    50  
    51  func (m *MockLocal) SignFunc(data []byte, hasher hash.Hasher, f func(crypto.PrivateKey, []byte, hash.Hasher) (crypto.Signature,
    52  	error)) (crypto.Signature, error) {
    53  	return f(m.sk, data, hasher)
    54  }