rpc: fix Bloom filter response (#321)

* fix bloomfilter in rpc response

* add comments
This commit is contained in:
Thomas Nguy
2021-07-20 15:16:02 +00:00
committed by GitHub
parent bb6622b7fb
commit 0276f3465d
9 changed files with 165 additions and 92 deletions
+3 -3
View File
@@ -272,10 +272,10 @@ func (k Keeper) BlockLogs(c context.Context, req *types.QueryBlockLogsRequest) (
}
// BlockBloom implements the Query/BlockBloom gRPC method
func (k Keeper) BlockBloom(c context.Context, _ *types.QueryBlockBloomRequest) (*types.QueryBlockBloomResponse, error) {
func (k Keeper) BlockBloom(c context.Context, req *types.QueryBlockBloomRequest) (*types.QueryBlockBloomResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
bloom, found := k.GetBlockBloom(ctx, ctx.BlockHeight())
bloom, found := k.GetBlockBloom(ctx, req.Height)
if !found {
// if the bloom is not found, query the transient store at the current height
k.ctx = ctx
@@ -283,7 +283,7 @@ func (k Keeper) BlockBloom(c context.Context, _ *types.QueryBlockBloomRequest) (
if bloomInt.Sign() == 0 {
return nil, status.Error(
codes.NotFound, sdkerrors.Wrapf(types.ErrBloomNotFound, "height: %d", ctx.BlockHeight()).Error(),
codes.NotFound, sdkerrors.Wrapf(types.ErrBloomNotFound, "height: %d", req.Height).Error(),
)
}
+9 -7
View File
@@ -540,14 +540,16 @@ func (suite *KeeperTestSuite) TestQueryBlockBloom() {
malleate func()
expPass bool
}{
{"marshal error",
func() {},
{"bad height",
func() {
req = &types.QueryBlockBloomRequest{Height: -2}
},
false,
},
{
"bloom from transient store",
func() {
req = &types.QueryBlockBloomRequest{}
req = &types.QueryBlockBloomRequest{Height: 1}
bloom := ethtypes.BytesToBloom([]byte("bloom"))
expBloom = bloom.Bytes()
suite.app.EvmKeeper.WithContext(suite.ctx.WithBlockHeight(1))
@@ -557,7 +559,7 @@ func (suite *KeeperTestSuite) TestQueryBlockBloom() {
},
{"bloom not found for height",
func() {
req = &types.QueryBlockBloomRequest{}
req = &types.QueryBlockBloomRequest{Height: 100}
bloom := ethtypes.BytesToBloom([]byte("bloom"))
expBloom = bloom.Bytes()
suite.ctx = suite.ctx.WithBlockHeight(100)
@@ -568,11 +570,11 @@ func (suite *KeeperTestSuite) TestQueryBlockBloom() {
{
"success",
func() {
req = &types.QueryBlockBloomRequest{}
req = &types.QueryBlockBloomRequest{Height: 3}
bloom := ethtypes.BytesToBloom([]byte("bloom"))
expBloom = bloom.Bytes()
suite.ctx = suite.ctx.WithBlockHeight(1)
suite.app.EvmKeeper.SetBlockBloom(suite.ctx, 1, bloom)
suite.ctx = suite.ctx.WithBlockHeight(3)
suite.app.EvmKeeper.SetBlockBloom(suite.ctx, 3, bloom)
},
true,
},