fixed ethtest

This commit is contained in:
obscuren 2015-03-12 19:41:56 +01:00
parent d1c872bace
commit 347cb272be
4 changed files with 21 additions and 13 deletions

View File

@ -38,6 +38,7 @@ import (
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper" "github.com/ethereum/go-ethereum/tests/helper"
"github.com/ethereum/go-ethereum/vm"
) )
type Log struct { type Log struct {
@ -164,7 +165,7 @@ func RunVmTest(r io.Reader) (failed int) {
} }
if !bytes.Equal(ethutil.Hex2Bytes(test.PostStateRoot), statedb.Root()) { 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()) fmt.Printf("%s's : Post state root error. Expected %s, got %x\n", name, test.PostStateRoot, statedb.Root())
failed = 1 failed = 1
} }
@ -194,6 +195,7 @@ func RunVmTest(r io.Reader) (failed int) {
func main() { func main() {
helper.Logger.SetLogLevel(5) helper.Logger.SetLogLevel(5)
vm.Debug = true
if len(os.Args) > 1 { if len(os.Args) > 1 {
os.Exit(RunVmTest(strings.NewReader(os.Args[1]))) os.Exit(RunVmTest(strings.NewReader(os.Args[1])))

View File

@ -54,7 +54,7 @@ func (self *StateDB) Refund(addr []byte, gas *big.Int) {
// Retrieve the balance from the given address or 0 if object not found // Retrieve the balance from the given address or 0 if object not found
func (self *StateDB) GetBalance(addr []byte) *big.Int { func (self *StateDB) GetBalance(addr []byte) *big.Int {
stateObject := self.GetOrNewStateObject(addr) stateObject := self.GetStateObject(addr)
if stateObject != nil { if stateObject != nil {
return stateObject.balance return stateObject.balance
} }
@ -63,14 +63,14 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
} }
func (self *StateDB) AddBalance(addr []byte, amount *big.Int) { func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
stateObject := self.GetOrNewStateObject(addr) stateObject := self.GetStateObject(addr)
if stateObject != nil { if stateObject != nil {
stateObject.AddBalance(amount) stateObject.AddBalance(amount)
} }
} }
func (self *StateDB) GetNonce(addr []byte) uint64 { func (self *StateDB) GetNonce(addr []byte) uint64 {
stateObject := self.GetOrNewStateObject(addr) stateObject := self.GetStateObject(addr)
if stateObject != nil { if stateObject != nil {
return stateObject.nonce return stateObject.nonce
} }
@ -79,7 +79,7 @@ func (self *StateDB) GetNonce(addr []byte) uint64 {
} }
func (self *StateDB) GetCode(addr []byte) []byte { func (self *StateDB) GetCode(addr []byte) []byte {
stateObject := self.GetOrNewStateObject(addr) stateObject := self.GetStateObject(addr)
if stateObject != nil { if stateObject != nil {
return stateObject.code return stateObject.code
} }
@ -88,7 +88,7 @@ func (self *StateDB) GetCode(addr []byte) []byte {
} }
func (self *StateDB) GetState(a, b []byte) []byte { func (self *StateDB) GetState(a, b []byte) []byte {
stateObject := self.GetOrNewStateObject(a) stateObject := self.GetStateObject(a)
if stateObject != nil { if stateObject != nil {
return stateObject.GetState(b).Bytes() return stateObject.GetState(b).Bytes()
} }
@ -97,28 +97,28 @@ func (self *StateDB) GetState(a, b []byte) []byte {
} }
func (self *StateDB) SetNonce(addr []byte, nonce uint64) { func (self *StateDB) SetNonce(addr []byte, nonce uint64) {
stateObject := self.GetOrNewStateObject(addr) stateObject := self.GetStateObject(addr)
if stateObject != nil { if stateObject != nil {
stateObject.SetNonce(nonce) stateObject.SetNonce(nonce)
} }
} }
func (self *StateDB) SetCode(addr, code []byte) { func (self *StateDB) SetCode(addr, code []byte) {
stateObject := self.GetOrNewStateObject(addr) stateObject := self.GetStateObject(addr)
if stateObject != nil { if stateObject != nil {
stateObject.SetCode(code) stateObject.SetCode(code)
} }
} }
func (self *StateDB) SetState(addr, key []byte, value interface{}) { func (self *StateDB) SetState(addr, key []byte, value interface{}) {
stateObject := self.GetOrNewStateObject(addr) stateObject := self.GetStateObject(addr)
if stateObject != nil { if stateObject != nil {
stateObject.SetState(key, ethutil.NewValue(value)) stateObject.SetState(key, ethutil.NewValue(value))
} }
} }
func (self *StateDB) Delete(addr []byte) bool { func (self *StateDB) Delete(addr []byte) bool {
stateObject := self.GetOrNewStateObject(addr) stateObject := self.GetStateObject(addr)
if stateObject != nil { if stateObject != nil {
stateObject.MarkForDeletion() stateObject.MarkForDeletion()
stateObject.balance = new(big.Int) stateObject.balance = new(big.Int)

View File

@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper" "github.com/ethereum/go-ethereum/tests/helper"
"github.com/ethereum/go-ethereum/vm"
) )
type Account struct { type Account struct {
@ -80,6 +81,11 @@ func RunVmTest(p string, t *testing.T) {
helper.CreateFileTests(t, p, &tests) helper.CreateFileTests(t, p, &tests)
for name, test := range tests { for name, test := range tests {
vm.Debug = true
helper.Logger.SetLogLevel(4)
if name != "signextend_Overflow_dj42" {
continue
}
db, _ := ethdb.NewMemDatabase() db, _ := ethdb.NewMemDatabase()
statedb := state.New(nil, db) statedb := state.New(nil, db)
for addr, account := range test.Pre { for addr, account := range test.Pre {

View File

@ -235,9 +235,9 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
stack.push(base) stack.push(base)
case SIGNEXTEND: case SIGNEXTEND:
back := stack.pop().Uint64() back := stack.pop()
if back < 31 { if back.Cmp(big.NewInt(31)) < 0 {
bit := uint(back*8 + 7) bit := uint(back.Uint64()*8 + 7)
num := stack.pop() num := stack.pop()
mask := new(big.Int).Lsh(ethutil.Big1, bit) mask := new(big.Int).Lsh(ethutil.Big1, bit)
mask.Sub(mask, ethutil.Big1) mask.Sub(mask, ethutil.Big1)