try whisper key copy

This commit is contained in:
Daniel Whitenack 2016-07-02 10:54:00 -05:00
parent 271a42a5a1
commit 8ac7e83305
2 changed files with 28 additions and 2 deletions

View File

@ -5,6 +5,10 @@ import (
"os"
"testing"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/whisper"
)
// TestAccountBindings makes sure we can create an account and subsequently
@ -19,12 +23,33 @@ func TestAccountBindings(t *testing.T) {
}
// create an account
address, _, err := createAccount("badpassword")
address, pubkey, err := createAccount("badpassword")
if err != nil {
fmt.Println(err.Error())
t.Error("Test failed: could not create account")
}
// test to see if the account was injected in whisper
whisperInstance := (*accountSync)[0].(*whisper.Whisper)
identitySucess := whisperInstance.HasIdentity(crypto.ToECDSAPub(common.FromHex(pubkey)))
if !identitySucess || err != nil {
t.Error("Test failed: identity not injected into whisper")
}
// test to see if we can post with the injected whisper identity
postArgs := whisper.PostArgs{
From: pubkey,
To: pubkey,
TTL: 100,
Topics: [][]byte{[]byte("test topic")},
Payload: "test message",
}
whisperAPI := whisper.NewPublicWhisperAPI(whisperInstance)
postSucess, err := whisperAPI.Post(postArgs)
if !postSucess || err != nil {
t.Error("Test failed: Could not post to whisper")
}
// unlock the created account
err = unlockAccount(address, "badpassword", 10)
if err != nil {

View File

@ -150,7 +150,8 @@ func (self *Whisper) GetIdentity(key *ecdsa.PublicKey) *ecdsa.PrivateKey {
func (self *Whisper) InjectIdentity(key *ecdsa.PrivateKey) error {
identity := string(crypto.FromECDSAPub(&key.PublicKey))
self.keys[identity] = key
keyCopy := *key
self.keys[identity] = &keyCopy
if _, ok := self.keys[identity]; !ok {
return fmt.Errorf("key insert into keys map failed")
}