diff --git a/common/types_test.go b/common/types_test.go new file mode 100644 index 0000000000..9f303152c4 --- /dev/null +++ b/common/types_test.go @@ -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) + } +} diff --git a/core/state_transition.go b/core/state_transition.go index 72999de7eb..1509a5258c 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -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()) + contract := state.GetOrNewStateObject(addr) + contract.SetInitCode(msg.Data()) - return contract - */ - return nil + return contract } diff --git a/core/vm_env.go b/core/vm_env.go index 1ddbd5e5ed..7845d1cd95 100644 --- a/core/vm_env.go +++ b/core/vm_env.go @@ -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) } diff --git a/tests/helper/vm.go b/tests/helper/vm.go index f59abd23ad..44c1088702 100644 --- a/tests/helper/vm.go +++ b/tests/helper/vm.go @@ -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) diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 159561c623..f352e862d2 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -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 { diff --git a/vm/environment.go b/vm/environment.go index 6976d6749b..fdce526eed 100644 --- a/vm/environment.go +++ b/vm/environment.go @@ -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 { diff --git a/vm/vm.go b/vm/vm.go index 706a3e1085..49e8cca98f 100644 --- a/vm/vm.go +++ b/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)