aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ethereum/js.go6
-rw-r--r--cmd/ethereum/main.go13
-rw-r--r--cmd/ethtest/main.go116
-rw-r--r--cmd/mist/assets/qml/views/miner.qml58
-rw-r--r--cmd/mist/assets/qml/views/network.qml1
-rw-r--r--cmd/mist/ui_lib.go18
6 files changed, 128 insertions, 84 deletions
diff --git a/cmd/ethereum/js.go b/cmd/ethereum/js.go
index 5432fb9b1..3b98b588e 100644
--- a/cmd/ethereum/js.go
+++ b/cmd/ethereum/js.go
@@ -249,12 +249,14 @@ func (self *jsre) dump(call otto.FunctionCall) otto.Value {
}
func (self *jsre) stopMining(call otto.FunctionCall) otto.Value {
- self.xeth.Miner().Stop()
+ self.ethereum.StopMining()
return otto.TrueValue()
}
func (self *jsre) startMining(call otto.FunctionCall) otto.Value {
- self.xeth.Miner().Start()
+ if err := self.ethereum.StartMining(); err != nil {
+ return otto.FalseValue()
+ }
return otto.TrueValue()
}
diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go
index 73c67bdc9..8b01457e6 100644
--- a/cmd/ethereum/main.go
+++ b/cmd/ethereum/main.go
@@ -30,7 +30,6 @@ import (
"time"
"github.com/codegangsta/cli"
- "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
@@ -158,10 +157,7 @@ func run(ctx *cli.Context) {
fmt.Printf("Welcome to the FRONTIER\n")
utils.HandleInterrupt()
eth, err := utils.GetEthereum(ClientIdentifier, Version, ctx)
- if err == accounts.ErrNoKeys {
- utils.Fatalf(`No accounts configured.
-Please run 'ethereum account new' to create a new account.`)
- } else if err != nil {
+ if err != nil {
utils.Fatalf("%v", err)
}
@@ -172,10 +168,7 @@ Please run 'ethereum account new' to create a new account.`)
func runjs(ctx *cli.Context) {
eth, err := utils.GetEthereum(ClientIdentifier, Version, ctx)
- if err == accounts.ErrNoKeys {
- utils.Fatalf(`No accounts configured.
-Please run 'ethereum account new' to create a new account.`)
- } else if err != nil {
+ if err != nil {
utils.Fatalf("%v", err)
}
@@ -214,7 +207,7 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
utils.StartRPC(eth, ctx)
}
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) {
- eth.Miner().Start()
+ eth.StartMining()
}
}
diff --git a/cmd/ethtest/main.go b/cmd/ethtest/main.go
index 40874616c..e929d1de8 100644
--- a/cmd/ethtest/main.go
+++ b/cmd/ethtest/main.go
@@ -24,10 +24,13 @@ package main
import (
"bytes"
"encoding/json"
+ "fmt"
"io"
"io/ioutil"
"log"
+ "math/big"
"os"
+ "strconv"
"strings"
"github.com/ethereum/go-ethereum/ethdb"
@@ -37,6 +40,24 @@ import (
"github.com/ethereum/go-ethereum/tests/helper"
)
+type Log struct {
+ AddressF string `json:"address"`
+ DataF string `json:"data"`
+ TopicsF []string `json:"topics"`
+ BloomF string `json:"bloom"`
+}
+
+func (self Log) Address() []byte { return ethutil.Hex2Bytes(self.AddressF) }
+func (self Log) Data() []byte { return ethutil.Hex2Bytes(self.DataF) }
+func (self Log) RlpData() interface{} { return nil }
+func (self Log) Topics() [][]byte {
+ t := make([][]byte, len(self.TopicsF))
+ for i, topic := range self.TopicsF {
+ t[i] = ethutil.Hex2Bytes(topic)
+ }
+ return t
+}
+
type Account struct {
Balance string
Code string
@@ -59,12 +80,25 @@ func StateObjectFromAccount(db ethutil.Database, addr string, account Account) *
type VmTest struct {
Callcreates interface{}
- Env map[string]string
- Exec map[string]string
- Gas string
- Out string
- Post map[string]Account
- Pre map[string]Account
+ //Env map[string]string
+ Env Env
+ Exec map[string]string
+ Transaction map[string]string
+ Logs []Log
+ Gas string
+ Out string
+ Post map[string]Account
+ Pre map[string]Account
+ PostStateRoot string
+}
+
+type Env struct {
+ CurrentCoinbase string
+ CurrentDifficulty string
+ CurrentGasLimit string
+ CurrentNumber string
+ CurrentTimestamp interface{}
+ PreviousHash string
}
func RunVmTest(r io.Reader) (failed int) {
@@ -78,49 +112,75 @@ func RunVmTest(r io.Reader) (failed int) {
for name, test := range tests {
db, _ := ethdb.NewMemDatabase()
- state := state.New(nil, db)
+ statedb := state.New(nil, db)
for addr, account := range test.Pre {
obj := StateObjectFromAccount(db, addr, account)
- state.SetStateObject(obj)
+ statedb.SetStateObject(obj)
}
- ret, _, gas, err := helper.RunVm(state, test.Env, test.Exec)
- // When an error is returned it doesn't always mean the tests fails.
- // Have to come up with some conditional failing mechanism.
- if err != nil {
- log.Println(err)
+ env := make(map[string]string)
+ env["currentCoinbase"] = test.Env.CurrentCoinbase
+ env["currentDifficulty"] = test.Env.CurrentDifficulty
+ env["currentGasLimit"] = test.Env.CurrentGasLimit
+ env["currentNumber"] = test.Env.CurrentNumber
+ env["previousHash"] = test.Env.PreviousHash
+ if n, ok := test.Env.CurrentTimestamp.(float64); ok {
+ env["currentTimestamp"] = strconv.Itoa(int(n))
+ } else {
+ env["currentTimestamp"] = test.Env.CurrentTimestamp.(string)
}
+ ret, logs, _, _ := helper.RunState(statedb, env, test.Transaction)
+ statedb.Sync()
+
rexp := helper.FromHex(test.Out)
if bytes.Compare(rexp, ret) != 0 {
- log.Printf("%s's return failed. Expected %x, got %x\n", name, rexp, ret)
- failed = 1
+ fmt.Printf("%s's return failed. Expected %x, got %x\n", name, rexp, ret)
}
- if len(test.Gas) == 0 && err == nil {
- log.Printf("0 gas indicates error but no error given by VM")
- failed = 1
- } else {
- gexp := ethutil.Big(test.Gas)
- if gexp.Cmp(gas) != 0 {
- log.Printf("%s's gas failed. Expected %v, got %v\n", name, gexp, gas)
- failed = 1
+ for addr, account := range test.Post {
+ obj := statedb.GetStateObject(helper.FromHex(addr))
+ if obj == nil {
+ continue
+ }
+
+ if len(test.Exec) == 0 {
+ if obj.Balance().Cmp(ethutil.Big(account.Balance)) != 0 {
+ fmt.Printf("%s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(ethutil.Big(account.Balance), obj.Balance()))
+ }
}
- }
- for addr, account := range test.Post {
- obj := state.GetStateObject(helper.FromHex(addr))
for addr, value := range account.Storage {
v := obj.GetState(helper.FromHex(addr)).Bytes()
vexp := helper.FromHex(value)
if bytes.Compare(v, vexp) != 0 {
- log.Printf("%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)\n", name, obj.Address()[0:4], addr, vexp, v, ethutil.BigD(vexp), ethutil.BigD(v))
- failed = 1
+ fmt.Printf("%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)\n", name, obj.Address()[0:4], addr, vexp, v, ethutil.BigD(vexp), ethutil.BigD(v))
}
}
}
+ if !bytes.Equal(ethutil.Hex2Bytes(test.PostStateRoot), statedb.Root()) {
+ fmt.Printf("%s's : Post state root error. Expected %s, got %x", name, test.PostStateRoot, statedb.Root())
+ }
+
+ if len(test.Logs) > 0 {
+ if len(test.Logs) != len(logs) {
+ fmt.Printf("log length mismatch. Expected %d, got %d", len(test.Logs), len(logs))
+ } else {
+ /*
+ fmt.Println("A", test.Logs)
+ fmt.Println("B", logs)
+ for i, log := range test.Logs {
+ genBloom := ethutil.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
+ if !bytes.Equal(genBloom, ethutil.Hex2Bytes(log.BloomF)) {
+ t.Errorf("bloom mismatch")
+ }
+ }
+ */
+ }
+ }
+
logger.Flush()
}
diff --git a/cmd/mist/assets/qml/views/miner.qml b/cmd/mist/assets/qml/views/miner.qml
index 4025ff485..ff2bf85ca 100644
--- a/cmd/mist/assets/qml/views/miner.qml
+++ b/cmd/mist/assets/qml/views/miner.qml
@@ -55,8 +55,8 @@ Rectangle {
Button {
text: "Start"
onClicked: {
- eth.setGasPrice(minGasPrice.text || "10000000000000");
- eth.setExtra(blockExtra.text)
+ // eth.setGasPrice(minGasPrice.text || "10000000000000");
+ // eth.setExtra(blockExtra.text)
if (eth.toggleMining()) {
this.text = "Stop";
} else {
@@ -65,35 +65,35 @@ Rectangle {
}
}
- Rectangle {
- id: minGasPriceRect
- anchors.top: parent.top
- anchors.topMargin: 2
- width: 200
- TextField {
- id: minGasPrice
- placeholderText: "Min Gas: 10000000000000"
- width: 200
- validator: RegExpValidator { regExp: /\d*/ }
- }
- }
+ // Rectangle {
+ // id: minGasPriceRect
+ // anchors.top: parent.top
+ // anchors.topMargin: 2
+ // width: 200
+ // TextField {
+ // id: minGasPrice
+ // placeholderText: "Min Gas: 10000000000000"
+ // width: 200
+ // validator: RegExpValidator { regExp: /\d*/ }
+ // }
+ // }
- Rectangle {
- width: 300
- anchors {
- left: minGasPriceRect.right
- leftMargin: 5
- top: parent.top
- topMargin: 2
- }
+ // Rectangle {
+ // width: 300
+ // anchors {
+ // left: minGasPriceRect.right
+ // leftMargin: 5
+ // top: parent.top
+ // topMargin: 2
+ // }
- TextField {
- id: blockExtra
- placeholderText: "Extra"
- width: parent.width
- maximumLength: 1024
- }
- }
+ // TextField {
+ // id: blockExtra
+ // placeholderText: "Extra"
+ // width: parent.width
+ // maximumLength: 1024
+ // }
+ // }
}
}
diff --git a/cmd/mist/assets/qml/views/network.qml b/cmd/mist/assets/qml/views/network.qml
index d33b5773c..fe4c7734f 100644
--- a/cmd/mist/assets/qml/views/network.qml
+++ b/cmd/mist/assets/qml/views/network.qml
@@ -93,7 +93,6 @@ Rectangle {
// Check if it's mining and set it accordingly
if (miningSliderValue > 0 && !eth.miner().mining()) {
// If the
- eth.setGasPrice("10000000000000");
eth.miner().start();
} else if (miningSliderValue == 0 && eth.miner().mining()) {
eth.miner().stop();
diff --git a/cmd/mist/ui_lib.go b/cmd/mist/ui_lib.go
index 4198c6316..2679e0f95 100644
--- a/cmd/mist/ui_lib.go
+++ b/cmd/mist/ui_lib.go
@@ -175,22 +175,12 @@ func (self *UiLib) RemoveLocalTransaction(id int) {
//self.miner.RemoveLocalTx(id)
}
-func (self *UiLib) SetGasPrice(price string) {
- self.Miner().MinAcceptedGasPrice = ethutil.Big(price)
-}
-
-func (self *UiLib) SetExtra(extra string) {
- self.Miner().Extra = extra
-}
-
func (self *UiLib) ToggleMining() bool {
- if !self.Miner().Mining() {
- self.Miner().Start()
-
- return true
+ if !self.eth.IsMining() {
+ err := self.eth.StartMining()
+ return err == nil
} else {
- self.Miner().Stop()
-
+ self.eth.StopMining()
return false
}
}