@@ -14,22 +14,30 @@ import (
1414 "github.com/ethereum/go-ethereum/ethstate"
1515 "github.com/ethereum/go-ethereum/ethtrie"
1616 "github.com/ethereum/go-ethereum/ethutil"
17+ "github.com/obscuren/mutan"
1718)
1819
19- type TestEnv struct {
20+ type TestEnv struct {}
21+
22+ func (TestEnv ) Origin () []byte { return nil }
23+ func (TestEnv ) BlockNumber () * big.Int { return nil }
24+ func (TestEnv ) BlockHash () []byte { return nil }
25+ func (TestEnv ) PrevHash () []byte { return nil }
26+ func (TestEnv ) Coinbase () []byte { return nil }
27+ func (TestEnv ) Time () int64 { return 0 }
28+ func (TestEnv ) GasLimit () * big.Int { return nil }
29+ func (TestEnv ) Difficulty () * big.Int { return nil }
30+ func (TestEnv ) Value () * big.Int { return nil }
31+ func (TestEnv ) AddLog (Log ) {}
32+
33+ func (TestEnv ) Transfer (from , to Account , amount * big.Int ) error {
34+ return nil
2035}
2136
22- func (self TestEnv ) Origin () []byte { return nil }
23- func (self TestEnv ) BlockNumber () * big.Int { return nil }
24- func (self TestEnv ) BlockHash () []byte { return nil }
25- func (self TestEnv ) PrevHash () []byte { return nil }
26- func (self TestEnv ) Coinbase () []byte { return nil }
27- func (self TestEnv ) Time () int64 { return 0 }
28- func (self TestEnv ) Difficulty () * big.Int { return nil }
29- func (self TestEnv ) Value () * big.Int { return nil }
30-
3137// This is likely to fail if anything ever gets looked up in the state trie :-)
32- func (self TestEnv ) State () * ethstate.State { return ethstate .New (ethtrie .New (nil , "" )) }
38+ func (TestEnv ) State () * ethstate.State {
39+ return ethstate .New (ethtrie .New (nil , "" ))
40+ }
3341
3442const mutcode = `
3543var x = 0;
@@ -56,27 +64,35 @@ func setup(level ethlog.LogLevel, typ Type) (*Closure, VirtualMachine) {
5664 return callerClosure , New (TestEnv {}, typ )
5765}
5866
67+ var big9 = ethutil .Hex2Bytes ("0000000000000000000000000000000000000000000000000000000000000009" )
68+
5969func TestDebugVm (t * testing.T ) {
70+ if mutan .Version < "0.6" {
71+ t .Skip ("skipping for mutan version" , mutan .Version , " < 0.6" )
72+ }
73+
6074 closure , vm := setup (ethlog .DebugLevel , DebugVmTy )
6175 ret , _ , e := closure .Call (vm , nil )
6276 if e != nil {
63- fmt . Println ( " error" , e )
77+ t . Fatalf ( "Call returned error: %v " , e )
6478 }
65-
66- if ret [len (ret )- 1 ] != 9 {
67- t .Errorf ("Expected VM to return 9, got" , ret , "instead." )
79+ if ! bytes .Equal (ret , big9 ) {
80+ t .Errorf ("Wrong return value '%x', want '%x'" , ret , big9 )
6881 }
6982}
7083
7184func TestVm (t * testing.T ) {
85+ if mutan .Version < "0.6" {
86+ t .Skip ("skipping for mutan version" , mutan .Version , " < 0.6" )
87+ }
88+
7289 closure , vm := setup (ethlog .DebugLevel , StandardVmTy )
7390 ret , _ , e := closure .Call (vm , nil )
7491 if e != nil {
75- fmt . Println ( " error" , e )
92+ t . Fatalf ( "Call returned error: %v " , e )
7693 }
77-
78- if ret [len (ret )- 1 ] != 9 {
79- t .Errorf ("Expected VM to return 9, got" , ret , "instead." )
94+ if ! bytes .Equal (ret , big9 ) {
95+ t .Errorf ("Wrong return value '%x', want '%x'" , ret , big9 )
8096 }
8197}
8298
0 commit comments