added nil check

This commit is contained in:
obscuren 2015-01-02 13:00:25 +01:00
parent d336e24dce
commit e2d1d832ef
5 changed files with 8 additions and 39 deletions

View File

@ -16,17 +16,9 @@ import (
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
) )
//var Logger logpkg.LogSystem
//var Log = logpkg.NewLogger("TEST")
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
//Logger = logpkg.NewStdLogSystem(os.Stdout, log.LstdFlags, logpkg.DebugLevel)
//logpkg.AddLogSystem(Logger)
ethutil.ReadConfig("/tmp/ethtest", "/tmp/ethtest", "ETH") ethutil.ReadConfig("/tmp/ethtest", "/tmp/ethtest", "ETH")
} }
func reset() { func reset() {
@ -38,7 +30,7 @@ func reset() {
} }
func loadChain(fn string, t *testing.T) (types.Blocks, error) { func loadChain(fn string, t *testing.T) (types.Blocks, error) {
fh, err := os.OpenFile(path.Join("..", "_data", fn), os.O_RDONLY, os.ModePerm) fh, err := os.OpenFile(path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "_data", fn), os.O_RDONLY, os.ModePerm)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -1,23 +1 @@
package types package types
import (
"bytes"
"testing"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/rlp"
)
func init() {
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
ethutil.Config.Db, _ = ethdb.NewMemDatabase()
}
func TestNewBlock(t *testing.T) {
block := GenesisBlock()
data := ethutil.Encode(block)
var genesis Block
err := rlp.Decode(bytes.NewReader(data), &genesis)
}

View File

@ -5,7 +5,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/ptrie"
) )
type StateSuite struct { type StateSuite struct {
@ -18,9 +18,8 @@ var _ = checker.Suite(&StateSuite{})
func (s *StateSuite) TestDump(c *checker.C) { func (s *StateSuite) TestDump(c *checker.C) {
key := []byte{0x01} key := []byte{0x01}
value := "foo" value := []byte("foo")
node := []interface{}{key, value} s.state.trie.Update(key, value)
s.state.Trie.Put(node)
dump := s.state.Dump() dump := s.state.Dump()
c.Assert(dump, checker.NotNil) c.Assert(dump, checker.NotNil)
} }
@ -29,7 +28,7 @@ func (s *StateSuite) SetUpTest(c *checker.C) {
db, _ := ethdb.NewMemDatabase() db, _ := ethdb.NewMemDatabase()
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "") ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
ethutil.Config.Db = db ethutil.Config.Db = db
s.state = New(trie.New(db, "")) s.state = New(ptrie.New(nil, db))
} }
func (s *StateSuite) TestSnapshot(c *checker.C) { func (s *StateSuite) TestSnapshot(c *checker.C) {

View File

@ -79,6 +79,7 @@ func (self *Envelope) Open(prv *ecdsa.PrivateKey) (msg *Message, err error) {
if prv != nil { if prv != nil {
message.Payload, err = crypto.Decrypt(prv, payload) message.Payload, err = crypto.Decrypt(prv, payload)
switch err { switch err {
case nil: // OK
case ecies.ErrInvalidPublicKey: // Payload isn't encrypted case ecies.ErrInvalidPublicKey: // Payload isn't encrypted
message.Payload = payload message.Payload = payload
return &message, err return &message, err

View File

@ -40,12 +40,11 @@ func TestMessageEncryptDecrypt(t *testing.T) {
msg1, err := envelope.Open(prv2) msg1, err := envelope.Open(prv2)
if err != nil { if err != nil {
fmt.Println(err) t.Error(err)
t.FailNow() t.FailNow()
} }
if !bytes.Equal(msg1.Payload, data) { if !bytes.Equal(msg1.Payload, data) {
fmt.Println("encryption error. data did not match") t.Error("encryption error. data did not match")
t.FailNow()
} }
} }