From a22056db5988bfa2b1354e0092eabb734c30701c Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 1 Dec 2014 20:49:56 +0100 Subject: Make an attempt to pay for the gas prior to expanding the mem. --- tests/vm/gh_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests/vm') diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 7d98983e7..bd107249b 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -2,6 +2,7 @@ package vm import ( "bytes" + "fmt" "testing" "github.com/ethereum/go-ethereum/ethutil" @@ -44,6 +45,7 @@ func RunVmTest(p string, t *testing.T) { helper.CreateFileTests(t, p, &tests) for name, test := range tests { + fmt.Println(name) state := state.New(helper.NewTrie()) for addr, account := range test.Pre { obj := StateObjectFromAccount(addr, account) @@ -113,7 +115,7 @@ func TestEnvironmentalInfo(t *testing.T) { } func TestFlowOperation(t *testing.T) { - helper.Logger.SetLogLevel(5) + //helper.Logger.SetLogLevel(5) const fn = "../files/vmtests/vmIOandFlowOperationsTest.json" RunVmTest(fn, t) } @@ -124,6 +126,7 @@ func TestPushDupSwap(t *testing.T) { } func TestVMSha3(t *testing.T) { + helper.Logger.SetLogLevel(5) const fn = "../files/vmtests/vmSha3Test.json" RunVmTest(fn, t) } -- cgit v1.2.3 From a052357872217d5e99e7ee1a7a4b524b53addcdd Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 1 Dec 2014 22:05:38 +0100 Subject: Fixed EXP gas --- tests/vm/gh_test.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'tests/vm') diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index bd107249b..eb641b034 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -2,7 +2,6 @@ package vm import ( "bytes" - "fmt" "testing" "github.com/ethereum/go-ethereum/ethutil" @@ -45,7 +44,6 @@ func RunVmTest(p string, t *testing.T) { helper.CreateFileTests(t, p, &tests) for name, test := range tests { - fmt.Println(name) state := state.New(helper.NewTrie()) for addr, account := range test.Pre { obj := StateObjectFromAccount(addr, account) @@ -85,20 +83,10 @@ func RunVmTest(p 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 TestVMArithmetic(t *testing.T) { - //helper.Logger.SetLogLevel(5) const fn = "../files/vmtests/vmArithmeticTest.json" RunVmTest(fn, t) } -/* -deleted? -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) @@ -126,7 +114,7 @@ func TestPushDupSwap(t *testing.T) { } func TestVMSha3(t *testing.T) { - helper.Logger.SetLogLevel(5) + //helper.Logger.SetLogLevel(5) const fn = "../files/vmtests/vmSha3Test.json" RunVmTest(fn, t) } -- cgit v1.2.3 From 2df8ad6307d741d0a6d2f746d53f97c7b27ad796 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 2 Dec 2014 00:03:53 +0100 Subject: Added state tests --- tests/vm/gh_test.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) (limited to 'tests/vm') diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index eb641b034..7e6160860 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -2,6 +2,8 @@ package vm import ( "bytes" + "math/big" + "strconv" "testing" "github.com/ethereum/go-ethereum/ethutil" @@ -29,10 +31,21 @@ func StateObjectFromAccount(addr string, account Account) *state.StateObject { return obj } +type Env struct { + CurrentCoinbase string + CurrentDifficulty string + CurrentGasLimit string + CurrentNumber string + CurrentTimestamp interface{} + PreviousHash string +} + type VmTest struct { Callcreates interface{} - Env map[string]string + //Env map[string]string + Env Env Exec map[string]string + Transaction map[string]string Gas string Out string Post map[string]Account @@ -50,7 +63,31 @@ func RunVmTest(p string, t *testing.T) { state.SetStateObject(obj) } - ret, gas, err := helper.RunVm(state, test.Env, test.Exec) + // XXX Yeah, yeah... + env := make(map[string]string) + env["currentCoinbase"] = test.Env.CurrentCoinbase + env["currentDifficulty"] = test.Env.CurrentDifficulty + env["currentGasLimit"] = test.Env.CurrentGasLimit + env["currentNumber"] = test.Env.CurrentNumber + env["previousHash"] = test.Env.PreviousHash + if n, ok := test.Env.CurrentTimestamp.(float64); ok { + env["currentTimestamp"] = strconv.Itoa(int(n)) + } else { + env["currentTimestamp"] = test.Env.CurrentTimestamp.(string) + } + + var ( + ret []byte + gas *big.Int + err error + ) + + if len(test.Exec) > 0 { + ret, gas, err = helper.RunVm(state, env, test.Exec) + } else { + ret, gas, err = helper.RunState(state, 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. if err != nil { @@ -62,9 +99,11 @@ func RunVmTest(p string, t *testing.T) { 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) + 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) + } } for addr, account := range test.Post { @@ -123,3 +162,23 @@ func TestVm(t *testing.T) { const fn = "../files/vmtests/vmtests.json" RunVmTest(fn, t) } + +func TestStateSystemOperations(t *testing.T) { + const fn = "../files/StateTests/stSystemOperationsTest.json" + RunVmTest(fn, t) +} + +func TestStatePreCompiledContracts(t *testing.T) { + const fn = "../files/StateTests/stPreCompiledContracts.json" + RunVmTest(fn, t) +} + +func TestStateRecursiveCreate(t *testing.T) { + const fn = "../files/StateTests/stRecursiveCreate.json" + RunVmTest(fn, t) +} + +func TestStateSpecialTest(t *testing.T) { + const fn = "../files/StateTests/stSpecialTest.json" + RunVmTest(fn, t) +} -- cgit v1.2.3 From 99481a245adc2c4814ab6b38d94d63114f7bbb15 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 2 Dec 2014 11:37:33 +0100 Subject: Check for known block err and ignore --- tests/vm/gh_test.go | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/vm') diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go index 7e6160860..5391e0500 100644 --- a/tests/vm/gh_test.go +++ b/tests/vm/gh_test.go @@ -142,7 +142,6 @@ func TestEnvironmentalInfo(t *testing.T) { } func TestFlowOperation(t *testing.T) { - //helper.Logger.SetLogLevel(5) const fn = "../files/vmtests/vmIOandFlowOperationsTest.json" RunVmTest(fn, t) } @@ -153,7 +152,6 @@ func TestPushDupSwap(t *testing.T) { } func TestVMSha3(t *testing.T) { - //helper.Logger.SetLogLevel(5) const fn = "../files/vmtests/vmSha3Test.json" RunVmTest(fn, t) } -- cgit v1.2.3