mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
all: use direct equality for Hash/Address instead of bytes.Equal on .Bytes()
This commit is contained in:
parent
b04df226fa
commit
2573deca3d
5 changed files with 6 additions and 7 deletions
|
|
@ -219,7 +219,7 @@ func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
|
||||||
// ABI and returns nil if none found.
|
// ABI and returns nil if none found.
|
||||||
func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
|
func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
|
||||||
for _, event := range abi.Events {
|
for _, event := range abi.Events {
|
||||||
if bytes.Equal(event.ID.Bytes(), topic.Bytes()) {
|
if event.ID == topic {
|
||||||
return &event, nil
|
return &event, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -110,7 +109,7 @@ func (basic *snapshotTestBasic) prepare(t *testing.T) (*BlockChain, []*types.Blo
|
||||||
// will be persisted atomically.
|
// will be persisted atomically.
|
||||||
chain.snaps.Cap(blocks[point-1].Root(), 0)
|
chain.snaps.Cap(blocks[point-1].Root(), 0)
|
||||||
diskRoot, blockRoot := chain.snaps.DiskRoot(), blocks[point-1].Root()
|
diskRoot, blockRoot := chain.snaps.DiskRoot(), blocks[point-1].Root()
|
||||||
if !bytes.Equal(diskRoot.Bytes(), blockRoot.Bytes()) {
|
if diskRoot != blockRoot {
|
||||||
t.Fatalf("Failed to flush disk layer change, want %x, got %x", blockRoot, diskRoot)
|
t.Fatalf("Failed to flush disk layer change, want %x, got %x", blockRoot, diskRoot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +148,7 @@ func (basic *snapshotTestBasic) verify(t *testing.T, chain *BlockChain, blocks [
|
||||||
if block == nil {
|
if block == nil {
|
||||||
t.Errorf("The corresponding block[%d] of snapshot disk layer is missing", basic.expSnapshotBottom)
|
t.Errorf("The corresponding block[%d] of snapshot disk layer is missing", basic.expSnapshotBottom)
|
||||||
} else if basic.scheme == rawdb.HashScheme {
|
} else if basic.scheme == rawdb.HashScheme {
|
||||||
if !bytes.Equal(chain.snaps.DiskRoot().Bytes(), block.Root().Bytes()) {
|
if chain.snaps.DiskRoot() != block.Root() {
|
||||||
t.Errorf("The snapshot disk layer root is incorrect, want %x, get %x", block.Root(), chain.snaps.DiskRoot())
|
t.Errorf("The snapshot disk layer root is incorrect, want %x, get %x", block.Root(), chain.snaps.DiskRoot())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -680,7 +680,7 @@ func TestCreate2Addresses(t *testing.T) {
|
||||||
fmt.Printf("Example %d\n* address `0x%x`\n* salt `0x%x`\n* init_code `0x%x`\n* gas (assuming no mem expansion): `%v`\n* result: `%s`\n\n", i,origin, salt, code, gas, address.String())
|
fmt.Printf("Example %d\n* address `0x%x`\n* salt `0x%x`\n* init_code `0x%x`\n* gas (assuming no mem expansion): `%v`\n* result: `%s`\n\n", i,origin, salt, code, gas, address.String())
|
||||||
*/
|
*/
|
||||||
expected := common.BytesToAddress(common.FromHex(tt.expected))
|
expected := common.BytesToAddress(common.FromHex(tt.expected))
|
||||||
if !bytes.Equal(expected.Bytes(), address.Bytes()) {
|
if expected != address {
|
||||||
t.Errorf("test %d: expected %s, got %s", i, expected.String(), address.String())
|
t.Errorf("test %d: expected %s, got %s", i, expected.String(), address.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ func (db *Database) ValidateTransaction(selector *string, tx *apitypes.SendTxArg
|
||||||
if !tx.To.ValidChecksum() {
|
if !tx.To.ValidChecksum() {
|
||||||
messages.Warn("Invalid checksum on recipient address")
|
messages.Warn("Invalid checksum on recipient address")
|
||||||
}
|
}
|
||||||
if bytes.Equal(tx.To.Address().Bytes(), common.Address{}.Bytes()) {
|
if tx.To.Address() == (common.Address{}) {
|
||||||
messages.Crit("Transaction recipient is the zero address")
|
messages.Crit("Transaction recipient is the zero address")
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ func (db *Database) loadJournal(diskRoot common.Hash) (layer, error) {
|
||||||
}
|
}
|
||||||
// The journal is not matched with persistent state, discard them.
|
// The journal is not matched with persistent state, discard them.
|
||||||
// It can happen that geth crashes without persisting the journal.
|
// It can happen that geth crashes without persisting the journal.
|
||||||
if !bytes.Equal(root.Bytes(), diskRoot.Bytes()) {
|
if root != diskRoot {
|
||||||
return nil, fmt.Errorf("%w want %x got %x", errUnmatchedJournal, root, diskRoot)
|
return nil, fmt.Errorf("%w want %x got %x", errUnmatchedJournal, root, diskRoot)
|
||||||
}
|
}
|
||||||
// Load the disk layer from the journal
|
// Load the disk layer from the journal
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue