Merge pull request #1063 from tendermint/feature/Issue1020
NewInquiring returns error instead of swallowing it
This commit is contained in:
commit
90c691df2b
|
@ -23,16 +23,20 @@ type Inquiring struct {
|
||||||
//
|
//
|
||||||
// Example: The trusted provider should a CacheProvider, MemProvider or files.Provider. The source
|
// Example: The trusted provider should a CacheProvider, MemProvider or files.Provider. The source
|
||||||
// provider should be a client.HTTPProvider.
|
// provider should be a client.HTTPProvider.
|
||||||
func NewInquiring(chainID string, fc FullCommit, trusted Provider, source Provider) *Inquiring {
|
func NewInquiring(chainID string, fc FullCommit, trusted Provider,
|
||||||
|
source Provider) (*Inquiring, error) {
|
||||||
|
|
||||||
// store the data in trusted
|
// store the data in trusted
|
||||||
// TODO: StoredCommit() can return an error and we need to handle this.
|
err := trusted.StoreCommit(fc)
|
||||||
trusted.StoreCommit(fc)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &Inquiring{
|
return &Inquiring{
|
||||||
cert: NewDynamic(chainID, fc.Validators, fc.Height()),
|
cert: NewDynamic(chainID, fc.Validators, fc.Height()),
|
||||||
trusted: trusted,
|
trusted: trusted,
|
||||||
Source: source,
|
Source: source,
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChainID returns the chain id.
|
// ChainID returns the chain id.
|
||||||
|
|
|
@ -32,18 +32,20 @@ func TestInquirerValidPath(t *testing.T) {
|
||||||
vals := keys.ToValidators(vote, 0)
|
vals := keys.ToValidators(vote, 0)
|
||||||
h := int64(20 + 10*i)
|
h := int64(20 + 10*i)
|
||||||
appHash := []byte(fmt.Sprintf("h=%d", h))
|
appHash := []byte(fmt.Sprintf("h=%d", h))
|
||||||
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, consHash, resHash, 0, len(keys))
|
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, consHash, resHash, 0,
|
||||||
|
len(keys))
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize a certifier with the initial state
|
// initialize a certifier with the initial state
|
||||||
cert := lite.NewInquiring(chainID, commits[0], trust, source)
|
cert, err := lite.NewInquiring(chainID, commits[0], trust, source)
|
||||||
|
require.Nil(err)
|
||||||
|
|
||||||
// this should fail validation....
|
// this should fail validation....
|
||||||
commit := commits[count-1].Commit
|
commit := commits[count-1].Commit
|
||||||
err := cert.Certify(commit)
|
err = cert.Certify(commit)
|
||||||
require.NotNil(err)
|
require.NotNil(err)
|
||||||
|
|
||||||
// add a few seed in the middle should be insufficient
|
// adding a few commits in the middle should be insufficient
|
||||||
for i := 10; i < 13; i++ {
|
for i := 10; i < 13; i++ {
|
||||||
err := source.StoreCommit(commits[i])
|
err := source.StoreCommit(commits[i])
|
||||||
require.Nil(err)
|
require.Nil(err)
|
||||||
|
@ -81,11 +83,12 @@ func TestInquirerMinimalPath(t *testing.T) {
|
||||||
h := int64(5 + 10*i)
|
h := int64(5 + 10*i)
|
||||||
appHash := []byte(fmt.Sprintf("h=%d", h))
|
appHash := []byte(fmt.Sprintf("h=%d", h))
|
||||||
resHash := []byte(fmt.Sprintf("res=%d", h))
|
resHash := []byte(fmt.Sprintf("res=%d", h))
|
||||||
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, consHash, resHash, 0, len(keys))
|
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, consHash, resHash, 0,
|
||||||
|
len(keys))
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize a certifier with the initial state
|
// initialize a certifier with the initial state
|
||||||
cert := lite.NewInquiring(chainID, commits[0], trust, source)
|
cert, _ := lite.NewInquiring(chainID, commits[0], trust, source)
|
||||||
|
|
||||||
// this should fail validation....
|
// this should fail validation....
|
||||||
commit := commits[count-1].Commit
|
commit := commits[count-1].Commit
|
||||||
|
@ -130,11 +133,12 @@ func TestInquirerVerifyHistorical(t *testing.T) {
|
||||||
h := int64(20 + 10*i)
|
h := int64(20 + 10*i)
|
||||||
appHash := []byte(fmt.Sprintf("h=%d", h))
|
appHash := []byte(fmt.Sprintf("h=%d", h))
|
||||||
resHash := []byte(fmt.Sprintf("res=%d", h))
|
resHash := []byte(fmt.Sprintf("res=%d", h))
|
||||||
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, consHash, resHash, 0, len(keys))
|
commits[i] = keys.GenFullCommit(chainID, h, nil, vals, appHash, consHash, resHash, 0,
|
||||||
|
len(keys))
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize a certifier with the initial state
|
// initialize a certifier with the initial state
|
||||||
cert := lite.NewInquiring(chainID, commits[0], trust, source)
|
cert, _ := lite.NewInquiring(chainID, commits[0], trust, source)
|
||||||
|
|
||||||
// store a few commits as trust
|
// store a few commits as trust
|
||||||
for _, i := range []int{2, 5} {
|
for _, i := range []int{2, 5} {
|
||||||
|
|
|
@ -25,6 +25,11 @@ func GetCertifier(chainID, rootDir, nodeAddr string) (*lite.Inquiring, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cert := lite.NewInquiring(chainID, fc, trust, source)
|
|
||||||
|
cert, err := lite.NewInquiring(chainID, fc, trust, source)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return cert, nil
|
return cert, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue