From 1ef82b2ceede665a670c0aaa5b7c06b35c65bf2a Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 27 Aug 2018 10:53:52 +0300 Subject: [PATCH] test message signing --- sign_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sign_test.go diff --git a/sign_test.go b/sign_test.go new file mode 100644 index 0000000..507a6c1 --- /dev/null +++ b/sign_test.go @@ -0,0 +1,42 @@ +package floodsub + +import ( + "testing" + + pb "github.com/libp2p/go-floodsub/pb" + + crypto "github.com/libp2p/go-libp2p-crypto" + peer "github.com/libp2p/go-libp2p-peer" +) + +func TestSigning(t *testing.T) { + privk, _, err := crypto.GenerateKeyPair(crypto.RSA, 2048) + if err != nil { + t.Fatal(err) + } + testSignVerify(t, privk) + + privk, _, err = crypto.GenerateKeyPair(crypto.Ed25519, 0) + if err != nil { + t.Fatal(err) + } + testSignVerify(t, privk) +} + +func testSignVerify(t *testing.T, privk crypto.PrivKey) { + id, err := peer.IDFromPublicKey(privk.GetPublic()) + if err != nil { + t.Fatal(err) + } + m := pb.Message{ + Data: []byte("abc"), + TopicIDs: []string{"foo"}, + From: []byte(id), + Seqno: []byte("123"), + } + signMessage(privk, &m) + err = verifyMessageSignature(&m) + if err != nil { + t.Fatal(err) + } +}