github.com/holochain/holochain-proto@v0.1.0-alpha-26.0.20200915073418-5c83169c9b5b/action_update_test.go (about)

     1  package holochain
     2  
     3  import (
     4  	peer "github.com/libp2p/go-libp2p-peer"
     5  	. "github.com/smartystreets/goconvey/convey"
     6  	"testing"
     7  )
     8  
     9  func TestSysValidateMod(t *testing.T) {
    10  	d, _, h := PrepareTestChain("test")
    11  	defer CleanupTestChain(h, d)
    12  
    13  	hash := commit(h, "evenNumbers", "2")
    14  	_, def, _ := h.GetEntryDef("evenNumbers")
    15  
    16  	/* This is actually bogus because it assumes we have the entry type in our chain but
    17  	           might be in a different chain.
    18  		Convey("it should check that entry types match on mod", t, func() {
    19  			a := NewModAction("oddNumbers", &GobEntry{}, hash)
    20  			err := a.SysValidation(h, def, nil, []peer.ID{h.nodeID})
    21  			So(err, ShouldEqual, ErrEntryTypeMismatch)
    22  		})
    23  	*/
    24  
    25  	Convey("it should check that entry isn't linking ", t, func() {
    26  		a := NewModAction("rating", &GobEntry{}, hash)
    27  		_, ratingsDef, _ := h.GetEntryDef("rating")
    28  		err := a.SysValidation(h, ratingsDef, nil, []peer.ID{h.nodeID})
    29  		So(err, ShouldEqual, ErrModInvalidForLinks)
    30  	})
    31  
    32  	Convey("it should check that entry validates", t, func() {
    33  		a := NewModAction("evenNumbers", nil, hash)
    34  		err := a.SysValidation(h, def, nil, []peer.ID{h.nodeID})
    35  		So(err, ShouldEqual, ErrNilEntryInvalid)
    36  	})
    37  
    38  	Convey("it should check that header isn't missing", t, func() {
    39  		a := NewModAction("evenNumbers", &GobEntry{}, hash)
    40  		err := a.SysValidation(h, def, nil, []peer.ID{h.nodeID})
    41  		So(err, ShouldBeError)
    42  		So(err, ShouldEqual, ErrModMissingHeader)
    43  	})
    44  
    45  	Convey("it should check that replaces is doesn't make a loop", t, func() {
    46  		a := NewModAction("evenNumbers", &GobEntry{}, hash)
    47  		a.header = &Header{EntryLink: hash}
    48  		err := a.SysValidation(h, def, nil, []peer.ID{h.nodeID})
    49  		So(err, ShouldBeError)
    50  		So(err, ShouldEqual, ErrModReplacesHashNotDifferent)
    51  	})
    52  
    53  }