Fixed VM & Tests w/ conversion
This commit is contained in:
parent
ff55c6f5ba
commit
0fa7859b94
15
common/types_test.go
Normal file
15
common/types_test.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestBytesConversion(t *testing.T) {
|
||||||
|
bytes := []byte{5}
|
||||||
|
hash := BytesToHash(bytes)
|
||||||
|
|
||||||
|
var exp Hash
|
||||||
|
exp[31] = 5
|
||||||
|
|
||||||
|
if hash != exp {
|
||||||
|
t.Errorf("expected %x got %x", exp, hash)
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/ethereum/go-ethereum/vm"
|
"github.com/ethereum/go-ethereum/vm"
|
||||||
)
|
)
|
||||||
@ -195,9 +196,9 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
|
|||||||
vmenv := self.env
|
vmenv := self.env
|
||||||
var ref vm.ContextRef
|
var ref vm.ContextRef
|
||||||
if MessageCreatesContract(msg) {
|
if MessageCreatesContract(msg) {
|
||||||
//contract := makeContract(msg, self.state)
|
contract := makeContract(msg, self.state)
|
||||||
//addr := contract.Address()
|
addr := contract.Address()
|
||||||
ret, err, ref = vmenv.Create(sender, self.msg.Data(), self.gas, self.gasPrice, self.value)
|
ret, err, ref = vmenv.Create(sender, &addr, self.msg.Data(), self.gas, self.gasPrice, self.value)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
dataGas := big.NewInt(int64(len(ret)))
|
dataGas := big.NewInt(int64(len(ret)))
|
||||||
dataGas.Mul(dataGas, vm.GasCreateByte)
|
dataGas.Mul(dataGas, vm.GasCreateByte)
|
||||||
@ -243,13 +244,11 @@ func (self *StateTransition) gasUsed() *big.Int {
|
|||||||
|
|
||||||
// Converts an message in to a state object
|
// Converts an message in to a state object
|
||||||
func makeContract(msg Message, state *state.StateDB) *state.StateObject {
|
func makeContract(msg Message, state *state.StateDB) *state.StateObject {
|
||||||
/*
|
faddr, _ := msg.From()
|
||||||
addr := AddressFromMessage(msg)
|
addr := crypto.CreateAddress(faddr, msg.Nonce())
|
||||||
|
|
||||||
contract := state.GetOrNewStateObject(addr)
|
contract := state.GetOrNewStateObject(addr)
|
||||||
contract.SetInitCode(msg.Data())
|
contract.SetInitCode(msg.Data())
|
||||||
|
|
||||||
return contract
|
return contract
|
||||||
*/
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func (self *VMEnv) CallCode(me vm.ContextRef, addr common.Address, data []byte,
|
|||||||
return exe.Call(addr, me)
|
return exe.Call(addr, me)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *VMEnv) Create(me vm.ContextRef, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
|
func (self *VMEnv) Create(me vm.ContextRef, addr *common.Address, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
|
||||||
exe := self.vm(nil, data, gas, price, value)
|
exe := self.vm(addr, data, gas, price, value)
|
||||||
return exe.Create(me)
|
return exe.Create(me)
|
||||||
}
|
}
|
||||||
|
@ -119,8 +119,8 @@ func (self *Env) CallCode(caller vm.ContextRef, addr common.Address, data []byte
|
|||||||
return exe.Call(addr, caller)
|
return exe.Call(addr, caller)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Env) Create(caller vm.ContextRef, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
|
func (self *Env) Create(caller vm.ContextRef, addr *common.Address, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
|
||||||
exe := self.vm(nil, data, gas, price, value)
|
exe := self.vm(addr, data, gas, price, value)
|
||||||
if self.vmTest {
|
if self.vmTest {
|
||||||
caller.ReturnGas(gas, price)
|
caller.ReturnGas(gas, price)
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ 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 {
|
||||||
@ -81,11 +80,6 @@ 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 {
|
||||||
helper.Logger.SetLogLevel(5)
|
|
||||||
vm.Debug = true
|
|
||||||
if name != "TransactionCreateSuicideContract" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
statedb := state.New(common.Hash{}, db)
|
statedb := state.New(common.Hash{}, db)
|
||||||
for addr, account := range test.Pre {
|
for addr, account := range test.Pre {
|
||||||
|
@ -31,7 +31,7 @@ type Environment interface {
|
|||||||
|
|
||||||
Call(me ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error)
|
Call(me ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error)
|
||||||
CallCode(me ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error)
|
CallCode(me ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error)
|
||||||
Create(me ContextRef, data []byte, gas, price, value *big.Int) ([]byte, error, ContextRef)
|
Create(me ContextRef, addr *common.Address, data []byte, gas, price, value *big.Int) ([]byte, error, ContextRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Account interface {
|
type Account interface {
|
||||||
|
2
vm/vm.go
2
vm/vm.go
@ -641,7 +641,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
|
|||||||
self.Endl()
|
self.Endl()
|
||||||
|
|
||||||
context.UseGas(context.Gas)
|
context.UseGas(context.Gas)
|
||||||
ret, suberr, ref := self.env.Create(context, input, gas, price, value)
|
ret, suberr, ref := self.env.Create(context, nil, input, gas, price, value)
|
||||||
if suberr != nil {
|
if suberr != nil {
|
||||||
stack.push(common.BigFalse)
|
stack.push(common.BigFalse)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user