(t *testing.T)
| 394 | } |
| 395 | |
| 396 | func 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 | |
| 429 | func TestPruneBlocks(t *testing.T) { |
| 430 | config := cfg.ResetTestRoot("blockchain_reactor_test") |
nothing calls this directly
no test coverage detected