Skip to content

Commit

Permalink
Merge pull request ethereum#2458 from fjl/go-vet
Browse files Browse the repository at this point in the history
all: fix go vet warnings
  • Loading branch information
fjl committed Apr 15, 2016
2 parents 5c17b2f + bf5ae50 commit 6197fbf
Show file tree
Hide file tree
Showing 51 changed files with 130 additions and 118 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ test: all
build/env.sh go test ./...

travis-test-with-coverage: all
build/env.sh go vet ./...
build/env.sh build/test-global-coverage.sh

xgo:
Expand Down
10 changes: 5 additions & 5 deletions accounts/abi/numbers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ func TestNumberTypes(t *testing.T) {

unsigned := U256(big.NewInt(1))
if !bytes.Equal(unsigned, ubytes) {
t.Error("expected %x got %x", ubytes, unsigned)
t.Errorf("expected %x got %x", ubytes, unsigned)
}

signed := S256(big.NewInt(1))
if !bytes.Equal(signed, ubytes) {
t.Error("expected %x got %x", ubytes, unsigned)
t.Errorf("expected %x got %x", ubytes, unsigned)
}

signed = S256(big.NewInt(-1))
if !bytes.Equal(signed, sbytesmin) {
t.Error("expected %x got %x", ubytes, unsigned)
t.Errorf("expected %x got %x", ubytes, unsigned)
}
}

Expand Down Expand Up @@ -75,10 +75,10 @@ func TestPackNumber(t *testing.T) {

func TestSigned(t *testing.T) {
if isSigned(reflect.ValueOf(uint(10))) {
t.Error()
t.Error("signed")
}

if !isSigned(reflect.ValueOf(int(10))) {
t.Error()
t.Error("not signed")
}
}
2 changes: 1 addition & 1 deletion cmd/bootnode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func main() {
func writeKey(target string) {
key, err := crypto.GenerateKey()
if err != nil {
log.Fatal("could not generate key: %v", err)
log.Fatalf("could not generate key: %v", err)
}
b := crypto.FromECDSA(key)
if target == "-" {
Expand Down
3 changes: 2 additions & 1 deletion cmd/ethtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func runTestWithReader(test string, r io.Reader) error {
case "bk", "block", "blocktest", "blockchaintest", "blocktests", "blockchaintests":
err = tests.RunBlockTestWithReader(params.MainNetHomesteadBlock, r, skipTests)
case "st", "state", "statetest", "statetests":
err = tests.RunStateTestWithReader(tests.RuleSet{params.MainNetHomesteadBlock}, r, skipTests)
rs := tests.RuleSet{HomesteadBlock: params.MainNetHomesteadBlock}
err = tests.RunStateTestWithReader(rs, r, skipTests)
case "tx", "transactiontest", "transactiontests":
err = tests.RunTransactionTestsWithReader(r, skipTests)
case "vm", "vmtest", "vmtests":
Expand Down
5 changes: 4 additions & 1 deletion cmd/geth/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *nod
// Initialize and register the Ethereum protocol
accman := accounts.NewPlaintextManager(filepath.Join(tmp, "keystore"))
db, _ := ethdb.NewMemDatabase()
core.WriteGenesisBlockForTesting(db, core.GenesisAccount{common.HexToAddress(testAddress), common.String2Big(testBalance)})
core.WriteGenesisBlockForTesting(db, core.GenesisAccount{
Address: common.HexToAddress(testAddress),
Balance: common.String2Big(testBalance),
})
ethConf := &eth.Config{
ChainConfig: &core.ChainConfig{HomesteadBlock: new(big.Int)},
TestGenesisState: db,
Expand Down
9 changes: 3 additions & 6 deletions cmd/utils/jeth.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,11 @@ func (self *Jeth) NewAccount(call otto.FunctionCall) (response otto.Value) {
return otto.FalseValue()
}

if ret, err := call.Otto.Call("jeth.newAccount", nil, passwd); err == nil {
ret, err := call.Otto.Call("jeth.newAccount", nil, passwd)
if err == nil {
return ret
} else {
fmt.Printf("%v\n", err)
return otto.FalseValue()
}

fmt.Println(err)
return otto.FalseValue()
}

Expand Down Expand Up @@ -233,7 +231,6 @@ func (self *Jeth) Send(call otto.FunctionCall) (response otto.Value) {
func throwJSExeception(msg interface{}) otto.Value {
p, _ := otto.ToValue(msg)
panic(p)
return p
}

// Sleep will halt the console for arg[0] seconds.
Expand Down
2 changes: 1 addition & 1 deletion common/compiler/solidity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestCompiler(t *testing.T) {
}

if len(contracts) != 1 {
t.Errorf("one contract expected, got\n%s", len(contracts))
t.Errorf("one contract expected, got %d", len(contracts))
}

if contracts["test"].Code != code {
Expand Down
2 changes: 1 addition & 1 deletion common/math/dist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestSum(t *testing.T) {
summer := summer{numbers: []*big.Int{big.NewInt(1), big.NewInt(2), big.NewInt(3)}}
sum := Sum(summer)
if sum.Cmp(big.NewInt(6)) != 0 {
t.Errorf("not 6", sum)
t.Errorf("got sum = %d, want 6", sum)
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func MakeName(name, version string) string {

func ExpandHomePath(p string) (path string) {
path = p
sep := fmt.Sprintf("%s", os.PathSeparator)
sep := string(os.PathSeparator)

// Check in case of paths like "/something/~/something/"
if len(p) > 1 && p[:1+len(sep)] == "~"+sep {
Expand Down
2 changes: 0 additions & 2 deletions core/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,4 @@ func Disassemble(script []byte) (asm []string) {

pc.Add(pc, common.Big1)
}

return asm
}
6 changes: 3 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ func (self *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain
}
}
// Write all the data out into the database
if err := WriteBody(self.chainDb, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
if err := WriteBody(self.chainDb, block.Hash(), block.Body()); err != nil {
errs[index] = fmt.Errorf("failed to write block body: %v", err)
atomic.AddInt32(&failed, 1)
glog.Fatal(errs[index])
Expand Down Expand Up @@ -993,15 +993,15 @@ func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
// first reduce whoever is higher bound
if oldBlock.NumberU64() > newBlock.NumberU64() {
// reduce old chain
for oldBlock = oldBlock; oldBlock != nil && oldBlock.NumberU64() != newBlock.NumberU64(); oldBlock = self.GetBlock(oldBlock.ParentHash()) {
for ; oldBlock != nil && oldBlock.NumberU64() != newBlock.NumberU64(); oldBlock = self.GetBlock(oldBlock.ParentHash()) {
oldChain = append(oldChain, oldBlock)
deletedTxs = append(deletedTxs, oldBlock.Transactions()...)

collectLogs(oldBlock.Hash())
}
} else {
// reduce new chain and append new chain blocks for inserting later on
for newBlock = newBlock; newBlock != nil && newBlock.NumberU64() != oldBlock.NumberU64(); newBlock = self.GetBlock(newBlock.ParentHash()) {
for ; newBlock != nil && newBlock.NumberU64() != oldBlock.NumberU64(); newBlock = self.GetBlock(newBlock.ParentHash()) {
newChain = append(newChain, newBlock)
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/database_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func WriteTd(db ethdb.Database, hash common.Hash, td *big.Int) error {
// WriteBlock serializes a block into the database, header and body separately.
func WriteBlock(db ethdb.Database, block *types.Block) error {
// Store the body first to retain database consistency
if err := WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
if err := WriteBody(db, block.Hash(), block.Body()); err != nil {
return err
}
// Store the header too, signaling full block ownership
Expand Down
6 changes: 3 additions & 3 deletions core/database_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func TestBlockStorage(t *testing.T) {
if entry := GetBody(db, block.Hash()); entry == nil {
t.Fatalf("Stored body not found")
} else if types.DeriveSha(types.Transactions(entry.Transactions)) != types.DeriveSha(block.Transactions()) || types.CalcUncleHash(entry.Uncles) != types.CalcUncleHash(block.Uncles()) {
t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, &types.Body{block.Transactions(), block.Uncles()})
t.Fatalf("Retrieved body mismatch: have %v, want %v", entry, block.Body())
}
// Delete the block and verify the execution
DeleteBlock(db, block.Hash())
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestPartialBlockStorage(t *testing.T) {
DeleteHeader(db, block.Hash())

// Store a body and check that it's not recognized as a block
if err := WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
if err := WriteBody(db, block.Hash(), block.Body()); err != nil {
t.Fatalf("Failed to write body into database: %v", err)
}
if entry := GetBlock(db, block.Hash()); entry != nil {
Expand All @@ -242,7 +242,7 @@ func TestPartialBlockStorage(t *testing.T) {
if err := WriteHeader(db, block.Header()); err != nil {
t.Fatalf("Failed to write header into database: %v", err)
}
if err := WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
if err := WriteBody(db, block.Hash(), block.Body()); err != nil {
t.Fatalf("Failed to write body into database: %v", err)
}
if entry := GetBlock(db, block.Hash()); entry == nil {
Expand Down
16 changes: 12 additions & 4 deletions core/state/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,19 @@ func (self *StateDB) RawDump() World {
it := self.trie.Iterator()
for it.Next() {
addr := self.trie.GetKey(it.Key)
stateObject, _ := DecodeObject(common.BytesToAddress(addr), self.db, it.Value)

account := Account{Balance: stateObject.balance.String(), Nonce: stateObject.nonce, Root: common.Bytes2Hex(stateObject.Root()), CodeHash: common.Bytes2Hex(stateObject.codeHash), Code: common.Bytes2Hex(stateObject.Code())}
account.Storage = make(map[string]string)
stateObject, err := DecodeObject(common.BytesToAddress(addr), self.db, it.Value)
if err != nil {
panic(err)
}

account := Account{
Balance: stateObject.balance.String(),
Nonce: stateObject.nonce,
Root: common.Bytes2Hex(stateObject.Root()),
CodeHash: common.Bytes2Hex(stateObject.codeHash),
Code: common.Bytes2Hex(stateObject.Code()),
Storage: make(map[string]string),
}
storageIt := stateObject.trie.Iterator()
for storageIt.Next() {
account.Storage[common.Bytes2Hex(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value)
Expand Down
2 changes: 1 addition & 1 deletion core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func DecodeObject(address common.Address, db trie.Database, data []byte) (*State
}
if !bytes.Equal(ext.CodeHash, emptyCodeHash) {
if obj.code, err = db.Get(ext.CodeHash); err != nil {
return nil, fmt.Errorf("can't find code for hash %x: %v", ext.CodeHash, err)
return nil, fmt.Errorf("can't get code for hash %x: %v", ext.CodeHash, err)
}
}
obj.nonce = ext.Nonce
Expand Down
18 changes: 14 additions & 4 deletions core/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var _ = checker.Suite(&StateSuite{})
var toAddr = common.BytesToAddress

func (s *StateSuite) TestDump(c *checker.C) {
return
// generate a few entries
obj1 := s.state.GetOrNewStateObject(toAddr([]byte{0x01}))
obj1.AddBalance(big.NewInt(22))
Expand All @@ -48,24 +47,35 @@ func (s *StateSuite) TestDump(c *checker.C) {
// write some of them to the trie
s.state.UpdateStateObject(obj1)
s.state.UpdateStateObject(obj2)
s.state.Commit()

// check that dump contains the state objects that are in trie
got := string(s.state.Dump())
want := `{
"root": "6e277ae8357d013e50f74eedb66a991f6922f93ae03714de58b3d0c5e9eee53f",
"root": "71edff0130dd2385947095001c73d9e28d862fc286fca2b922ca6f6f3cddfdd2",
"accounts": {
"1468288056310c82aa4c01a7e12a10f8111a0560e72b700555479031b86c357d": {
"0000000000000000000000000000000000000001": {
"balance": "22",
"nonce": 0,
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
"code": "",
"storage": {}
},
"a17eacbc25cda025e81db9c5c62868822c73ce097cee2a63e33a2e41268358a1": {
"0000000000000000000000000000000000000002": {
"balance": "44",
"nonce": 0,
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
"code": "",
"storage": {}
},
"0000000000000000000000000000000000000102": {
"balance": "0",
"nonce": 0,
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"codeHash": "87874902497a5bb968da31a2998d8f22e949d1ef6214bcdedd8bae24cca4b9e3",
"code": "03030303030303",
"storage": {}
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/state/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func testIterativeStateSync(t *testing.T, batch int) {
if err != nil {
t.Fatalf("failed to retrieve node data for %x: %v", hash, err)
}
results[i] = trie.SyncResult{hash, data}
results[i] = trie.SyncResult{Hash: hash, Data: data}
}
if index, err := sched.Process(results); err != nil {
t.Fatalf("failed to process result #%d: %v", index, err)
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestIterativeDelayedStateSync(t *testing.T) {
if err != nil {
t.Fatalf("failed to retrieve node data for %x: %v", hash, err)
}
results[i] = trie.SyncResult{hash, data}
results[i] = trie.SyncResult{Hash: hash, Data: data}
}
if index, err := sched.Process(results); err != nil {
t.Fatalf("failed to process result #%d: %v", index, err)
Expand Down Expand Up @@ -212,7 +212,7 @@ func testIterativeRandomStateSync(t *testing.T, batch int) {
if err != nil {
t.Fatalf("failed to retrieve node data for %x: %v", hash, err)
}
results = append(results, trie.SyncResult{hash, data})
results = append(results, trie.SyncResult{Hash: hash, Data: data})
}
// Feed the retrieved results back and queue new tasks
if index, err := sched.Process(results); err != nil {
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestIterativeRandomDelayedStateSync(t *testing.T) {
if err != nil {
t.Fatalf("failed to retrieve node data for %x: %v", hash, err)
}
results = append(results, trie.SyncResult{hash, data})
results = append(results, trie.SyncResult{Hash: hash, Data: data})

if len(results) >= cap(results) {
break
Expand Down Expand Up @@ -289,7 +289,7 @@ func TestIncompleteStateSync(t *testing.T) {
if err != nil {
t.Fatalf("failed to retrieve node data for %x: %v", hash, err)
}
results[i] = trie.SyncResult{hash, data}
results[i] = trie.SyncResult{Hash: hash, Data: data}
}
// Process each of the state nodes
if index, err := sched.Process(results); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ func (b *Block) Extra() []byte { return common.CopyBytes(b.header.Ext

func (b *Block) Header() *Header { return CopyHeader(b.header) }

// Body returns the non-header content of the block.
func (b *Block) Body() *Body { return &Body{b.transactions, b.uncles} }

func (b *Block) HashNoNonce() common.Hash {
return b.header.HashNoNonce()
}
Expand Down
2 changes: 0 additions & 2 deletions core/vm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,4 @@ func Disassemble(script []byte) (asm []string) {

pc.Add(pc, common.Big1)
}

return
}
2 changes: 1 addition & 1 deletion core/vm/jit_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestParser(t *testing.T) {
t.Fatal("empty output")
}
if output[0] != test.output {
t.Error("%v failed: expected %v but got %v", test.base+OpCode(i), output[0])
t.Errorf("%v failed: expected %v but got %v", test.base+OpCode(i), test.output, output[0])
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func ToECDSAPub(pub []byte) *ecdsa.PublicKey {
return nil
}
x, y := elliptic.Unmarshal(secp256k1.S256(), pub)
return &ecdsa.PublicKey{secp256k1.S256(), x, y}
return &ecdsa.PublicKey{Curve: secp256k1.S256(), X: x, Y: y}
}

func FromECDSAPub(pub *ecdsa.PublicKey) []byte {
Expand Down Expand Up @@ -189,7 +189,7 @@ func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) {
}

x, y := elliptic.Unmarshal(secp256k1.S256(), s)
return &ecdsa.PublicKey{secp256k1.S256(), x, y}, nil
return &ecdsa.PublicKey{Curve: secp256k1.S256(), X: x, Y: y}, nil
}

func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) {
Expand Down
4 changes: 2 additions & 2 deletions crypto/ecies/ecies.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type PublicKey struct {

// Export an ECIES public key as an ECDSA public key.
func (pub *PublicKey) ExportECDSA() *ecdsa.PublicKey {
return &ecdsa.PublicKey{pub.Curve, pub.X, pub.Y}
return &ecdsa.PublicKey{Curve: pub.Curve, X: pub.X, Y: pub.Y}
}

// Import an ECDSA public key as an ECIES public key.
Expand All @@ -83,7 +83,7 @@ type PrivateKey struct {
func (prv *PrivateKey) ExportECDSA() *ecdsa.PrivateKey {
pub := &prv.PublicKey
pubECDSA := pub.ExportECDSA()
return &ecdsa.PrivateKey{*pubECDSA, prv.D}
return &ecdsa.PrivateKey{PublicKey: *pubECDSA, D: prv.D}
}

// Import an ECDSA private key as an ECIES private key.
Expand Down
4 changes: 2 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func upgradeChainDatabase(db ethdb.Database) error {
if err := core.WriteTd(db, block.Hash(), block.DeprecatedTd()); err != nil {
return err
}
if err := core.WriteBody(db, block.Hash(), &types.Body{block.Transactions(), block.Uncles()}); err != nil {
if err := core.WriteBody(db, block.Hash(), block.Body()); err != nil {
return err
}
if err := core.WriteHeader(db, block.Header()); err != nil {
Expand All @@ -573,7 +573,7 @@ func upgradeChainDatabase(db ethdb.Database) error {
if err := core.WriteTd(db, current.Hash(), current.DeprecatedTd()); err != nil {
return err
}
if err := core.WriteBody(db, current.Hash(), &types.Body{current.Transactions(), current.Uncles()}); err != nil {
if err := core.WriteBody(db, current.Hash(), current.Body()); err != nil {
return err
}
if err := core.WriteHeader(db, current.Header()); err != nil {
Expand Down
Loading

0 comments on commit 6197fbf

Please sign in to comment.