Skip to content

Commit

Permalink
feat: add testRandBlob CLI for testground tests (#1311)
Browse files Browse the repository at this point in the history
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

## Overview

ATM, `test-infra` repo is using my fork of celestia-app, which is not
ok.
We need a CLI command for tests to trigger PFBs from apps' side, hence
we have added another command named `TestRandBlob`

This PR contains another renaming, touching removal of `Wire` prefixes

Ref: celestiaorg/test-infra#159
<!-- 
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue. 
-->

## Checklist

<!-- 
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [x] New and updated code has appropriate documentation
- [x] New and updated code has new and/or updated testing
- [x] Required CI checks are passing
- [x] Visual proof for any user facing features like CLI or
documentation updates
- [x] Linked issues closed with keywords

---------

Co-authored-by: Rootul P <[email protected]>
Co-authored-by: Evan Forbes <[email protected]>
  • Loading branch information
3 people authored Jan 30, 2023
1 parent 422be7f commit 852a229
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@ import (
coretypes "github.com/tendermint/tendermint/types"
)

func CmdWirePayForBlob() *cobra.Command {
func CmdPayForBlob() *cobra.Command {
cmd := &cobra.Command{
Use: "PayForBlobs [hexNamespace] [hexBlob]",
Short: "Pay for a data blob to be published to the Celestia blockchain",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

// decode the namespace
namespace, err := hex.DecodeString(args[0])
if err != nil {
Expand All @@ -47,41 +42,52 @@ func CmdWirePayForBlob() *cobra.Command {
return err
}

// TODO: allow the user to override the share version via a new flag
// See https://github.com/celestiaorg/celestia-app/issues/1041
pfbMsg, err := types.NewMsgPayForBlobs(clientCtx.FromAddress.String(), blob)
if err != nil {
return err
}
return broadcastPFB(cmd, blob)
},
}

// run message checks
if err = pfbMsg.ValidateBasic(); err != nil {
return err
}
flags.AddTxFlagsToCmd(cmd)

txBytes, err := writeTx(clientCtx, sdktx.NewFactoryCLI(clientCtx, cmd.Flags()), pfbMsg)
if err != nil {
return err
}
return cmd
}

blobTx, err := coretypes.MarshalBlobTx(txBytes, blob)
if err != nil {
return err
}
// broadcastPFB creates the new PFB message type that will later be broadcast to tendermint nodes
// this private func is used in CmdPayForBlob and CmdTestRandBlob
func broadcastPFB(cmd *cobra.Command, blob *types.Blob) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

// broadcast to a Tendermint node
res, err := clientCtx.BroadcastTx(blobTx)
if err != nil {
return err
}
// TODO: allow the user to override the share version via a new flag
// See https://github.com/celestiaorg/celestia-app/issues/1041
pfbMsg, err := types.NewMsgPayForBlobs(clientCtx.FromAddress.String(), blob)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
// run message checks
if err = pfbMsg.ValidateBasic(); err != nil {
return err
}

flags.AddTxFlagsToCmd(cmd)
txBytes, err := writeTx(clientCtx, sdktx.NewFactoryCLI(clientCtx, cmd.Flags()), pfbMsg)
if err != nil {
return err
}

return cmd
blobTx, err := coretypes.MarshalBlobTx(txBytes, blob)
if err != nil {
return err
}

// broadcast to a Tendermint node
res, err := clientCtx.BroadcastTx(blobTx)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
}

// writeTx attempts to generate and sign a transaction using the normal
Expand Down
46 changes: 46 additions & 0 deletions x/blob/client/cli/testrandblob.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cli

import (
"fmt"
"strconv"

"github.com/celestiaorg/celestia-app/testutil/namespace"
"github.com/celestiaorg/celestia-app/testutil/testfactory"
"github.com/celestiaorg/celestia-app/x/blob/types"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client/flags"
)

// CmdTestRandBlob is triggered by testground's tests as part of apps' node scenario
// to increase the block size by user-defined amount.
//
// CAUTION: This func should not be used in production env!
func CmdTestRandBlob() *cobra.Command {
cmd := &cobra.Command{
Use: "TestRandBlob [blobSize]",
Short: "Generates a random blob for a random namespace to be published to the Celestia blockchain",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// decode the blob size
size, err := strconv.Atoi(args[0])
if err != nil {
return fmt.Errorf("failure to decode blob size: %w", err)
}

nid := namespace.RandomBlobNamespace()
coreBlob := testfactory.GenerateBlobsWithNamespace(1, size, nid)
blob, err := types.NewBlob(coreBlob[0].NamespaceID, coreBlob[0].Data)
if err != nil {
return fmt.Errorf("failure on generating random blob: %w", err)
}

return broadcastPFB(cmd, blob)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
3 changes: 2 additions & 1 deletion x/blob/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func GetTxCmd() *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdWirePayForBlob())
cmd.AddCommand(CmdPayForBlob())
cmd.AddCommand(CmdTestRandBlob())

return cmd
}
2 changes: 1 addition & 1 deletion x/blob/client/testutil/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *IntegrationTestSuite) TestSubmitWirePayForBlob() {
tc := tc
s.Require().NoError(s.network.WaitForNextBlock())
s.Run(tc.name, func() {
cmd := paycli.CmdWirePayForBlob()
cmd := paycli.CmdPayForBlob()
clientCtx := val.ClientCtx

out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
Expand Down

0 comments on commit 852a229

Please sign in to comment.