all: fix issues reported by honnef.co/go/simple/cmd/gosimple

pull/3525/head
Felix Lange 8 years ago
parent 35a7dcb162
commit f2da6581ba
  1. 20
      accounts/abi/bind/bind.go
  2. 2
      accounts/abi/type.go
  3. 5
      cmd/ethtest/main.go
  4. 8
      cmd/geth/accountcmd_test.go
  5. 2
      cmd/utils/cmd.go
  6. 6
      common/big_test.go
  7. 4
      common/bytes_test.go
  8. 2
      common/compiler/solidity.go
  9. 2
      common/format.go
  10. 4
      compression/rle/read_write.go
  11. 11
      console/console.go
  12. 5
      core/blockchain.go
  13. 4
      core/dao.go
  14. 4
      core/database_util_test.go
  15. 2
      core/state/iterator.go
  16. 4
      core/state/sync_test.go
  17. 8
      core/types/bloom9.go
  18. 2
      crypto/crypto_test.go
  19. 5
      crypto/ecies/ecies.go
  20. 28
      eth/handler.go
  21. 29
      ethstats/ethstats.go
  22. 2
      miner/worker.go
  23. 29
      mobile/bind.go
  24. 2
      node/config_test.go
  25. 4
      node/node_test.go
  26. 2
      p2p/discover/database.go
  27. 5
      p2p/discover/node.go
  28. 2
      p2p/discv5/database.go
  29. 5
      p2p/discv5/node.go
  30. 2
      swarm/storage/dbstore.go
  31. 2
      swarm/storage/types.go
  32. 4
      tests/block_test_util.go
  33. 6
      tests/init.go
  34. 2
      tests/state_test_util.go
  35. 2
      tests/vm_test_util.go
  36. 2
      trie/sync_test.go
  37. 6
      whisper/shhapi/api.go
  38. 2
      whisper/shhapi/api_test.go
  39. 12
      whisper/whisperv2/envelope_test.go
  40. 5
      whisper/whisperv2/filter.go
  41. 8
      whisper/whisperv2/filter_test.go
  42. 4
      whisper/whisperv2/message_test.go
  43. 8
      whisper/whisperv2/topic_test.go
  44. 8
      whisper/whisperv5/message_test.go
  45. 2
      whisper/whisperv5/peer_test.go
  46. 6
      whisper/whisperv5/whisper_test.go

@ -147,21 +147,21 @@ func bindTypeGo(kind abi.Type) string {
switch { switch {
case strings.HasPrefix(stringKind, "address"): case strings.HasPrefix(stringKind, "address"):
parts := regexp.MustCompile("address(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) parts := regexp.MustCompile(`address(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
if len(parts) != 2 { if len(parts) != 2 {
return stringKind return stringKind
} }
return fmt.Sprintf("%scommon.Address", parts[1]) return fmt.Sprintf("%scommon.Address", parts[1])
case strings.HasPrefix(stringKind, "bytes"): case strings.HasPrefix(stringKind, "bytes"):
parts := regexp.MustCompile("bytes([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) parts := regexp.MustCompile(`bytes([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
if len(parts) != 3 { if len(parts) != 3 {
return stringKind return stringKind
} }
return fmt.Sprintf("%s[%s]byte", parts[2], parts[1]) return fmt.Sprintf("%s[%s]byte", parts[2], parts[1])
case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"): case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"):
parts := regexp.MustCompile("(u)?int([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
if len(parts) != 4 { if len(parts) != 4 {
return stringKind return stringKind
} }
@ -172,7 +172,7 @@ func bindTypeGo(kind abi.Type) string {
return fmt.Sprintf("%s*big.Int", parts[3]) return fmt.Sprintf("%s*big.Int", parts[3])
case strings.HasPrefix(stringKind, "bool") || strings.HasPrefix(stringKind, "string"): case strings.HasPrefix(stringKind, "bool") || strings.HasPrefix(stringKind, "string"):
parts := regexp.MustCompile("([a-z]+)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) parts := regexp.MustCompile(`([a-z]+)(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
if len(parts) != 3 { if len(parts) != 3 {
return stringKind return stringKind
} }
@ -191,7 +191,7 @@ func bindTypeJava(kind abi.Type) string {
switch { switch {
case strings.HasPrefix(stringKind, "address"): case strings.HasPrefix(stringKind, "address"):
parts := regexp.MustCompile("address(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) parts := regexp.MustCompile(`address(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
if len(parts) != 2 { if len(parts) != 2 {
return stringKind return stringKind
} }
@ -201,7 +201,7 @@ func bindTypeJava(kind abi.Type) string {
return fmt.Sprintf("Addresses") return fmt.Sprintf("Addresses")
case strings.HasPrefix(stringKind, "bytes"): case strings.HasPrefix(stringKind, "bytes"):
parts := regexp.MustCompile("bytes([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) parts := regexp.MustCompile(`bytes([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
if len(parts) != 3 { if len(parts) != 3 {
return stringKind return stringKind
} }
@ -211,7 +211,7 @@ func bindTypeJava(kind abi.Type) string {
return "byte[]" return "byte[]"
case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"): case strings.HasPrefix(stringKind, "int") || strings.HasPrefix(stringKind, "uint"):
parts := regexp.MustCompile("(u)?int([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
if len(parts) != 4 { if len(parts) != 4 {
return stringKind return stringKind
} }
@ -230,7 +230,7 @@ func bindTypeJava(kind abi.Type) string {
return fmt.Sprintf("BigInts") return fmt.Sprintf("BigInts")
case strings.HasPrefix(stringKind, "bool"): case strings.HasPrefix(stringKind, "bool"):
parts := regexp.MustCompile("bool(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) parts := regexp.MustCompile(`bool(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
if len(parts) != 2 { if len(parts) != 2 {
return stringKind return stringKind
} }
@ -240,7 +240,7 @@ func bindTypeJava(kind abi.Type) string {
return fmt.Sprintf("bool[]") return fmt.Sprintf("bool[]")
case strings.HasPrefix(stringKind, "string"): case strings.HasPrefix(stringKind, "string"):
parts := regexp.MustCompile("string(\\[[0-9]*\\])?").FindStringSubmatch(stringKind) parts := regexp.MustCompile(`string(\[[0-9]*\])?`).FindStringSubmatch(stringKind)
if len(parts) != 2 { if len(parts) != 2 {
return stringKind return stringKind
} }
@ -278,7 +278,7 @@ func namedTypeJava(javaKind string, solKind abi.Type) string {
case "bool[]": case "bool[]":
return "Bools" return "Bools"
case "BigInt": case "BigInt":
parts := regexp.MustCompile("(u)?int([0-9]*)(\\[[0-9]*\\])?").FindStringSubmatch(solKind.String()) parts := regexp.MustCompile(`(u)?int([0-9]*)(\[[0-9]*\])?`).FindStringSubmatch(solKind.String())
if len(parts) != 4 { if len(parts) != 4 {
return javaKind return javaKind
} }

@ -65,7 +65,7 @@ var (
// string int uint fixed // string int uint fixed
// string32 int8 uint8 uint[] // string32 int8 uint8 uint[]
// address int256 uint256 fixed128x128[2] // address int256 uint256 fixed128x128[2]
fullTypeRegex = regexp.MustCompile("([a-zA-Z0-9]+)(\\[([0-9]*)\\])?") fullTypeRegex = regexp.MustCompile(`([a-zA-Z0-9]+)(\[([0-9]*)\])?`)
// typeRegex parses the abi sub types // typeRegex parses the abi sub types
typeRegex = regexp.MustCompile("([a-zA-Z]+)(([0-9]+)(x([0-9]+))?)?") typeRegex = regexp.MustCompile("([a-zA-Z]+)(([0-9]+)(x([0-9]+))?)?")
) )

@ -88,12 +88,7 @@ func runTestWithReader(test string, r io.Reader) error {
default: default:
err = fmt.Errorf("Invalid test type specified: %v", test) err = fmt.Errorf("Invalid test type specified: %v", test)
} }
if err != nil {
return err return err
}
return nil
} }
func getFiles(path string) ([]string, error) { func getFiles(path string) ([]string, error) {

@ -148,7 +148,7 @@ Passphrase: {{.InputLine "foobar"}}
"Unlocked account f466859ead1932d743d622cb74fc058882e8648a", "Unlocked account f466859ead1932d743d622cb74fc058882e8648a",
} }
for _, m := range wantMessages { for _, m := range wantMessages {
if strings.Index(geth.stderrText(), m) == -1 { if !strings.Contains(geth.stderrText(), m) {
t.Errorf("stderr text does not contain %q", m) t.Errorf("stderr text does not contain %q", m)
} }
} }
@ -193,7 +193,7 @@ Passphrase: {{.InputLine "foobar"}}
"Unlocked account 289d485d9771714cce91d3393d764e1311907acc", "Unlocked account 289d485d9771714cce91d3393d764e1311907acc",
} }
for _, m := range wantMessages { for _, m := range wantMessages {
if strings.Index(geth.stderrText(), m) == -1 { if !strings.Contains(geth.stderrText(), m) {
t.Errorf("stderr text does not contain %q", m) t.Errorf("stderr text does not contain %q", m)
} }
} }
@ -212,7 +212,7 @@ func TestUnlockFlagPasswordFile(t *testing.T) {
"Unlocked account 289d485d9771714cce91d3393d764e1311907acc", "Unlocked account 289d485d9771714cce91d3393d764e1311907acc",
} }
for _, m := range wantMessages { for _, m := range wantMessages {
if strings.Index(geth.stderrText(), m) == -1 { if !strings.Contains(geth.stderrText(), m) {
t.Errorf("stderr text does not contain %q", m) t.Errorf("stderr text does not contain %q", m)
} }
} }
@ -260,7 +260,7 @@ In order to avoid this warning, you need to remove the following duplicate key f
"Unlocked account f466859ead1932d743d622cb74fc058882e8648a", "Unlocked account f466859ead1932d743d622cb74fc058882e8648a",
} }
for _, m := range wantMessages { for _, m := range wantMessages {
if strings.Index(geth.stderrText(), m) == -1 { if !strings.Contains(geth.stderrText(), m) {
t.Errorf("stderr text does not contain %q", m) t.Errorf("stderr text does not contain %q", m)
} }
} }

@ -95,7 +95,7 @@ func StartNode(stack *node.Node) {
func FormatTransactionData(data string) []byte { func FormatTransactionData(data string) []byte {
d := common.StringToByteFunc(data, func(s string) (ret []byte) { d := common.StringToByteFunc(data, func(s string) (ret []byte) {
slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000) slice := regexp.MustCompile(`\n|\s`).Split(s, 1000000000)
for _, dataItem := range slice { for _, dataItem := range slice {
d := common.FormatData(dataItem) d := common.FormatData(dataItem)
ret = append(ret, d...) ret = append(ret, d...)

@ -27,7 +27,7 @@ func TestMisc(t *testing.T) {
c := []byte{1, 2, 3, 4} c := []byte{1, 2, 3, 4}
z := BitTest(a, 1) z := BitTest(a, 1)
if z != true { if !z {
t.Error("Expected true got", z) t.Error("Expected true got", z)
} }
@ -79,11 +79,11 @@ func TestBigCopy(t *testing.T) {
z := BigToBytes(c, 16) z := BigToBytes(c, 16)
zbytes := []byte{232, 212, 165, 16, 0} zbytes := []byte{232, 212, 165, 16, 0}
if bytes.Compare(y, ybytes) != 0 { if !bytes.Equal(y, ybytes) {
t.Error("Got", ybytes) t.Error("Got", ybytes)
} }
if bytes.Compare(z, zbytes) != 0 { if !bytes.Equal(z, zbytes) {
t.Error("Got", zbytes) t.Error("Got", zbytes)
} }
} }

@ -181,7 +181,7 @@ func TestFromHex(t *testing.T) {
input := "0x01" input := "0x01"
expected := []byte{1} expected := []byte{1}
result := FromHex(input) result := FromHex(input)
if bytes.Compare(expected, result) != 0 { if !bytes.Equal(expected, result) {
t.Errorf("Expected % x got % x", expected, result) t.Errorf("Expected % x got % x", expected, result)
} }
} }
@ -190,7 +190,7 @@ func TestFromHexOddLength(t *testing.T) {
input := "0x1" input := "0x1"
expected := []byte{1} expected := []byte{1}
result := FromHex(input) result := FromHex(input)
if bytes.Compare(expected, result) != 0 { if !bytes.Equal(expected, result) {
t.Errorf("Expected % x got % x", expected, result) t.Errorf("Expected % x got % x", expected, result)
} }
} }

@ -32,7 +32,7 @@ import (
) )
var ( var (
versionRegexp = regexp.MustCompile("[0-9]+\\.[0-9]+\\.[0-9]+") versionRegexp = regexp.MustCompile(`[0-9]+\.[0-9]+\.[0-9]+`)
solcParams = []string{ solcParams = []string{
"--combined-json", "bin,abi,userdoc,devdoc", "--combined-json", "bin,abi,userdoc,devdoc",
"--add-std", // include standard lib contracts "--add-std", // include standard lib contracts

@ -27,7 +27,7 @@ import (
// the unnecessary precision off from the formatted textual representation. // the unnecessary precision off from the formatted textual representation.
type PrettyDuration time.Duration type PrettyDuration time.Duration
var prettyDurationRe = regexp.MustCompile("\\.[0-9]+") var prettyDurationRe = regexp.MustCompile(`\.[0-9]+`)
// String implements the Stringer interface, allowing pretty printing of duration // String implements the Stringer interface, allowing pretty printing of duration
// values rounded to three decimals. // values rounded to three decimals.

@ -76,9 +76,9 @@ func compressChunk(dat []byte) (ret []byte, n int) {
} }
return []byte{token, byte(j + 2)}, j return []byte{token, byte(j + 2)}, j
case len(dat) >= 32: case len(dat) >= 32:
if dat[0] == empty[0] && bytes.Compare(dat[:32], empty) == 0 { if dat[0] == empty[0] && bytes.Equal(dat[:32], empty) {
return []byte{token, emptyShaToken}, 32 return []byte{token, emptyShaToken}, 32
} else if dat[0] == emptyList[0] && bytes.Compare(dat[:32], emptyList) == 0 { } else if dat[0] == emptyList[0] && bytes.Equal(dat[:32], emptyList) {
return []byte{token, emptyListShaToken}, 32 return []byte{token, emptyListShaToken}, 32
} }
fallthrough fallthrough

@ -36,9 +36,9 @@ import (
) )
var ( var (
passwordRegexp = regexp.MustCompile("personal.[nus]") passwordRegexp = regexp.MustCompile(`personal.[nus]`)
onlyWhitespace = regexp.MustCompile("^\\s*$") onlyWhitespace = regexp.MustCompile(`^\s*$`)
exit = regexp.MustCompile("^\\s*exit\\s*;*\\s*$") exit = regexp.MustCompile(`^\s*exit\s*;*\s*$`)
) )
// HistoryFile is the file within the data directory to store input scrollback. // HistoryFile is the file within the data directory to store input scrollback.
@ -275,10 +275,7 @@ func (c *Console) Evaluate(statement string) error {
fmt.Fprintf(c.printer, "[native] error: %v\n", r) fmt.Fprintf(c.printer, "[native] error: %v\n", r)
} }
}() }()
if err := c.jsre.Evaluate(statement, c.printer); err != nil { return c.jsre.Evaluate(statement, c.printer)
return err
}
return nil
} }
// Interactive starts an interactive user session, where input is propted from // Interactive starts an interactive user session, where input is propted from

@ -402,10 +402,7 @@ func (bc *BlockChain) ResetWithGenesisBlock(genesis *types.Block) {
// Export writes the active chain to the given writer. // Export writes the active chain to the given writer.
func (self *BlockChain) Export(w io.Writer) error { func (self *BlockChain) Export(w io.Writer) error {
if err := self.ExportN(w, uint64(0), self.currentBlock.NumberU64()); err != nil { return self.ExportN(w, uint64(0), self.currentBlock.NumberU64())
return err
}
return nil
} }
// ExportN writes a subset of the active chain to the given writer. // ExportN writes a subset of the active chain to the given writer.

@ -45,11 +45,11 @@ func ValidateDAOHeaderExtraData(config *params.ChainConfig, header *types.Header
} }
// Depending whether we support or oppose the fork, validate the extra-data contents // Depending whether we support or oppose the fork, validate the extra-data contents
if config.DAOForkSupport { if config.DAOForkSupport {
if bytes.Compare(header.Extra, params.DAOForkBlockExtra) != 0 { if !bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
return ValidationError("DAO pro-fork bad block extra-data: 0x%x", header.Extra) return ValidationError("DAO pro-fork bad block extra-data: 0x%x", header.Extra)
} }
} else { } else {
if bytes.Compare(header.Extra, params.DAOForkBlockExtra) == 0 { if bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
return ValidationError("DAO no-fork bad block extra-data: 0x%x", header.Extra) return ValidationError("DAO no-fork bad block extra-data: 0x%x", header.Extra)
} }
} }

@ -430,7 +430,7 @@ func TestReceiptStorage(t *testing.T) {
rlpHave, _ := rlp.EncodeToBytes(r) rlpHave, _ := rlp.EncodeToBytes(r)
rlpWant, _ := rlp.EncodeToBytes(receipt) rlpWant, _ := rlp.EncodeToBytes(receipt)
if bytes.Compare(rlpHave, rlpWant) != 0 { if !bytes.Equal(rlpHave, rlpWant) {
t.Fatalf("receipt #%d [%x]: receipt mismatch: have %v, want %v", i, receipt.TxHash, r, receipt) t.Fatalf("receipt #%d [%x]: receipt mismatch: have %v, want %v", i, receipt.TxHash, r, receipt)
} }
} }
@ -488,7 +488,7 @@ func TestBlockReceiptStorage(t *testing.T) {
rlpHave, _ := rlp.EncodeToBytes(rs[i]) rlpHave, _ := rlp.EncodeToBytes(rs[i])
rlpWant, _ := rlp.EncodeToBytes(receipts[i]) rlpWant, _ := rlp.EncodeToBytes(receipts[i])
if bytes.Compare(rlpHave, rlpWant) != 0 { if !bytes.Equal(rlpHave, rlpWant) {
t.Fatalf("receipt #%d: receipt mismatch: have %v, want %v", i, rs[i], receipts[i]) t.Fatalf("receipt #%d: receipt mismatch: have %v, want %v", i, rs[i], receipts[i])
} }
} }

@ -123,7 +123,7 @@ func (it *NodeIterator) step() error {
if !it.dataIt.Next() { if !it.dataIt.Next() {
it.dataIt = nil it.dataIt = nil
} }
if bytes.Compare(account.CodeHash, emptyCodeHash) != 0 { if !bytes.Equal(account.CodeHash, emptyCodeHash) {
it.codeHash = common.BytesToHash(account.CodeHash) it.codeHash = common.BytesToHash(account.CodeHash)
it.code, err = it.state.db.Get(account.CodeHash) it.code, err = it.state.db.Get(account.CodeHash)
if err != nil { if err != nil {

@ -84,7 +84,7 @@ func checkStateAccounts(t *testing.T, db ethdb.Database, root common.Hash, accou
if nonce := state.GetNonce(acc.address); nonce != acc.nonce { if nonce := state.GetNonce(acc.address); nonce != acc.nonce {
t.Errorf("account %d: nonce mismatch: have %v, want %v", i, nonce, acc.nonce) t.Errorf("account %d: nonce mismatch: have %v, want %v", i, nonce, acc.nonce)
} }
if code := state.GetCode(acc.address); bytes.Compare(code, acc.code) != 0 { if code := state.GetCode(acc.address); !bytes.Equal(code, acc.code) {
t.Errorf("account %d: code mismatch: have %x, want %x", i, code, acc.code) t.Errorf("account %d: code mismatch: have %x, want %x", i, code, acc.code)
} }
} }
@ -294,7 +294,7 @@ func TestIncompleteStateSync(t *testing.T) {
// Skim through the accounts and make sure the root hash is not a code node // Skim through the accounts and make sure the root hash is not a code node
codeHash := false codeHash := false
for _, acc := range srcAccounts { for _, acc := range srcAccounts {
if bytes.Compare(root.Bytes(), crypto.Sha3(acc.code)) == 0 { if root == crypto.Keccak256Hash(acc.code) {
codeHash = true codeHash = true
break break
} }

@ -97,14 +97,8 @@ func CreateBloom(receipts Receipts) Bloom {
func LogsBloom(logs []*Log) *big.Int { func LogsBloom(logs []*Log) *big.Int {
bin := new(big.Int) bin := new(big.Int)
for _, log := range logs { for _, log := range logs {
data := make([]common.Hash, len(log.Topics))
bin.Or(bin, bloom9(log.Address.Bytes())) bin.Or(bin, bloom9(log.Address.Bytes()))
for _, b := range log.Topics {
for i, topic := range log.Topics {
data[i] = topic
}
for _, b := range data {
bin.Or(bin, bloom9(b[:])) bin.Or(bin, bloom9(b[:]))
} }
} }

@ -217,7 +217,7 @@ func TestValidateSignatureValues(t *testing.T) {
func checkhash(t *testing.T, name string, f func([]byte) []byte, msg, exp []byte) { func checkhash(t *testing.T, name string, f func([]byte) []byte, msg, exp []byte) {
sum := f(msg) sum := f(msg)
if bytes.Compare(exp, sum) != 0 { if !bytes.Equal(exp, sum) {
t.Fatalf("hash %s mismatch: want: %x have: %x", name, exp, sum) t.Fatalf("hash %s mismatch: want: %x have: %x", name, exp, sum)
} }
} }

@ -291,9 +291,8 @@ func Encrypt(rand io.Reader, pub *PublicKey, m, s1, s2 []byte) (ct []byte, err e
// Decrypt decrypts an ECIES ciphertext. // Decrypt decrypts an ECIES ciphertext.
func (prv *PrivateKey) Decrypt(rand io.Reader, c, s1, s2 []byte) (m []byte, err error) { func (prv *PrivateKey) Decrypt(rand io.Reader, c, s1, s2 []byte) (m []byte, err error) {
if c == nil || len(c) == 0 { if len(c) == 0 {
err = ErrInvalidMessage return nil, ErrInvalidMessage
return
} }
params := prv.PublicKey.Params params := prv.PublicKey.Params
if params == nil { if params == nil {

@ -607,38 +607,16 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
} }
case msg.Code == NewBlockHashesMsg: case msg.Code == NewBlockHashesMsg:
// Retrieve and deserialize the remote new block hashes notification var announces newBlockHashesData
type announce struct { if err := msg.Decode(&announces); err != nil {
Hash common.Hash
Number uint64
}
var announces = []announce{}
if p.version < eth62 {
// We're running the old protocol, make block number unknown (0)
var hashes []common.Hash
if err := msg.Decode(&hashes); err != nil {
return errResp(ErrDecode, "%v: %v", msg, err) return errResp(ErrDecode, "%v: %v", msg, err)
} }
for _, hash := range hashes {
announces = append(announces, announce{hash, 0})
}
} else {
// Otherwise extract both block hash and number
var request newBlockHashesData
if err := msg.Decode(&request); err != nil {
return errResp(ErrDecode, "%v: %v", msg, err)
}
for _, block := range request {
announces = append(announces, announce{block.Hash, block.Number})
}
}
// Mark the hashes as present at the remote node // Mark the hashes as present at the remote node
for _, block := range announces { for _, block := range announces {
p.MarkBlock(block.Hash) p.MarkBlock(block.Hash)
} }
// Schedule all the unknown hashes for retrieval // Schedule all the unknown hashes for retrieval
unknown := make([]announce, 0, len(announces)) unknown := make(newBlockHashesData, 0, len(announces))
for _, block := range announces { for _, block := range announces {
if !pm.blockchain.HasBlock(block.Hash) { if !pm.blockchain.HasBlock(block.Hash) {
unknown = append(unknown, block) unknown = append(unknown, block)

@ -388,10 +388,7 @@ func (s *Service) reportLatency(out *json.Encoder) error {
"latency": strconv.Itoa(int((time.Since(start) / time.Duration(2)).Nanoseconds() / 1000000)), "latency": strconv.Itoa(int((time.Since(start) / time.Duration(2)).Nanoseconds() / 1000000)),
}}, }},
} }
if err := out.Encode(latency); err != nil { return out.Encode(latency)
return err
}
return nil
} }
// blockStats is the information to report about individual blocks. // blockStats is the information to report about individual blocks.
@ -440,10 +437,7 @@ func (s *Service) reportBlock(out *json.Encoder, block *types.Block) error {
report := map[string][]interface{}{ report := map[string][]interface{}{
"emit": {"block", stats}, "emit": {"block", stats},
} }
if err := out.Encode(report); err != nil { return out.Encode(report)
return err
}
return nil
} }
// assembleBlockStats retrieves any required metadata to report a single block // assembleBlockStats retrieves any required metadata to report a single block
@ -497,9 +491,7 @@ func (s *Service) reportHistory(out *json.Encoder, list []uint64) error {
indexes := make([]uint64, 0, historyUpdateRange) indexes := make([]uint64, 0, historyUpdateRange)
if len(list) > 0 { if len(list) > 0 {
// Specific indexes requested, send them back in particular // Specific indexes requested, send them back in particular
for _, idx := range list { indexes = append(indexes, list...)
indexes = append(indexes, idx)
}
} else { } else {
// No indexes requested, send back the top ones // No indexes requested, send back the top ones
var head *types.Header var head *types.Header
@ -533,10 +525,7 @@ func (s *Service) reportHistory(out *json.Encoder, list []uint64) error {
report := map[string][]interface{}{ report := map[string][]interface{}{
"emit": {"history", stats}, "emit": {"history", stats},
} }
if err := out.Encode(report); err != nil { return out.Encode(report)
return err
}
return nil
} }
// pendStats is the information to report about pending transactions. // pendStats is the information to report about pending transactions.
@ -564,10 +553,7 @@ func (s *Service) reportPending(out *json.Encoder) error {
report := map[string][]interface{}{ report := map[string][]interface{}{
"emit": {"pending", stats}, "emit": {"pending", stats},
} }
if err := out.Encode(report); err != nil { return out.Encode(report)
return err
}
return nil
} }
// blockStats is the information to report about the local node. // blockStats is the information to report about the local node.
@ -618,8 +604,5 @@ func (s *Service) reportStats(out *json.Encoder) error {
report := map[string][]interface{}{ report := map[string][]interface{}{
"emit": {"stats", stats}, "emit": {"stats", stats},
} }
if err := out.Encode(report); err != nil { return out.Encode(report)
return err
}
return nil
} }

@ -449,7 +449,7 @@ func (self *worker) commitNewWork() {
// Depending whether we support or oppose the fork, override differently // Depending whether we support or oppose the fork, override differently
if self.config.DAOForkSupport { if self.config.DAOForkSupport {
header.Extra = common.CopyBytes(params.DAOForkBlockExtra) header.Extra = common.CopyBytes(params.DAOForkBlockExtra)
} else if bytes.Compare(header.Extra, params.DAOForkBlockExtra) == 0 { } else if bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data
} }
} }

@ -114,17 +114,12 @@ type BoundContract struct {
// DeployContract deploys a contract onto the Ethereum blockchain and binds the // DeployContract deploys a contract onto the Ethereum blockchain and binds the
// deployment address with a wrapper. // deployment address with a wrapper.
func DeployContract(opts *TransactOpts, abiJSON string, bytecode []byte, client *EthereumClient, args *Interfaces) (contract *BoundContract, _ error) { func DeployContract(opts *TransactOpts, abiJSON string, bytecode []byte, client *EthereumClient, args *Interfaces) (contract *BoundContract, _ error) {
// Convert all the deployment parameters to Go types
params := make([]interface{}, len(args.objects))
for i, obj := range args.objects {
params[i] = obj
}
// Deploy the contract to the network // Deploy the contract to the network
parsed, err := abi.JSON(strings.NewReader(abiJSON)) parsed, err := abi.JSON(strings.NewReader(abiJSON))
if err != nil { if err != nil {
return nil, err return nil, err
} }
addr, tx, bound, err := bind.DeployContract(&opts.opts, parsed, bytecode, client.client, params...) addr, tx, bound, err := bind.DeployContract(&opts.opts, parsed, bytecode, client.client, args.objects...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -159,32 +154,18 @@ func (c *BoundContract) GetDeployer() *Transaction {
// Call invokes the (constant) contract method with params as input values and // Call invokes the (constant) contract method with params as input values and
// sets the output to result. // sets the output to result.
func (c *BoundContract) Call(opts *CallOpts, out *Interfaces, method string, args *Interfaces) error { func (c *BoundContract) Call(opts *CallOpts, out *Interfaces, method string, args *Interfaces) error {
// Convert all the input and output parameters to Go types
params := make([]interface{}, len(args.objects))
for i, obj := range args.objects {
params[i] = obj
}
results := make([]interface{}, len(out.objects)) results := make([]interface{}, len(out.objects))
for i, obj := range out.objects { copy(results, out.objects)
results[i] = obj if err := c.contract.Call(&opts.opts, &results, method, args.objects...); err != nil {
}
// Execute the call to the contract and wrap any results
if err := c.contract.Call(&opts.opts, &results, method, params...); err != nil {
return err return err
} }
for i, res := range results { copy(out.objects, results)
out.objects[i] = res
}
return nil return nil
} }
// Transact invokes the (paid) contract method with params as input values. // Transact invokes the (paid) contract method with params as input values.
func (c *BoundContract) Transact(opts *TransactOpts, method string, args *Interfaces) (tx *Transaction, _ error) { func (c *BoundContract) Transact(opts *TransactOpts, method string, args *Interfaces) (tx *Transaction, _ error) {
params := make([]interface{}, len(args.objects)) rawTx, err := c.contract.Transact(&opts.opts, method, args.objects)
for i, obj := range args.objects {
params[i] = obj
}
rawTx, err := c.contract.Transact(&opts.opts, method, params)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -137,7 +137,7 @@ func TestNodeKeyPersistency(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("failed to read previously persisted node key: %v", err) t.Fatalf("failed to read previously persisted node key: %v", err)
} }
if bytes.Compare(blob1, blob2) != 0 { if !bytes.Equal(blob1, blob2) {
t.Fatalf("persisted node key mismatch: have %x, want %x", blob2, blob1) t.Fatalf("persisted node key mismatch: have %x, want %x", blob2, blob1)
} }

@ -218,7 +218,7 @@ func TestServiceRestarts(t *testing.T) {
} }
defer stack.Stop() defer stack.Stop()
if running != true || started != 1 { if running || started != 1 {
t.Fatalf("running/started mismatch: have %v/%d, want true/1", running, started) t.Fatalf("running/started mismatch: have %v/%d, want true/1", running, started)
} }
// Restart the stack a few times and check successful service restarts // Restart the stack a few times and check successful service restarts
@ -227,7 +227,7 @@ func TestServiceRestarts(t *testing.T) {
t.Fatalf("iter %d: failed to restart stack: %v", i, err) t.Fatalf("iter %d: failed to restart stack: %v", i, err)
} }
} }
if running != true || started != 4 { if !running || started != 4 {
t.Fatalf("running/started mismatch: have %v/%d, want true/4", running, started) t.Fatalf("running/started mismatch: have %v/%d, want true/4", running, started)
} }
} }

@ -258,7 +258,7 @@ func (db *nodeDB) expireNodes() error {
continue continue
} }
// Skip the node if not expired yet (and not self) // Skip the node if not expired yet (and not self)
if bytes.Compare(id[:], db.self[:]) != 0 { if !bytes.Equal(id[:], db.self[:]) {
if seen := db.lastPong(id); seen.After(threshold) { if seen := db.lastPong(id); seen.After(threshold) {
continue continue
} }

@ -224,11 +224,8 @@ func (n NodeID) GoString() string {
// HexID converts a hex string to a NodeID. // HexID converts a hex string to a NodeID.
// The string may be prefixed with 0x. // The string may be prefixed with 0x.
func HexID(in string) (NodeID, error) { func HexID(in string) (NodeID, error) {
if strings.HasPrefix(in, "0x") {
in = in[2:]
}
var id NodeID var id NodeID
b, err := hex.DecodeString(in) b, err := hex.DecodeString(strings.TrimPrefix(in, "0x"))
if err != nil { if err != nil {
return id, err return id, err
} else if len(b) != len(id) { } else if len(b) != len(id) {

@ -269,7 +269,7 @@ func (db *nodeDB) expireNodes() error {
continue continue
} }
// Skip the node if not expired yet (and not self) // Skip the node if not expired yet (and not self)
if bytes.Compare(id[:], db.self[:]) != 0 { if !bytes.Equal(id[:], db.self[:]) {
if seen := db.lastPong(id); seen.After(threshold) { if seen := db.lastPong(id); seen.After(threshold) {
continue continue
} }

@ -262,11 +262,8 @@ func (n NodeID) GoString() string {
// HexID converts a hex string to a NodeID. // HexID converts a hex string to a NodeID.
// The string may be prefixed with 0x. // The string may be prefixed with 0x.
func HexID(in string) (NodeID, error) { func HexID(in string) (NodeID, error) {
if strings.HasPrefix(in, "0x") {
in = in[2:]
}
var id NodeID var id NodeID
b, err := hex.DecodeString(in) b, err := hex.DecodeString(strings.TrimPrefix(in, "0x"))
if err != nil { if err != nil {
return id, err return id, err
} else if len(b) != len(id) { } else if len(b) != len(id) {

@ -354,7 +354,7 @@ func (s *DbStore) Get(key Key) (chunk *Chunk, err error) {
hasher := s.hashfunc() hasher := s.hashfunc()
hasher.Write(data) hasher.Write(data)
hash := hasher.Sum(nil) hash := hasher.Sum(nil)
if bytes.Compare(hash, key) != 0 { if !bytes.Equal(hash, key) {
s.db.Delete(getDataKey(index.Idx)) s.db.Delete(getDataKey(index.Idx))
err = fmt.Errorf("invalid chunk. hash=%x, key=%v", hash, key[:]) err = fmt.Errorf("invalid chunk. hash=%x, key=%v", hash, key[:])
return return

@ -41,7 +41,7 @@ func (x Key) Size() uint {
} }
func (x Key) isEqual(y Key) bool { func (x Key) isEqual(y Key) bool {
return bytes.Compare(x, y) == 0 return bytes.Equal(x, y)
} }
func (h Key) bits(i, j uint) uint { func (h Key) bits(i, j uint) uint {

@ -552,9 +552,7 @@ func LoadBlockTests(file string) (map[string]*BlockTest, error) {
// Nothing to see here, please move along... // Nothing to see here, please move along...
func prepInt(base int, s string) string { func prepInt(base int, s string) string {
if base == 16 { if base == 16 {
if strings.HasPrefix(s, "0x") { s = strings.TrimPrefix(s, "0x")
s = s[2:]
}
if len(s) == 0 { if len(s) == 0 {
s = "00" s = "00"
} }

@ -87,11 +87,7 @@ func readJsonHttp(uri string, value interface{}) error {
} }
defer resp.Body.Close() defer resp.Body.Close()
err = readJson(resp.Body, value) return readJson(resp.Body, value)
if err != nil {
return err
}
return nil
} }
func readJsonFile(fn string, value interface{}) error { func readJsonFile(fn string, value interface{}) error {

@ -159,7 +159,7 @@ func runStateTest(chainConfig *params.ChainConfig, test VmTest) error {
} else { } else {
rexp = common.FromHex(test.Out) rexp = common.FromHex(test.Out)
} }
if bytes.Compare(rexp, ret) != 0 { if !bytes.Equal(rexp, ret) {
return fmt.Errorf("return failed. Expected %x, got %x\n", rexp, ret) return fmt.Errorf("return failed. Expected %x, got %x\n", rexp, ret)
} }

@ -172,7 +172,7 @@ func runVmTest(test VmTest) error {
// Compare expected and actual return // Compare expected and actual return
rexp := common.FromHex(test.Out) rexp := common.FromHex(test.Out)
if bytes.Compare(rexp, ret) != 0 { if !bytes.Equal(rexp, ret) {
return fmt.Errorf("return failed. Expected %x, got %x\n", rexp, ret) return fmt.Errorf("return failed. Expected %x, got %x\n", rexp, ret)
} }

@ -67,7 +67,7 @@ func checkTrieContents(t *testing.T, db Database, root []byte, content map[strin
t.Fatalf("inconsistent trie at %x: %v", root, err) t.Fatalf("inconsistent trie at %x: %v", root, err)
} }
for key, val := range content { for key, val := range content {
if have := trie.Get([]byte(key)); bytes.Compare(have, val) != 0 { if have := trie.Get([]byte(key)); !bytes.Equal(have, val) {
t.Errorf("entry %x: content mismatch: have %x, want %x", key, have, val) t.Errorf("entry %x: content mismatch: have %x, want %x", key, have, val)
} }
} }

@ -178,14 +178,10 @@ func (api *PublicWhisperAPI) NewFilter(args WhisperFilterArgs) (uint32, error) {
Messages: make(map[common.Hash]*whisperv5.ReceivedMessage), Messages: make(map[common.Hash]*whisperv5.ReceivedMessage),
AcceptP2P: args.AcceptP2P, AcceptP2P: args.AcceptP2P,
} }
if len(filter.KeySym) > 0 { if len(filter.KeySym) > 0 {
filter.SymKeyHash = crypto.Keccak256Hash(filter.KeySym) filter.SymKeyHash = crypto.Keccak256Hash(filter.KeySym)
} }
filter.Topics = append(filter.Topics, args.Topics...)
for _, t := range args.Topics {
filter.Topics = append(filter.Topics, t)
}
if len(args.Topics) == 0 { if len(args.Topics) == 0 {
info := "NewFilter: at least one topic must be specified" info := "NewFilter: at least one topic must be specified"

@ -253,7 +253,7 @@ func TestUnmarshalPostArgs(t *testing.T) {
if a.FilterID != 64 { if a.FilterID != 64 {
t.Fatalf("wrong FilterID: %d.", a.FilterID) t.Fatalf("wrong FilterID: %d.", a.FilterID)
} }
if bytes.Compare(a.PeerID[:], a.Topic[:]) != 0 { if !bytes.Equal(a.PeerID[:], a.Topic[:]) {
t.Fatalf("wrong PeerID: %x.", a.PeerID) t.Fatalf("wrong PeerID: %x.", a.PeerID)
} }
} }

@ -40,10 +40,10 @@ func TestEnvelopeOpen(t *testing.T) {
if opened.Flags != message.Flags { if opened.Flags != message.Flags {
t.Fatalf("flags mismatch: have %d, want %d", opened.Flags, message.Flags) t.Fatalf("flags mismatch: have %d, want %d", opened.Flags, message.Flags)
} }
if bytes.Compare(opened.Signature, message.Signature) != 0 { if !bytes.Equal(opened.Signature, message.Signature) {
t.Fatalf("signature mismatch: have 0x%x, want 0x%x", opened.Signature, message.Signature) t.Fatalf("signature mismatch: have 0x%x, want 0x%x", opened.Signature, message.Signature)
} }
if bytes.Compare(opened.Payload, message.Payload) != 0 { if !bytes.Equal(opened.Payload, message.Payload) {
t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, message.Payload) t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, message.Payload)
} }
if opened.Sent.Unix() != message.Sent.Unix() { if opened.Sent.Unix() != message.Sent.Unix() {
@ -71,7 +71,7 @@ func TestEnvelopeAnonymousOpenUntargeted(t *testing.T) {
if opened.To != nil { if opened.To != nil {
t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To) t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To)
} }
if bytes.Compare(opened.Payload, payload) != 0 { if !bytes.Equal(opened.Payload, payload) {
t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload) t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload)
} }
} }
@ -96,7 +96,7 @@ func TestEnvelopeAnonymousOpenTargeted(t *testing.T) {
if opened.To != nil { if opened.To != nil {
t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To) t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To)
} }
if bytes.Compare(opened.Payload, payload) == 0 { if bytes.Equal(opened.Payload, payload) {
t.Fatalf("payload match, should have been encrypted: 0x%x", opened.Payload) t.Fatalf("payload match, should have been encrypted: 0x%x", opened.Payload)
} }
} }
@ -127,7 +127,7 @@ func TestEnvelopeIdentifiedOpenUntargeted(t *testing.T) {
if opened.To != nil { if opened.To != nil {
t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To) t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To)
} }
if bytes.Compare(opened.Payload, payload) != 0 { if !bytes.Equal(opened.Payload, payload) {
t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload) t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload)
} }
} }
@ -152,7 +152,7 @@ func TestEnvelopeIdentifiedOpenTargeted(t *testing.T) {
if opened.To != nil { if opened.To != nil {
t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To) t.Fatalf("recipient mismatch: have 0x%x, want nil", opened.To)
} }
if bytes.Compare(opened.Payload, payload) != 0 { if !bytes.Equal(opened.Payload, payload) {
t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload) t.Fatalf("payload mismatch: have 0x%x, want 0x%x", opened.Payload, payload)
} }
} }

@ -120,10 +120,7 @@ func (self filterer) Compare(f filter.Filter) bool {
break break
} }
} }
if !self.matcher.Matches(topics) { return self.matcher.Matches(topics)
return false
}
return true
} }
// Trigger is called when a filter successfully matches an inbound message. // Trigger is called when a filter successfully matches an inbound message.

@ -91,7 +91,7 @@ func TestFilterTopicsCreation(t *testing.T) {
continue continue
} }
for k := 0; k < len(condition); k++ { for k := 0; k < len(condition); k++ {
if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 { if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) {
t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k]) t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k])
} }
} }
@ -115,7 +115,7 @@ func TestFilterTopicsCreation(t *testing.T) {
continue continue
} }
for k := 0; k < len(condition); k++ { for k := 0; k < len(condition); k++ {
if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 { if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) {
t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k]) t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k])
} }
} }
@ -135,7 +135,7 @@ func TestFilterTopicsCreation(t *testing.T) {
continue continue
} }
for k := 0; k < len(condition); k++ { for k := 0; k < len(condition); k++ {
if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 { if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) {
t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k]) t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k])
} }
} }
@ -156,7 +156,7 @@ func TestFilterTopicsCreation(t *testing.T) {
continue continue
} }
for k := 0; k < len(condition); k++ { for k := 0; k < len(condition); k++ {
if bytes.Compare(condition[k][:], tt.filter[j][k][:]) != 0 { if !bytes.Equal(condition[k][:], tt.filter[j][k][:]) {
t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k]) t.Errorf("test %d, condition %d, segment %d: filter mismatch: have 0x%x, want 0x%x", i, j, k, condition[k], tt.filter[j][k])
} }
} }

@ -40,7 +40,7 @@ func TestMessageSimpleWrap(t *testing.T) {
if len(msg.Signature) != 0 { if len(msg.Signature) != 0 {
t.Fatalf("signature found for simple wrapping: 0x%x", msg.Signature) t.Fatalf("signature found for simple wrapping: 0x%x", msg.Signature)
} }
if bytes.Compare(msg.Payload, payload) != 0 { if !bytes.Equal(msg.Payload, payload) {
t.Fatalf("payload mismatch after wrapping: have 0x%x, want 0x%x", msg.Payload, payload) t.Fatalf("payload mismatch after wrapping: have 0x%x, want 0x%x", msg.Payload, payload)
} }
if msg.TTL/time.Second != DefaultTTL/time.Second { if msg.TTL/time.Second != DefaultTTL/time.Second {
@ -65,7 +65,7 @@ func TestMessageCleartextSignRecover(t *testing.T) {
if msg.Flags&signatureFlag != signatureFlag { if msg.Flags&signatureFlag != signatureFlag {
t.Fatalf("signature flag mismatch: have %d, want %d", msg.Flags&signatureFlag, signatureFlag) t.Fatalf("signature flag mismatch: have %d, want %d", msg.Flags&signatureFlag, signatureFlag)
} }
if bytes.Compare(msg.Payload, payload) != 0 { if !bytes.Equal(msg.Payload, payload) {
t.Fatalf("payload mismatch after signing: have 0x%x, want 0x%x", msg.Payload, payload) t.Fatalf("payload mismatch after signing: have 0x%x, want 0x%x", msg.Payload, payload)
} }

@ -33,13 +33,13 @@ func TestTopicCreation(t *testing.T) {
// Create the topics individually // Create the topics individually
for i, tt := range topicCreationTests { for i, tt := range topicCreationTests {
topic := NewTopic(tt.data) topic := NewTopic(tt.data)
if bytes.Compare(topic[:], tt.hash[:]) != 0 { if !bytes.Equal(topic[:], tt.hash[:]) {
t.Errorf("binary test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash) t.Errorf("binary test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash)
} }
} }
for i, tt := range topicCreationTests { for i, tt := range topicCreationTests {
topic := NewTopicFromString(string(tt.data)) topic := NewTopicFromString(string(tt.data))
if bytes.Compare(topic[:], tt.hash[:]) != 0 { if !bytes.Equal(topic[:], tt.hash[:]) {
t.Errorf("textual test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash) t.Errorf("textual test %d: hash mismatch: have %v, want %v.", i, topic, tt.hash)
} }
} }
@ -55,13 +55,13 @@ func TestTopicCreation(t *testing.T) {
topics := NewTopics(binaryData...) topics := NewTopics(binaryData...)
for i, tt := range topicCreationTests { for i, tt := range topicCreationTests {
if bytes.Compare(topics[i][:], tt.hash[:]) != 0 { if !bytes.Equal(topics[i][:], tt.hash[:]) {
t.Errorf("binary batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash) t.Errorf("binary batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash)
} }
} }
topics = NewTopicsFromStrings(textualData...) topics = NewTopicsFromStrings(textualData...)
for i, tt := range topicCreationTests { for i, tt := range topicCreationTests {
if bytes.Compare(topics[i][:], tt.hash[:]) != 0 { if !bytes.Equal(topics[i][:], tt.hash[:]) {
t.Errorf("textual batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash) t.Errorf("textual batch test %d: hash mismatch: have %v, want %v.", i, topics[i], tt.hash)
} }
} }

@ -104,10 +104,10 @@ func singleMessageTest(t *testing.T, symmetric bool) {
} }
padsz := len(decrypted.Padding) padsz := len(decrypted.Padding)
if bytes.Compare(steg[:padsz], decrypted.Padding) != 0 { if !bytes.Equal(steg[:padsz], decrypted.Padding) {
t.Fatalf("failed with seed %d: compare padding.", seed) t.Fatalf("failed with seed %d: compare padding.", seed)
} }
if bytes.Compare(text, decrypted.Payload) != 0 { if !bytes.Equal(text, decrypted.Payload) {
t.Fatalf("failed with seed %d: compare payload.", seed) t.Fatalf("failed with seed %d: compare payload.", seed)
} }
if !isMessageSigned(decrypted.Raw[0]) { if !isMessageSigned(decrypted.Raw[0]) {
@ -256,10 +256,10 @@ func singleEnvelopeOpenTest(t *testing.T, symmetric bool) {
} }
padsz := len(decrypted.Padding) padsz := len(decrypted.Padding)
if bytes.Compare(steg[:padsz], decrypted.Padding) != 0 { if !bytes.Equal(steg[:padsz], decrypted.Padding) {
t.Fatalf("failed with seed %d: compare padding.", seed) t.Fatalf("failed with seed %d: compare padding.", seed)
} }
if bytes.Compare(text, decrypted.Payload) != 0 { if !bytes.Equal(text, decrypted.Payload) {
t.Fatalf("failed with seed %d: compare payload.", seed) t.Fatalf("failed with seed %d: compare payload.", seed)
} }
if !isMessageSigned(decrypted.Raw[0]) { if !isMessageSigned(decrypted.Raw[0]) {

@ -207,7 +207,7 @@ func checkPropagation(t *testing.T) {
func validateMail(t *testing.T, index int, mail []*ReceivedMessage) bool { func validateMail(t *testing.T, index int, mail []*ReceivedMessage) bool {
var cnt int var cnt int
for _, m := range mail { for _, m := range mail {
if bytes.Compare(m.Payload, expectedMessage) == 0 { if bytes.Equal(m.Payload, expectedMessage) {
cnt++ cnt++
} }
} }

@ -239,7 +239,7 @@ func TestWhisperSymKeyManagement(t *testing.T) {
if k1 == nil { if k1 == nil {
t.Fatalf("first key does not exist.") t.Fatalf("first key does not exist.")
} }
if bytes.Compare(k1, randomKey) == 0 { if bytes.Equal(k1, randomKey) {
t.Fatalf("k1 == randomKey.") t.Fatalf("k1 == randomKey.")
} }
if k2 != nil { if k2 != nil {
@ -264,10 +264,10 @@ func TestWhisperSymKeyManagement(t *testing.T) {
if k2 == nil { if k2 == nil {
t.Fatalf("k2 does not exist.") t.Fatalf("k2 does not exist.")
} }
if bytes.Compare(k1, k2) == 0 { if bytes.Equal(k1, k2) {
t.Fatalf("k1 == k2.") t.Fatalf("k1 == k2.")
} }
if bytes.Compare(k1, randomKey) == 0 { if bytes.Equal(k1, randomKey) {
t.Fatalf("k1 == randomKey.") t.Fatalf("k1 == randomKey.")
} }
if len(k1) != aesKeyLength { if len(k1) != aesKeyLength {

Loading…
Cancel
Save