Browse Source

NewInquiring returns error instead of swallowing it

pull/1063/head
Adrian Brink 7 years ago
parent
commit
ed81fb54ec
No known key found for this signature in database GPG Key ID: 9168AC350E33CEF2
3 changed files with 19 additions and 9 deletions
  1. +8
    -4
      lite/inquirer.go
  2. +5
    -4
      lite/inquirer_test.go
  3. +6
    -1
      lite/proxy/certifier.go

+ 8
- 4
lite/inquirer.go View File

@ -23,16 +23,20 @@ type Inquiring struct {
//
// Example: The trusted provider should a CacheProvider, MemProvider or files.Provider. The source
// 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
// TODO: StoredCommit() can return an error and we need to handle this.
trusted.StoreCommit(fc)
err := trusted.StoreCommit(fc)
if err != nil {
return nil, err
}
return &Inquiring{
cert: NewDynamic(chainID, fc.Validators, fc.Height()),
trusted: trusted,
Source: source,
}
}, nil
}
// ChainID returns the chain id.


+ 5
- 4
lite/inquirer_test.go View File

@ -36,7 +36,7 @@ func TestInquirerValidPath(t *testing.T) {
}
// 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....
commit := commits[count-1].Commit
@ -85,7 +85,7 @@ func TestInquirerMinimalPath(t *testing.T) {
}
// 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....
commit := commits[count-1].Commit
@ -130,11 +130,12 @@ func TestInquirerVerifyHistorical(t *testing.T) {
h := int64(20 + 10*i)
appHash := []byte(fmt.Sprintf("h=%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
cert := lite.NewInquiring(chainID, commits[0], trust, source)
cert, _ := lite.NewInquiring(chainID, commits[0], trust, source)
// store a few commits as trust
for _, i := range []int{2, 5} {


+ 6
- 1
lite/proxy/certifier.go View File

@ -25,6 +25,11 @@ func GetCertifier(chainID, rootDir, nodeAddr string) (*lite.Inquiring, error) {
if err != nil {
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
}

Loading…
Cancel
Save