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

Add square sizes flag to the payForMessage cli command #202

Merged
merged 25 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1fecce2
add new flags
toanngosy Feb 5, 2022
41f9319
add celestia flags
toanngosy Feb 5, 2022
ecec3f0
use square size in cli wirepayformessage
toanngosy Feb 5, 2022
de95c78
add square size in app
toanngosy Feb 7, 2022
ff0637e
update test for arbitrary square size
toanngosy Feb 7, 2022
962b407
refactor flags
toanngosy Feb 9, 2022
8b1ec7f
shorten flags file
toanngosy Feb 11, 2022
e5f4b35
update nwpfm to receive list of square sizes
toanngosy Feb 11, 2022
f18fc52
add a new test case for list of square sizes
toanngosy Feb 11, 2022
8f30563
add back square size
toanngosy Feb 11, 2022
c71313c
unchange abci
toanngosy Feb 11, 2022
78b9fd4
refactor parse uint to uint64
toanngosy Feb 11, 2022
bb2c8db
add power of 2 check
toanngosy Feb 11, 2022
ae9f466
add test case for invalid square size
toanngosy Feb 11, 2022
b08447b
update description flags
toanngosy Feb 11, 2022
08ea197
move and update powerof2 func
toanngosy Feb 12, 2022
d3cca6f
update powerOf2 func
toanngosy Feb 12, 2022
5498a55
add test to powerOf2
toanngosy Feb 12, 2022
c94130c
delete gap
toanngosy Feb 13, 2022
33c7791
move check power of 2 first
toanngosy Feb 13, 2022
2d58081
move flag to wirepayformessage
toanngosy Feb 13, 2022
27928a7
move const FlagSquareSizes to wirepayformessage
toanngosy Feb 13, 2022
6da8dc9
add test for invalid square size in pfm ValidateBasic
toanngosy Feb 13, 2022
28bb0c4
add 1 more test where change square size to another power of 2 number
toanngosy Feb 13, 2022
80b52ab
change squaresize to 4 to pass the test
toanngosy Feb 14, 2022
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 app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ func hasWirePayForMessage(tx sdk.Tx) bool {
// hardcoded. todo(evan): don't hardcode the square size
func (app *App) SquareSize() uint64 {
return consts.MaxSquareSize
}
}
17 changes: 17 additions & 0 deletions flags/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package flags

import (
"github.com/cosmos/cosmos-sdk/client/flags"

"github.com/spf13/cobra"
"github.com/tendermint/tendermint/pkg/consts"
)

// List of CLI flags
const FlagSquareSizes = "square-sizes"

// AddTxFlagsToCmd adds common flags to a module tx command.
func AddTxFlagsToCmd(cmd *cobra.Command) {
flags.AddTxFlagsToCmd(cmd)
cmd.Flags().UintSlice(FlagSquareSizes, []uint{consts.MaxSquareSize, 128, 64}, "Specify the square size")
}
17 changes: 14 additions & 3 deletions x/payment/client/cli/wirepayformessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/tendermint/tendermint/pkg/consts"
//"github.com/tendermint/tendermint/pkg/consts"

"github.com/celestiaorg/celestia-app/x/payment/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
cflags "github.com/celestiaorg/celestia-app/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -52,7 +53,17 @@ func CmdWirePayForMessage() *cobra.Command {
}

// create the MsgPayForMessage
pfmMsg, err := types.NewWirePayForMessage(namespace, message, consts.MaxSquareSize)
squareSizes, err := cmd.Flags().GetUintSlice(cflags.FlagSquareSizes)
if err != nil {
return err
}

squareSizes64 := make([]uint64, len(squareSizes))
for i := range squareSizes {
squareSizes64[i] = uint64(squareSizes[i])
}
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
pfmMsg, err := types.NewWirePayForMessage(namespace, message, squareSizes64...)

evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down Expand Up @@ -101,7 +112,7 @@ func CmdWirePayForMessage() *cobra.Command {
},
}

flags.AddTxFlagsToCmd(cmd)
cflags.AddTxFlagsToCmd(cmd)

return cmd
}
14 changes: 14 additions & 0 deletions x/payment/client/testutil/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/cosmos/cosmos-sdk/client/flags"
cflags "github.com/celestiaorg/celestia-app/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -82,6 +83,19 @@ func (s *IntegrationTestSuite) TestSubmitWirePayForMessage() {
},
false, 0, &sdk.TxResponse{},
},
{
"valid transaction list of square sizes",
[]string{
hexNS,
hexMsg,
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=%s", cflags.FlagSquareSizes, "256,128,64"),
},
false, 0, &sdk.TxResponse{},
},
}

for _, tc := range testCases {
Expand Down