Skip to content

Commit

Permalink
admin String, JSON tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSnow committed Apr 22, 2017
1 parent 04f0011 commit bf6da97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/adminBlock/adminBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (c *AdminBlock) Init() {
h := new(ABlockHeader)
h.Init()
c.Header = h
c.ABEntries = make([]interfaces.IABEntry, 0)
}
}

Expand Down
17 changes: 17 additions & 0 deletions common/adminBlock/adminBlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/FactomProject/factomd/common/primitives"
"github.com/FactomProject/factomd/common/primitives/random"
"github.com/FactomProject/factomd/testHelper"
"fmt"
)

func TestAdminBlockUnmarshalComplexBlock(t *testing.T) {
Expand Down Expand Up @@ -452,6 +453,20 @@ func TestAdminBlockMarshalUnmarshal(t *testing.T) {
t.Error("ABEntries are not identical")
}
}
str1, err1 := block.JSONString()
str2, err2 := block2.JSONString()
if err1 != nil || err2 != nil || str1 != str2 {
fmt.Println("One ", str1, "\nTwo ", str2)
t.Errorf("JSON doesn't match. %d",b)
}
b1, err1 := block.JSONByte()
b2, err2 := block.JSONByte()
if err1 != nil || err2 != nil || bytes.Compare(b1,b2) != 0 {
t.Errorf("JSON Byte doesn't match. %d",b)
}
if block.String() != block2.String() {
t.Errorf("String representation doesn't match %d",b)
}
}
}

Expand Down Expand Up @@ -731,6 +746,7 @@ func TestAddServerFault(t *testing.T) {

func createTestAdminBlock() (block interfaces.IAdminBlock) {
block = new(AdminBlock)
block.(*AdminBlock).Init()
block.SetHeader(createTestAdminHeader())
/**
p, _ := hex.DecodeString("cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc")
Expand All @@ -753,6 +769,7 @@ func createTestAdminBlock() (block interfaces.IAdminBlock) {

func createSmallTestAdminBlock() (block interfaces.IAdminBlock) {
block = new(AdminBlock)
block.(*AdminBlock).Init()
block.SetHeader(createSmallTestAdminHeader())
block.GetHeader().SetMessageCount(uint32(len(block.GetABEntries())))
return block
Expand Down

0 comments on commit bf6da97

Please sign in to comment.