github.com/holochain/holochain-proto@v0.1.0-alpha-26.0.20200915073418-5c83169c9b5b/action_sign_test.go (about) 1 package holochain 2 3 import ( 4 b58 "github.com/jbenet/go-base58" 5 . "github.com/smartystreets/goconvey/convey" 6 "testing" 7 ) 8 9 func TestActionSigning(t *testing.T) { 10 d, _, h := PrepareTestChain("test") 11 defer CleanupTestChain(h, d) 12 13 privKey := h.agent.PrivKey() 14 sig, err := privKey.Sign([]byte("3")) 15 if err != nil { 16 panic(err) 17 } 18 19 var b58sig string 20 Convey("sign action should return a b58 encoded signature", t, func() { 21 fn := &APIFnSign{[]byte("3")} 22 result, err := fn.Call(h) 23 So(err, ShouldBeNil) 24 b58sig = result.(string) 25 26 So(b58sig, ShouldEqual, b58.Encode(sig)) 27 }) 28 var pubKey string 29 pubKey, err = h.agent.EncodePubKey() 30 if err != nil { 31 panic(err) 32 } 33 34 Convey("verify signture action should test a signature", t, func() { 35 fn := &APIFnVerifySignature{b58signature: b58sig, data: string([]byte("3")), b58pubKey: pubKey} 36 result, err := fn.Call(h) 37 So(err, ShouldBeNil) 38 So(result.(bool), ShouldBeTrue) 39 fn = &APIFnVerifySignature{b58signature: b58sig, data: string([]byte("34")), b58pubKey: pubKey} 40 result, err = fn.Call(h) 41 So(err, ShouldBeNil) 42 So(result.(bool), ShouldBeFalse) 43 }) 44 }