forked from cerc-io/plugeth
commit
81ec564ef6
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user