Convert vm test to checker
Tests are skipped due to reliance on deprecated mutan
This commit is contained in:
parent
ffab36c7d8
commit
9095b37343
|
@ -0,0 +1,9 @@
|
||||||
|
package vm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
checker "gopkg.in/check.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test(t *testing.T) { checker.TestingT(t) }
|
286
vm/vm_test.go
286
vm/vm_test.go
|
@ -1,189 +1,181 @@
|
||||||
package vm
|
package vm
|
||||||
|
|
||||||
// import (
|
import (
|
||||||
// "bytes"
|
"fmt"
|
||||||
// "fmt"
|
"io/ioutil"
|
||||||
// "io/ioutil"
|
"log"
|
||||||
// "log"
|
"math/big"
|
||||||
// "math/big"
|
"os"
|
||||||
// "os"
|
|
||||||
// "testing"
|
|
||||||
|
|
||||||
// "github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
// "github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
// "github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
// "github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
// "github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
// // "github.com/obscuren/mutan"
|
checker "gopkg.in/check.v1"
|
||||||
// )
|
// "github.com/obscuren/mutan"
|
||||||
|
)
|
||||||
|
|
||||||
// type TestEnv struct{}
|
type VmSuite struct{}
|
||||||
|
|
||||||
// func (TestEnv) Origin() []byte { return nil }
|
var _ = checker.Suite(&VmSuite{})
|
||||||
// func (TestEnv) BlockNumber() *big.Int { return nil }
|
var big9 = ethutil.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000009")
|
||||||
// func (TestEnv) BlockHash() []byte { return nil }
|
|
||||||
// func (TestEnv) PrevHash() []byte { return nil }
|
|
||||||
// func (TestEnv) Coinbase() []byte { return nil }
|
|
||||||
// func (TestEnv) Time() int64 { return 0 }
|
|
||||||
// func (TestEnv) GasLimit() *big.Int { return nil }
|
|
||||||
// func (TestEnv) Difficulty() *big.Int { return nil }
|
|
||||||
// func (TestEnv) Value() *big.Int { return nil }
|
|
||||||
// func (TestEnv) AddLog(state.Log) {}
|
|
||||||
|
|
||||||
// func (TestEnv) Transfer(from, to Account, amount *big.Int) error {
|
const mutcode = `
|
||||||
// return nil
|
var x = 0;
|
||||||
// }
|
for i := 0; i < 10; i++ {
|
||||||
|
x = i
|
||||||
|
}
|
||||||
|
|
||||||
// // This is likely to fail if anything ever gets looked up in the state trie :-)
|
return x`
|
||||||
// func (TestEnv) State() *state.State {
|
|
||||||
// return state.New(trie.New(nil, ""))
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const mutcode = `
|
type TestEnv struct{}
|
||||||
// var x = 0;
|
|
||||||
// for i := 0; i < 10; i++ {
|
|
||||||
// x = i
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return x`
|
func (TestEnv) Origin() []byte { return nil }
|
||||||
|
func (TestEnv) BlockNumber() *big.Int { return nil }
|
||||||
|
func (TestEnv) BlockHash() []byte { return nil }
|
||||||
|
func (TestEnv) PrevHash() []byte { return nil }
|
||||||
|
func (TestEnv) Coinbase() []byte { return nil }
|
||||||
|
func (TestEnv) Time() int64 { return 0 }
|
||||||
|
func (TestEnv) GasLimit() *big.Int { return nil }
|
||||||
|
func (TestEnv) Difficulty() *big.Int { return nil }
|
||||||
|
func (TestEnv) Value() *big.Int { return nil }
|
||||||
|
func (TestEnv) AddLog(*state.Log) {}
|
||||||
|
func (TestEnv) Transfer(from, to Account, amount *big.Int) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// func setup(level logger.LogLevel, typ Type) (*Closure, VirtualMachine) {
|
// This is likely to fail if anything ever gets looked up in the state trie :-)
|
||||||
// code, err := ethutil.Compile(mutcode, true)
|
func (TestEnv) State() *state.State {
|
||||||
// if err != nil {
|
return state.New(trie.New(nil, ""))
|
||||||
// log.Fatal(err)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
// // Pipe output to /dev/null
|
func setup(level logger.LogLevel, typ Type) (*Closure, VirtualMachine) {
|
||||||
// logger.AddLogSystem(logger.NewStdLogSystem(ioutil.Discard, log.LstdFlags, level))
|
code, err := ethutil.Compile(mutcode, true)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
|
// Pipe output to /dev/null
|
||||||
|
logger.AddLogSystem(logger.NewStdLogSystem(ioutil.Discard, log.LstdFlags, level))
|
||||||
|
|
||||||
// stateObject := state.NewStateObject([]byte{'j', 'e', 'f', 'f'})
|
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
|
||||||
// callerClosure := NewClosure(nil, stateObject, stateObject, code, big.NewInt(1000000), big.NewInt(0))
|
|
||||||
|
|
||||||
// return callerClosure, New(TestEnv{}, typ)
|
stateObject := state.NewStateObject([]byte{'j', 'e', 'f', 'f'})
|
||||||
// }
|
callerClosure := NewClosure(nil, stateObject, stateObject, code, big.NewInt(1000000), big.NewInt(0))
|
||||||
|
|
||||||
// var big9 = ethutil.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000009")
|
return callerClosure, New(TestEnv{}, typ)
|
||||||
|
}
|
||||||
|
|
||||||
// func TestDebugVm(t *testing.T) {
|
func (s *VmSuite) TestDebugVm(c *checker.C) {
|
||||||
// // if mutan.Version < "0.6" {
|
// if mutan.Version < "0.6" {
|
||||||
// // t.Skip("skipping for mutan version", mutan.Version, " < 0.6")
|
// t.Skip("skipping for mutan version", mutan.Version, " < 0.6")
|
||||||
// // }
|
// }
|
||||||
|
closure, vm := setup(logger.DebugLevel, DebugVmTy)
|
||||||
|
ret, _, e := closure.Call(vm, nil)
|
||||||
|
c.Assert(e, checker.NotNil)
|
||||||
|
c.Skip("Depends on mutan")
|
||||||
|
c.Assert(ret, checker.DeepEquals, big9)
|
||||||
|
}
|
||||||
|
|
||||||
// closure, vm := setup(logger.DebugLevel, DebugVmTy)
|
func (s *VmSuite) TestVm(c *checker.C) {
|
||||||
// ret, _, e := closure.Call(vm, nil)
|
// if mutan.Version < "0.6" {
|
||||||
// if e != nil {
|
// t.Skip("skipping for mutan version", mutan.Version, " < 0.6")
|
||||||
// t.Fatalf("Call returned error: %v", e)
|
// }
|
||||||
// }
|
closure, vm := setup(logger.DebugLevel, StandardVmTy)
|
||||||
// if !bytes.Equal(ret, big9) {
|
ret, _, e := closure.Call(vm, nil)
|
||||||
// t.Errorf("Wrong return value '%x', want '%x'", ret, big9)
|
c.Assert(e, checker.NotNil)
|
||||||
// }
|
c.Skip("Depends on mutan")
|
||||||
// }
|
c.Assert(ret, checker.DeepEquals, big9)
|
||||||
|
}
|
||||||
|
|
||||||
// func TestVm(t *testing.T) {
|
func (s *VmSuite) BenchmarkDebugVm(c *checker.C) {
|
||||||
// // if mutan.Version < "0.6" {
|
closure, vm := setup(logger.InfoLevel, StandardVmTy)
|
||||||
// // t.Skip("skipping for mutan version", mutan.Version, " < 0.6")
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// closure, vm := setup(logger.DebugLevel, StandardVmTy)
|
c.ResetTimer()
|
||||||
// ret, _, e := closure.Call(vm, nil)
|
|
||||||
// if e != nil {
|
|
||||||
// t.Fatalf("Call returned error: %v", e)
|
|
||||||
// }
|
|
||||||
// if !bytes.Equal(ret, big9) {
|
|
||||||
// t.Errorf("Wrong return value '%x', want '%x'", ret, big9)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func BenchmarkDebugVm(b *testing.B) {
|
for i := 0; i < c.N; i++ {
|
||||||
// closure, vm := setup(logger.InfoLevel, DebugVmTy)
|
closure.Call(vm, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// b.ResetTimer()
|
func (s *VmSuite) BenchmarkVm(c *checker.C) {
|
||||||
|
closure, vm := setup(logger.InfoLevel, DebugVmTy)
|
||||||
|
|
||||||
// for i := 0; i < b.N; i++ {
|
c.ResetTimer()
|
||||||
// closure.Call(vm, nil)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func BenchmarkVm(b *testing.B) {
|
for i := 0; i < c.N; i++ {
|
||||||
// closure, vm := setup(logger.InfoLevel, StandardVmTy)
|
closure.Call(vm, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// b.ResetTimer()
|
func RunCode(mutCode string, typ Type) []byte {
|
||||||
|
code, err := ethutil.Compile(mutCode, true)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// for i := 0; i < b.N; i++ {
|
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.InfoLevel))
|
||||||
// closure.Call(vm, nil)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func RunCode(mutCode string, typ Type) []byte {
|
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
|
||||||
// code, err := ethutil.Compile(mutCode, true)
|
|
||||||
// if err != nil {
|
|
||||||
// log.Fatal(err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.InfoLevel))
|
stateObject := state.NewStateObject([]byte{'j', 'e', 'f', 'f'})
|
||||||
|
closure := NewClosure(nil, stateObject, stateObject, code, big.NewInt(1000000), big.NewInt(0))
|
||||||
|
|
||||||
// ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
|
vm := New(TestEnv{}, typ)
|
||||||
|
ret, _, e := closure.Call(vm, nil)
|
||||||
|
if e != nil {
|
||||||
|
fmt.Println(e)
|
||||||
|
}
|
||||||
|
|
||||||
// stateObject := state.NewStateObject([]byte{'j', 'e', 'f', 'f'})
|
return ret
|
||||||
// closure := NewClosure(nil, stateObject, stateObject, code, big.NewInt(1000000), big.NewInt(0))
|
}
|
||||||
|
|
||||||
// vm := New(TestEnv{}, typ)
|
func (s *VmSuite) TestBuildInSha256(c *checker.C) {
|
||||||
// ret, _, e := closure.Call(vm, nil)
|
ret := RunCode(`
|
||||||
// if e != nil {
|
var in = 42
|
||||||
// fmt.Println(e)
|
var out = 0
|
||||||
// }
|
|
||||||
|
|
||||||
// return ret
|
call(0x2, 0, 10000, in, out)
|
||||||
// }
|
|
||||||
|
|
||||||
// func TestBuildInSha256(t *testing.T) {
|
return out
|
||||||
// ret := RunCode(`
|
`, DebugVmTy)
|
||||||
// var in = 42
|
|
||||||
// var out = 0
|
|
||||||
|
|
||||||
// call(0x2, 0, 10000, in, out)
|
exp := crypto.Sha256(ethutil.LeftPadBytes([]byte{42}, 32))
|
||||||
|
c.Skip("Depends on mutan")
|
||||||
|
c.Assert(ret, checker.DeepEquals, exp)
|
||||||
|
}
|
||||||
|
|
||||||
// return out
|
func (s *VmSuite) TestBuildInRipemd(c *checker.C) {
|
||||||
// `, DebugVmTy)
|
ret := RunCode(`
|
||||||
|
var in = 42
|
||||||
|
var out = 0
|
||||||
|
|
||||||
// exp := crypto.Sha256(ethutil.LeftPadBytes([]byte{42}, 32))
|
call(0x3, 0, 10000, in, out)
|
||||||
// if bytes.Compare(ret, exp) != 0 {
|
|
||||||
// t.Errorf("Expected %x, got %x", exp, ret)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func TestBuildInRipemd(t *testing.T) {
|
return out
|
||||||
// ret := RunCode(`
|
`, DebugVmTy)
|
||||||
// var in = 42
|
|
||||||
// var out = 0
|
|
||||||
|
|
||||||
// call(0x3, 0, 10000, in, out)
|
exp := ethutil.RightPadBytes(crypto.Ripemd160(ethutil.LeftPadBytes([]byte{42}, 32)), 32)
|
||||||
|
c.Skip("Depends on mutan")
|
||||||
|
c.Assert(ret, checker.DeepEquals, exp)
|
||||||
|
}
|
||||||
|
|
||||||
// return out
|
func (s *VmSuite) TestOog(c *checker.C) {
|
||||||
// `, DebugVmTy)
|
// This tests takes a long time and will eventually run out of gas
|
||||||
|
// t.Skip()
|
||||||
|
c.Skip("This tests takes a long time and will eventually run out of gas")
|
||||||
|
|
||||||
// exp := ethutil.RightPadBytes(crypto.Ripemd160(ethutil.LeftPadBytes([]byte{42}, 32)), 32)
|
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.InfoLevel))
|
||||||
// if bytes.Compare(ret, exp) != 0 {
|
|
||||||
// t.Errorf("Expected %x, got %x", exp, ret)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func TestOog(t *testing.T) {
|
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
|
||||||
// // This tests takes a long time and will eventually run out of gas
|
|
||||||
// // t.Skip()
|
|
||||||
|
|
||||||
// logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.InfoLevel))
|
stateObject := state.NewStateObject([]byte{'j', 'e', 'f', 'f'})
|
||||||
|
closure := NewClosure(nil, stateObject, stateObject, ethutil.Hex2Bytes("60ff60ff600057"), big.NewInt(1000000), big.NewInt(0))
|
||||||
|
|
||||||
// ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
|
vm := New(TestEnv{}, DebugVmTy)
|
||||||
|
_, _, e := closure.Call(vm, nil)
|
||||||
// stateObject := state.NewStateObject([]byte{'j', 'e', 'f', 'f'})
|
if e != nil {
|
||||||
// closure := NewClosure(nil, stateObject, stateObject, ethutil.Hex2Bytes("60ff60ff600057"), big.NewInt(1000000), big.NewInt(0))
|
fmt.Println(e)
|
||||||
|
}
|
||||||
// vm := New(TestEnv{}, DebugVmTy)
|
}
|
||||||
// _, _, e := closure.Call(vm, nil)
|
|
||||||
// if e != nil {
|
|
||||||
// fmt.Println(e)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
Loading…
Reference in New Issue