37 lines
878 B
Go
37 lines
878 B
Go
|
package tests
|
||
|
|
||
|
import (
|
||
|
"kerma/models"
|
||
|
"testing"
|
||
|
|
||
|
. "github.com/smartystreets/goconvey/convey"
|
||
|
)
|
||
|
|
||
|
func TestChaintip(t *testing.T) {
|
||
|
Convey("Given a new chaintip", t, func() {
|
||
|
blockID := models.GetGenesisBlock().GetID()
|
||
|
var chaintip models.Chaintip
|
||
|
|
||
|
Convey("When the constructor is called with a value", func() {
|
||
|
chaintip.Construct(blockID)
|
||
|
|
||
|
Convey("The value should be set", func() {
|
||
|
So(chaintip.Type, ShouldEqual, "chaintip")
|
||
|
So(chaintip.BlockID, ShouldEqual, blockID)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
Convey("When the MarshalJson is called", func() {
|
||
|
chaintip.Construct(blockID)
|
||
|
|
||
|
Convey("The canonical json and no error should be returned", func() {
|
||
|
chaintipJSON, err := chaintip.MarshalJson()
|
||
|
canonJSON := `{"blockid":"` + blockID + `","type":"chaintip"}`
|
||
|
|
||
|
So(string(chaintipJSON), ShouldEqualJSON, canonJSON)
|
||
|
So(err, ShouldBeNil)
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
}
|