diff options
author | obscuren <geffobscura@gmail.com> | 2015-01-12 21:40:40 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-01-12 21:40:40 +0800 |
commit | 75cd9cd2de315f8680ff6a382e9b3bd48e17ecad (patch) | |
tree | 7bd375c116a705862dfa8a0e32b49e634733d60d | |
parent | 00348756bce00c2d19f16ce8df5eff7a62f5cfc6 (diff) | |
download | dexon-75cd9cd2de315f8680ff6a382e9b3bd48e17ecad.tar dexon-75cd9cd2de315f8680ff6a382e9b3bd48e17ecad.tar.gz dexon-75cd9cd2de315f8680ff6a382e9b3bd48e17ecad.tar.bz2 dexon-75cd9cd2de315f8680ff6a382e9b3bd48e17ecad.tar.lz dexon-75cd9cd2de315f8680ff6a382e9b3bd48e17ecad.tar.xz dexon-75cd9cd2de315f8680ff6a382e9b3bd48e17ecad.tar.zst dexon-75cd9cd2de315f8680ff6a382e9b3bd48e17ecad.zip |
updated tests
-rw-r--r-- | core/execution.go | 15 | ||||
-rw-r--r-- | tests/files/VMTests/RandomTests/201501121148GO.json | 31 | ||||
-rw-r--r-- | tests/files/VMTests/RandomTests/201501121149GO.json | 31 | ||||
-rw-r--r-- | tests/files/VMTests/RandomTests/201501121151GO.json | 31 | ||||
-rw-r--r-- | tests/files/VMTests/RandomTests/201501121256GO.json | 46 | ||||
-rw-r--r-- | tests/files/VMTests/RandomTests/201501121301GO.json | 47 | ||||
-rw-r--r-- | tests/files/VMTests/RandomTests/201501121303GO.json | 47 | ||||
-rw-r--r-- | tests/helper/vm.go | 8 | ||||
-rw-r--r-- | vm/vm_debug.go | 4 |
9 files changed, 247 insertions, 13 deletions
diff --git a/core/execution.go b/core/execution.go index 43f4b58fb..1057089f1 100644 --- a/core/execution.go +++ b/core/execution.go @@ -13,7 +13,6 @@ type Execution struct { env vm.Environment address, input []byte Gas, price, value *big.Int - SkipTransfer bool } func NewExecution(env vm.Environment, address, input []byte, gas, gasPrice, value *big.Int) *Execution { @@ -43,14 +42,12 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ContextRef) (ret from, to := env.State().GetStateObject(caller.Address()), env.State().GetOrNewStateObject(self.address) // Skipping transfer is used on testing for the initial call - if !self.SkipTransfer { - err = env.Transfer(from, to, self.value) - if err != nil { - caller.ReturnGas(self.Gas, self.price) - - err = fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, from.Balance) - return - } + err = env.Transfer(from, to, self.value) + if err != nil { + caller.ReturnGas(self.Gas, self.price) + + err = fmt.Errorf("insufficient funds to transfer value. Req %v, has %v", self.value, from.Balance()) + return } snapshot := env.State().Copy() diff --git a/tests/files/VMTests/RandomTests/201501121148GO.json b/tests/files/VMTests/RandomTests/201501121148GO.json new file mode 100644 index 000000000..fb72e9c9f --- /dev/null +++ b/tests/files/VMTests/RandomTests/201501121148GO.json @@ -0,0 +1,31 @@ +{ + "randomVMtest" : { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "256", + "currentGasLimit" : "1000000", + "currentNumber" : "0", + "currentTimestamp" : "1", + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "code" : "0x0c", + "data" : "0x", + "gas" : "10000", + "gasPrice" : "100000000000000", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x0c", + "nonce" : "0", + "storage" : { + } + } + } + } +} diff --git a/tests/files/VMTests/RandomTests/201501121149GO.json b/tests/files/VMTests/RandomTests/201501121149GO.json new file mode 100644 index 000000000..bd8a769ae --- /dev/null +++ b/tests/files/VMTests/RandomTests/201501121149GO.json @@ -0,0 +1,31 @@ +{ + "randomVMtest" : { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "256", + "currentGasLimit" : "1000000", + "currentNumber" : "0", + "currentTimestamp" : "1", + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "code" : "0x0c0b8a4494328e02", + "data" : "0x", + "gas" : "10000", + "gasPrice" : "100000000000000", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x0c0b8a4494328e02", + "nonce" : "0", + "storage" : { + } + } + } + } +} diff --git a/tests/files/VMTests/RandomTests/201501121151GO.json b/tests/files/VMTests/RandomTests/201501121151GO.json new file mode 100644 index 000000000..56904da1b --- /dev/null +++ b/tests/files/VMTests/RandomTests/201501121151GO.json @@ -0,0 +1,31 @@ +{ + "randomVMtest" : { + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "256", + "currentGasLimit" : "1000000", + "currentNumber" : "0", + "currentTimestamp" : "1", + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "code" : "0x590c", + "data" : "0x", + "gas" : "10000", + "gasPrice" : "100000000000000", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000" + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x590c", + "nonce" : "0", + "storage" : { + } + } + } + } +} diff --git a/tests/files/VMTests/RandomTests/201501121256GO.json b/tests/files/VMTests/RandomTests/201501121256GO.json new file mode 100644 index 000000000..156805eb4 --- /dev/null +++ b/tests/files/VMTests/RandomTests/201501121256GO.json @@ -0,0 +1,46 @@ +{ + "randomVMtest" : { + "callcreates" : [ + ], + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "115792089237316195423570985008687907853269984665640564039457584007913129639935", + "currentGasLimit" : "1000000", + "currentNumber" : "0", + "currentTimestamp" : "2", + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "code" : "0x4542424283434544f063ff78ff1355", + "data" : "0x", + "gas" : "10000", + "gasPrice" : "100000000000000", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000" + }, + "gas" : "9791", + "logs" : [ + ], + "out" : "0x", + "post" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x4542424283434544f063ff78ff1355", + "nonce" : "0", + "storage" : { + } + } + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x4542424283434544f063ff78ff1355", + "nonce" : "0", + "storage" : { + } + } + } + } +} diff --git a/tests/files/VMTests/RandomTests/201501121301GO.json b/tests/files/VMTests/RandomTests/201501121301GO.json new file mode 100644 index 000000000..b392bedd5 --- /dev/null +++ b/tests/files/VMTests/RandomTests/201501121301GO.json @@ -0,0 +1,47 @@ +{ + "randomVMtest" : { + "callcreates" : [ + ], + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "115792089237316195423570985008687907853269984665640564039457584007913129639935", + "currentGasLimit" : "1000000", + "currentNumber" : "0", + "currentTimestamp" : "2", + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "code" : "0x4545434244f04343161755", + "data" : "0x", + "gas" : "10000", + "gasPrice" : "100000000000000", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000" + }, + "gas" : "9591", + "logs" : [ + ], + "out" : "0x", + "post" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x4545434244f04343161755", + "nonce" : "0", + "storage" : { + "0x" : "0x0f4240" + } + } + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x4545434244f04343161755", + "nonce" : "0", + "storage" : { + } + } + } + } +} diff --git a/tests/files/VMTests/RandomTests/201501121303GO.json b/tests/files/VMTests/RandomTests/201501121303GO.json new file mode 100644 index 000000000..7e58edbae --- /dev/null +++ b/tests/files/VMTests/RandomTests/201501121303GO.json @@ -0,0 +1,47 @@ +{ + "randomVMtest" : { + "callcreates" : [ + ], + "env" : { + "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "currentDifficulty" : "115792089237316195423570985008687907853269984665640564039457584007913129639935", + "currentGasLimit" : "1000000", + "currentNumber" : "0", + "currentTimestamp" : "2", + "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" + }, + "exec" : { + "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", + "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "code" : "0x4245454345424344f055", + "data" : "0x", + "gas" : "10000", + "gasPrice" : "100000000000000", + "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", + "value" : "1000000000000000000" + }, + "gas" : "9591", + "logs" : [ + ], + "out" : "0x", + "post" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x4245454345424344f055", + "nonce" : "0", + "storage" : { + "0x" : "0x0f4240" + } + } + }, + "pre" : { + "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : { + "balance" : "1000000000000000000", + "code" : "0x4245454345424344f055", + "nonce" : "0", + "storage" : { + } + } + } + } +} diff --git a/tests/helper/vm.go b/tests/helper/vm.go index dac279753..797a2acf5 100644 --- a/tests/helper/vm.go +++ b/tests/helper/vm.go @@ -1,6 +1,7 @@ package helper import ( + "errors" "math/big" "github.com/ethereum/go-ethereum/core" @@ -66,12 +67,16 @@ func (self *Env) AddLog(log state.Log) { func (self *Env) Depth() int { return self.depth } func (self *Env) SetDepth(i int) { self.depth = i } func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error { + if self.skipTransfer { + if from.Balance().Cmp(amount) < 0 { + return errors.New("Insufficient balance in account") + } + } return vm.Transfer(from, to, amount) } func (self *Env) vm(addr, data []byte, gas, price, value *big.Int) *core.Execution { exec := core.NewExecution(self, addr, data, gas, price, value) - exec.SkipTransfer = self.skipTransfer return exec } @@ -104,6 +109,7 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log ) caller := state.GetOrNewStateObject(from) + caller.SetBalance(ethutil.Big("1000000000000000000")) vmenv := NewEnvFromMap(state, env, exec) vmenv.skipTransfer = true diff --git a/vm/vm_debug.go b/vm/vm_debug.go index eec8c518f..fee42d3d8 100644 --- a/vm/vm_debug.go +++ b/vm/vm_debug.go @@ -743,9 +743,7 @@ func (self *DebugVm) Run(me, caller ContextRef, code []byte, value, gas, price * default: vmlogger.Debugf("(pc) %-3v Invalid opcode %x\n", pc, op) - context.ReturnGas(big.NewInt(1), nil) - - return context.Return(nil), fmt.Errorf("Invalid opcode %x", op) + panic(fmt.Errorf("Invalid opcode %x", op)) } pc++ |