mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
tests: remove staticcheck warnings
This commit is contained in:
parent
36a684ca1e
commit
dbef66a6b8
3 changed files with 23 additions and 27 deletions
|
|
@ -179,7 +179,7 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
|
||||||
if b.BlockHeader == nil {
|
if b.BlockHeader == nil {
|
||||||
continue // OK - block is supposed to be invalid, continue with next block
|
continue // OK - block is supposed to be invalid, continue with next block
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("Block RLP decoding failed when expected to succeed: %v", err)
|
return nil, fmt.Errorf("block RLP decoding failed when expected to succeed: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// RLP decoding worked, try to insert into chain:
|
// RLP decoding worked, try to insert into chain:
|
||||||
|
|
@ -189,16 +189,16 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
|
||||||
if b.BlockHeader == nil {
|
if b.BlockHeader == nil {
|
||||||
continue // OK - block is supposed to be invalid, continue with next block
|
continue // OK - block is supposed to be invalid, continue with next block
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("Block #%v insertion into chain failed: %v", blocks[i].Number(), err)
|
return nil, fmt.Errorf("block #%v insertion into chain failed: %v", blocks[i].Number(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if b.BlockHeader == nil {
|
if b.BlockHeader == nil {
|
||||||
return nil, fmt.Errorf("Block insertion should have failed")
|
return nil, fmt.Errorf("block insertion should have failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate RLP decoding by checking all values against test file JSON
|
// validate RLP decoding by checking all values against test file JSON
|
||||||
if err = validateHeader(b.BlockHeader, cb.Header()); err != nil {
|
if err = validateHeader(b.BlockHeader, cb.Header()); err != nil {
|
||||||
return nil, fmt.Errorf("Deserialised block header validation failed: %v", err)
|
return nil, fmt.Errorf("deserialised block header validation failed: %v", err)
|
||||||
}
|
}
|
||||||
validBlocks = append(validBlocks, b)
|
validBlocks = append(validBlocks, b)
|
||||||
}
|
}
|
||||||
|
|
@ -207,49 +207,49 @@ func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error)
|
||||||
|
|
||||||
func validateHeader(h *btHeader, h2 *types.Header) error {
|
func validateHeader(h *btHeader, h2 *types.Header) error {
|
||||||
if h.Bloom != h2.Bloom {
|
if h.Bloom != h2.Bloom {
|
||||||
return fmt.Errorf("Bloom: want: %x have: %x", h.Bloom, h2.Bloom)
|
return fmt.Errorf("bloom: want: %x have: %x", h.Bloom, h2.Bloom)
|
||||||
}
|
}
|
||||||
if h.Coinbase != h2.Coinbase {
|
if h.Coinbase != h2.Coinbase {
|
||||||
return fmt.Errorf("Coinbase: want: %x have: %x", h.Coinbase, h2.Coinbase)
|
return fmt.Errorf("coinbase: want: %x have: %x", h.Coinbase, h2.Coinbase)
|
||||||
}
|
}
|
||||||
if h.MixHash != h2.MixDigest {
|
if h.MixHash != h2.MixDigest {
|
||||||
return fmt.Errorf("MixHash: want: %x have: %x", h.MixHash, h2.MixDigest)
|
return fmt.Errorf("MixHash: want: %x have: %x", h.MixHash, h2.MixDigest)
|
||||||
}
|
}
|
||||||
if h.Nonce != h2.Nonce {
|
if h.Nonce != h2.Nonce {
|
||||||
return fmt.Errorf("Nonce: want: %x have: %x", h.Nonce, h2.Nonce)
|
return fmt.Errorf("nonce: want: %x have: %x", h.Nonce, h2.Nonce)
|
||||||
}
|
}
|
||||||
if h.Number.Cmp(h2.Number) != 0 {
|
if h.Number.Cmp(h2.Number) != 0 {
|
||||||
return fmt.Errorf("Number: want: %v have: %v", h.Number, h2.Number)
|
return fmt.Errorf("number: want: %v have: %v", h.Number, h2.Number)
|
||||||
}
|
}
|
||||||
if h.ParentHash != h2.ParentHash {
|
if h.ParentHash != h2.ParentHash {
|
||||||
return fmt.Errorf("Parent hash: want: %x have: %x", h.ParentHash, h2.ParentHash)
|
return fmt.Errorf("parent hash: want: %x have: %x", h.ParentHash, h2.ParentHash)
|
||||||
}
|
}
|
||||||
if h.ReceiptTrie != h2.ReceiptHash {
|
if h.ReceiptTrie != h2.ReceiptHash {
|
||||||
return fmt.Errorf("Receipt hash: want: %x have: %x", h.ReceiptTrie, h2.ReceiptHash)
|
return fmt.Errorf("receipt hash: want: %x have: %x", h.ReceiptTrie, h2.ReceiptHash)
|
||||||
}
|
}
|
||||||
if h.TransactionsTrie != h2.TxHash {
|
if h.TransactionsTrie != h2.TxHash {
|
||||||
return fmt.Errorf("Tx hash: want: %x have: %x", h.TransactionsTrie, h2.TxHash)
|
return fmt.Errorf("tx hash: want: %x have: %x", h.TransactionsTrie, h2.TxHash)
|
||||||
}
|
}
|
||||||
if h.StateRoot != h2.Root {
|
if h.StateRoot != h2.Root {
|
||||||
return fmt.Errorf("State hash: want: %x have: %x", h.StateRoot, h2.Root)
|
return fmt.Errorf("state hash: want: %x have: %x", h.StateRoot, h2.Root)
|
||||||
}
|
}
|
||||||
if h.UncleHash != h2.UncleHash {
|
if h.UncleHash != h2.UncleHash {
|
||||||
return fmt.Errorf("Uncle hash: want: %x have: %x", h.UncleHash, h2.UncleHash)
|
return fmt.Errorf("uncle hash: want: %x have: %x", h.UncleHash, h2.UncleHash)
|
||||||
}
|
}
|
||||||
if !bytes.Equal(h.ExtraData, h2.Extra) {
|
if !bytes.Equal(h.ExtraData, h2.Extra) {
|
||||||
return fmt.Errorf("Extra data: want: %x have: %x", h.ExtraData, h2.Extra)
|
return fmt.Errorf("extra data: want: %x have: %x", h.ExtraData, h2.Extra)
|
||||||
}
|
}
|
||||||
if h.Difficulty.Cmp(h2.Difficulty) != 0 {
|
if h.Difficulty.Cmp(h2.Difficulty) != 0 {
|
||||||
return fmt.Errorf("Difficulty: want: %v have: %v", h.Difficulty, h2.Difficulty)
|
return fmt.Errorf("difficulty: want: %v have: %v", h.Difficulty, h2.Difficulty)
|
||||||
}
|
}
|
||||||
if h.GasLimit != h2.GasLimit {
|
if h.GasLimit != h2.GasLimit {
|
||||||
return fmt.Errorf("GasLimit: want: %d have: %d", h.GasLimit, h2.GasLimit)
|
return fmt.Errorf("gasLimit: want: %d have: %d", h.GasLimit, h2.GasLimit)
|
||||||
}
|
}
|
||||||
if h.GasUsed != h2.GasUsed {
|
if h.GasUsed != h2.GasUsed {
|
||||||
return fmt.Errorf("GasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
|
return fmt.Errorf("gasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
|
||||||
}
|
}
|
||||||
if h.Timestamp != h2.Time {
|
if h.Timestamp != h2.Time {
|
||||||
return fmt.Errorf("Timestamp: want: %v have: %v", h.Timestamp, h2.Time)
|
return fmt.Errorf("timestamp: want: %v have: %v", h.Timestamp, h2.Time)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -287,7 +287,7 @@ func (t *BlockTest) validateImportedHeaders(cm *core.BlockChain, validBlocks []b
|
||||||
// be part of the longest chain until last block is imported.
|
// be part of the longest chain until last block is imported.
|
||||||
for b := cm.CurrentBlock(); b != nil && b.NumberU64() != 0; b = cm.GetBlockByHash(b.Header().ParentHash) {
|
for b := cm.CurrentBlock(); b != nil && b.NumberU64() != 0; b = cm.GetBlockByHash(b.Header().ParentHash) {
|
||||||
if err := validateHeader(bmap[b.Hash()].BlockHeader, b.Header()); err != nil {
|
if err := validateHeader(bmap[b.Hash()].BlockHeader, b.Header()); err != nil {
|
||||||
return fmt.Errorf("Imported block header validation failed: %v", err)
|
return fmt.Errorf("imported block header validation failed: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -136,10 +136,6 @@ func (tm *testMatcher) fails(pattern string, reason string) {
|
||||||
tm.failpat = append(tm.failpat, testFailure{regexp.MustCompile(pattern), reason})
|
tm.failpat = append(tm.failpat, testFailure{regexp.MustCompile(pattern), reason})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tm *testMatcher) whitelist(pattern string) {
|
|
||||||
tm.whitelistpat = regexp.MustCompile(pattern)
|
|
||||||
}
|
|
||||||
|
|
||||||
// config defines chain config for tests matching the pattern.
|
// config defines chain config for tests matching the pattern.
|
||||||
func (tm *testMatcher) config(pattern string, cfg params.ChainConfig) {
|
func (tm *testMatcher) config(pattern string, cfg params.ChainConfig) {
|
||||||
tm.configpat = append(tm.configpat, testConfig{regexp.MustCompile(pattern), cfg})
|
tm.configpat = append(tm.configpat, testConfig{regexp.MustCompile(pattern), cfg})
|
||||||
|
|
|
||||||
|
|
@ -86,25 +86,25 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error {
|
||||||
|
|
||||||
if testcase.fork.Sender == (common.UnprefixedAddress{}) {
|
if testcase.fork.Sender == (common.UnprefixedAddress{}) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return fmt.Errorf("Expected error, got none (address %v)[%v]", sender.String(), testcase.name)
|
return fmt.Errorf("expected error, got none (address %v)[%v]", sender.String(), testcase.name)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Should resolve the right address
|
// Should resolve the right address
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Got error, expected none: %v", err)
|
return fmt.Errorf("got error, expected none: %v", err)
|
||||||
}
|
}
|
||||||
if sender == nil {
|
if sender == nil {
|
||||||
return fmt.Errorf("sender was nil, should be %x", common.Address(testcase.fork.Sender))
|
return fmt.Errorf("sender was nil, should be %x", common.Address(testcase.fork.Sender))
|
||||||
}
|
}
|
||||||
if *sender != common.Address(testcase.fork.Sender) {
|
if *sender != common.Address(testcase.fork.Sender) {
|
||||||
return fmt.Errorf("Sender mismatch: got %x, want %x", sender, testcase.fork.Sender)
|
return fmt.Errorf("sender mismatch: got %x, want %x", sender, testcase.fork.Sender)
|
||||||
}
|
}
|
||||||
if txhash == nil {
|
if txhash == nil {
|
||||||
return fmt.Errorf("txhash was nil, should be %x", common.Hash(testcase.fork.Hash))
|
return fmt.Errorf("txhash was nil, should be %x", common.Hash(testcase.fork.Hash))
|
||||||
}
|
}
|
||||||
if *txhash != common.Hash(testcase.fork.Hash) {
|
if *txhash != common.Hash(testcase.fork.Hash) {
|
||||||
return fmt.Errorf("Hash mismatch: got %x, want %x", *txhash, testcase.fork.Hash)
|
return fmt.Errorf("hash mismatch: got %x, want %x", *txhash, testcase.fork.Hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue