prysm-pulse/validator/keymanager/v2/testing/mock.go
Raul Jordan 132ad5beb8
Implement Accounts-v2 List: Direct Keymanager (#6510)
* begin list accounts impl
* colorize
* show deposit data
* separate responsibility
* comprehensive test for list complete
* gaz viz
* print account creation timestamp
* handle errs
* ask for wallet and pass dir
* Merge refs/heads/master into implement-v2-list
2020-07-08 19:21:54 +00:00

43 lines
1.1 KiB
Go

package testing
import (
"context"
"errors"
validatorpb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
)
// MockKeymanager --
type MockKeymanager struct {
ConfigFileContents []byte
PublicKeys [][48]byte
PubkeystoSecretKeys map[[48]byte]bls.SecretKey
}
// CreateAccount --
func (m *MockKeymanager) CreateAccount(ctx context.Context, password string) (string, error) {
return "", nil
}
// MarshalConfigFile --
func (m *MockKeymanager) MarshalConfigFile(ctx context.Context) ([]byte, error) {
return m.ConfigFileContents, nil
}
// FetchValidatingPublicKeys --
func (m *MockKeymanager) FetchValidatingPublicKeys(ctx context.Context) ([][48]byte, error) {
return m.PublicKeys, nil
}
// Sign --
func (m *MockKeymanager) Sign(ctx context.Context, req *validatorpb.SignRequest) (bls.Signature, error) {
pubKey := bytesutil.ToBytes48(req.PublicKey)
secretKey, ok := m.PubkeystoSecretKeys[pubKey]
if !ok {
return nil, errors.New("no secret key found")
}
return secretKey.Sign(req.Data), nil
}