Skip to content

Commit

Permalink
all: fix go vet warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Apr 15, 2016
1 parent 68c755a commit 6fdd089
Show file tree
Hide file tree
Showing 41 changed files with 83 additions and 93 deletions.
10 changes: 5 additions & 5 deletions accounts/abi/numbers_test.go
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
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
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
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
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
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
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
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
Expand Up @@ -61,6 +61,4 @@ func Disassemble(script []byte) (asm []string) {

pc.Add(pc, common.Big1)
}

return asm
}
4 changes: 2 additions & 2 deletions core/blockchain.go
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
10 changes: 5 additions & 5 deletions core/state/sync_test.go
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
2 changes: 0 additions & 2 deletions core/vm/asm.go
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
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
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
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
6 changes: 2 additions & 4 deletions eth/downloader/downloader.go
Expand Up @@ -892,8 +892,7 @@ func (d *Downloader) fetchBlocks61(from uint64) error {
// case, the internal state of the downloader and the queue is very wrong so
// better hard crash and note the error instead of silently accumulating into
// a much bigger issue.
panic(fmt.Sprintf("%v: fetch assignment failed, hard panic", peer))
d.queue.CancelBlocks(request) // noop for now
panic(fmt.Sprintf("%v: fetch assignment failed", peer))
}
}
// Make sure that we have peers available for fetching. If all peers have been tried
Expand Down Expand Up @@ -1525,8 +1524,7 @@ func (d *Downloader) fetchParts(errCancel error, deliveryCh chan dataPack, deliv
// case, the internal state of the downloader and the queue is very wrong so
// better hard crash and note the error instead of silently accumulating into
// a much bigger issue.
panic(fmt.Sprintf("%v: %s fetch assignment failed, hard panic", peer, strings.ToLower(kind)))
cancel(request) // noop for now
panic(fmt.Sprintf("%v: %s fetch assignment failed", peer, strings.ToLower(kind)))
}
running = true
}
Expand Down
2 changes: 1 addition & 1 deletion eth/downloader/queue.go
Expand Up @@ -983,7 +983,7 @@ func (q *queue) DeliverNodeData(id string, data [][]byte, callback func(error, i
continue
}
// Inject the next state trie item into the processing queue
process = append(process, trie.SyncResult{hash, blob})
process = append(process, trie.SyncResult{Hash: hash, Data: blob})
accepted++

delete(request.Hashes, hash)
Expand Down
8 changes: 4 additions & 4 deletions eth/filters/api.go
Expand Up @@ -331,7 +331,7 @@ func (args *NewFilterArgs) UnmarshalJSON(data []byte) error {
if decAddr, err := hex.DecodeString(strAddr); err == nil {
addresses = append(addresses, common.BytesToAddress(decAddr))
} else {
fmt.Errorf("invalid address given")
return fmt.Errorf("invalid address given")
}
} else {
return fmt.Errorf("invalid address on index %d", i)
Expand All @@ -344,10 +344,10 @@ func (args *NewFilterArgs) UnmarshalJSON(data []byte) error {
if decAddr, err := hex.DecodeString(singleAddr); err == nil {
addresses = append(addresses, common.BytesToAddress(decAddr))
} else {
fmt.Errorf("invalid address given")
return fmt.Errorf("invalid address given")
}
} else {
errors.New("invalid address(es) given")
return errors.New("invalid address(es) given")
}
args.Addresses = addresses
}
Expand Down Expand Up @@ -394,7 +394,7 @@ func (args *NewFilterArgs) UnmarshalJSON(data []byte) error {
parsedTopics[i] = []common.Hash{t}
}
} else {
fmt.Errorf("topic[%d][%d] not a string", i, j)
return fmt.Errorf("topic[%d][%d] not a string", i, j)
}
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions eth/filters/filter_system_test.go
Expand Up @@ -76,8 +76,8 @@ func TestCallbacks(t *testing.T) {
mux.Post(core.ChainEvent{})
mux.Post(core.TxPreEvent{})
mux.Post(vm.Logs{&vm.Log{}})
mux.Post(core.RemovedLogsEvent{vm.Logs{&vm.Log{}}})
mux.Post(core.PendingLogsEvent{vm.Logs{&vm.Log{}}})
mux.Post(core.RemovedLogsEvent{Logs: vm.Logs{&vm.Log{}}})
mux.Post(core.PendingLogsEvent{Logs: vm.Logs{&vm.Log{}}})

const dura = 5 * time.Second
failTimer := time.NewTimer(dura)
Expand Down
4 changes: 2 additions & 2 deletions eth/filters/filter_test.go
Expand Up @@ -56,7 +56,7 @@ func BenchmarkMipmaps(b *testing.B) {
)
defer db.Close()

genesis := core.WriteGenesisBlockForTesting(db, core.GenesisAccount{addr1, big.NewInt(1000000)})
genesis := core.WriteGenesisBlockForTesting(db, core.GenesisAccount{Address: addr1, Balance: big.NewInt(1000000)})
chain, receipts := core.GenerateChain(genesis, db, 100010, func(i int, gen *core.BlockGen) {
var receipts types.Receipts
switch i {
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestFilters(t *testing.T) {
)
defer db.Close()

genesis := core.WriteGenesisBlockForTesting(db, core.GenesisAccount{addr, big.NewInt(1000000)})
genesis := core.WriteGenesisBlockForTesting(db, core.GenesisAccount{Address: addr, Balance: big.NewInt(1000000)})
chain, receipts := core.GenerateChain(genesis, db, 1000, func(i int, gen *core.BlockGen) {
var receipts types.Receipts
switch i {
Expand Down
1 change: 0 additions & 1 deletion eth/handler.go
Expand Up @@ -245,7 +245,6 @@ func (pm *ProtocolManager) handle(p *peer) error {
return err
}
}
return nil
}

// handleMsg is invoked whenever an inbound message is received from a remote
Expand Down
13 changes: 6 additions & 7 deletions eth/handler_test.go
Expand Up @@ -17,7 +17,6 @@
package eth

import (
"fmt"
"math/big"
"math/rand"
"testing"
Expand Down Expand Up @@ -448,12 +447,12 @@ func testGetNodeData(t *testing.T, protocol int) {
switch i {
case 0:
// In block 1, the test bank sends account #1 some ether.
tx, _ := types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil).SignECDSA(testBankKey)
tx, _ := types.NewTransaction(block.TxNonce(testBank.Address), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil).SignECDSA(testBankKey)
block.AddTx(tx)
case 1:
// In block 2, the test bank sends some more ether to account #1.
// acc1Addr passes it on to account #2.
tx1, _ := types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(testBankKey)
tx1, _ := types.NewTransaction(block.TxNonce(testBank.Address), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(testBankKey)
tx2, _ := types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(acc1Key)
block.AddTx(tx1)
block.AddTx(tx2)
Expand Down Expand Up @@ -498,14 +497,14 @@ func testGetNodeData(t *testing.T, protocol int) {
// Verify that all hashes correspond to the requested data, and reconstruct a state tree
for i, want := range hashes {
if hash := crypto.Keccak256Hash(data[i]); hash != want {
fmt.Errorf("data hash mismatch: have %x, want %x", hash, want)
t.Errorf("data hash mismatch: have %x, want %x", hash, want)
}
}
statedb, _ := ethdb.NewMemDatabase()
for i := 0; i < len(data); i++ {
statedb.Put(hashes[i].Bytes(), data[i])
}
accounts := []common.Address{testBankAddress, acc1Addr, acc2Addr}
accounts := []common.Address{testBank.Address, acc1Addr, acc2Addr}
for i := uint64(0); i <= pm.blockchain.CurrentBlock().NumberU64(); i++ {
trie, _ := state.New(pm.blockchain.GetBlockByNumber(i).Root(), statedb)

Expand Down Expand Up @@ -539,12 +538,12 @@ func testGetReceipt(t *testing.T, protocol int) {
switch i {
case 0:
// In block 1, the test bank sends account #1 some ether.
tx, _ := types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil).SignECDSA(testBankKey)
tx, _ := types.NewTransaction(block.TxNonce(testBank.Address), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil).SignECDSA(testBankKey)
block.AddTx(tx)
case 1:
// In block 2, the test bank sends some more ether to account #1.
// acc1Addr passes it on to account #2.
tx1, _ := types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(testBankKey)
tx1, _ := types.NewTransaction(block.TxNonce(testBank.Address), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(testBankKey)
tx2, _ := types.NewTransaction(block.TxNonce(acc1Addr), acc2Addr, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(acc1Key)
block.AddTx(tx1)
block.AddTx(tx2)
Expand Down

0 comments on commit 6fdd089

Please sign in to comment.