tests: remove eth, node, accounts dependencies
Unlocking the accounts in the test doesn't help with anything.
This commit is contained in:
parent
8627680e24
commit
83877a0f9d
@ -123,7 +123,7 @@ func MakeSystemNode(keydir string, privkey string, test *tests.BlockTest) (*node
|
|||||||
}
|
}
|
||||||
// Initialize and register the Ethereum protocol
|
// Initialize and register the Ethereum protocol
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
if _, err := test.InsertPreState(db, accman); err != nil {
|
if _, err := test.InsertPreState(db); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ethConf := ð.Config{
|
ethConf := ð.Config{
|
||||||
|
@ -217,19 +217,6 @@ func Decrypt(prv *ecdsa.PrivateKey, ct []byte) ([]byte, error) {
|
|||||||
return key.Decrypt(rand.Reader, ct, nil, nil)
|
return key.Decrypt(rand.Reader, ct, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Used only by block tests.
|
|
||||||
func ImportBlockTestKey(privKeyBytes []byte) error {
|
|
||||||
ks := NewKeyStorePassphrase(common.DefaultDataDir()+"/keystore", LightScryptN, LightScryptP)
|
|
||||||
ecKey := ToECDSA(privKeyBytes)
|
|
||||||
key := &Key{
|
|
||||||
Id: uuid.NewRandom(),
|
|
||||||
Address: PubkeyToAddress(ecKey.PublicKey),
|
|
||||||
PrivateKey: ecKey,
|
|
||||||
}
|
|
||||||
err := ks.StoreKey(key, "")
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// creates a Key and stores that in the given KeyStore by decrypting a presale key JSON
|
// creates a Key and stores that in the given KeyStore by decrypting a presale key JSON
|
||||||
func ImportPreSaleKey(keyStore KeyStore, keyJSON []byte, password string) (*Key, error) {
|
func ImportPreSaleKey(keyStore KeyStore, keyJSON []byte, password string) (*Key, error) {
|
||||||
key, err := decryptPreSaleKey(keyJSON, password)
|
key, err := decryptPreSaleKey(keyJSON, password)
|
||||||
|
@ -22,23 +22,18 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/ethash"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -160,45 +155,39 @@ func runBlockTests(homesteadBlock *big.Int, bt map[string]*BlockTest, skipTests
|
|||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
func runBlockTest(homesteadBlock *big.Int, test *BlockTest) error {
|
|
||||||
ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore"), crypto.StandardScryptN, crypto.StandardScryptP)
|
|
||||||
am := accounts.NewManager(ks)
|
|
||||||
db, _ := ethdb.NewMemDatabase()
|
|
||||||
|
|
||||||
|
func runBlockTest(homesteadBlock *big.Int, test *BlockTest) error {
|
||||||
// import pre accounts & construct test genesis block & state root
|
// import pre accounts & construct test genesis block & state root
|
||||||
_, err := test.InsertPreState(db, am)
|
db, _ := ethdb.NewMemDatabase()
|
||||||
if err != nil {
|
if _, err := test.InsertPreState(db); err != nil {
|
||||||
return fmt.Errorf("InsertPreState: %v", err)
|
return fmt.Errorf("InsertPreState: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := ð.Config{
|
core.WriteTd(db, test.Genesis.Hash(), test.Genesis.Difficulty())
|
||||||
ChainConfig: &core.ChainConfig{HomesteadBlock: homesteadBlock},
|
core.WriteBlock(db, test.Genesis)
|
||||||
TestGenesisState: db,
|
core.WriteCanonicalHash(db, test.Genesis.Hash(), test.Genesis.NumberU64())
|
||||||
TestGenesisBlock: test.Genesis,
|
core.WriteHeadBlockHash(db, test.Genesis.Hash())
|
||||||
Etherbase: common.Address{},
|
evmux := new(event.TypeMux)
|
||||||
AccountManager: am,
|
config := &core.ChainConfig{HomesteadBlock: homesteadBlock}
|
||||||
PowShared: true,
|
chain, err := core.NewBlockChain(db, config, ethash.NewShared(), evmux)
|
||||||
}
|
|
||||||
ethereum, err := eth.New(&node.ServiceContext{EventMux: new(event.TypeMux)}, cfg)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cm := ethereum.BlockChain()
|
|
||||||
//vm.Debug = true
|
//vm.Debug = true
|
||||||
validBlocks, err := test.TryBlocksInsert(cm)
|
validBlocks, err := test.TryBlocksInsert(chain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
lastblockhash := common.HexToHash(test.lastblockhash)
|
lastblockhash := common.HexToHash(test.lastblockhash)
|
||||||
cmlast := cm.LastBlockHash()
|
cmlast := chain.LastBlockHash()
|
||||||
if lastblockhash != cmlast {
|
if lastblockhash != cmlast {
|
||||||
return fmt.Errorf("lastblockhash validation mismatch: want: %x, have: %x", lastblockhash, cmlast)
|
return fmt.Errorf("lastblockhash validation mismatch: want: %x, have: %x", lastblockhash, cmlast)
|
||||||
}
|
}
|
||||||
|
|
||||||
newDB, err := cm.State()
|
newDB, err := chain.State()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -206,21 +195,17 @@ func runBlockTest(homesteadBlock *big.Int, test *BlockTest) error {
|
|||||||
return fmt.Errorf("post state validation failed: %v", err)
|
return fmt.Errorf("post state validation failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return test.ValidateImportedHeaders(cm, validBlocks)
|
return test.ValidateImportedHeaders(chain, validBlocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertPreState populates the given database with the genesis
|
// InsertPreState populates the given database with the genesis
|
||||||
// accounts defined by the test.
|
// accounts defined by the test.
|
||||||
func (t *BlockTest) InsertPreState(db ethdb.Database, am *accounts.Manager) (*state.StateDB, error) {
|
func (t *BlockTest) InsertPreState(db ethdb.Database) (*state.StateDB, error) {
|
||||||
statedb, err := state.New(common.Hash{}, db)
|
statedb, err := state.New(common.Hash{}, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for addrString, acct := range t.preAccounts {
|
for addrString, acct := range t.preAccounts {
|
||||||
addr, err := hex.DecodeString(addrString)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
code, err := hex.DecodeString(strings.TrimPrefix(acct.Code, "0x"))
|
code, err := hex.DecodeString(strings.TrimPrefix(acct.Code, "0x"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -233,16 +218,6 @@ func (t *BlockTest) InsertPreState(db ethdb.Database, am *accounts.Manager) (*st
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if acct.PrivateKey != "" {
|
|
||||||
privkey, err := hex.DecodeString(strings.TrimPrefix(acct.PrivateKey, "0x"))
|
|
||||||
err = crypto.ImportBlockTestKey(privkey)
|
|
||||||
err = am.TimedUnlock(common.BytesToAddress(addr), "", 999999*time.Second)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
obj := statedb.CreateAccount(common.HexToAddress(addrString))
|
obj := statedb.CreateAccount(common.HexToAddress(addrString))
|
||||||
obj.SetCode(code)
|
obj.SetCode(code)
|
||||||
obj.SetBalance(balance)
|
obj.SetBalance(balance)
|
||||||
|
Loading…
Reference in New Issue
Block a user