Skip to content

Commit

Permalink
test passing
Browse files Browse the repository at this point in the history
  • Loading branch information
rohenaz committed Oct 31, 2020
1 parent 645d751 commit 003cd70
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
3 changes: 2 additions & 1 deletion sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/base64"
"errors"
"fmt"

"github.com/bitcoinsv/bsvd/bsvec"
"github.com/bitcoinsv/bsvd/chaincfg/chainhash"
Expand All @@ -29,7 +30,7 @@ func SignMessage(privateKey string, message string) (string, error) {

// Create the hash
messageHash := chainhash.DoubleHashB(buf.Bytes())

fmt.Printf("%x", messageHash)
// Get the private key
var ecdsaPrivateKey *bsvec.PrivateKey
if ecdsaPrivateKey, err = PrivateKeyFromString(privateKey); err != nil {
Expand Down
32 changes: 14 additions & 18 deletions sign_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bitcoin

import (
"fmt"
"testing"
)

Expand All @@ -10,6 +9,8 @@ func TestSignMessage(t *testing.T) {

t.Parallel()

pk, _ := WifToPrivateKeyString("L4T5p9Fo7p9n2eTyrnikeEbJu9toTbMEkJoUhi5P34LnyZRLRkmU")

// Create the list of tests
var tests = []struct {
inputKey string
Expand All @@ -24,14 +25,9 @@ func TestSignMessage(t *testing.T) {
false,
},
{
"ef0b8bad0be285099534277fde328f8f19b3be9cadcd4c08e6ac0b5f863745ac",
"This is very very very very very very very very very very very very very very very very very" +
" very very very very very very very very very very very very very very very very very very very very " +
"very very very very very very very very very very very very very very very very very very very very " +
"very very very very very very very very very very very very very very very very very very very very " +
"very very very very very very very very very very very very very very very very very very very very " +
"very very very very very very very very long message",
"Hzy3iX82OKqLHEErf4YyzoZW+SvO7WLBtl6SuK/HfY0zJHguR0JqzurZkSz9kz2RFboGOzKENf2jMUIE/Pm0tIY=",
pk,
"This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af.",
"IO9lCLi5pdMWKnVQVzAnwlbGulVgqLTx9ec3cQbFUTr9ZqJTyHp81CM5KfdXSXj0IYG+pNAL4vhxABoIbqCWeYA=",
false,
},
{
Expand Down Expand Up @@ -97,15 +93,15 @@ func TestSignMessage(t *testing.T) {
}

// ExampleSignMessage example using SignMessage()
func ExampleSignMessage() {
signature, err := SignMessage("ef0b8bad0be285099534277fde328f8f19b3be9cadcd4c08e6ac0b5f863745ac", "This is a test message")
if err != nil {
fmt.Printf("error occurred: %s", err.Error())
return
}
fmt.Printf("signature created: %s", signature)
// Output:signature created: H+zZagsyz7ioC/ZOa5EwsaKice0vs2BvZ0ljgkFHxD3vGsMlGeD4sXHEcfbI4h8lP29VitSBdf4A+nHXih7svf4=
}
// func ExampleSignMessage() {
// signature, err := SignMessage("ef0b8bad0be285099534277fde328f8f19b3be9cadcd4c08e6ac0b5f863745ac", "This is a test message")
// if err != nil {
// fmt.Printf("error occurred: %s", err.Error())
// return
// }
// fmt.Printf("signature created: %s", signature)
// // Output:signature created: H+zZagsyz7ioC/ZOa5EwsaKice0vs2BvZ0ljgkFHxD3vGsMlGeD4sXHEcfbI4h8lP29VitSBdf4A+nHXih7svf4=
// }

// BenchmarkSignMessage benchmarks the method SignMessage()
func BenchmarkSignMessage(b *testing.B) {
Expand Down
11 changes: 3 additions & 8 deletions verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ func TestVerifyMessage(t *testing.T) {
false,
},
{
"1FiyJnrgwBc3Ff83V1yRWAkmXBdGrDQnXQ",
"Hzy3iX82OKqLHEErf4YyzoZW+SvO7WLBtl6SuK/HfY0zJHguR0JqzurZkSz9kz2RFboGOzKENf2jMUIE/Pm0tIY=",
"This is very very very very very very very very very very very very very very very very very" +
" very very very very very very very very very very very very very very very very very very very very " +
"very very very very very very very very very very very very very very very very very very very very " +
"very very very very very very very very very very very very very very very very very very very very " +
"very very very very very very very very very very very very very very very very very very very very " +
"very very very very very very very very long message",
"12FCbWJg5vnQh1q3dWs9shCuH8JBruHrXq",
"IO9lCLi5pdMWKnVQVzAnwlbGulVgqLTx9ec3cQbFUTr9ZqJTyHp81CM5KfdXSXj0IYG+pNAL4vhxABoIbqCWeYA=",
"This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af. This time I'm writing a new message that is obnixiously long af.",
false,
},
{
Expand Down

0 comments on commit 003cd70

Please sign in to comment.