2022-04-05 07:09:27 +00:00
|
|
|
package testutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-09-07 06:36:11 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/bond/client/cli"
|
|
|
|
"github.com/cerc-io/laconicd/x/bond/types"
|
2022-04-05 07:09:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
|
|
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
tmcli "github.com/tendermint/tendermint/libs/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestTxCreateBond() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
err bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"without deposit",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.accountName),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"create bond",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("10%s", s.cfg.BondDenom),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.accountName),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(fmt.Sprintf("Case %s", tc.name), func() {
|
|
|
|
clientCtx := val.ClientCtx
|
|
|
|
cmd := cli.NewCreateBondCmd()
|
|
|
|
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
|
|
|
if tc.err {
|
|
|
|
sr.Error(err)
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
var d sdk.TxResponse
|
|
|
|
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
|
|
|
sr.Nil(err)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.Zero(d.Code)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-17 06:47:56 +00:00
|
|
|
//nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
func (s *IntegrationTestSuite) TestTxRefillBond() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
getBondId bool
|
|
|
|
err bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"without refill amount and bond id",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.accountName),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"refill bond",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("10%s", s.cfg.BondDenom),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.accountName),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(fmt.Sprintf("Case %s", tc.name), func() {
|
|
|
|
clientCtx := val.ClientCtx
|
|
|
|
cmd := cli.RefillBondCmd()
|
|
|
|
if tc.getBondId {
|
|
|
|
cmd := cli.GetQueryBondLists()
|
|
|
|
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
|
|
|
var queryResponse types.QueryGetBondsResponse
|
|
|
|
err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
|
|
|
sr.NoError(err)
|
|
|
|
|
|
|
|
// extract bond id from bonds list
|
|
|
|
bond := queryResponse.GetBonds()[0]
|
2022-10-17 11:03:31 +00:00
|
|
|
tc.args = append([]string{bond.GetID()}, tc.args...)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
|
|
|
if tc.err {
|
|
|
|
sr.Error(err)
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
var d sdk.TxResponse
|
|
|
|
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.Zero(d.Code)
|
|
|
|
|
|
|
|
// checking the balance of bond
|
2022-10-17 11:03:31 +00:00
|
|
|
cmd := cli.GetBondByIDCmd()
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{
|
|
|
|
fmt.Sprintf(tc.args[0]),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
2022-10-17 11:03:31 +00:00
|
|
|
var queryResponse types.QueryGetBondByIDResponse
|
2022-04-05 07:09:27 +00:00
|
|
|
err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
|
|
|
sr.NoError(err)
|
|
|
|
|
|
|
|
sr.True(queryResponse.GetBond().GetBalance().IsEqual(
|
|
|
|
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(20)))))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-17 06:47:56 +00:00
|
|
|
//nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
func (s *IntegrationTestSuite) TestTxWithdrawAmountFromBond() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
|
|
|
getBondId bool
|
|
|
|
err bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"without withdraw amount and bond id",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.accountName),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"withdraw amount from bond",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("10%s", s.cfg.BondDenom),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.accountName),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(fmt.Sprintf("Case %s", tc.name), func() {
|
|
|
|
clientCtx := val.ClientCtx
|
|
|
|
cmd := cli.WithdrawBondCmd()
|
|
|
|
if tc.getBondId {
|
|
|
|
cmd := cli.GetQueryBondLists()
|
|
|
|
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
|
|
|
var queryResponse types.QueryGetBondsResponse
|
|
|
|
err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
|
|
|
sr.NoError(err)
|
|
|
|
|
|
|
|
// extract bond id from bonds list
|
|
|
|
bond := queryResponse.GetBonds()[0]
|
2022-10-17 11:03:31 +00:00
|
|
|
tc.args = append([]string{bond.GetID()}, tc.args...)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
|
|
|
if tc.err {
|
|
|
|
sr.Error(err)
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
var d sdk.TxResponse
|
|
|
|
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.Zero(d.Code)
|
|
|
|
|
|
|
|
// checking the balance of bond
|
2022-10-17 11:03:31 +00:00
|
|
|
cmd := cli.GetBondByIDCmd()
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{
|
|
|
|
fmt.Sprintf(tc.args[0]),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
2022-10-17 11:03:31 +00:00
|
|
|
var queryResponse types.QueryGetBondByIDResponse
|
2022-04-05 07:09:27 +00:00
|
|
|
err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
|
|
|
sr.NoError(err)
|
|
|
|
|
|
|
|
sr.True(queryResponse.GetBond().GetBalance().IsEqual(
|
|
|
|
sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10)))))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestTxCancelBond() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
args []string
|
2022-10-17 07:15:01 +00:00
|
|
|
getBondID bool
|
2022-04-05 07:09:27 +00:00
|
|
|
err bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"without bond id",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.accountName),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cancel bond",
|
|
|
|
[]string{
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.accountName),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(fmt.Sprintf("Case %s", tc.name), func() {
|
|
|
|
clientCtx := val.ClientCtx
|
|
|
|
cmd := cli.CancelBondCmd()
|
2022-10-17 07:15:01 +00:00
|
|
|
if tc.getBondID {
|
2022-04-05 07:09:27 +00:00
|
|
|
cmd := cli.GetQueryBondLists()
|
|
|
|
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
|
|
|
var queryResponse types.QueryGetBondsResponse
|
|
|
|
err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
|
|
|
sr.NoError(err)
|
|
|
|
|
|
|
|
// extract bond id from bonds list
|
|
|
|
bond := queryResponse.GetBonds()[0]
|
2022-10-17 11:03:31 +00:00
|
|
|
tc.args = append([]string{bond.GetID()}, tc.args...)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
|
|
|
if tc.err {
|
|
|
|
sr.Error(err)
|
|
|
|
} else {
|
|
|
|
sr.NoError(err)
|
|
|
|
var d sdk.TxResponse
|
|
|
|
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.Zero(d.Code)
|
|
|
|
|
|
|
|
// checking the bond exists or not after cancel
|
2022-10-17 11:03:31 +00:00
|
|
|
cmd := cli.GetBondByIDCmd()
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{
|
|
|
|
fmt.Sprintf(tc.args[0]),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
})
|
|
|
|
sr.NoError(err)
|
2022-10-17 11:03:31 +00:00
|
|
|
var queryResponse types.QueryGetBondByIDResponse
|
2022-04-05 07:09:27 +00:00
|
|
|
err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
|
|
|
sr.NoError(err)
|
|
|
|
|
2022-10-17 11:03:31 +00:00
|
|
|
sr.Zero(queryResponse.GetBond().GetID())
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|