fixed error strings (#708)

This commit is contained in:
terence tsao
2018-10-31 23:05:55 +01:00
committed by Raul Jordan
parent 95625629f7
commit 80d6c60769
11 changed files with 30 additions and 30 deletions

View File

@@ -265,7 +265,7 @@ func TestProcessBlocksWithCorrectAttestations(t *testing.T) {
Slot: 0,
})
if saveErr := chainService.beaconDB.SaveBlock(block0); saveErr != nil {
t.Fatalf("Cannot save block: %v", saveErr)
t.Fatalf("Could not save block: %v", saveErr)
}
block0Hash, err := block0.Hash()
if err != nil {

View File

@@ -77,7 +77,7 @@ func GetShardAndCommitteesForSlot(shardCommittees []*pb.ShardAndCommitteeArray,
func AreAttesterBitfieldsValid(attestation *pb.AggregatedAttestation, attesterIndices []uint32) bool {
// Validate attester bit field has the correct length.
if bitutil.BitLength(len(attesterIndices)) != len(attestation.AttesterBitfield) {
log.Debugf("attestation has incorrect bitfield length. Found %v, expected %v",
log.Debugf("Attestation has incorrect bitfield length. Found %v, expected %v",
len(attestation.AttesterBitfield), bitutil.BitLength(len(attesterIndices)))
return false
}
@@ -97,7 +97,7 @@ func AreAttesterBitfieldsValid(attestation *pb.AggregatedAttestation, attesterIn
}
if isBitSet {
log.Error("attestation has non-zero trailing bits")
log.Error("Attestation has non-zero trailing bits")
return false
}
}

View File

@@ -198,15 +198,15 @@ func (db *BeaconDB) GetBlockBySlot(slot uint64) (*types.Block, error) {
func (db *BeaconDB) GetGenesisTime() (time.Time, error) {
genesis, err := db.GetBlockBySlot(0)
if err != nil {
return time.Time{}, fmt.Errorf("Could not get genesis block: %v", err)
return time.Time{}, fmt.Errorf("could not get genesis block: %v", err)
}
if genesis == nil {
return time.Time{}, fmt.Errorf("Genesis block not found: %v", err)
return time.Time{}, fmt.Errorf("genesis block not found: %v", err)
}
genesisTime, err := genesis.Timestamp()
if err != nil {
return time.Time{}, fmt.Errorf("Could not get genesis timestamp: %v", err)
return time.Time{}, fmt.Errorf("could not get genesis timestamp: %v", err)
}
return genesisTime, nil

View File

@@ -71,7 +71,7 @@ func TestStart(t *testing.T) {
web3Service.Start()
msg := hook.LastEntry().Message
want := "Cannot connect to PoW chain RPC client"
want := "Could not connect to PoW chain RPC client"
if strings.Contains(want, msg) {
t.Errorf("incorrect log, expected %s, got %s", want, msg)
}

View File

@@ -119,7 +119,7 @@ func (s *Service) Start() {
if s.withCert != "" && s.withKey != "" {
creds, err := credentials.NewServerTLSFromFile(s.withCert, s.withKey)
if err != nil {
log.Errorf("could not load TLS keys: %s", err)
log.Errorf("Could not load TLS keys: %s", err)
}
s.grpcServer = grpc.NewServer(grpc.Creds(creds))
} else {

View File

@@ -284,7 +284,7 @@ func (ss *Service) receiveAttestation(msg p2p.Message) {
attestation, err := ss.db.GetAttestation(h)
if err != nil {
log.Errorf("Can not check for attestation in DB: %v", err)
log.Errorf("Could not check for attestation in DB: %v", err)
return
}
if attestation != nil {

View File

@@ -324,7 +324,7 @@ func (a *ActiveState) CalculateNewActiveState(
cState.LastStateRecalculationSlot(),
parentSlot)
if err != nil {
return nil, fmt.Errorf("Can not get proposer index %v", err)
return nil, fmt.Errorf("could not get proposer index %v", err)
}
newRandao := setRandaoMix(block.RandaoReveal(), a.RandaoMix())

View File

@@ -167,7 +167,7 @@ func (b *Block) IsValid(
}
if b.SlotNumber() == 0 {
log.Error("Cannot process a genesis block")
log.Error("Could not process a genesis block")
return false
}
@@ -187,7 +187,7 @@ func (b *Block) IsValid(
cState.LastStateRecalculationSlot(),
b.SlotNumber())
if err != nil {
log.Errorf("Cannot get proposer index: %v", err)
log.Errorf("Could not get proposer index: %v", err)
return false
}
@@ -205,7 +205,7 @@ func (b *Block) IsValid(
func (b *Block) areAttestationsValid(db beaconDB, aState *ActiveState, cState *CrystallizedState, parentSlot uint64) bool {
for index, attestation := range b.Attestations() {
if !b.isAttestationValid(index, db, aState, cState, parentSlot) {
log.Errorf("attestation invalid: %v", attestation)
log.Errorf("Attestation invalid: %v", attestation)
return false
}
}
@@ -219,13 +219,13 @@ func (b *Block) doesParentProposerExist(cState *CrystallizedState, parentSlot ui
cState.LastStateRecalculationSlot(),
parentSlot)
if err != nil {
log.Errorf("Cannot get proposer index: %v", err)
log.Errorf("Could not get proposer index: %v", err)
return false
}
// verify proposer from last slot is in the first attestation object in AggregatedAttestation.
if isBitSet, err := bitutil.CheckBit(b.Attestations()[0].AttesterBitfield, int(parentProposerIndex)); !isBitSet {
log.Errorf("Can not locate proposer in the first attestation of AttestionRecord %v", err)
log.Errorf("Could not locate proposer in the first attestation of AttestionRecord %v", err)
return false
}
@@ -274,7 +274,7 @@ func (b *Block) isAttestationValid(attestationIndex int, db beaconDB, aState *Ac
// Get all the block hashes up to cycle length.
parentHashes, err := aState.getSignedParentHashes(b, attestation)
if err != nil {
log.Errorf("unable to get signed parent hashes: %v", err)
log.Errorf("Unable to get signed parent hashes: %v", err)
return false
}

View File

@@ -122,7 +122,7 @@ func (s *Service) fetchCurrentAssignmentsAndGenesisTime(client pb.BeaconServiceC
// since the genesis block.
genesisTimestamp, err := ptypes.Timestamp(res.GetGenesisTimestamp())
if err != nil {
return fmt.Errorf("cannot compute genesis timestamp: %v", err)
return fmt.Errorf("could not compute genesis timestamp: %v", err)
}
s.genesisTimestamp = genesisTimestamp

View File

@@ -75,7 +75,7 @@ func (s *Shard) HeaderByHash(hash *common.Hash) (*CollationHeader, error) {
func (s *Shard) CollationByHeaderHash(headerHash *common.Hash) (*Collation, error) {
header, err := s.HeaderByHash(headerHash)
if err != nil {
return nil, fmt.Errorf("cannot fetch header by hash: %v", err)
return nil, fmt.Errorf("could not fetch header by hash: %v", err)
}
if header == nil {
@@ -84,12 +84,12 @@ func (s *Shard) CollationByHeaderHash(headerHash *common.Hash) (*Collation, erro
body, err := s.BodyByChunkRoot(header.ChunkRoot())
if err != nil {
return nil, fmt.Errorf("cannot fetch body by chunk root: %v", err)
return nil, fmt.Errorf("could not fetch body by chunk root: %v", err)
}
txs, err := DeserializeBlobToTx(body)
if err != nil {
return nil, fmt.Errorf("cannot deserialize body: %v", err)
return nil, fmt.Errorf("could not deserialize body: %v", err)
}
return NewCollation(header, body, *txs), nil
}
@@ -186,7 +186,7 @@ func (s *Shard) SaveHeader(header *CollationHeader) error {
encoded, err := header.EncodeRLP()
if err != nil {
return fmt.Errorf("cannot encode header: %v", err)
return fmt.Errorf("could not encode header: %v", err)
}
// uses the hash of the header as the key.
@@ -240,7 +240,7 @@ func (s *Shard) SetCanonical(header *CollationHeader) error {
key := canonicalCollationLookupKey(dbHeader.ShardID(), dbHeader.Period())
encoded, err := dbHeader.EncodeRLP()
if err != nil {
return fmt.Errorf("cannot encode header: %v", err)
return fmt.Errorf("could not encode header: %v", err)
}
// sets the key to be the canonical collation lookup key and val as RLP encoded
// collation header.

View File

@@ -85,7 +85,7 @@ func TestShard_HeaderByHash(t *testing.T) {
errorShard := NewShard(big.NewInt(1), mockDB)
if err := shard.SaveHeader(header); err != nil {
t.Fatalf("cannot save collation header: %v", err)
t.Fatalf("could not save collation header: %v", err)
}
hash := header.Hash()
@@ -150,7 +150,7 @@ func TestShard_CollationByHeaderHash(t *testing.T) {
// properly saves the collation.
if err := shard.SaveCollation(collation); err != nil {
t.Fatalf("cannot save collation: %v", err)
t.Fatalf("could not save collation: %v", err)
}
dbCollation, err := shard.CollationByHeaderHash(&hash)
@@ -215,7 +215,7 @@ func TestShard_CanonicalHeaderHash(t *testing.T) {
// should not be able to set as canonical before saving the header and body first.
if err := shard.SetCanonical(header); err == nil {
t.Errorf("cannot set as canonical before saving header and body first")
t.Errorf("could not set as canonical before saving header and body first")
}
if err := shard.SaveCollation(collation); err != nil {
@@ -317,7 +317,7 @@ func TestShard_BodyByChunkRoot(t *testing.T) {
shard := NewShard(shardID, shardDB)
if err := shard.SaveBody(body); err != nil {
t.Fatalf("cannot save body: %v", err)
t.Fatalf("could not save body: %v", err)
}
chunks := Chunks(body) // wrapper allowing us to merklizing the chunks.
@@ -325,7 +325,7 @@ func TestShard_BodyByChunkRoot(t *testing.T) {
dbBody, err := shard.BodyByChunkRoot(&chunkRoot)
if err != nil {
t.Errorf("cannot fetch body by chunk root: %v", err)
t.Errorf("could not fetch body by chunk root: %v", err)
}
// it should throw error if fetching non-existent chunk root.
@@ -369,11 +369,11 @@ func TestShard_CheckAvailability(t *testing.T) {
// should throw error if checking availability before header is even saved.
if _, err := shard.CheckAvailability(header); err == nil {
t.Errorf("error should be thrown: cannot check availability before saving header first")
t.Errorf("error should be thrown: could not check availability before saving header first")
}
if err := shard.SaveBody(collation.body); err != nil {
t.Fatalf("cannot save body: %v", err)
t.Fatalf("could not save body: %v", err)
}
available, err := shard.CheckAvailability(header)
@@ -439,7 +439,7 @@ func TestShard_SaveCollation(t *testing.T) {
collation.CalculateChunkRoot()
if err := shard.SaveCollation(collation); err == nil {
t.Errorf("cannot save collation in shard with wrong shardID")
t.Errorf("could not save collation in shard with wrong shardID")
}
}