forked from cerc-io/plugeth
Updated the VM & VM tests
* Stack Error shouldn't revert to previous state * Updated VM Test tool * Added Transfer method to VM Env
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user