Skip to content

Commit a59dd39

Browse files
committed
core: fix tests
1 parent b5b83db commit a59dd39

5 files changed

Lines changed: 13 additions & 19 deletions

File tree

‎core/block_processor_test.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"math/big"
55
"testing"
66

7+
"github.com/ethereum/go-ethereum/common"
78
"github.com/ethereum/go-ethereum/ethdb"
89
"github.com/ethereum/go-ethereum/event"
910
"github.com/ethereum/go-ethereum/pow/ezp"
@@ -19,15 +20,15 @@ func proc() (*BlockProcessor, *ChainManager) {
1920

2021
func TestNumber(t *testing.T) {
2122
bp, chain := proc()
22-
block1 := chain.NewBlock(nil)
23+
block1 := chain.NewBlock(common.Address{})
2324
block1.Header().Number = big.NewInt(3)
2425

2526
err := bp.ValidateHeader(block1.Header(), chain.Genesis().Header())
2627
if err != BlockNumberErr {
2728
t.Errorf("expected block number error")
2829
}
2930

30-
block1 = chain.NewBlock(nil)
31+
block1 = chain.NewBlock(common.Address{})
3132
err = bp.ValidateHeader(block1.Header(), chain.Genesis().Header())
3233
if err == BlockNumberErr {
3334
t.Errorf("didn't expect block number error")

‎core/chain_manager_test.go‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package core
22

33
import (
4-
"bytes"
54
"fmt"
65
"math/big"
76
"os"
@@ -35,7 +34,7 @@ func testFork(t *testing.T, bman *BlockProcessor, i, N int, f func(td1, td2 *big
3534
// asert the bmans have the same block at i
3635
bi1 := bman.bc.GetBlockByNumber(uint64(i)).Hash()
3736
bi2 := bman2.bc.GetBlockByNumber(uint64(i)).Hash()
38-
if bytes.Compare(bi1, bi2) != 0 {
37+
if bi1 != bi2 {
3938
t.Fatal("chains do not have the same hash at height", i)
4039
}
4140

@@ -270,11 +269,11 @@ func TestChainInsertions(t *testing.T) {
270269
<-done
271270
}
272271

273-
if bytes.Equal(chain2[len(chain2)-1].Hash(), chainMan.CurrentBlock().Hash()) {
272+
if chain2[len(chain2)-1].Hash() != chainMan.CurrentBlock().Hash() {
274273
t.Error("chain2 is canonical and shouldn't be")
275274
}
276275

277-
if !bytes.Equal(chain1[len(chain1)-1].Hash(), chainMan.CurrentBlock().Hash()) {
276+
if chain1[len(chain1)-1].Hash() != chainMan.CurrentBlock().Hash() {
278277
t.Error("chain1 isn't canonical and should be")
279278
}
280279
}
@@ -320,7 +319,7 @@ func TestChainMultipleInsertions(t *testing.T) {
320319
<-done
321320
}
322321

323-
if !bytes.Equal(chains[longest][len(chains[longest])-1].Hash(), chainMan.CurrentBlock().Hash()) {
322+
if chains[longest][len(chains[longest])-1].Hash() != chainMan.CurrentBlock().Hash() {
324323
t.Error("Invalid canonical chain")
325324
}
326325
}

‎core/genesis.go‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88

99
"github.com/ethereum/go-ethereum/common"
1010
"github.com/ethereum/go-ethereum/core/types"
11-
"github.com/ethereum/go-ethereum/crypto"
1211
"github.com/ethereum/go-ethereum/state"
1312
)
1413

@@ -19,9 +18,6 @@ import (
1918
var ZeroHash256 = make([]byte, 32)
2019
var ZeroHash160 = make([]byte, 20)
2120
var ZeroHash512 = make([]byte, 64)
22-
var EmptyShaList = crypto.Sha3(common.Encode([]interface{}{}))
23-
var EmptyListRoot = crypto.Sha3(common.Encode(""))
24-
2521
var GenesisDiff = big.NewInt(131072)
2622
var GenesisGasLimit = big.NewInt(3141592)
2723

‎core/transaction_pool.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func NewTxPool(eventMux *event.TypeMux) *TxPool {
6363
func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
6464
// Validate sender
6565
if _, err := tx.From(); err != nil {
66-
return err
66+
return ErrInvalidSender
6767
}
6868
// Validate curve param
6969
v, _, _ := tx.Curve()

‎core/transaction_pool_test.go‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"crypto/ecdsa"
55
"testing"
66

7+
"github.com/ethereum/go-ethereum/common"
78
"github.com/ethereum/go-ethereum/core/types"
89
"github.com/ethereum/go-ethereum/crypto"
910
"github.com/ethereum/go-ethereum/ethdb"
10-
"github.com/ethereum/go-ethereum/common"
1111
"github.com/ethereum/go-ethereum/event"
1212
"github.com/ethereum/go-ethereum/state"
1313
)
@@ -21,11 +21,11 @@ func SQ() stateQuery {
2121
}
2222

2323
func (self stateQuery) GetAccount(addr []byte) *state.StateObject {
24-
return state.NewStateObject(addr, self.db)
24+
return state.NewStateObject(common.BytesToAddress(addr), self.db)
2525
}
2626

2727
func transaction() *types.Transaction {
28-
return types.NewTransactionMessage(make([]byte, 20), common.Big0, common.Big0, common.Big0, nil)
28+
return types.NewTransactionMessage(common.Address{}, common.Big0, common.Big0, common.Big0, nil)
2929
}
3030

3131
func setup() (*TxPool, *ecdsa.PrivateKey) {
@@ -88,10 +88,8 @@ func TestRemoveInvalid(t *testing.T) {
8888

8989
func TestInvalidSender(t *testing.T) {
9090
pool, _ := setup()
91-
tx := new(types.Transaction)
92-
tx.V = 28
93-
err := pool.ValidateTransaction(tx)
91+
err := pool.ValidateTransaction(new(types.Transaction))
9492
if err != ErrInvalidSender {
95-
t.Error("expected %v, got %v", ErrInvalidSender, err)
93+
t.Errorf("expected %v, got %v", ErrInvalidSender, err)
9694
}
9795
}

0 commit comments

Comments
 (0)