diff options
author | obscuren <geffobscura@gmail.com> | 2014-10-23 07:01:26 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-10-23 07:01:26 +0800 |
commit | 29b8a0bc5ffa7a674a06a211e1c8bdd1b6ed07b1 (patch) | |
tree | cd850fc126869e382ceb56f546aa579b37f7b63d /ethchain | |
parent | 51ecab6967a15b82f9285cd0ffd3352607dc8612 (diff) | |
download | dexon-29b8a0bc5ffa7a674a06a211e1c8bdd1b6ed07b1.tar dexon-29b8a0bc5ffa7a674a06a211e1c8bdd1b6ed07b1.tar.gz dexon-29b8a0bc5ffa7a674a06a211e1c8bdd1b6ed07b1.tar.bz2 dexon-29b8a0bc5ffa7a674a06a211e1c8bdd1b6ed07b1.tar.lz dexon-29b8a0bc5ffa7a674a06a211e1c8bdd1b6ed07b1.tar.xz dexon-29b8a0bc5ffa7a674a06a211e1c8bdd1b6ed07b1.tar.zst dexon-29b8a0bc5ffa7a674a06a211e1c8bdd1b6ed07b1.zip |
Updated the VM & VM tests
* Stack Error shouldn't revert to previous state
* Updated VM Test tool
* Added Transfer method to VM Env
Diffstat (limited to 'ethchain')
-rw-r--r-- | ethchain/chain_manager.go | 2 | ||||
-rw-r--r-- | ethchain/state_transition.go | 23 | ||||
-rw-r--r-- | ethchain/transaction_pool.go | 2 | ||||
-rw-r--r-- | ethchain/vm_env.go | 4 |
4 files changed, 11 insertions, 20 deletions
diff --git a/ethchain/chain_manager.go b/ethchain/chain_manager.go index 227b02c0a..9f82eae41 100644 --- a/ethchain/chain_manager.go +++ b/ethchain/chain_manager.go @@ -162,7 +162,7 @@ func AddTestNetFunds(block *Block) { } { codedAddr := ethutil.Hex2Bytes(addr) account := block.state.GetAccount(codedAddr) - account.Balance = ethutil.Big("1606938044258990275541962092341162602522202993782792835301376") //ethutil.BigPow(2, 200) + account.SetBalance(ethutil.Big("1606938044258990275541962092341162602522202993782792835301376")) //ethutil.BigPow(2, 200) block.state.UpdateStateObject(account) } } diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go index 79321eaac..1e6834729 100644 --- a/ethchain/state_transition.go +++ b/ethchain/state_transition.go @@ -89,8 +89,8 @@ func (self *StateTransition) BuyGas() error { var err error sender := self.Sender() - if sender.Balance.Cmp(self.tx.GasValue()) < 0 { - return fmt.Errorf("Insufficient funds to pre-pay gas. Req %v, has %v", self.tx.GasValue(), sender.Balance) + if sender.Balance().Cmp(self.tx.GasValue()) < 0 { + return fmt.Errorf("Insufficient funds to pre-pay gas. Req %v, has %v", self.tx.GasValue(), sender.Balance()) } coinbase := self.Coinbase() @@ -171,7 +171,7 @@ func (self *StateTransition) TransitionState() (err error) { return } - if sender.Balance.Cmp(self.value) < 0 { + if sender.Balance().Cmp(self.value) < 0 { return fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, sender.Balance) } @@ -243,19 +243,6 @@ func (self *StateTransition) TransitionState() (err error) { return } -func (self *StateTransition) transferValue(sender, receiver *ethstate.StateObject) error { - if sender.Balance.Cmp(self.value) < 0 { - return fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, sender.Balance) - } - - // Subtract the amount from the senders account - sender.SubAmount(self.value) - // Add the amount to receivers account which should conclude this transaction - receiver.AddAmount(self.value) - - return nil -} - func (self *StateTransition) Eval(msg *ethstate.Message, script []byte, context *ethstate.StateObject) (ret []byte, err error) { var ( transactor = self.Sender() @@ -265,9 +252,9 @@ func (self *StateTransition) Eval(msg *ethstate.Message, script []byte, context ) //vm := vm.New(env, vm.Type(ethutil.Config.VmType)) - vm := vm.New(env, vm.DebugVmTy) + evm := vm.New(env, vm.DebugVmTy) - ret, _, err = callerClosure.Call(vm, self.tx.Data) + ret, _, err = callerClosure.Call(evm, self.tx.Data) return } diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go index ff3184582..0ddc4e435 100644 --- a/ethchain/transaction_pool.go +++ b/ethchain/transaction_pool.go @@ -117,7 +117,7 @@ func (pool *TxPool) ValidateTransaction(tx *Transaction) error { totAmount := new(big.Int).Set(tx.Value) // Make sure there's enough in the sender's account. Having insufficient // funds won't invalidate this transaction but simple ignores it. - if sender.Balance.Cmp(totAmount) < 0 { + if sender.Balance().Cmp(totAmount) < 0 { return fmt.Errorf("[TXPL] Insufficient amount in sender's (%x) account", tx.Sender()) } diff --git a/ethchain/vm_env.go b/ethchain/vm_env.go index 4600878d1..36c9d6002 100644 --- a/ethchain/vm_env.go +++ b/ethchain/vm_env.go @@ -4,6 +4,7 @@ import ( "math/big" "github.com/ethereum/eth-go/ethstate" + "github.com/ethereum/eth-go/vm" ) type VMEnv struct { @@ -30,3 +31,6 @@ func (self *VMEnv) BlockHash() []byte { return self.block.Hash() } func (self *VMEnv) Value() *big.Int { return self.tx.Value } func (self *VMEnv) State() *ethstate.State { return self.state } func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit } +func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { + return vm.Transfer(from, to, amount) +} |