-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move functions to common and add unit test
- Loading branch information
Jin Liu
authored and
Jin Liu
committed
Nov 26, 2019
1 parent
f4e61fa
commit 6daf776
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package crypto | ||
|
||
import ( | ||
"testing" | ||
|
||
ledgerPb "github.com/tron-us/go-btfs-common/protos/ledger" | ||
) | ||
|
||
const ( | ||
KeyString = "CAISIJFNZZd5ZSvi9OlJP/mz/vvUobvlrr2//QN4DzX/EShP" | ||
) | ||
|
||
func TestSignVerify(t *testing.T) { | ||
// test get privKey and pubKey | ||
privKey, err := ToPrivKey(KeyString) | ||
if err != nil { | ||
t.Error("ToPrivKey failed") | ||
return | ||
} | ||
|
||
rawPubKey, err := privKey.GetPublic().Raw() | ||
if err != nil { | ||
t.Error("get raw public key from privKey failed") | ||
return | ||
} | ||
pubKey, err := ToPubKey(rawPubKey) | ||
if err != nil { | ||
t.Error("ToPubKey failed") | ||
return | ||
} | ||
|
||
// test sign and verify the key string | ||
message := &ledgerPb.PublicKey{ | ||
Key: rawPubKey, | ||
} | ||
|
||
sign, err := Sign(privKey, message) | ||
if err != nil { | ||
t.Error("Sign with private key failed") | ||
return | ||
} | ||
ret, err := Verify(pubKey, message, sign) | ||
if err != nil || !ret { | ||
t.Error("Verify with public key failed") | ||
} | ||
} |