MCPcopy Create free account
hub / github.com/DeAI-Artist/Linkis / TestLoadBlockPart

Function TestLoadBlockPart

store/store_test.go:396–427  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

394}
395
396func TestLoadBlockPart(t *testing.T) {
397 bs, db := freshBlockStore()
398 height, index := int64(10), 1
399 loadPart := func() (interface{}, error) {
400 part := bs.LoadBlockPart(height, index)
401 return part, nil
402 }
403
404 // Initially no contents.
405 // 1. Requesting for a non-existent block shouldn't fail
406 res, _, panicErr := doFn(loadPart)
407 require.Nil(t, panicErr, "a non-existent block part shouldn't cause a panic")
408 require.Nil(t, res, "a non-existent block part should return nil")
409
410 // 2. Next save a corrupted block then try to load it
411 err := db.Set(calcBlockPartKey(height, index), []byte("Tendermint"))
412 require.NoError(t, err)
413 res, _, panicErr = doFn(loadPart)
414 require.NotNil(t, panicErr, "expecting a non-nil panic")
415 require.Contains(t, panicErr.Error(), "unmarshal to tmproto.Part failed")
416
417 // 3. A good block serialized and saved to the DB should be retrievable
418 pb1, err := part1.ToProto()
419 require.NoError(t, err)
420 err = db.Set(calcBlockPartKey(height, index), mustEncode(pb1))
421 require.NoError(t, err)
422 gotPart, _, panicErr := doFn(loadPart)
423 require.Nil(t, panicErr, "an existent and proper block should not panic")
424 require.Nil(t, res, "a properly saved block should return a proper block")
425 require.Equal(t, gotPart.(*types.Part), part1,
426 "expecting successful retrieval of previously saved block")
427}
428
429func TestPruneBlocks(t *testing.T) {
430 config := cfg.ResetTestRoot("blockchain_reactor_test")

Callers

nothing calls this directly

Calls 9

freshBlockStoreFunction · 0.85
doFnFunction · 0.85
calcBlockPartKeyFunction · 0.85
mustEncodeFunction · 0.85
LoadBlockPartMethod · 0.65
SetMethod · 0.65
ErrorMethod · 0.65
EqualMethod · 0.65
ToProtoMethod · 0.45

Tested by

no test coverage detected