func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) { os.RemoveAll("/tmp/eth-natspec/") err = os.MkdirAll("/tmp/eth-natspec/keys/e273f01c99144c438695e10f24926dc1f9fbf62d/", os.ModePerm) if err != nil { t.Errorf("%v", err) return } err = os.MkdirAll("/tmp/eth-natspec/data", os.ModePerm) if err != nil { t.Errorf("%v", err) return } ks := crypto.NewKeyStorePlain("/tmp/eth-natspec/keys") ioutil.WriteFile("/tmp/eth-natspec/keys/e273f01c99144c438695e10f24926dc1f9fbf62d/e273f01c99144c438695e10f24926dc1f9fbf62d", []byte(`{"Id":"RhRXD+fNRKS4jx+7ZfEsNA==","Address":"4nPwHJkUTEOGleEPJJJtwfn79i0=","PrivateKey":"h4ACVpe74uIvi5Cg/2tX/Yrm2xdr3J7QoMbMtNX2CNc="}`), os.ModePerm) port++ ethereum, err = eth.New(ð.Config{ DataDir: "/tmp/eth-natspec", AccountManager: accounts.NewManager(ks), Name: "test", }) if err != nil { t.Errorf("%v", err) return } return }
// New creates a Ethereum client, pre-configured to one of the supported networks. func New(datadir string, network EthereumNetwork) (*Geth, error) { // Tag the data dir with the network name switch network { case MainNet: datadir = filepath.Join(datadir, "mainnet") case TestNet: datadir = filepath.Join(datadir, "testnet") default: return nil, fmt.Errorf("unsupported network: %v", network) } // Select the bootstrap nodes based on the network bootnodes := utils.FrontierBootNodes if network == TestNet { bootnodes = utils.TestNetBootNodes } // Configure the node's service container stackConf := &node.Config{ DataDir: datadir, Name: common.MakeName(NodeName, NodeVersion), BootstrapNodes: bootnodes, ListenAddr: fmt.Sprintf(":%d", NodePort), MaxPeers: NodeMaxPeers, } // Configure the bare-bone Ethereum service keystore := crypto.NewKeyStorePassphrase(filepath.Join(datadir, "keystore"), crypto.StandardScryptN, crypto.StandardScryptP) ethConf := ð.Config{ FastSync: true, DatabaseCache: 64, NetworkId: int(network), AccountManager: accounts.NewManager(keystore), // Blatantly initialize the gas oracle to the defaults from go-ethereum GpoMinGasPrice: new(big.Int).Mul(big.NewInt(50), common.Shannon), GpoMaxGasPrice: new(big.Int).Mul(big.NewInt(500), common.Shannon), GpoFullBlockRatio: 80, GpobaseStepDown: 10, GpobaseStepUp: 100, GpobaseCorrectionFactor: 110, } // Override any default configs in the test network if network == TestNet { ethConf.NetworkId = 2 ethConf.Genesis = core.TestNetGenesisBlock() state.StartingNonce = 1048576 // (2**20) params.HomesteadBlock = params.TestNetHomesteadBlock } // Assemble and return the protocol stack stack, err := node.New(stackConf) if err != nil { return nil, fmt.Errorf("protocol stack: %v", err) } if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { return eth.New(ctx, ethConf) }); err != nil { return nil, fmt.Errorf("ethereum service: %v", err) } return &Geth{ stack: stack, keystore: keystore, }, nil }
func testEthConfig() *eth.Config { ks := crypto.NewKeyStorePassphrase(path.Join(common.DefaultDataDir(), "keys")) return ð.Config{ DataDir: common.DefaultDataDir(), LogLevel: 5, Etherbase: "primary", AccountManager: accounts.NewManager(ks), NewDB: func(path string) (common.Database, error) { return ethdb.NewMemDatabase() }, } }
func (test *BlockTest) makeEthConfig() *eth.Config { ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore")) return ð.Config{ DataDir: common.DefaultDataDir(), Verbosity: 5, Etherbase: common.Address{}, AccountManager: accounts.NewManager(ks), NewDB: func(path string) (common.Database, error) { return ethdb.NewMemDatabase() }, } }
// MakeAccountManager creates an account manager from set command line flags. func MakeAccountManager(ctx *cli.Context) *accounts.Manager { // Create the keystore crypto primitive, light if requested scryptN := accounts.StandardScryptN scryptP := accounts.StandardScryptP if ctx.GlobalBool(LightKDFFlag.Name) { scryptN = accounts.LightScryptN scryptP = accounts.LightScryptP } datadir := MustMakeDataDir(ctx) keydir := MakeKeyStoreDir(datadir, ctx) return accounts.NewManager(keydir, scryptN, scryptP) }
func runBlockTest(test *BlockTest) error { ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore"), crypto.StandardScryptN, crypto.StandardScryptP) am := accounts.NewManager(ks) db, _ := ethdb.NewMemDatabase() cfg := ð.Config{ DataDir: common.DefaultDataDir(), Verbosity: 5, Etherbase: common.Address{}, AccountManager: am, NewDB: func(path string) (ethdb.Database, error) { return db, nil }, } cfg.GenesisBlock = test.Genesis // import pre accounts & construct test genesis block & state root _, err := test.InsertPreState(db, am) if err != nil { return fmt.Errorf("InsertPreState: %v", err) } ethereum, err := eth.New(cfg) if err != nil { return err } err = ethereum.Start() if err != nil { return err } cm := ethereum.BlockChain() validBlocks, err := test.TryBlocksInsert(cm) if err != nil { return err } lastblockhash := common.HexToHash(test.lastblockhash) cmlast := cm.LastBlockHash() if lastblockhash != cmlast { return fmt.Errorf("lastblockhash validation mismatch: want: %x, have: %x", lastblockhash, cmlast) } newDB, err := cm.State() if err != nil { return err } if err = test.ValidatePostState(newDB); err != nil { return fmt.Errorf("post state validation failed: %v", err) } return test.ValidateImportedHeaders(cm, validBlocks) }
func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *eth.Ethereum) { tmp, err := ioutil.TempDir("", "geth-test") if err != nil { t.Fatal(err) } db, _ := ethdb.NewMemDatabase() core.WriteGenesisBlockForTesting(db, core.GenesisAccount{common.HexToAddress(testAddress), common.String2Big(testBalance)}) ks := crypto.NewKeyStorePlain(filepath.Join(tmp, "keystore")) am := accounts.NewManager(ks) conf := ð.Config{ NodeKey: testNodeKey, DataDir: tmp, AccountManager: am, MaxPeers: 0, Name: "test", SolcPath: testSolcPath, PowTest: true, NewDB: func(path string) (ethdb.Database, error) { return db, nil }, } if config != nil { config(conf) } ethereum, err := eth.New(conf) if err != nil { t.Fatal("%v", err) } keyb, err := crypto.HexToECDSA(testKey) if err != nil { t.Fatal(err) } key := crypto.NewKeyFromECDSA(keyb) err = ks.StoreKey(key, "") if err != nil { t.Fatal(err) } err = am.Unlock(key.Address, "") if err != nil { t.Fatal(err) } assetPath := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext") client := comms.NewInProcClient(codec.JSON) ds := docserver.New("/") tf := &testjethre{ds: ds} repl := newJSRE(ethereum, assetPath, "", client, false, tf) tf.jsre = repl return tmp, tf, ethereum }
// MakeChain creates an account manager from set command line flags. func MakeAccountManager(ctx *cli.Context) *accounts.Manager { dataDir := MustDataDir(ctx) if ctx.GlobalBool(TestNetFlag.Name) { dataDir += "/testnet" } scryptN := crypto.StandardScryptN scryptP := crypto.StandardScryptP if ctx.GlobalBool(LightKDFFlag.Name) { scryptN = crypto.LightScryptN scryptP = crypto.LightScryptP } ks := crypto.NewKeyStorePassphrase(filepath.Join(dataDir, "keystore"), scryptN, scryptP) return accounts.NewManager(ks) }
func testJEthRE(t *testing.T) (string, *testjethre, *eth.Ethereum) { tmp, err := ioutil.TempDir("", "geth-test") if err != nil { t.Fatal(err) } // set up mock genesis with balance on the testAddress core.GenesisAccounts = []byte(testGenesis) ks := crypto.NewKeyStorePlain(filepath.Join(tmp, "keystore")) am := accounts.NewManager(ks) ethereum, err := eth.New(ð.Config{ NodeKey: testNodeKey, DataDir: tmp, AccountManager: am, MaxPeers: 0, Name: "test", SolcPath: testSolcPath, }) if err != nil { t.Fatal("%v", err) } keyb, err := crypto.HexToECDSA(testKey) if err != nil { t.Fatal(err) } key := crypto.NewKeyFromECDSA(keyb) err = ks.StoreKey(key, "") if err != nil { t.Fatal(err) } err = am.Unlock(key.Address, "") if err != nil { t.Fatal(err) } assetPath := filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext") ds, err := docserver.New("/") if err != nil { t.Errorf("Error creating DocServer: %v", err) } tf := &testjethre{ds: ds, stateDb: ethereum.ChainManager().State().Copy()} client := comms.NewInProcClient(codec.JSON) repl := newJSRE(ethereum, assetPath, "", client, false, tf) tf.jsre = repl return tmp, tf, ethereum }
// MakeAccountManager creates an account manager from set command line flags. func MakeAccountManager(ctx *cli.Context) *accounts.Manager { // Create the keystore crypto primitive, light if requested scryptN := crypto.StandardScryptN scryptP := crypto.StandardScryptP if ctx.GlobalBool(LightKDFFlag.Name) { scryptN = crypto.LightScryptN scryptP = crypto.LightScryptP } // Assemble an account manager using the configured datadir var ( datadir = MustMakeDataDir(ctx) keystore = crypto.NewKeyStorePassphrase(filepath.Join(datadir, "keystore"), scryptN, scryptP) ) return accounts.NewManager(keystore) }
func gethkey(ctx *cli.Context) { account := ctx.Args().First() if len(account) == 0 { utils.Fatalf("account address must be given as first argument") } keyfile := ctx.Args().Get(1) if len(keyfile) == 0 { utils.Fatalf("keyfile must be given as second argument") } keydir := ctx.GlobalString(keyDirFlag.Name) ks := crypto.NewKeyStorePassphrase(keydir) am := accounts.NewManager(ks) auth := unlockAccount(ctx, am, account) err := am.Export(keyfile, common.FromHex(account), auth) if err != nil { utils.Fatalf("Account export failed: %v", err) } }
func testJEthRE(t *testing.T) (*jsre, *eth.Ethereum) { tmp, err := ioutil.TempDir("", "geth-test") if err != nil { t.Fatal(err) } defer os.RemoveAll(tmp) ks := crypto.NewKeyStorePlain(filepath.Join(tmp, "keys")) ethereum, err := eth.New(ð.Config{ DataDir: tmp, AccountManager: accounts.NewManager(ks), MaxPeers: 0, Name: "test", }) if err != nil { t.Fatal("%v", err) } assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist", "assets", "ext") repl := newJSRE(ethereum, assetPath, false, "") return repl, ethereum }
func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) { os.RemoveAll("/tmp/eth-natspec/") err = os.MkdirAll("/tmp/eth-natspec/keystore", os.ModePerm) if err != nil { panic(err) } // create a testAddress ks := crypto.NewKeyStorePassphrase("/tmp/eth-natspec/keystore") am := accounts.NewManager(ks) testAccount, err := am.NewAccount("password") if err != nil { panic(err) } testAddress := strings.TrimPrefix(testAccount.Address.Hex(), "0x") db, _ := ethdb.NewMemDatabase() // set up mock genesis with balance on the testAddress core.WriteGenesisBlockForTesting(db, core.GenesisAccount{common.HexToAddress(testAddress), common.String2Big(testBalance)}) // only use minimalistic stack with no networking ethereum, err = eth.New(ð.Config{ DataDir: "/tmp/eth-natspec", AccountManager: am, MaxPeers: 0, PowTest: true, Etherbase: common.HexToAddress(testAddress), NewDB: func(path string) (ethdb.Database, error) { return db, nil }, }) if err != nil { panic(err) } return }
func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) { tmp, err := ioutil.TempDir("", "natspec-test") if err != nil { t.Fatal(err) } db, _ := ethdb.NewMemDatabase() addr := common.HexToAddress(testAddress) core.WriteGenesisBlockForTesting(db, core.GenesisAccount{addr, common.String2Big(testBalance)}) ks := crypto.NewKeyStorePassphrase(filepath.Join(tmp, "keystore"), crypto.LightScryptN, crypto.LightScryptP) am := accounts.NewManager(ks) keyb, err := crypto.HexToECDSA(testKey) if err != nil { t.Fatal(err) } key := crypto.NewKeyFromECDSA(keyb) err = ks.StoreKey(key, "") if err != nil { t.Fatal(err) } err = am.Unlock(key.Address, "") if err != nil { t.Fatal(err) } // only use minimalistic stack with no networking return eth.New(ð.Config{ DataDir: tmp, AccountManager: am, Etherbase: common.HexToAddress(testAddress), MaxPeers: 0, PowTest: true, NewDB: func(path string) (ethdb.Database, error) { return db, nil }, GpoMinGasPrice: common.Big1, GpobaseCorrectionFactor: 1, GpoMaxGasPrice: common.Big1, }) }
func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) { os.RemoveAll("/tmp/eth-natspec/") err = os.MkdirAll("/tmp/eth-natspec/keystore", os.ModePerm) if err != nil { panic(err) } // create a testAddress ks := crypto.NewKeyStorePassphrase("/tmp/eth-natspec/keystore") am := accounts.NewManager(ks) testAccount, err := am.NewAccount("password") if err != nil { panic(err) } testAddress := strings.TrimPrefix(testAccount.Address.Hex(), "0x") // set up mock genesis with balance on the testAddress core.GenesisAccounts = []byte(`{ "` + testAddress + `": {"balance": "` + testBalance + `"} }`) // only use minimalistic stack with no networking ethereum, err = eth.New(ð.Config{ DataDir: "/tmp/eth-natspec", AccountManager: am, MaxPeers: 0, PowTest: true, Etherbase: common.HexToAddress(testAddress), }) if err != nil { panic(err) } return }
func GetAccountManager(ctx *cli.Context) *accounts.Manager { dataDir := ctx.GlobalString(DataDirFlag.Name) ks := crypto.NewKeyStorePassphrase(path.Join(dataDir, "keys")) return accounts.NewManager(ks) }