aboutsummaryrefslogtreecommitdiffstats
path: root/tests/vm/gh_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-02 17:30:27 +0800
committerobscuren <geffobscura@gmail.com>2015-01-02 17:30:27 +0800
commit0fb1bcd32192b8bf05a328b955a08da4cefe0180 (patch)
tree67460b927eb41b2876e8e6b7eb9dece494dbd088 /tests/vm/gh_test.go
parent8da07e91e40c1d1bb43763b7e959ae92e5770af2 (diff)
parenta4dc12f12c7a06f5e28d5b1e760249875ef7a8c5 (diff)
downloadgo-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar
go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar.gz
go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar.bz2
go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar.lz
go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar.xz
go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.tar.zst
go-tangerine-0fb1bcd32192b8bf05a328b955a08da4cefe0180.zip
Merge branch 'poc8' into docbranch
Diffstat (limited to 'tests/vm/gh_test.go')
-rw-r--r--tests/vm/gh_test.go44
1 files changed, 34 insertions, 10 deletions
diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go
index da5a41251..f1e4d1acc 100644
--- a/tests/vm/gh_test.go
+++ b/tests/vm/gh_test.go
@@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/tests/helper"
)
@@ -81,6 +82,9 @@ func RunVmTest(p string, t *testing.T) {
for addr, account := range test.Pre {
obj := StateObjectFromAccount(addr, account)
statedb.SetStateObject(obj)
+ for a, v := range account.Storage {
+ obj.SetState(helper.FromHex(a), ethutil.NewValue(helper.FromHex(v)))
+ }
}
// XXX Yeah, yeah...
@@ -103,16 +107,17 @@ func RunVmTest(p string, t *testing.T) {
logs state.Logs
)
- if len(test.Exec) > 0 {
+ isVmTest := len(test.Exec) > 0
+ if isVmTest {
ret, logs, gas, err = helper.RunVm(statedb, env, test.Exec)
} else {
ret, logs, gas, err = helper.RunState(statedb, env, test.Transaction)
}
- // When an error is returned it doesn't always mean the tests fails.
- // Have to come up with some conditional failing mechanism.
+ // Log the error if there is one. Error does not mean failing test.
+ // A test fails if err != nil and post params are specified in the test.
if err != nil {
- helper.Log.Infoln(err)
+ helper.Log.Infof("%s's: %v\n", name, err)
}
rexp := helper.FromHex(test.Out)
@@ -120,15 +125,29 @@ func RunVmTest(p string, t *testing.T) {
t.Errorf("%s's return failed. Expected %x, got %x\n", name, rexp, ret)
}
- if len(test.Gas) > 0 {
- gexp := ethutil.Big(test.Gas)
- if gexp.Cmp(gas) != 0 {
- t.Errorf("%s's gas failed. Expected %v, got %v\n", name, gexp, gas)
+ if isVmTest {
+ if len(test.Gas) == 0 && err == nil {
+ t.Errorf("%s's gas unspecified, indicating an error. VM returned (incorrectly) successfull")
+ } else {
+ 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 := statedb.GetStateObject(helper.FromHex(addr))
+ if obj == nil {
+ continue
+ }
+
+ if len(test.Exec) == 0 {
+ if obj.Balance().Cmp(ethutil.Big(account.Balance)) != 0 {
+ t.Errorf("%s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(ethutil.Big(account.Balance), obj.Balance()))
+ }
+ }
+
for addr, value := range account.Storage {
v := obj.GetState(helper.FromHex(addr)).Bytes()
vexp := helper.FromHex(value)
@@ -140,7 +159,6 @@ func RunVmTest(p string, t *testing.T) {
}
if len(test.Logs) > 0 {
- // Logs within the test itself aren't correct, missing empty fields (32 0s)
for i, log := range test.Logs {
genBloom := ethutil.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 64)
if !bytes.Equal(genBloom, ethutil.Hex2Bytes(log.BloomF)) {
@@ -149,6 +167,7 @@ func RunVmTest(p string, t *testing.T) {
}
}
}
+ logger.Flush()
}
// I've created a new function for each tests so it's easier to identify where the problem lies if any of them fail.
@@ -212,7 +231,12 @@ func TestStateRecursiveCreate(t *testing.T) {
RunVmTest(fn, t)
}
-func TestStateSpecialTest(t *testing.T) {
+func TestStateSpecial(t *testing.T) {
const fn = "../files/StateTests/stSpecialTest.json"
RunVmTest(fn, t)
}
+
+func TestStateRefund(t *testing.T) {
+ const fn = "../files/StateTests/stRefundTest.json"
+ RunVmTest(fn, t)
+}