github.com/holochain/holochain-proto@v0.1.0-alpha-26.0.20200915073418-5c83169c9b5b/revocation_test.go (about) 1 package holochain 2 3 import ( 4 "fmt" 5 . "github.com/smartystreets/goconvey/convey" 6 "testing" 7 ) 8 9 func TestSelfRevocationVerify(t *testing.T) { 10 _, oldPrivKey := makePeer("peer1") 11 _, newPrivKey := makePeer("peer2") 12 13 revocation, err := NewSelfRevocation(oldPrivKey, newPrivKey, []byte("extra data")) 14 15 Convey("verify should check the revocation", t, func() { 16 So(err, ShouldBeNil) 17 err = revocation.Verify() 18 So(err, ShouldBeNil) 19 }) 20 21 Convey("verify should fail on modified data", t, func() { 22 //x := revocation.data[len(revocation.data)-3] 23 revocation.Data[len(revocation.Data)-3] = 1 24 err := revocation.Verify() 25 So(err, ShouldEqual, SelfRevocationDoesNotVerify) 26 }) 27 } 28 29 func TestSelfRevocationMarshal(t *testing.T) { 30 _, oldPrivKey := makePeer("peer1") 31 _, newPrivKey := makePeer("peer2") 32 33 revocation, _ := NewSelfRevocation(oldPrivKey, newPrivKey, []byte("extra data")) 34 35 Convey("should marshal and unmarshal", t, func() { 36 data, err := revocation.Marshal() 37 So(err, ShouldBeNil) 38 So(string(data), ShouldEqual, `{"Data":"JAgBEiC8/nwPO4mS3MSCLuHPqfQO2ffxwHUvVV0f9e1GjtihlggBEiBFvAl5ouxGA7GzS1vDHeB7CmdHkTq9RE6ojWuZ/b03KGV4dHJhIGRhdGE=","OldSig":"x7YRx7qrxd5Csh0xi1O4yi4BEO+Bn26gNoi0rLf1+QKH2BzYcVtczZXDTJi/C7r+RHOTUrY09AYHVIy/bOCCBA==","NewSig":"xVBsmxp+5y/Kr8TqQ5EfjJKJa4Q162eQPI3bNYJjqwk5HdHcXuO8xlk7cuCWUGnHBr1IGI5D6L0IEdiwBRPEDQ=="}`) 39 40 newr := &SelfRevocation{} 41 42 err = newr.Unmarshal(data) 43 So(err, ShouldBeNil) 44 So(fmt.Sprintf("%v", newr), ShouldEqual, fmt.Sprintf("%v", revocation)) 45 }) 46 }