Merge remote-tracking branch 'origin/account-sync' into rpc-flags
This commit is contained in:
commit
3ae7b939ae
|
@ -5,6 +5,10 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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
|
// TestAccountBindings makes sure we can create an account and subsequently
|
||||||
|
@ -19,12 +23,33 @@ func TestAccountBindings(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create an account
|
// create an account
|
||||||
address, _, err := createAccount("badpassword")
|
address, pubkey, err := createAccount("badpassword")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
t.Error("Test failed: could not create account")
|
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
|
// unlock the created account
|
||||||
err = unlockAccount(address, "badpassword", 10)
|
err = unlockAccount(address, "badpassword", 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -150,7 +150,8 @@ func (self *Whisper) GetIdentity(key *ecdsa.PublicKey) *ecdsa.PrivateKey {
|
||||||
func (self *Whisper) InjectIdentity(key *ecdsa.PrivateKey) error {
|
func (self *Whisper) InjectIdentity(key *ecdsa.PrivateKey) error {
|
||||||
|
|
||||||
identity := string(crypto.FromECDSAPub(&key.PublicKey))
|
identity := string(crypto.FromECDSAPub(&key.PublicKey))
|
||||||
self.keys[identity] = key
|
keyCopy := *key
|
||||||
|
self.keys[identity] = &keyCopy
|
||||||
if _, ok := self.keys[identity]; !ok {
|
if _, ok := self.keys[identity]; !ok {
|
||||||
return fmt.Errorf("key insert into keys map failed")
|
return fmt.Errorf("key insert into keys map failed")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue