Merge branch 'develop' of github.com-obscure:ethereum/go-ethereum into develop

This commit is contained in:
obscuren 2014-11-01 01:18:13 +01:00
commit c8438979a9
15 changed files with 74 additions and 72 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@
*un~
.DS_Store
*/**/.DS_Store
.ethtest

View File

@ -3,12 +3,14 @@ package chain
import (
"testing"
"github.com/ethereum/go-ethereum/vm"
"github.com/ethereum/go-ethereum/state"
)
func TestBloom9(t *testing.T) {
testCase := []byte("testtest")
bin := LogsBloom([]vm.Log{vm.Log{testCase, [][]byte{[]byte("hellohello")}, nil}}).Bytes()
bin := LogsBloom([]state.Log{
{testCase, [][]byte{[]byte("hellohello")}, nil},
}).Bytes()
res := BloomLookup(bin, testCase)
if !res {

View File

@ -4,11 +4,11 @@ import (
"container/list"
"fmt"
"github.com/ethereum/go-ethereum/ethcrypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethwire"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/wire"
)
// Implement our EthTest Manager
@ -53,14 +53,14 @@ func (tm *TestManager) StateManager() *StateManager {
func (tm *TestManager) EventMux() *event.TypeMux {
return tm.eventMux
}
func (tm *TestManager) Broadcast(msgType ethwire.MsgType, data []interface{}) {
func (tm *TestManager) Broadcast(msgType wire.MsgType, data []interface{}) {
fmt.Println("Broadcast not implemented")
}
func (tm *TestManager) ClientIdentity() ethwire.ClientIdentity {
func (tm *TestManager) ClientIdentity() wire.ClientIdentity {
return nil
}
func (tm *TestManager) KeyManager() *ethcrypto.KeyManager {
func (tm *TestManager) KeyManager() *crypto.KeyManager {
return nil
}

View File

@ -26,7 +26,6 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethgo.old/ethlog"
)
const (
@ -131,5 +130,5 @@ func main() {
// this blocks the thread
ethereum.WaitForShutdown()
ethlog.Flush()
logger.Flush()
}

View File

@ -9,7 +9,7 @@ import (
"sync"
"time"
"github.com/ethereum/eth-go/ethlog"
logpkg "github.com/ethereum/go-ethereum/logger"
)
const (
@ -93,7 +93,7 @@ type Server struct {
handlers Handlers
}
var logger = ethlog.NewLogger("P2P")
var logger = logpkg.NewLogger("P2P")
func New(network Network, addr net.Addr, identity ClientIdentity, handlers Handlers, maxPeers int, blacklist Blacklist) *Server {
// get alphabetical list of protocol names from handlers map

View File

@ -3,10 +3,10 @@ package ar
import (
"math/big"
"github.com/ethereum/go-ethereum/ethtrie"
"github.com/ethereum/go-ethereum/trie"
)
type Block interface {
Trie() *ethtrie.Trie
Trie() *trie.Trie
Diff() *big.Int
}

View File

@ -6,17 +6,17 @@ import (
"testing"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethtrie"
"github.com/ethereum/go-ethereum/trie"
)
type TestBlock struct {
trie *ethtrie.Trie
trie *trie.Trie
}
func NewTestBlock() *TestBlock {
db, _ := ethdb.NewMemDatabase()
return &TestBlock{
trie: ethtrie.New(db, ""),
trie: trie.New(db, ""),
}
}
@ -24,7 +24,7 @@ func (self *TestBlock) Diff() *big.Int {
return b(10)
}
func (self *TestBlock) Trie() *ethtrie.Trie {
func (self *TestBlock) Trie() *trie.Trie {
return self.trie
}

View File

@ -3,7 +3,7 @@ package ar
import (
"math/big"
"github.com/ethereum/go-ethereum/ethcrypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
)
@ -21,16 +21,16 @@ func (self ByteNode) Big() *big.Int {
func Sha3(v interface{}) *big.Int {
if b, ok := v.(*big.Int); ok {
return ethutil.BigD(ethcrypto.Sha3(b.Bytes()))
return ethutil.BigD(crypto.Sha3(b.Bytes()))
} else if b, ok := v.([]interface{}); ok {
return ethutil.BigD(ethcrypto.Sha3(ethutil.Encode(b)))
return ethutil.BigD(crypto.Sha3(ethutil.Encode(b)))
} else if s, ok := v.([]*big.Int); ok {
v := make([]interface{}, len(s))
for i, b := range s {
v[i] = b
}
return ethutil.BigD(ethcrypto.Sha3(ethutil.Encode(v)))
return ethutil.BigD(crypto.Sha3(ethutil.Encode(v)))
}
return nil

View File

@ -4,8 +4,8 @@ import (
"testing"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethtrie"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/trie"
)
var ZeroHash256 = make([]byte, 32)
@ -15,7 +15,7 @@ func TestSnapshot(t *testing.T) {
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
ethutil.Config.Db = db
state := New(ethtrie.New(db, ""))
state := New(trie.New(db, ""))
stateObject := state.GetOrNewStateObject([]byte("aa"))

View File

@ -8,8 +8,8 @@ import (
"os"
"strings"
"github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper"
)
@ -20,8 +20,8 @@ type Account struct {
Storage map[string]string
}
func StateObjectFromAccount(addr string, account Account) *ethstate.StateObject {
obj := ethstate.NewStateObject(ethutil.Hex2Bytes(addr))
func StateObjectFromAccount(addr string, account Account) *state.StateObject {
obj := state.NewStateObject(ethutil.Hex2Bytes(addr))
obj.SetBalance(ethutil.Big(account.Balance))
if ethutil.IsHex(account.Code) {
@ -53,7 +53,7 @@ func RunVmTest(js string) (failed int) {
}
for name, test := range tests {
state := ethstate.New(helper.NewTrie())
state := state.New(helper.NewTrie())
for addr, account := range test.Pre {
obj := StateObjectFromAccount(addr, account)
state.SetStateObject(obj)

View File

@ -4,16 +4,16 @@ import (
"log"
"os"
"github.com/ethereum/go-ethereum/ethlog"
"github.com/ethereum/go-ethereum/ethutil"
logpkg "github.com/ethereum/go-ethereum/logger"
)
var Logger ethlog.LogSystem
var Log = ethlog.NewLogger("TEST")
var Logger logpkg.LogSystem
var Log = logpkg.NewLogger("TEST")
func init() {
Logger = ethlog.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlog.InfoLevel)
ethlog.AddLogSystem(Logger)
Logger = logpkg.NewStdLogSystem(os.Stdout, log.LstdFlags, logpkg.InfoLevel)
logpkg.AddLogSystem(Logger)
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
}

View File

@ -1,6 +1,6 @@
package helper
import "github.com/ethereum/go-ethereum/ethtrie"
import "github.com/ethereum/go-ethereum/trie"
type MemDatabase struct {
db map[string][]byte
@ -24,8 +24,8 @@ func (db *MemDatabase) Print() {}
func (db *MemDatabase) Close() {}
func (db *MemDatabase) LastKnownTD() []byte { return nil }
func NewTrie() *ethtrie.Trie {
func NewTrie() *trie.Trie {
db, _ := NewMemDatabase()
return ethtrie.New(db, "")
return trie.New(db, "")
}

View File

@ -3,13 +3,13 @@ package helper
import (
"math/big"
"github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/vm"
)
type Env struct {
state *ethstate.State
state *state.State
origin []byte
parent []byte
@ -21,13 +21,13 @@ type Env struct {
gasLimit *big.Int
}
func NewEnv(state *ethstate.State) *Env {
func NewEnv(state *state.State) *Env {
return &Env{
state: state,
}
}
func NewEnvFromMap(state *ethstate.State, envValues map[string]string, exeValues map[string]string) *Env {
func NewEnvFromMap(state *state.State, envValues map[string]string, exeValues map[string]string) *Env {
env := NewEnv(state)
env.origin = ethutil.Hex2Bytes(exeValues["caller"])
@ -41,21 +41,21 @@ func NewEnvFromMap(state *ethstate.State, envValues map[string]string, exeValues
return env
}
func (self *Env) Origin() []byte { return self.origin }
func (self *Env) BlockNumber() *big.Int { return self.number }
func (self *Env) PrevHash() []byte { return self.parent }
func (self *Env) Coinbase() []byte { return self.coinbase }
func (self *Env) Time() int64 { return self.time }
func (self *Env) Difficulty() *big.Int { return self.difficulty }
func (self *Env) BlockHash() []byte { return nil }
func (self *Env) State() *ethstate.State { return self.state }
func (self *Env) GasLimit() *big.Int { return self.gasLimit }
func (self *Env) AddLog(vm.Log) {}
func (self *Env) Origin() []byte { return self.origin }
func (self *Env) BlockNumber() *big.Int { return self.number }
func (self *Env) PrevHash() []byte { return self.parent }
func (self *Env) Coinbase() []byte { return self.coinbase }
func (self *Env) Time() int64 { return self.time }
func (self *Env) Difficulty() *big.Int { return self.difficulty }
func (self *Env) BlockHash() []byte { return nil }
func (self *Env) State() *state.State { return self.state }
func (self *Env) GasLimit() *big.Int { return self.gasLimit }
func (self *Env) AddLog(state.Log) {}
func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error {
return vm.Transfer(from, to, amount)
}
func RunVm(state *ethstate.State, env, exec map[string]string) ([]byte, *big.Int, error) {
func RunVm(state *state.State, env, exec map[string]string) ([]byte, *big.Int, error) {
address := FromHex(exec["address"])
caller := state.GetOrNewStateObject(FromHex(exec["caller"]))

View File

@ -4,8 +4,8 @@ import (
"bytes"
"testing"
"github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper"
)
@ -16,8 +16,8 @@ type Account struct {
Storage map[string]string
}
func StateObjectFromAccount(addr string, account Account) *ethstate.StateObject {
obj := ethstate.NewStateObject(ethutil.Hex2Bytes(addr))
func StateObjectFromAccount(addr string, account Account) *state.StateObject {
obj := state.NewStateObject(ethutil.Hex2Bytes(addr))
obj.SetBalance(ethutil.Big(account.Balance))
if ethutil.IsHex(account.Code) {
@ -44,7 +44,7 @@ func RunVmTest(p string, t *testing.T) {
helper.CreateFileTests(t, p, &tests)
for name, test := range tests {
state := ethstate.New(helper.NewTrie())
state := state.New(helper.NewTrie())
for addr, account := range test.Pre {
obj := StateObjectFromAccount(addr, account)
state.SetStateObject(obj)

View File

@ -9,11 +9,11 @@ import (
"os"
"testing"
"github.com/ethereum/go-ethereum/ethcrypto"
"github.com/ethereum/go-ethereum/ethlog"
"github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethtrie"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/trie"
"github.com/obscuren/mutan"
)
@ -28,15 +28,15 @@ func (TestEnv) Time() int64 { return 0 }
func (TestEnv) GasLimit() *big.Int { return nil }
func (TestEnv) Difficulty() *big.Int { return nil }
func (TestEnv) Value() *big.Int { return nil }
func (TestEnv) AddLog(Log) {}
func (TestEnv) AddLog(state.Log) {}
func (TestEnv) Transfer(from, to Account, amount *big.Int) error {
return nil
}
// This is likely to fail if anything ever gets looked up in the state trie :-)
func (TestEnv) State() *ethstate.State {
return ethstate.New(ethtrie.New(nil, ""))
func (TestEnv) State() *state.State {
return state.New(trie.New(nil, ""))
}
const mutcode = `
@ -47,18 +47,18 @@ for i := 0; i < 10; i++ {
return x`
func setup(level ethlog.LogLevel, typ Type) (*Closure, VirtualMachine) {
func setup(level logger.LogLevel, typ Type) (*Closure, VirtualMachine) {
code, err := ethutil.Compile(mutcode, true)
if err != nil {
log.Fatal(err)
}
// Pipe output to /dev/null
ethlog.AddLogSystem(ethlog.NewStdLogSystem(ioutil.Discard, log.LstdFlags, level))
logger.AddLogSystem(logger.NewStdLogSystem(ioutil.Discard, log.LstdFlags, level))
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
stateObject := ethstate.NewStateObject([]byte{'j', 'e', 'f', 'f'})
stateObject := state.NewStateObject([]byte{'j', 'e', 'f', 'f'})
callerClosure := NewClosure(nil, stateObject, stateObject, code, big.NewInt(1000000), big.NewInt(0))
return callerClosure, New(TestEnv{}, typ)
@ -71,7 +71,7 @@ func TestDebugVm(t *testing.T) {
t.Skip("skipping for mutan version", mutan.Version, " < 0.6")
}
closure, vm := setup(ethlog.DebugLevel, DebugVmTy)
closure, vm := setup(logger.DebugLevel, DebugVmTy)
ret, _, e := closure.Call(vm, nil)
if e != nil {
t.Fatalf("Call returned error: %v", e)
@ -86,7 +86,7 @@ func TestVm(t *testing.T) {
t.Skip("skipping for mutan version", mutan.Version, " < 0.6")
}
closure, vm := setup(ethlog.DebugLevel, StandardVmTy)
closure, vm := setup(logger.DebugLevel, StandardVmTy)
ret, _, e := closure.Call(vm, nil)
if e != nil {
t.Fatalf("Call returned error: %v", e)
@ -97,7 +97,7 @@ func TestVm(t *testing.T) {
}
func BenchmarkDebugVm(b *testing.B) {
closure, vm := setup(ethlog.InfoLevel, DebugVmTy)
closure, vm := setup(logger.InfoLevel, DebugVmTy)
b.ResetTimer()
@ -107,7 +107,7 @@ func BenchmarkDebugVm(b *testing.B) {
}
func BenchmarkVm(b *testing.B) {
closure, vm := setup(ethlog.InfoLevel, StandardVmTy)
closure, vm := setup(logger.InfoLevel, StandardVmTy)
b.ResetTimer()
@ -122,11 +122,11 @@ func RunCode(mutCode string, typ Type) []byte {
log.Fatal(err)
}
ethlog.AddLogSystem(ethlog.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlog.InfoLevel))
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.InfoLevel))
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
stateObject := ethstate.NewStateObject([]byte{'j', 'e', 'f', 'f'})
stateObject := state.NewStateObject([]byte{'j', 'e', 'f', 'f'})
closure := NewClosure(nil, stateObject, stateObject, code, big.NewInt(1000000), big.NewInt(0))
vm := New(TestEnv{}, typ)
@ -148,7 +148,7 @@ func TestBuildInSha256(t *testing.T) {
return out
`, DebugVmTy)
exp := ethcrypto.Sha256(ethutil.LeftPadBytes([]byte{42}, 32))
exp := crypto.Sha256(ethutil.LeftPadBytes([]byte{42}, 32))
if bytes.Compare(ret, exp) != 0 {
t.Errorf("Expected %x, got %x", exp, ret)
}
@ -164,7 +164,7 @@ func TestBuildInRipemd(t *testing.T) {
return out
`, DebugVmTy)
exp := ethutil.RightPadBytes(ethcrypto.Ripemd160(ethutil.LeftPadBytes([]byte{42}, 32)), 32)
exp := ethutil.RightPadBytes(crypto.Ripemd160(ethutil.LeftPadBytes([]byte{42}, 32)), 32)
if bytes.Compare(ret, exp) != 0 {
t.Errorf("Expected %x, got %x", exp, ret)
}