diff options
author | obscuren <geffobscura@gmail.com> | 2014-10-17 00:27:05 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-10-17 00:27:05 +0800 |
commit | 93fcabd25189b447cc5c52523134cca2fa1d794e (patch) | |
tree | 152b24831fbb2d547bc2189b0b92a2b18c8f64b7 /tests | |
parent | bb5038699ef7e08054ef154107e359dce2e3b106 (diff) | |
download | go-tangerine-93fcabd25189b447cc5c52523134cca2fa1d794e.tar.gz go-tangerine-93fcabd25189b447cc5c52523134cca2fa1d794e.tar.zst go-tangerine-93fcabd25189b447cc5c52523134cca2fa1d794e.zip |
Fixed most of the tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/helper/init.go | 3 | ||||
-rw-r--r-- | tests/helper/vm.go | 18 | ||||
-rw-r--r-- | tests/vm/gh_test.go | 51 |
3 files changed, 49 insertions, 23 deletions
diff --git a/tests/helper/init.go b/tests/helper/init.go index 5f95dfc2f..7c34913fc 100644 --- a/tests/helper/init.go +++ b/tests/helper/init.go @@ -9,9 +9,10 @@ import ( ) var Logger ethlog.LogSystem +var Log = ethlog.NewLogger("TEST") func init() { - Logger = ethlog.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlog.LogLevel(4)) + Logger = ethlog.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlog.LogLevel(0)) ethlog.AddLogSystem(Logger) ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "") diff --git a/tests/helper/vm.go b/tests/helper/vm.go index 4a0d2f8b1..da06b2cc2 100644 --- a/tests/helper/vm.go +++ b/tests/helper/vm.go @@ -18,6 +18,7 @@ type Env struct { number *big.Int time int64 difficulty *big.Int + gasLimit *big.Int } func NewEnv(state *ethstate.State) *Env { @@ -33,7 +34,9 @@ func NewEnvFromMap(state *ethstate.State, envValues map[string]string, exeValues env.parent = ethutil.Hex2Bytes(envValues["previousHash"]) env.coinbase = ethutil.Hex2Bytes(envValues["currentCoinbase"]) env.number = ethutil.Big(envValues["currentNumber"]) - env.time = ethutil.Big(envValues["currentTime"]).Int64() + env.time = ethutil.Big(envValues["currentTimestamp"]).Int64() + env.difficulty = ethutil.Big(envValues["currentDifficulty"]) + env.gasLimit = ethutil.Big(envValues["currentGasLimit"]) return env } @@ -46,14 +49,17 @@ func (self *Env) Time() int64 { return self.time } func (self *Env) Difficulty() *big.Int { return self.difficulty } func (self *Env) BlockHash() []byte { return nil } func (self *Env) State() *ethstate.State { return self.state } +func (self *Env) GasLimit() *big.Int { return self.gasLimit } func RunVm(state *ethstate.State, env, exec map[string]string) ([]byte, *big.Int, error) { - caller := state.GetOrNewStateObject(ethutil.Hex2Bytes(exec["caller"])) - callee := state.GetStateObject(ethutil.Hex2Bytes(exec["address"])) - closure := ethvm.NewClosure(nil, caller, callee, callee.Code, ethutil.Big(exec["gas"]), ethutil.Big(exec["gasPrice"])) + address := FromHex(exec["address"]) + caller := state.GetOrNewStateObject(FromHex(exec["caller"])) + caller.Balance = ethutil.Big(exec["value"]) vm := ethvm.New(NewEnvFromMap(state, env, exec), ethvm.DebugVmTy) - ret, _, e := closure.Call(vm, nil) - return ret, closure.Gas, e + execution := ethvm.NewExecution(vm, address, FromHex(exec["data"]), ethutil.Big(exec["gas"]), ethutil.Big(exec["gasPrice"]), ethutil.Big(exec["value"])) + ret, err := execution.Exec(address, caller) + + return ret, execution.Gas, err } diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 6ae1cf29a..5de5b6433 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -2,7 +2,6 @@ package ethvm import ( "bytes" - "fmt" "testing" "github.com/ethereum/eth-go/ethstate" @@ -55,7 +54,7 @@ func RunVmTest(url string, t *testing.T) { // When an error is returned it doesn't always mean the tests fails. // Have to come up with some conditional failing mechanism. if err != nil { - fmt.Println(err) + helper.Log.Infoln(err) } /* if err != nil { @@ -80,7 +79,7 @@ func RunVmTest(url string, t *testing.T) { vexp := helper.FromHex(value) if bytes.Compare(v, vexp) != 0 { - t.Errorf("%s's : (%x: %s) storage failed. Expected %x, got %x\n", name, obj.Address()[0:4], addr, vexp, v) + t.Errorf("%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)\n", name, obj.Address()[0:4], addr, vexp, v, ethutil.BigD(vexp), ethutil.BigD(v)) } } } @@ -88,29 +87,49 @@ func RunVmTest(url string, t *testing.T) { } // I've created a new function for each tests so it's easier to identify where the problem lies if any of them fail. -func TestVMSha3(t *testing.T) { - helper.Logger.SetLogLevel(0) - defer helper.Logger.SetLogLevel(4) - const url = "https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmSha3Test.json" +func TestVMArithmetic(t *testing.T) { + const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmArithmeticTest.json" RunVmTest(url, t) } -func TestVMArithmetic(t *testing.T) { - helper.Logger.SetLogLevel(0) - defer helper.Logger.SetLogLevel(4) +func TestVMSystemOperation(t *testing.T) { + //helper.Logger.SetLogLevel(5) + const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmSystemOperationsTest.json" + RunVmTest(url, t) +} + +func TestBitwiseLogicOperation(t *testing.T) { + const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmBitwiseLogicOperationTest.json" + RunVmTest(url, t) +} + +func TestBlockInfo(t *testing.T) { + const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmBlockInfoTest.json" + RunVmTest(url, t) +} + +func TestEnvironmentalInfo(t *testing.T) { + const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmEnvironmentalInfoTest.json" + RunVmTest(url, t) +} - const url = "https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmArithmeticTest.json" +func TestFlowOperation(t *testing.T) { + const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmIOandFlowOperationsTest.json" RunVmTest(url, t) } -func TestVMSystemOperations(t *testing.T) { - const url = "https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmSystemOperationsTest.json" +func TestPushDupSwap(t *testing.T) { + const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmPushDupSwapTest.json" + RunVmTest(url, t) +} + +func TestVMSha3(t *testing.T) { + const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmSha3Test.json" RunVmTest(url, t) } -func TestOperations(t *testing.T) { - t.Skip() - const url = "https://raw.githubusercontent.com/ethereum/tests/master/vmtests/vmSystemOperationsTest.json" +func TestVm(t *testing.T) { + const url = "https://raw.githubusercontent.com/ethereum/tests/develop/vmtests/vmtests.json" RunVmTest(url, t) } |