|
|
@ -1,7 +1,8 @@ |
|
|
|
package mock |
|
|
|
|
|
|
|
import ( |
|
|
|
"github.com/pkg/errors" |
|
|
|
"fmt" |
|
|
|
"strings" |
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/lite2/provider" |
|
|
|
"github.com/tendermint/tendermint/types" |
|
|
@ -23,10 +24,25 @@ func New(chainID string, headers map[int64]*types.SignedHeader, vals map[int64]* |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ChainID returns the blockchain ID.
|
|
|
|
func (p *mock) ChainID() string { |
|
|
|
return p.chainID |
|
|
|
} |
|
|
|
|
|
|
|
func (p *mock) String() string { |
|
|
|
var headers strings.Builder |
|
|
|
for _, h := range p.headers { |
|
|
|
fmt.Fprintf(&headers, " %d:%X", h.Height, h.Hash()) |
|
|
|
} |
|
|
|
|
|
|
|
var vals strings.Builder |
|
|
|
for _, v := range p.vals { |
|
|
|
fmt.Fprintf(&vals, " %X", v.Hash()) |
|
|
|
} |
|
|
|
|
|
|
|
return fmt.Sprintf("mock{headers: %s, vals: %v}", headers.String(), vals.String()) |
|
|
|
} |
|
|
|
|
|
|
|
func (p *mock) SignedHeader(height int64) (*types.SignedHeader, error) { |
|
|
|
if height == 0 && len(p.headers) > 0 { |
|
|
|
return p.headers[int64(len(p.headers))], nil |
|
|
@ -46,24 +62,3 @@ func (p *mock) ValidatorSet(height int64) (*types.ValidatorSet, error) { |
|
|
|
} |
|
|
|
return nil, provider.ErrValidatorSetNotFound |
|
|
|
} |
|
|
|
|
|
|
|
type deadMock struct { |
|
|
|
chainID string |
|
|
|
} |
|
|
|
|
|
|
|
// NewDeadMock creates a mock provider that always errors.
|
|
|
|
func NewDeadMock(chainID string) provider.Provider { |
|
|
|
return &deadMock{chainID: chainID} |
|
|
|
} |
|
|
|
|
|
|
|
func (p *deadMock) ChainID() string { |
|
|
|
return p.chainID |
|
|
|
} |
|
|
|
|
|
|
|
func (p *deadMock) SignedHeader(height int64) (*types.SignedHeader, error) { |
|
|
|
return nil, errors.New("no response from provider") |
|
|
|
} |
|
|
|
|
|
|
|
func (p *deadMock) ValidatorSet(height int64) (*types.ValidatorSet, error) { |
|
|
|
return nil, errors.New("no response from provider") |
|
|
|
} |