forked from cerc-io/laconicd-deprecated
rpc: implement personal_importRawKey (#552)
This commit is contained in:
+21
-2
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -42,6 +43,24 @@ func TestPersonal_Sign(t *testing.T) {
|
||||
// TODO: check that signature is same as with geth, requires importing a key
|
||||
}
|
||||
|
||||
func TestPersonal_ImportRawKey(t *testing.T) {
|
||||
privkey, err := ethcrypto.GenerateKey()
|
||||
require.NoError(t, err)
|
||||
|
||||
// parse priv key to hex
|
||||
hexPriv := common.Bytes2Hex(ethcrypto.FromECDSA(privkey))
|
||||
rpcRes := call(t, "personal_importRawKey", []string{hexPriv, "password"})
|
||||
|
||||
var res hexutil.Bytes
|
||||
err = json.Unmarshal(rpcRes.Result, &res)
|
||||
require.NoError(t, err)
|
||||
|
||||
addr := ethcrypto.PubkeyToAddress(privkey.PublicKey)
|
||||
resAddr := common.BytesToAddress(res)
|
||||
|
||||
require.Equal(t, addr.String(), resAddr.String())
|
||||
}
|
||||
|
||||
func TestPersonal_EcRecover(t *testing.T) {
|
||||
data := hexutil.Bytes{0x88}
|
||||
rpcRes := call(t, "personal_sign", []interface{}{data, hexutil.Bytes(from), ""})
|
||||
@@ -67,7 +86,7 @@ func TestPersonal_UnlockAccount(t *testing.T) {
|
||||
|
||||
// try to sign, should be locked
|
||||
_, err = callWithError("personal_sign", []interface{}{hexutil.Bytes{0x88}, addr, ""})
|
||||
require.NotNil(t, err)
|
||||
require.Error(t, err)
|
||||
|
||||
rpcRes = call(t, "personal_unlockAccount", []interface{}{addr, ""})
|
||||
var unlocked bool
|
||||
@@ -104,5 +123,5 @@ func TestPersonal_LockAccount(t *testing.T) {
|
||||
|
||||
// try to sign, should be locked
|
||||
_, err = callWithError("personal_sign", []interface{}{hexutil.Bytes{0x88}, addr, ""})
|
||||
require.NotNil(t, err)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user