-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: address serialization in PayForBlobs event (#2793)
Closes #2781 Note this _shouldn't_ be consensus breaking b/c the ABCI response results hash shouldn't depend on events. [`deterministicResponseDeliverTx`](https://github.com/celestiaorg/celestia-core/blob/ffdb652634fb1b6b6426c0f1a2c5adec8af80253/types/results.go#L45-L55) filters events from the response. Thanks @cmwaters for identifying. ## Testing I tested on a Robusta devnet named app-v130-node-v0110. See #2794 (comment) and #2794 (comment)
- Loading branch information
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
"github.com/celestiaorg/celestia-app/pkg/blob" | ||
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 := blob.New(namespace, blobData, appconsts.ShareVersionZero) | ||
msg, err := types.NewMsgPayForBlobs(signer, blob) | ||
require.NoError(t, err) | ||
return msg | ||
} |