github.com/holochain/holochain-proto@v0.1.0-alpha-26.0.20200915073418-5c83169c9b5b/action_delete_test.go (about) 1 package holochain 2 3 import ( 4 "fmt" 5 . "github.com/holochain/holochain-proto/hash" 6 peer "github.com/libp2p/go-libp2p-peer" 7 . "github.com/smartystreets/goconvey/convey" 8 "testing" 9 ) 10 11 func TestDelName(t *testing.T) { 12 Convey("delete action should have the right name", t, func() { 13 // https://github.com/holochain/holochain-proto/issues/715 14 // a := NewDelAction(DelEntry{Hash: ""}) 15 a := ActionDel{entry: DelEntry{Hash: ""}} 16 So(a.Name(), ShouldEqual, "del") 17 }) 18 } 19 20 func TestAPIFnDelName(t *testing.T) { 21 Convey("delete action function should have the right name", t, func() { 22 // https://github.com/holochain/holochain-proto/issues/715 23 // a := NewDelAction(DelEntry{Hash: ""}) 24 a := ActionDel{entry: DelEntry{Hash: ""}} 25 fn := &APIFnDel{action: a} 26 So(fn.Name(), ShouldEqual, "del") 27 }) 28 } 29 30 func TestActionDelete(t *testing.T) { 31 nodesCount := 3 32 mt := setupMultiNodeTesting(nodesCount) 33 defer mt.cleanupMultiNodeTesting() 34 35 h := mt.nodes[0] 36 ringConnect(t, mt.ctx, mt.nodes, nodesCount) 37 38 profileHash := commit(h, "profile", `{"firstName":"Zippy","lastName":"Pinhead"}`) 39 entry := DelEntry{Hash: profileHash, Message: "expired"} 40 action := &ActionDel{entry: entry} 41 var hash Hash 42 deleteHash, err := h.commitAndShare(action, hash) 43 if err != nil { 44 panic(err) 45 } 46 47 Convey("when deleting a hash the del entry itself should be published to the DHT", t, func() { 48 for i := 0; i < nodesCount; i++ { 49 fmt.Printf("\nTesting retrieval of DelEntry from node %d\n", i) 50 51 request := GetReq{H: deleteHash, GetMask: GetMaskEntry} 52 response, err := callGet(mt.nodes[i], request, &GetOptions{GetMask: request.GetMask}) 53 r, ok := response.(GetResp) 54 55 So(ok, ShouldBeTrue) 56 So(err, ShouldBeNil) 57 58 So(&r.Entry, ShouldResemble, action.Entry()) 59 } 60 }) 61 } 62 63 func TestDelActionSysValidate(t *testing.T) { 64 d, _, h := PrepareTestChain("test") 65 defer CleanupTestChain(h, d) 66 67 hash := commit(h, "evenNumbers", "2") 68 // _, def, _ := h.GetEntryDef("evenNumbers") 69 70 Convey("it should check that entry isn't linking ", t, func() { 71 a := NewDelAction(DelEntry{Hash: hash}) 72 _, ratingsDef, _ := h.GetEntryDef("rating") 73 err := a.SysValidation(h, ratingsDef, nil, []peer.ID{h.nodeID}) 74 So(err, ShouldBeError) 75 }) 76 } 77 78 func TestSysDel(t *testing.T) { 79 d, _, h := PrepareTestChain("test") 80 defer CleanupTestChain(h, d) 81 var err error 82 83 Convey("deleting should fail for all sys entry types except delete", t, func() { 84 a := NewDelAction(DelEntry{}) 85 _, err = h.ValidateAction(a, DNAEntryType, nil, []peer.ID{h.nodeID}) 86 So(err, ShouldEqual, ErrEntryDefInvalid) 87 88 _, err = h.ValidateAction(a, KeyEntryType, nil, []peer.ID{h.nodeID}) 89 So(err, ShouldEqual, ErrEntryDefInvalid) 90 91 _, err = h.ValidateAction(a, AgentEntryType, nil, []peer.ID{h.nodeID}) 92 So(err, ShouldEqual, ErrEntryDefInvalid) 93 94 _, err = h.ValidateAction(a, HeadersEntryType, nil, []peer.ID{h.nodeID}) 95 So(err, ShouldEqual, ErrEntryDefInvalid) 96 }) 97 }