MCPcopy Create free account
hub / github.com/chain/Core / TestBlockHeaderValid

Function TestBlockHeaderValid

protocol/validation/validation_test.go:377–413  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

375}
376
377func TestBlockHeaderValid(t *testing.T) {
378 base := bc.NewBlockHeader(1, 1, &bc.Hash{}, 1, &bc.Hash{}, &bc.Hash{}, nil)
379 baseBytes, _ := proto.Marshal(base)
380
381 var bh bc.BlockHeader
382
383 cases := []struct {
384 f func()
385 err error
386 }{
387 {},
388 {
389 f: func() {
390 bh.Version = 2
391 },
392 },
393 {
394 f: func() {
395 bh.ExtHash = newHash(1)
396 },
397 err: errNonemptyExtHash,
398 },
399 }
400
401 for i, c := range cases {
402 t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) {
403 proto.Unmarshal(baseBytes, &bh)
404 if c.f != nil {
405 c.f()
406 }
407 err := checkValidBlockHeader(&bh)
408 if err != c.err {
409 t.Errorf("got error %s, want %s; bh is:\n%s", err, c.err, spew.Sdump(bh))
410 }
411 })
412 }
413}
414
415// A txFixture is returned by sample (below) to produce a sample
416// transaction, which takes a separate, optional _input_ txFixture to

Callers

nothing calls this directly

Calls 2

newHashFunction · 0.85
checkValidBlockHeaderFunction · 0.85

Tested by

no test coverage detected