本文整理汇总了Golang中github.com/skycoin/skycoin/src/coin.Block.Head方法的典型用法代码示例。如果您正苦于以下问题:Golang Block.Head方法的具体用法?Golang Block.Head怎么用?Golang Block.Head使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/skycoin/skycoin/src/coin.Block
的用法示例。
在下文中一共展示了Block.Head方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestVerifyBlockHeader
func TestVerifyBlockHeader(t *testing.T) {
ft := FakeTree{}
bc := NewBlockchain(&ft, nil)
gb := bc.CreateGenesisBlock(genAddress, _genCoins, _genTime)
b := coin.Block{Body: coin.BlockBody{}}
b.Body.Transactions = append(b.Body.Transactions, makeTransaction(t))
h := coin.BlockHeader{}
h.BkSeq = 1
h.Time = gb.Head.Time + 1
h.PrevHash = gb.HashHeader()
h.BodyHash = b.HashBody()
// Valid header
b.Head = h
assert.Nil(t, bc.verifyBlockHeader(b))
// Invalid bkSeq
i := h
i.BkSeq++
b.Head = i
assertError(t, bc.verifyBlockHeader(b), "BkSeq invalid")
// Invalid time
i = h
i.Time = gb.Head.Time
b.Head = i
assertError(t, bc.verifyBlockHeader(b),
"Block time must be > head time")
b.Head.Time--
assertError(t, bc.verifyBlockHeader(b),
"Block time must be > head time")
// Invalid prevHash
i = h
i.PrevHash = cipher.SHA256{}
b.Head = i
assertError(t, bc.verifyBlockHeader(b),
"PrevHash does not match current head")
// Invalid bodyHash
i = h
i.BodyHash = cipher.SHA256{}
b.Head = i
assertError(t, bc.verifyBlockHeader(b),
"Computed body hash does not match")
}