From 198cc69357a0f25ae486a041786e1239c6f5ab0f Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 21:58:26 +0100 Subject: Gas corrections and vm fixes --- tests/vm/gh_test.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'tests/vm/gh_test.go') diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index da5a41251..42dcc0ae1 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" ) @@ -76,11 +77,18 @@ func RunVmTest(p string, t *testing.T) { tests := make(map[string]VmTest) helper.CreateFileTests(t, p, &tests) + helper.Logger.SetLogLevel(5) for name, test := range tests { + if name != "ABAcalls1" { + continue + } statedb := state.New(helper.NewTrie()) 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... @@ -129,6 +137,16 @@ func RunVmTest(p string, t *testing.T) { 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) @@ -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) +} -- cgit v1.2.3 From 332568379454dce6b1fb3c3e023a53d0c52cded0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 22:38:51 +0100 Subject: Fixed refund model --- tests/vm/gh_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/vm/gh_test.go') diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 42dcc0ae1..ca63b90d3 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -77,11 +77,11 @@ func RunVmTest(p string, t *testing.T) { tests := make(map[string]VmTest) helper.CreateFileTests(t, p, &tests) - helper.Logger.SetLogLevel(5) + //helper.Logger.SetLogLevel(5) for name, test := range tests { - if name != "ABAcalls1" { - continue - } + // if name != "refund50_1" { + // continue + // } statedb := state.New(helper.NewTrie()) for addr, account := range test.Pre { obj := StateObjectFromAccount(addr, account) -- cgit v1.2.3 From 4789084998553befa5db1bfe5a14881aa567cb9e Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 23:32:58 +0100 Subject: updated tests --- tests/vm/gh_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/vm/gh_test.go') diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index ca63b90d3..10d63897d 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -77,11 +77,11 @@ func RunVmTest(p string, t *testing.T) { tests := make(map[string]VmTest) helper.CreateFileTests(t, p, &tests) - //helper.Logger.SetLogLevel(5) + helper.Logger.SetLogLevel(5) for name, test := range tests { - // if name != "refund50_1" { - // continue - // } + if name != "CallRecursiveBomb0" { + continue + } statedb := state.New(helper.NewTrie()) for addr, account := range test.Pre { obj := StateObjectFromAccount(addr, account) -- cgit v1.2.3 From a7f4ade7114ee962110cb7c140e7ce7bd3f6664f Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Dec 2014 23:59:53 +0100 Subject: Fixed tests --- tests/vm/gh_test.go | 4 ---- 1 file changed, 4 deletions(-) (limited to 'tests/vm/gh_test.go') diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 10d63897d..1efda7fe0 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -77,11 +77,7 @@ func RunVmTest(p string, t *testing.T) { tests := make(map[string]VmTest) helper.CreateFileTests(t, p, &tests) - helper.Logger.SetLogLevel(5) for name, test := range tests { - if name != "CallRecursiveBomb0" { - continue - } statedb := state.New(helper.NewTrie()) for addr, account := range test.Pre { obj := StateObjectFromAccount(addr, account) -- cgit v1.2.3 From 16460b0048b738b0474bc1556d0df469f64bcf26 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 30 Dec 2014 17:16:28 +0100 Subject: Fixed gas check for vm test --- tests/vm/gh_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'tests/vm/gh_test.go') diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 1efda7fe0..e06b0ed82 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -107,7 +107,9 @@ 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) @@ -124,10 +126,14 @@ 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) + } } } -- cgit v1.2.3 From a4dc12f12c7a06f5e28d5b1e760249875ef7a8c5 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 31 Dec 2014 11:21:39 +0100 Subject: Additional comments and added name to error output --- tests/vm/gh_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'tests/vm/gh_test.go') diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index e06b0ed82..f1e4d1acc 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -108,17 +108,16 @@ func RunVmTest(p string, t *testing.T) { ) 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) @@ -160,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)) { -- cgit v1.2.3