aboutsummaryrefslogtreecommitdiffstats
path: root/tests/vm
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2014-10-23 21:01:27 +0800
committerFelix Lange <fjl@twurst.com>2014-10-23 21:01:27 +0800
commit69baa465ea69ae60eed802445cf0132b9eb69934 (patch)
treeb09da7582b5c4850d4db13aee808f2fef2f97de0 /tests/vm
parent50fd46924900869e7210217c6a07979b544991c8 (diff)
parentfeef194829b07570e91873ed5d1e8cc51e8fa430 (diff)
downloaddexon-69baa465ea69ae60eed802445cf0132b9eb69934.tar
dexon-69baa465ea69ae60eed802445cf0132b9eb69934.tar.gz
dexon-69baa465ea69ae60eed802445cf0132b9eb69934.tar.bz2
dexon-69baa465ea69ae60eed802445cf0132b9eb69934.tar.lz
dexon-69baa465ea69ae60eed802445cf0132b9eb69934.tar.xz
dexon-69baa465ea69ae60eed802445cf0132b9eb69934.tar.zst
dexon-69baa465ea69ae60eed802445cf0132b9eb69934.zip
Merge eth-go repository into go-ethereum
mist, etheruem have been moved to cmd/
Diffstat (limited to 'tests/vm')
-rw-r--r--tests/vm/.ethtest0
-rw-r--r--tests/vm/gh_test.go130
2 files changed, 130 insertions, 0 deletions
diff --git a/tests/vm/.ethtest b/tests/vm/.ethtest
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/vm/.ethtest
diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go
new file mode 100644
index 000000000..0d3c2f93d
--- /dev/null
+++ b/tests/vm/gh_test.go
@@ -0,0 +1,130 @@
+package vm
+
+import (
+ "bytes"
+ "testing"
+
+ "github.com/ethereum/go-ethereum/ethstate"
+ "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/tests/helper"
+)
+
+type Account struct {
+ Balance string
+ Code string
+ Nonce string
+ Storage map[string]string
+}
+
+func StateObjectFromAccount(addr string, account Account) *ethstate.StateObject {
+ obj := ethstate.NewStateObject(ethutil.Hex2Bytes(addr))
+ obj.SetBalance(ethutil.Big(account.Balance))
+
+ if ethutil.IsHex(account.Code) {
+ account.Code = account.Code[2:]
+ }
+ obj.Code = ethutil.Hex2Bytes(account.Code)
+ obj.Nonce = ethutil.Big(account.Nonce).Uint64()
+
+ return obj
+}
+
+type VmTest struct {
+ Callcreates interface{}
+ Env map[string]string
+ Exec map[string]string
+ Gas string
+ Out string
+ Post map[string]Account
+ Pre map[string]Account
+}
+
+func RunVmTest(p string, t *testing.T) {
+ tests := make(map[string]VmTest)
+ helper.CreateFileTests(t, p, &tests)
+
+ for name, test := range tests {
+ state := ethstate.New(helper.NewTrie())
+ for addr, account := range test.Pre {
+ obj := StateObjectFromAccount(addr, account)
+ state.SetStateObject(obj)
+ }
+
+ ret, gas, err := helper.RunVm(state, test.Env, test.Exec)
+ // 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 {
+ helper.Log.Infoln(err)
+ }
+
+ rexp := helper.FromHex(test.Out)
+ if bytes.Compare(rexp, ret) != 0 {
+ t.Errorf("%s's return failed. Expected %x, got %x\n", name, rexp, ret)
+ }
+
+ gexp := ethutil.Big(test.Gas)
+ if gexp.Cmp(gas) != 0 {
+ t.Errorf("%s's gas failed. Expected %v, got %v\n", name, gexp, gas)
+ }
+
+ for addr, account := range test.Post {
+ obj := state.GetStateObject(helper.FromHex(addr))
+ for addr, value := range account.Storage {
+ v := obj.GetState(helper.FromHex(addr)).Bytes()
+ vexp := helper.FromHex(value)
+
+ if bytes.Compare(v, vexp) != 0 {
+ 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))
+ }
+ }
+ }
+ }
+}
+
+// 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 TestVMArithmetic(t *testing.T) {
+ //helper.Logger.SetLogLevel(5)
+ const fn = "../files/vmtests/vmArithmeticTest.json"
+ RunVmTest(fn, t)
+}
+
+func TestVMSystemOperation(t *testing.T) {
+ //helper.Logger.SetLogLevel(5)
+ const fn = "../files/vmtests/vmSystemOperationsTest.json"
+ RunVmTest(fn, t)
+}
+
+func TestBitwiseLogicOperation(t *testing.T) {
+ const fn = "../files/vmtests/vmBitwiseLogicOperationTest.json"
+ RunVmTest(fn, t)
+}
+
+func TestBlockInfo(t *testing.T) {
+ const fn = "../files/vmtests/vmBlockInfoTest.json"
+ RunVmTest(fn, t)
+}
+
+func TestEnvironmentalInfo(t *testing.T) {
+ const fn = "../files/vmtests/vmEnvironmentalInfoTest.json"
+ RunVmTest(fn, t)
+}
+
+func TestFlowOperation(t *testing.T) {
+ const fn = "../files/vmtests/vmIOandFlowOperationsTest.json"
+ RunVmTest(fn, t)
+}
+
+func TestPushDupSwap(t *testing.T) {
+ const fn = "../files/vmtests/vmPushDupSwapTest.json"
+ RunVmTest(fn, t)
+}
+
+func TestVMSha3(t *testing.T) {
+ const fn = "../files/vmtests/vmSha3Test.json"
+ RunVmTest(fn, t)
+}
+
+func TestVm(t *testing.T) {
+ const fn = "../files/vmtests/vmtests.json"
+ RunVmTest(fn, t)
+}