|
|
@ -6,6 +6,7 @@ import ( |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/chain" |
|
|
|
"github.com/ethereum/go-ethereum/ethutil" |
|
|
|
"github.com/ethereum/go-ethereum/ethutil" |
|
|
|
"github.com/ethereum/go-ethereum/state" |
|
|
|
"github.com/ethereum/go-ethereum/state" |
|
|
|
"github.com/ethereum/go-ethereum/tests/helper" |
|
|
|
"github.com/ethereum/go-ethereum/tests/helper" |
|
|
@ -18,6 +19,12 @@ type Account struct { |
|
|
|
Storage map[string]string |
|
|
|
Storage map[string]string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Log struct { |
|
|
|
|
|
|
|
Address string |
|
|
|
|
|
|
|
Data string |
|
|
|
|
|
|
|
Topics []string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func StateObjectFromAccount(addr string, account Account) *state.StateObject { |
|
|
|
func StateObjectFromAccount(addr string, account Account) *state.StateObject { |
|
|
|
obj := state.NewStateObject(ethutil.Hex2Bytes(addr)) |
|
|
|
obj := state.NewStateObject(ethutil.Hex2Bytes(addr)) |
|
|
|
obj.SetBalance(ethutil.Big(account.Balance)) |
|
|
|
obj.SetBalance(ethutil.Big(account.Balance)) |
|
|
@ -46,6 +53,7 @@ type VmTest struct { |
|
|
|
Env Env |
|
|
|
Env Env |
|
|
|
Exec map[string]string |
|
|
|
Exec map[string]string |
|
|
|
Transaction map[string]string |
|
|
|
Transaction map[string]string |
|
|
|
|
|
|
|
Logs map[string]Log |
|
|
|
Gas string |
|
|
|
Gas string |
|
|
|
Out string |
|
|
|
Out string |
|
|
|
Post map[string]Account |
|
|
|
Post map[string]Account |
|
|
@ -57,10 +65,10 @@ func RunVmTest(p string, t *testing.T) { |
|
|
|
helper.CreateFileTests(t, p, &tests) |
|
|
|
helper.CreateFileTests(t, p, &tests) |
|
|
|
|
|
|
|
|
|
|
|
for name, test := range tests { |
|
|
|
for name, test := range tests { |
|
|
|
state := state.New(helper.NewTrie()) |
|
|
|
statedb := state.New(helper.NewTrie()) |
|
|
|
for addr, account := range test.Pre { |
|
|
|
for addr, account := range test.Pre { |
|
|
|
obj := StateObjectFromAccount(addr, account) |
|
|
|
obj := StateObjectFromAccount(addr, account) |
|
|
|
state.SetStateObject(obj) |
|
|
|
statedb.SetStateObject(obj) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// XXX Yeah, yeah...
|
|
|
|
// XXX Yeah, yeah...
|
|
|
@ -80,12 +88,13 @@ func RunVmTest(p string, t *testing.T) { |
|
|
|
ret []byte |
|
|
|
ret []byte |
|
|
|
gas *big.Int |
|
|
|
gas *big.Int |
|
|
|
err error |
|
|
|
err error |
|
|
|
|
|
|
|
logs state.Logs |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if len(test.Exec) > 0 { |
|
|
|
if len(test.Exec) > 0 { |
|
|
|
ret, gas, err = helper.RunVm(state, env, test.Exec) |
|
|
|
ret, logs, gas, err = helper.RunVm(statedb, env, test.Exec) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ret, gas, err = helper.RunState(state, env, test.Transaction) |
|
|
|
ret, logs, gas, err = helper.RunState(statedb, env, test.Transaction) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// When an error is returned it doesn't always mean the tests fails.
|
|
|
|
// When an error is returned it doesn't always mean the tests fails.
|
|
|
@ -107,7 +116,7 @@ func RunVmTest(p string, t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for addr, account := range test.Post { |
|
|
|
for addr, account := range test.Post { |
|
|
|
obj := state.GetStateObject(helper.FromHex(addr)) |
|
|
|
obj := statedb.GetStateObject(helper.FromHex(addr)) |
|
|
|
for addr, value := range account.Storage { |
|
|
|
for addr, value := range account.Storage { |
|
|
|
v := obj.GetState(helper.FromHex(addr)).Bytes() |
|
|
|
v := obj.GetState(helper.FromHex(addr)).Bytes() |
|
|
|
vexp := helper.FromHex(value) |
|
|
|
vexp := helper.FromHex(value) |
|
|
@ -117,6 +126,16 @@ func RunVmTest(p string, t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(test.Logs) > 0 { |
|
|
|
|
|
|
|
genBloom := ethutil.LeftPadBytes(chain.LogsBloom(logs).Bytes(), 64) |
|
|
|
|
|
|
|
// Logs within the test itself aren't correct, missing empty fields (32 0s)
|
|
|
|
|
|
|
|
for bloom /*logs*/, _ := range test.Logs { |
|
|
|
|
|
|
|
if !bytes.Equal(genBloom, ethutil.Hex2Bytes(bloom)) { |
|
|
|
|
|
|
|
t.Errorf("bloom mismatch") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -161,6 +180,11 @@ func TestVm(t *testing.T) { |
|
|
|
RunVmTest(fn, t) |
|
|
|
RunVmTest(fn, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestVmLog(t *testing.T) { |
|
|
|
|
|
|
|
const fn = "../files/vmtests/vmLogTest.json" |
|
|
|
|
|
|
|
RunVmTest(fn, t) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestStateSystemOperations(t *testing.T) { |
|
|
|
func TestStateSystemOperations(t *testing.T) { |
|
|
|
const fn = "../files/StateTests/stSystemOperationsTest.json" |
|
|
|
const fn = "../files/StateTests/stSystemOperationsTest.json" |
|
|
|
RunVmTest(fn, t) |
|
|
|
RunVmTest(fn, t) |
|
|
|