More consistent test interfaces + test skipping

This commit is contained in:
Taylor Gerring 2015-06-10 17:04:06 -04:00
parent b6d40a9312
commit ac0637c413
7 changed files with 108 additions and 78 deletions

View File

@ -6,38 +6,68 @@ import (
) )
func TestBcValidBlockTests(t *testing.T) { func TestBcValidBlockTests(t *testing.T) {
runBlockTestsInFile(filepath.Join(blockTestDir, "bcValidBlockTest.json"), []string{"SimpleTx3"}) err := RunBlockTest(filepath.Join(blockTestDir, "bcValidBlockTest.json"))
if err != nil {
t.Fatal(err)
}
} }
func TestBcUncleTests(t *testing.T) { func TestBcUncleTests(t *testing.T) {
runBlockTestsInFile(filepath.Join(blockTestDir, "bcUncleTest.json"), []string{}) err := RunBlockTest(filepath.Join(blockTestDir, "bcUncleTest.json"))
runBlockTestsInFile(filepath.Join(blockTestDir, "bcBruncleTest.json"), []string{}) if err != nil {
t.Fatal(err)
}
err = RunBlockTest(filepath.Join(blockTestDir, "bcBruncleTest.json"))
if err != nil {
t.Fatal(err)
}
} }
func TestBcUncleHeaderValidityTests(t *testing.T) { func TestBcUncleHeaderValidityTests(t *testing.T) {
runBlockTestsInFile(filepath.Join(blockTestDir, "bcUncleHeaderValiditiy.json"), []string{}) err := RunBlockTest(filepath.Join(blockTestDir, "bcUncleHeaderValiditiy.json"))
if err != nil {
t.Fatal(err)
}
} }
func TestBcInvalidHeaderTests(t *testing.T) { func TestBcInvalidHeaderTests(t *testing.T) {
runBlockTestsInFile(filepath.Join(blockTestDir, "bcInvalidHeaderTest.json"), []string{}) err := RunBlockTest(filepath.Join(blockTestDir, "bcInvalidHeaderTest.json"))
if err != nil {
t.Fatal(err)
}
} }
func TestBcInvalidRLPTests(t *testing.T) { func TestBcInvalidRLPTests(t *testing.T) {
runBlockTestsInFile(filepath.Join(blockTestDir, "bcInvalidRLPTest.json"), []string{}) err := RunBlockTest(filepath.Join(blockTestDir, "bcInvalidRLPTest.json"))
if err != nil {
t.Fatal(err)
}
} }
func TestBcRPCAPITests(t *testing.T) { func TestBcRPCAPITests(t *testing.T) {
runBlockTestsInFile(filepath.Join(blockTestDir, "bcRPC_API_Test.json"), []string{}) err := RunBlockTest(filepath.Join(blockTestDir, "bcRPC_API_Test.json"))
if err != nil {
t.Fatal(err)
}
} }
func TestBcForkBlockTests(t *testing.T) { func TestBcForkBlockTests(t *testing.T) {
runBlockTestsInFile(filepath.Join(blockTestDir, "bcForkBlockTest.json"), []string{}) err := RunBlockTest(filepath.Join(blockTestDir, "bcForkBlockTest.json"))
if err != nil {
t.Fatal(err)
}
} }
func TestBcTotalDifficulty(t *testing.T) { func TestBcTotalDifficulty(t *testing.T) {
runBlockTestsInFile(filepath.Join(blockTestDir, "bcTotalDifficultyTest.json"), []string{}) err := RunBlockTest(filepath.Join(blockTestDir, "bcTotalDifficultyTest.json"))
if err != nil {
t.Fatal(err)
}
} }
func TestBcWallet(t *testing.T) { func TestBcWallet(t *testing.T) {
runBlockTestsInFile(filepath.Join(blockTestDir, "bcWalletTest.json"), []string{}) err := RunBlockTest(filepath.Join(blockTestDir, "bcWalletTest.json"))
if err != nil {
t.Fatal(err)
}
} }

View File

@ -86,28 +86,35 @@ type btTransaction struct {
Value string Value string
} }
func runBlockTestsInFile(filepath string, snafus []string) error { func RunBlockTest(filepath string) error {
bt, err := LoadBlockTests(filepath) bt, err := LoadBlockTests(filepath)
if err != nil { if err != nil {
return nil return nil
} }
notWorking := make(map[string]bool, 100) // map skipped tests to boolean set
for _, name := range snafus { skipTest := make(map[string]bool, len(blockSkipTests))
notWorking[name] = true for _, name := range blockSkipTests {
skipTest[name] = true
} }
for name, test := range bt { for name, test := range bt {
if !notWorking[name] { // if the test should be skipped, return
if err := runBlockTest(name, test); err != nil { if skipTest[name] {
fmt.Println("Skipping state test", name)
return nil
}
// test the block
if err := testBlock(test); err != nil {
return err return err
} }
} fmt.Println("Block test passed: ", name)
} }
return nil return nil
} }
func runBlockTest(name string, test *BlockTest) error { func testBlock(test *BlockTest) error {
cfg := testEthConfig() cfg := testEthConfig()
ethereum, err := eth.New(cfg) ethereum, err := eth.New(cfg)
if err != nil { if err != nil {
@ -136,8 +143,6 @@ func runBlockTest(name string, test *BlockTest) error {
if err = test.ValidatePostState(statedb); err != nil { if err = test.ValidatePostState(statedb); err != nil {
return fmt.Errorf("post state validation failed: %v", err) return fmt.Errorf("post state validation failed: %v", err)
} }
fmt.Println("Block test passed: ", name)
// t.Log("Block test passed: ", name)
return nil return nil
} }

View File

@ -15,6 +15,11 @@ var (
stateTestDir = filepath.Join(baseDir, "StateTests") stateTestDir = filepath.Join(baseDir, "StateTests")
transactionTestDir = filepath.Join(baseDir, "TransactionTests") transactionTestDir = filepath.Join(baseDir, "TransactionTests")
vmTestDir = filepath.Join(baseDir, "VMTests") vmTestDir = filepath.Join(baseDir, "VMTests")
blockSkipTests = []string{}
transSkipTests = []string{"TransactionWithHihghNonce256"}
stateSkipTests = []string{"mload32bitBound_return", "mload32bitBound_return2"}
vmSkipTests = []string{}
) )
func readJSON(reader io.Reader, value interface{}) error { func readJSON(reader io.Reader, value interface{}) error {

View File

@ -15,19 +15,19 @@ import (
) )
func RunStateTest(p string) error { func RunStateTest(p string) error {
skipTest := make(map[string]bool, len(stateSkipTests))
for _, name := range stateSkipTests {
skipTest[name] = true
}
tests := make(map[string]VmTest) tests := make(map[string]VmTest)
CreateFileTests(p, &tests) CreateFileTests(p, &tests)
for name, test := range tests { for name, test := range tests {
/* if skipTest[name] {
vm.Debug = true fmt.Println("Skipping state test", name)
glog.SetV(4) return nil
glog.SetToStderr(true)
if name != "Call50000_sha256" {
continue
} }
*/
db, _ := ethdb.NewMemDatabase() db, _ := ethdb.NewMemDatabase()
statedb := state.New(common.Hash{}, db) statedb := state.New(common.Hash{}, db)
for addr, account := range test.Pre { for addr, account := range test.Pre {
@ -60,17 +60,17 @@ func RunStateTest(p string) error {
ret, logs, _, _ = RunState(statedb, env, test.Transaction) ret, logs, _, _ = RunState(statedb, env, test.Transaction)
// Compare expected and actual return // // Compare expected and actual return
switch name { // switch name {
// the memory required for these tests (4294967297 bytes) would take too much time. // // the memory required for these tests (4294967297 bytes) would take too much time.
// on 19 May 2015 decided to skip these tests their output. // // on 19 May 2015 decided to skip these tests their output.
case "mload32bitBound_return", "mload32bitBound_return2": // case "mload32bitBound_return", "mload32bitBound_return2":
default: // default:
rexp := common.FromHex(test.Out) rexp := common.FromHex(test.Out)
if bytes.Compare(rexp, ret) != 0 { if bytes.Compare(rexp, ret) != 0 {
return fmt.Errorf("%s's return failed. Expected %x, got %x\n", name, rexp, ret) return fmt.Errorf("%s's return failed. Expected %x, got %x\n", name, rexp, ret)
} }
} // }
// check post state // check post state
for addr, account := range test.Post { for addr, account := range test.Post {

View File

@ -6,40 +6,21 @@ import (
) )
func TestTransactions(t *testing.T) { func TestTransactions(t *testing.T) {
notWorking := make(map[string]bool, 100) err := RunTransactionTests(filepath.Join(transactionTestDir, "ttTransactionTest.json"))
// TODO: all these tests should work! remove them from the array when they work
snafus := []string{
"TransactionWithHihghNonce256", // fails due to testing upper bound of 256 bit nonce
}
for _, name := range snafus {
notWorking[name] = true
}
var err error
err = RunTransactionTests(filepath.Join(transactionTestDir, "ttTransactionTest.json"),
notWorking)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func TestWrongRLPTransactions(t *testing.T) { func TestWrongRLPTransactions(t *testing.T) {
notWorking := make(map[string]bool, 100) err := RunTransactionTests(filepath.Join(transactionTestDir, "ttWrongRLPTransaction.json"))
var err error
err = RunTransactionTests(filepath.Join(transactionTestDir, "ttWrongRLPTransaction.json"),
notWorking)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }
func Test10MBtx(t *testing.T) { func Test10MBtx(t *testing.T) {
notWorking := make(map[string]bool, 100) err := RunTransactionTests(filepath.Join(transactionTestDir, "tt10mbDataField.json"))
var err error
err = RunTransactionTests(filepath.Join(transactionTestDir, "tt10mbDataField.json"),
notWorking)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -30,20 +30,29 @@ type TransactionTest struct {
Transaction TtTransaction Transaction TtTransaction
} }
func RunTransactionTests(file string, notWorking map[string]bool) error { func RunTransactionTests(file string) error {
skipTest := make(map[string]bool, len(transSkipTests))
for _, name := range transSkipTests {
skipTest[name] = true
}
bt := make(map[string]TransactionTest) bt := make(map[string]TransactionTest)
if err := LoadJSON(file, &bt); err != nil { if err := LoadJSON(file, &bt); err != nil {
return err return err
} }
for name, in := range bt {
var err error for name, test := range bt {
// TODO: remove this, we currently ignore some tests which are broken // if the test should be skipped, return
if !notWorking[name] { if skipTest[name] {
if err = runTest(in); err != nil { fmt.Println("Skipping state test", name)
return fmt.Errorf("bad test %s: %v", name, err) return nil
}
// test the block
if err := runTest(test); err != nil {
return err
} }
fmt.Println("Transaction test passed: ", name) fmt.Println("Transaction test passed: ", name)
}
} }
return nil return nil
} }

View File

@ -13,6 +13,10 @@ import (
) )
func RunVmTest(p string) error { func RunVmTest(p string) error {
skipTest := make(map[string]bool, len(vmSkipTests))
for _, name := range vmSkipTests {
skipTest[name] = true
}
tests := make(map[string]VmTest) tests := make(map[string]VmTest)
err := CreateFileTests(p, &tests) err := CreateFileTests(p, &tests)
@ -21,14 +25,10 @@ func RunVmTest(p string) error {
} }
for name, test := range tests { for name, test := range tests {
/* if skipTest[name] {
vm.Debug = true fmt.Println("Skipping state test", name)
glog.SetV(4) return nil
glog.SetToStderr(true)
if name != "Call50000_sha256" {
continue
} }
*/
db, _ := ethdb.NewMemDatabase() db, _ := ethdb.NewMemDatabase()
statedb := state.New(common.Hash{}, db) statedb := state.New(common.Hash{}, db)
for addr, account := range test.Pre { for addr, account := range test.Pre {