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"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
"github.com/ethereum/go-ethereum/vm"
|
||||
)
|
||||
@ -195,9 +196,9 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
|
||||
vmenv := self.env
|
||||
var ref vm.ContextRef
|
||||
if MessageCreatesContract(msg) {
|
||||
//contract := makeContract(msg, self.state)
|
||||
//addr := contract.Address()
|
||||
ret, err, ref = vmenv.Create(sender, self.msg.Data(), self.gas, self.gasPrice, self.value)
|
||||
contract := makeContract(msg, self.state)
|
||||
addr := contract.Address()
|
||||
ret, err, ref = vmenv.Create(sender, &addr, self.msg.Data(), self.gas, self.gasPrice, self.value)
|
||||
if err == nil {
|
||||
dataGas := big.NewInt(int64(len(ret)))
|
||||
dataGas.Mul(dataGas, vm.GasCreateByte)
|
||||
@ -243,13 +244,11 @@ func (self *StateTransition) gasUsed() *big.Int {
|
||||
|
||||
// Converts an message in to a state object
|
||||
func makeContract(msg Message, state *state.StateDB) *state.StateObject {
|
||||
/*
|
||||
addr := AddressFromMessage(msg)
|
||||
faddr, _ := msg.From()
|
||||
addr := crypto.CreateAddress(faddr, msg.Nonce())
|
||||
|
||||
contract := state.GetOrNewStateObject(addr)
|
||||
contract.SetInitCode(msg.Data())
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func (self *VMEnv) Create(me vm.ContextRef, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
|
||||
exe := self.vm(nil, data, gas, price, value)
|
||||
func (self *VMEnv) Create(me vm.ContextRef, addr *common.Address, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
|
||||
exe := self.vm(addr, data, gas, price, value)
|
||||
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)
|
||||
}
|
||||
|
||||
func (self *Env) Create(caller vm.ContextRef, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
|
||||
exe := self.vm(nil, data, gas, price, value)
|
||||
func (self *Env) Create(caller vm.ContextRef, addr *common.Address, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
|
||||
exe := self.vm(addr, data, gas, price, value)
|
||||
if self.vmTest {
|
||||
caller.ReturnGas(gas, price)
|
||||
|
||||
|
@ -11,7 +11,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
"github.com/ethereum/go-ethereum/tests/helper"
|
||||
"github.com/ethereum/go-ethereum/vm"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
@ -81,11 +80,6 @@ func RunVmTest(p string, t *testing.T) {
|
||||
helper.CreateFileTests(t, p, &tests)
|
||||
|
||||
for name, test := range tests {
|
||||
helper.Logger.SetLogLevel(5)
|
||||
vm.Debug = true
|
||||
if name != "TransactionCreateSuicideContract" {
|
||||
continue
|
||||
}
|
||||
db, _ := ethdb.NewMemDatabase()
|
||||
statedb := state.New(common.Hash{}, db)
|
||||
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)
|
||||
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 {
|
||||
|
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()
|
||||
|
||||
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 {
|
||||
stack.push(common.BigFalse)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user