Skip to content

Commit

Permalink
feat: update x/collection cli for hackwasm2023 (#1038)
Browse files Browse the repository at this point in the history
* Add burn cmds to x/collection

* Allow minting tokens of multiple classes

* Update CHANGELOG.md
  • Loading branch information
0Tech authored Jul 12, 2023
1 parent 4f96389 commit edb1434
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (x/collection) [\#1038](https://github.com/Finschia/finschia-sdk/pull/1038) Update x/collection cli for hackwasm2023

### Improvements

### Bug Fixes
Expand Down
19 changes: 10 additions & 9 deletions x/collection/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func NewTxCmd() *cobra.Command {
NewTxCmdIssueNFT(),
NewTxCmdMintFT(),
NewTxCmdMintNFT(),
NewTxCmdBurnFT(),
NewTxCmdBurnNFT(),
NewTxCmdAttach(),
NewTxCmdDetach(),
NewTxCmdOperatorAttach(),
Expand Down Expand Up @@ -414,11 +416,11 @@ func NewTxCmdIssueNFT() *cobra.Command {

func NewTxCmdMintFT() *cobra.Command {
cmd := &cobra.Command{
Use: "mint-ft [contract-id] [operator] [to] [class-id] [amount]",
Args: cobra.ExactArgs(5),
Use: "mint-ft [contract-id] [operator] [to] [amount]",
Args: cobra.ExactArgs(4),
Short: "mint fungible tokens",
Long: strings.TrimSpace(fmt.Sprintf(`
$ %s tx %s mint-ft [contract-id] [operator] [to] [class-id] [amount]`, version.AppName, collection.ModuleName),
$ %s tx %s mint-ft [contract-id] [operator] [to] [amount]`, version.AppName, collection.ModuleName),
),
RunE: func(cmd *cobra.Command, args []string) error {
operator := args[1]
Expand All @@ -431,18 +433,17 @@ func NewTxCmdMintFT() *cobra.Command {
return err
}

amountStr := args[4]
amount, ok := sdk.NewIntFromString(amountStr)
if !ok {
return sdkerrors.ErrInvalidType.Wrapf("failed to set amount: %s", amountStr)
amountStr := args[3]
amount, err := collection.ParseCoins(amountStr)
if err != nil {
return err
}

coins := collection.NewCoins(collection.NewFTCoin(args[3], amount))
msg := collection.MsgMintFT{
ContractId: args[0],
From: args[1],
To: args[2],
Amount: coins,
Amount: amount,
}
if err := msg.ValidateBasic(); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions x/collection/client/testutil/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ func (s *IntegrationTestSuite) createNFTClass(contractID string, operator sdk.Ac

func (s *IntegrationTestSuite) mintFT(contractID string, operator, to sdk.AccAddress, classID string, amount sdk.Int) {
val := s.network.Validators[0]
amt := collection.NewCoins(collection.NewFTCoin(classID, amount))
args := append([]string{
contractID,
operator.String(),
to.String(),
classID,
amount.String(),
amt.String(),
}, commonArgs...)

out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewTxCmdMintFT(), args)
Expand Down
11 changes: 4 additions & 7 deletions x/collection/client/testutil/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ func (s *IntegrationTestSuite) TestNewTxCmdMintFT() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
}

amount := collection.NewCoins(collection.NewFTCoin(s.ftClassID, s.balance))
testCases := map[string]struct {
args []string
valid bool
Expand All @@ -537,8 +538,7 @@ func (s *IntegrationTestSuite) TestNewTxCmdMintFT() {
s.contractID,
s.operator.String(),
s.customer.String(),
s.ftClassID,
s.balance.String(),
amount.String(),
},
true,
},
Expand All @@ -547,8 +547,7 @@ func (s *IntegrationTestSuite) TestNewTxCmdMintFT() {
s.contractID,
s.operator.String(),
s.customer.String(),
s.ftClassID,
s.balance.String(),
amount.String(),
"extra",
},
false,
Expand All @@ -558,7 +557,6 @@ func (s *IntegrationTestSuite) TestNewTxCmdMintFT() {
s.contractID,
s.operator.String(),
s.customer.String(),
s.ftClassID,
},
false,
},
Expand All @@ -567,8 +565,7 @@ func (s *IntegrationTestSuite) TestNewTxCmdMintFT() {
"",
s.operator.String(),
s.customer.String(),
s.ftClassID,
s.balance.String(),
amount.String(),
},
false,
},
Expand Down

0 comments on commit edb1434

Please sign in to comment.