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

feat: Introduce --namespace-version CLI flag #1585

Merged
merged 17 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
22 changes: 17 additions & 5 deletions x/blob/client/cli/payforblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
coretypes "github.com/tendermint/tendermint/types"
)

// FlagNamespaceVersion allows the user to override the namespace version when
// submitting a PayForBlob.
const FlagNamespaceVersion = "namespace-version"

func CmdPayForBlob() *cobra.Command {
cmd := &cobra.Command{
Use: "PayForBlobs [hexNamespaceID] [hexBlob]",
Expand All @@ -33,12 +37,10 @@ func CmdPayForBlob() *cobra.Command {
if err != nil {
return fmt.Errorf("failure to decode hex namespace ID: %w", err)
}

// TODO: allow the user to override the namespace version via a new flag
// See https://github.com/celestiaorg/celestia-app/issues/1528
namespace, err := appns.New(appns.NamespaceVersionZero, append(appns.NamespaceVersionZeroPrefix, namespaceID...))
namespaceVersion, _ := cmd.Flags().GetUint8(FlagNamespaceVersion)
rootulp marked this conversation as resolved.
Show resolved Hide resolved
namespace, err := getNamespace(namespaceID, namespaceVersion)
if err != nil {
return fmt.Errorf("failure to create namespace: %w", err)
return err
}

rawblob, err := hex.DecodeString(args[1])
Expand All @@ -57,10 +59,20 @@ func CmdPayForBlob() *cobra.Command {
}

flags.AddTxFlagsToCmd(cmd)
cmd.PersistentFlags().Uint8(FlagNamespaceVersion, 0, "Specify the namespace version")

return cmd
}

func getNamespace(namespaceID []byte, namespaceVersion uint8) (appns.Namespace, error) {
switch uint8(namespaceVersion) {
amityadav0 marked this conversation as resolved.
Show resolved Hide resolved
case appns.NamespaceVersionZero:
return appns.New(uint8(namespaceVersion), append(appns.NamespaceVersionZeroPrefix, namespaceID...))
amityadav0 marked this conversation as resolved.
Show resolved Hide resolved
default:
return appns.Namespace{}, fmt.Errorf("namespace version %d is not supported", namespaceVersion)
}
}

// 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 {
Expand Down
33 changes: 32 additions & 1 deletion x/blob/client/testutil/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testutil

import (
"bytes"
"encoding/hex"
"fmt"
"strconv"
Expand All @@ -20,6 +21,7 @@ import (
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/testutil/network"
"github.com/celestiaorg/celestia-app/testutil/testfactory"
"github.com/celestiaorg/celestia-app/x/blob/client/cli"
paycli "github.com/celestiaorg/celestia-app/x/blob/client/cli"
abci "github.com/tendermint/tendermint/abci/types"
)
Expand Down Expand Up @@ -62,8 +64,8 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() {
require := s.Require()
val := s.network.Validators[0]
hexNamespace := hex.EncodeToString(appns.RandomBlobNamespaceID())
invalidNamespaceID := hex.EncodeToString(bytes.Repeat([]byte{0}, 8)) // invalid because ID is expected to be 10 bytes
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved

// some hex blob
hexBlob := "0204033704032c0b162109000908094d425837422c2116"

testCases := []struct {
Expand All @@ -87,6 +89,35 @@ func (s *IntegrationTestSuite) TestSubmitPayForBlob() {
expectedCode: 0,
respType: &sdk.TxResponse{},
},
{
name: "invalid namespace ID",
args: []string{
invalidNamespaceID,
hexBlob,
fmt.Sprintf("--from=%s", username),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
},
expectErr: true,
expectedCode: 0,
respType: &sdk.TxResponse{},
},
{
name: "invalid namespace version",
args: []string{
hexNamespace,
hexBlob,
fmt.Sprintf("--from=%s", username),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(2))).String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=1", cli.FlagNamespaceVersion),
},
expectErr: true,
expectedCode: 0,
respType: &sdk.TxResponse{},
},
}

for _, tc := range testCases {
Expand Down