aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <obscuren@users.noreply.github.com>2014-10-30 02:48:38 +0800
committerJeffrey Wilcke <obscuren@users.noreply.github.com>2014-10-30 02:48:38 +0800
commit81ec564ef61a6dcd06cfdd98a515d366aaac719f (patch)
treeb75cc909fd773e840c274444f39f1b60f00afd23
parent9e2f071d26d5c4ed343d2a91e48fec4e7751b99d (diff)
parent4cf69d7cd34394fa7408bb5a6e152610a9daa81c (diff)
downloaddexon-81ec564ef61a6dcd06cfdd98a515d366aaac719f.tar.gz
dexon-81ec564ef61a6dcd06cfdd98a515d366aaac719f.tar.zst
dexon-81ec564ef61a6dcd06cfdd98a515d366aaac719f.zip
Merge pull request #168 from fjl/feature/working-tests
Fix the tests
-rw-r--r--ethchain/helper_test.go6
-rw-r--r--ethcrypto/crypto_test.go33
-rw-r--r--ethpipe/pipe_test.go58
-rw-r--r--ethwire/client_identity_test.go12
-rw-r--r--vm/vm_test.go54
5 files changed, 70 insertions, 93 deletions
diff --git a/ethchain/helper_test.go b/ethchain/helper_test.go
index e4aef67d0..a863c7541 100644
--- a/ethchain/helper_test.go
+++ b/ethchain/helper_test.go
@@ -18,7 +18,7 @@ type TestManager struct {
db ethutil.Database
txPool *TxPool
- blockChain *BlockChain
+ blockChain *ChainManager
Blocks []*Block
}
@@ -38,7 +38,7 @@ func (s *TestManager) Peers() *list.List {
return list.New()
}
-func (s *TestManager) BlockChain() *BlockChain {
+func (s *TestManager) ChainManager() *ChainManager {
return s.blockChain
}
@@ -82,7 +82,7 @@ func NewTestManager() *TestManager {
testManager.eventMux = new(event.TypeMux)
testManager.db = db
testManager.txPool = NewTxPool(testManager)
- testManager.blockChain = NewBlockChain(testManager)
+ testManager.blockChain = NewChainManager(testManager)
testManager.stateManager = NewStateManager(testManager)
// Start the tx pool
diff --git a/ethcrypto/crypto_test.go b/ethcrypto/crypto_test.go
index 689bcecb4..e8db6362f 100644
--- a/ethcrypto/crypto_test.go
+++ b/ethcrypto/crypto_test.go
@@ -2,16 +2,35 @@ package ethcrypto
import (
"bytes"
+ "encoding/hex"
"testing"
-
- "github.com/ethereum/go-ethereum/ethutil"
)
-// FIPS 202 test (reverted back to FIPS 180)
+// These tests are sanity checks.
+// They should ensure that we don't e.g. use Sha3-224 instead of Sha3-256
+// and that the sha3 library uses keccak-f permutation.
+
func TestSha3(t *testing.T) {
- const exp = "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"
- sha3_256 := Sha3Bin([]byte("abc"))
- if bytes.Compare(sha3_256, ethutil.Hex2Bytes(exp)) != 0 {
- t.Errorf("Sha3_256 failed. Incorrect result %x", sha3_256)
+ msg := []byte("abc")
+ exp, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
+ checkhash(t, "Sha3-256", Sha3, msg, exp)
+}
+
+func TestSha256(t *testing.T) {
+ msg := []byte("abc")
+ exp, _ := hex.DecodeString("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")
+ checkhash(t, "Sha256", Sha256, msg, exp)
+}
+
+func TestRipemd160(t *testing.T) {
+ msg := []byte("abc")
+ exp, _ := hex.DecodeString("8eb208f7e05d987a9b044a8e98c6b087f15a0bfc")
+ checkhash(t, "Ripemd160", Ripemd160, msg, exp)
+}
+
+func checkhash(t *testing.T, name string, f func([]byte) []byte, msg, exp []byte) {
+ sum := f(msg)
+ if bytes.Compare(exp, sum) != 0 {
+ t.Errorf("hash %s returned wrong result.\ngot: %x\nwant: %x", name, sum, exp)
}
}
diff --git a/ethpipe/pipe_test.go b/ethpipe/pipe_test.go
deleted file mode 100644
index 3b5dc5e4c..000000000
--- a/ethpipe/pipe_test.go
+++ /dev/null
@@ -1,58 +0,0 @@
-package ethpipe
-
-import (
- "testing"
-
- "github.com/ethereum/go-ethereum/ethcrypto"
- "github.com/ethereum/go-ethereum/ethstate"
- "github.com/ethereum/go-ethereum/ethutil"
-)
-
-func Val(v interface{}) *ethutil.Value {
- return ethutil.NewValue(v)
-}
-
-func TestNew(t *testing.T) {
- pipe := New(nil)
-
- var addr, privy, recp, data []byte
- var object *ethstate.StateObject
- var key *ethcrypto.KeyPair
-
- world := pipe.World()
- world.Get(addr)
- world.Coinbase()
- world.IsMining()
- world.IsListening()
- world.State()
- peers := world.Peers()
- peers.Len()
-
- // Shortcut functions
- pipe.Balance(addr)
- pipe.Nonce(addr)
- pipe.Block(addr)
- pipe.Storage(addr, addr)
- pipe.ToAddress(privy)
- pipe.Exists(addr)
- // Doesn't change state
- pipe.Execute(addr, nil, Val(0), Val(1000000), Val(10))
- // Doesn't change state
- pipe.ExecuteObject(object, nil, Val(0), Val(1000000), Val(10))
-
- conf := world.Config()
- namereg := conf.Get("NameReg")
- namereg.Storage(addr)
-
- var err error
- // Transact
- err = pipe.Transact(key, recp, ethutil.NewValue(0), ethutil.NewValue(0), ethutil.NewValue(0), nil)
- if err != nil {
- t.Error(err)
- }
- // Create
- err = pipe.Transact(key, nil, ethutil.NewValue(0), ethutil.NewValue(0), ethutil.NewValue(0), data)
- if err != nil {
- t.Error(err)
- }
-}
diff --git a/ethwire/client_identity_test.go b/ethwire/client_identity_test.go
index f3c8bfd50..1724fe57b 100644
--- a/ethwire/client_identity_test.go
+++ b/ethwire/client_identity_test.go
@@ -9,22 +9,22 @@ import (
func TestClientIdentity(t *testing.T) {
clientIdentity := NewSimpleClientIdentity("Ethereum(G)", "0.5.16", "test")
clientString := clientIdentity.String()
- expected := fmt.Sprintf("Ethereum(G)/v0.5.16/test/%s/Go", runtime.GOOS)
+ expected := fmt.Sprintf("Ethereum(G)/v0.5.16/test/%s/%s", runtime.GOOS, runtime.Version())
if clientString != expected {
- t.Error("Expected clientIdentity to be %v, got %v", expected, clientString)
+ t.Errorf("Expected clientIdentity to be %q, got %q", expected, clientString)
}
customIdentifier := clientIdentity.GetCustomIdentifier()
if customIdentifier != "test" {
- t.Error("Expected clientIdentity.GetCustomIdentifier() to be 'test', got %v", customIdentifier)
+ t.Errorf("Expected clientIdentity.GetCustomIdentifier() to be 'test', got %q", customIdentifier)
}
clientIdentity.SetCustomIdentifier("test2")
customIdentifier = clientIdentity.GetCustomIdentifier()
if customIdentifier != "test2" {
- t.Error("Expected clientIdentity.GetCustomIdentifier() to be 'test2', got %v", customIdentifier)
+ t.Errorf("Expected clientIdentity.GetCustomIdentifier() to be 'test2', got %q", customIdentifier)
}
clientString = clientIdentity.String()
- expected = fmt.Sprintf("Ethereum(G)/v0.5.16/test2/%s/Go", runtime.GOOS)
+ expected = fmt.Sprintf("Ethereum(G)/v0.5.16/test2/%s/%s", runtime.GOOS, runtime.Version())
if clientString != expected {
- t.Error("Expected clientIdentity to be %v, got %v", expected, clientString)
+ t.Errorf("Expected clientIdentity to be %q, got %q", expected, clientString)
}
}
diff --git a/vm/vm_test.go b/vm/vm_test.go
index 84cca3a9d..8818cc8ec 100644
--- a/vm/vm_test.go
+++ b/vm/vm_test.go
@@ -14,22 +14,30 @@ import (
"github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethtrie"
"github.com/ethereum/go-ethereum/ethutil"
+ "github.com/obscuren/mutan"
)
-type TestEnv struct {
+type TestEnv struct{}
+
+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(Log) {}
+
+func (TestEnv) Transfer(from, to Account, amount *big.Int) error {
+ return nil
}
-func (self TestEnv) Origin() []byte { return nil }
-func (self TestEnv) BlockNumber() *big.Int { return nil }
-func (self TestEnv) BlockHash() []byte { return nil }
-func (self TestEnv) PrevHash() []byte { return nil }
-func (self TestEnv) Coinbase() []byte { return nil }
-func (self TestEnv) Time() int64 { return 0 }
-func (self TestEnv) Difficulty() *big.Int { return nil }
-func (self TestEnv) Value() *big.Int { return nil }
-
// This is likely to fail if anything ever gets looked up in the state trie :-)
-func (self TestEnv) State() *ethstate.State { return ethstate.New(ethtrie.New(nil, "")) }
+func (TestEnv) State() *ethstate.State {
+ return ethstate.New(ethtrie.New(nil, ""))
+}
const mutcode = `
var x = 0;
@@ -56,27 +64,35 @@ func setup(level ethlog.LogLevel, typ Type) (*Closure, VirtualMachine) {
return callerClosure, New(TestEnv{}, typ)
}
+var big9 = ethutil.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000009")
+
func TestDebugVm(t *testing.T) {
+ if mutan.Version < "0.6" {
+ t.Skip("skipping for mutan version", mutan.Version, " < 0.6")
+ }
+
closure, vm := setup(ethlog.DebugLevel, DebugVmTy)
ret, _, e := closure.Call(vm, nil)
if e != nil {
- fmt.Println("error", e)
+ t.Fatalf("Call returned error: %v", e)
}
-
- if ret[len(ret)-1] != 9 {
- t.Errorf("Expected VM to return 9, got", ret, "instead.")
+ if !bytes.Equal(ret, big9) {
+ t.Errorf("Wrong return value '%x', want '%x'", ret, big9)
}
}
func TestVm(t *testing.T) {
+ if mutan.Version < "0.6" {
+ t.Skip("skipping for mutan version", mutan.Version, " < 0.6")
+ }
+
closure, vm := setup(ethlog.DebugLevel, StandardVmTy)
ret, _, e := closure.Call(vm, nil)
if e != nil {
- fmt.Println("error", e)
+ t.Fatalf("Call returned error: %v", e)
}
-
- if ret[len(ret)-1] != 9 {
- t.Errorf("Expected VM to return 9, got", ret, "instead.")
+ if !bytes.Equal(ret, big9) {
+ t.Errorf("Wrong return value '%x', want '%x'", ret, big9)
}
}