diff --git a/src/gethdep_test.go b/src/gethdep_test.go index c54cabf12..0fa976f7b 100644 --- a/src/gethdep_test.go +++ b/src/gethdep_test.go @@ -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 { diff --git a/src/vendor/github.com/ethereum/go-ethereum/whisper/whisper.go b/src/vendor/github.com/ethereum/go-ethereum/whisper/whisper.go index 13f4bcd8f..a2f5f9ba8 100644 --- a/src/vendor/github.com/ethereum/go-ethereum/whisper/whisper.go +++ b/src/vendor/github.com/ethereum/go-ethereum/whisper/whisper.go @@ -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") }