Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: address serialization in PayForBlobs event (backport #2793) #2794

Merged
merged 6 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/blob/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (k Keeper) PayForBlobs(goCtx context.Context, msg *types.MsgPayForBlobs) (*
ctx.GasMeter().ConsumeGas(gasToConsume, payForBlobGasDescriptor)

err := ctx.EventManager().EmitTypedEvent(
types.NewPayForBlobsEvent(sdk.AccAddress(msg.Signer).String(), msg.BlobSizes, msg.Namespaces),
types.NewPayForBlobsEvent(msg.Signer, msg.BlobSizes, msg.Namespaces),
)
if err != nil {
return &types.MsgPayForBlobsResponse{}, err
Expand Down
64 changes: 64 additions & 0 deletions x/blob/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package keeper

import (
"bytes"
"fmt"
"testing"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/x/blob/types"
sdk "github.com/cosmos/cosmos-sdk/types"
proto "github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

// TestPayForBlobs verifies the attributes on the emitted event.
func TestPayForBlobs(t *testing.T) {
k, stateStore := keeper(t)
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, nil)
signer := "celestia15drmhzw5kwgenvemy30rqqqgq52axf5wwrruf7"
namespace := appns.MustNewV0(bytes.Repeat([]byte{1}, appns.NamespaceVersionZeroIDSize))
namespaces := [][]byte{namespace.Bytes()}
blobData := []byte("blob")
blobSizes := []uint32{uint32(len(blobData))}

// verify no events exist yet
events := ctx.EventManager().Events().ToABCIEvents()
assert.Len(t, events, 0)

// emit an event by submitting a PayForBlob
msg := createMsgPayForBlob(t, signer, namespace, blobData)
_, err := k.PayForBlobs(ctx, msg)
require.NoError(t, err)

// verify that an event was emitted
events = ctx.EventManager().Events().ToABCIEvents()
assert.Len(t, events, 1)
protoEvent, err := sdk.ParseTypedEvent(events[0])
require.NoError(t, err)
event, err := convertToEventPayForBlobs(protoEvent)
require.NoError(t, err)

// verify the attributes of the event
assert.Equal(t, signer, event.Signer)
assert.Equal(t, namespaces, event.Namespaces)
assert.Equal(t, blobSizes, event.BlobSizes)
}

func convertToEventPayForBlobs(message proto.Message) (*types.EventPayForBlobs, error) {
if event, ok := message.(*types.EventPayForBlobs); ok {
return event, nil
}
return nil, fmt.Errorf("message is not of type EventPayForBlobs")
}

func createMsgPayForBlob(t *testing.T, signer string, namespace appns.Namespace, blobData []byte) *types.MsgPayForBlobs {
blob, err := types.NewBlob(namespace, blobData, appconsts.ShareVersionZero)
require.NoError(t, err)
msg, err := types.NewMsgPayForBlobs(signer, blob)
require.NoError(t, err)
return msg
}
Loading