Add e2e tests for gRPC requests and CLI commands #13

Merged
ashwin merged 14 commits from pm-cli-tests into main 2024-03-04 11:16:11 +00:00
13 changed files with 676 additions and 24 deletions
Showing only changes of commit 839e993e02 - Show all commits

View File

@ -9,7 +9,7 @@ import (
) )
const ( const (
randomAuctionID = "randomAuctionID" randomAuctionId = "randomAuctionId"
randomBidderAddress = "randomBidderAddress" randomBidderAddress = "randomBidderAddress"
randomOwnerAddress = "randomOwnerAddress" randomOwnerAddress = "randomOwnerAddress"
) )
@ -44,7 +44,7 @@ func (ets *E2ETestSuite) TestGetAllAuctionsGrpc() {
}{ }{
{ {
"invalid request to get all auctions", "invalid request to get all auctions",
reqURL + randomAuctionID, reqURL + randomAuctionId,
"", "",
true, true,
}, },
@ -85,7 +85,7 @@ func (ets *E2ETestSuite) TestGetAuctionGrpc() {
}{ }{
{ {
"invalid request to get an auction", "invalid request to get an auction",
reqURL + randomAuctionID, reqURL + randomAuctionId,
"", "",
true, true,
func() string { return "" }, func() string { return "" },
@ -100,8 +100,8 @@ func (ets *E2ETestSuite) TestGetAuctionGrpc() {
} }
for _, tc := range testCases { for _, tc := range testCases {
ets.Run(tc.msg, func() { ets.Run(tc.msg, func() {
auctionID := tc.preRun() auctionId := tc.preRun()
resp, err := testutil.GetRequest(tc.url + auctionID) resp, err := testutil.GetRequest(tc.url + auctionId)
if tc.isErrorExpected { if tc.isErrorExpected {
sr.Contains(string(resp), tc.errorMsg) sr.Contains(string(resp), tc.errorMsg)
} else { } else {
@ -109,7 +109,7 @@ func (ets *E2ETestSuite) TestGetAuctionGrpc() {
var auction auctiontypes.QueryAuctionResponse var auction auctiontypes.QueryAuctionResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &auction) err = val.ClientCtx.Codec.UnmarshalJSON(resp, &auction)
sr.NoError(err) sr.NoError(err)
sr.Equal(auctionID, auction.Auction.Id) sr.Equal(auctionId, auction.Auction.Id)
} }
}) })
} }
@ -144,8 +144,8 @@ func (ets *E2ETestSuite) TestGetBidsGrpc() {
for _, tc := range testCases { for _, tc := range testCases {
ets.Run(tc.msg, func() { ets.Run(tc.msg, func() {
auctionID := tc.preRun() auctionId := tc.preRun()
tc.url += auctionID tc.url += auctionId
resp, err := testutil.GetRequest(tc.url) resp, err := testutil.GetRequest(tc.url)
if tc.isErrorExpected { if tc.isErrorExpected {
sr.Contains(string(resp), tc.errorMsg) sr.Contains(string(resp), tc.errorMsg)
@ -154,7 +154,7 @@ func (ets *E2ETestSuite) TestGetBidsGrpc() {
var bids auctiontypes.QueryBidsResponse var bids auctiontypes.QueryBidsResponse
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &bids) err = val.ClientCtx.Codec.UnmarshalJSON(resp, &bids)
sr.NoError(err) sr.NoError(err)
sr.Equal(auctionID, bids.Bids[0].AuctionId) sr.Equal(auctionId, bids.Bids[0].AuctionId)
} }
}) })
} }
@ -176,7 +176,7 @@ func (ets *E2ETestSuite) TestGetBidGrpc() {
reqURL, reqURL,
"", "",
true, true,
func() string { return randomAuctionID }, func() string { return randomAuctionId },
}, },
{ {
"valid request to get bid", "valid request to get bid",
@ -188,8 +188,8 @@ func (ets *E2ETestSuite) TestGetBidGrpc() {
} }
for _, tc := range testCases { for _, tc := range testCases {
ets.Run(tc.msg, func() { ets.Run(tc.msg, func() {
auctionID := tc.preRun() auctionId := tc.preRun()
tc.url += auctionID + "/" + bidderAddress tc.url += auctionId + "/" + bidderAddress
resp, err := testutil.GetRequest(tc.url) resp, err := testutil.GetRequest(tc.url)
if tc.isErrorExpected { if tc.isErrorExpected {

View File

@ -113,7 +113,7 @@ func (ets *E2ETestSuite) TestGRPCGetBondsByOwner() {
} }
} }
func (ets *E2ETestSuite) TestGRPCGetBondByID() { func (ets *E2ETestSuite) TestGRPCGetBondById() {
val := ets.network.Validators[0] val := ets.network.Validators[0]
sr := ets.Require() sr := ets.Require()
reqURL := val.APIAddress + "/cerc/bond/v1/bonds/%s" reqURL := val.APIAddress + "/cerc/bond/v1/bonds/%s"
@ -139,10 +139,10 @@ func (ets *E2ETestSuite) TestGRPCGetBondByID() {
} }
for _, tc := range testCases { for _, tc := range testCases {
ets.Run(tc.name, func() { ets.Run(tc.name, func() {
var bondID string var bondId string
if !tc.expErr { if !tc.expErr {
bondID = tc.preRun() bondId = tc.preRun()
tc.url = fmt.Sprintf(reqURL, bondID) tc.url = fmt.Sprintf(reqURL, bondId)
} }
resp, err := testutil.GetRequest(tc.url) resp, err := testutil.GetRequest(tc.url)
@ -156,7 +156,7 @@ func (ets *E2ETestSuite) TestGRPCGetBondByID() {
} else { } else {
sr.NoError(err) sr.NoError(err)
sr.NotZero(bonds.GetBond().GetId()) sr.NotZero(bonds.GetBond().GetId())
sr.Equal(bonds.GetBond().GetId(), bondID) sr.Equal(bonds.GetBond().GetId(), bondId)
} }
}) })
} }

View File

@ -1,11 +1,15 @@
package registry package registry
import ( import (
"encoding/json"
"fmt" "fmt"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/testutil"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry" registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry"
"git.vdb.to/cerc-io/laconic2d/x/registry/client/cli"
) )
const badPath = "/asdasd" const badPath = "/asdasd"
@ -103,3 +107,323 @@ func (ets *E2ETestSuite) TestGRPCQueryWhoIs() {
}) })
} }
} }
func (ets *E2ETestSuite) TestGRPCQueryLookup() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := val.APIAddress + "/cerc/registry/v1/lookup"
authorityName := "QueryLookUp"
testCases := []struct {
name string
url string
expectErr bool
errorMsg string
preRun func(authorityName string)
}{
{
"invalid url",
reqURL + badPath,
true,
"",
func(authorityName string) {
},
},
{
"valid request",
fmt.Sprintf(reqURL+"?lrn=lrn://%s/", authorityName),
false,
"",
func(authorityName string) {
// create name record
ets.createNameRecord(authorityName)
},
},
}
for _, tc := range testCases {
ets.Run(tc.name, func() {
tc.preRun(authorityName)
resp, err := testutil.GetRequest(tc.url)
ets.NoError(err)
if tc.expectErr {
sr.Contains(string(resp), tc.errorMsg)
} else {
var response registrytypes.QueryLookupLrnResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
sr.NoError(err)
sr.NotZero(len(response.Name.Latest.Id))
}
})
}
}
func (ets *E2ETestSuite) TestGRPCQueryListRecords() {
val := ets.network.Validators[0]
sr := ets.Require()
reqUrl := val.APIAddress + "/cerc/registry/v1/records"
testCases := []struct {
name string
url string
expectErr bool
errorMsg string
preRun func(bondId string)
}{
{
"invalid url",
reqUrl + badPath,
true,
"",
func(bondId string) {
},
},
{
"valid request",
reqUrl,
false,
"",
func(bondId string) { ets.createRecord(bondId) },
},
}
for _, tc := range testCases {
ets.Run(tc.name, func() {
tc.preRun(ets.bondId)
resp, err := testutil.GetRequest(tc.url)
ets.NoError(err)
require := ets.Require()
if tc.expectErr {
require.Contains(string(resp), tc.errorMsg)
} else {
var response registrytypes.QueryRecordsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
sr.NoError(err)
sr.NotZero(len(response.GetRecords()))
sr.Equal(ets.bondId, response.GetRecords()[0].GetBondId())
}
})
}
}
func (ets *E2ETestSuite) TestGRPCQueryGetRecordById() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := val.APIAddress + "/cerc/registry/v1/records/%s"
testCases := []struct {
name string
url string
expectErr bool
errorMsg string
preRun func(bondId string) string
}{
{
"invalid url",
reqURL + badPath,
true,
"",
func(bondId string) string {
return ""
},
},
{
"valid request",
reqURL,
false,
"",
func(bondId string) string {
// creating the record
ets.createRecord(bondId)
// list the records
clientCtx := val.ClientCtx
cmd := cli.GetCmdList()
args := []string{
fmt.Sprintf("--%s=json", flags.FlagOutput),
}
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
sr.NoError(err)
var records []registrytypes.ReadableRecord
err = json.Unmarshal(out.Bytes(), &records)
sr.NoError(err)
return records[0].Id
},
},
}
for _, tc := range testCases {
ets.Run(tc.name, func() {
recordId := tc.preRun(ets.bondId)
tc.url = fmt.Sprintf(reqURL, recordId)
resp, err := testutil.GetRequest(tc.url)
ets.NoError(err)
require := ets.Require()
if tc.expectErr {
require.Contains(string(resp), tc.errorMsg)
} else {
var response registrytypes.QueryRecordByIdResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
sr.NoError(err)
record := response.GetRecord()
sr.NotZero(len(record.GetId()))
sr.Equal(record.GetId(), recordId)
}
})
}
}
func (ets *E2ETestSuite) TestGRPCQueryGetRecordByBondId() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := val.APIAddress + "/cerc/registry/v1/records-by-bond-id/%s"
testCases := []struct {
name string
url string
expectErr bool
errorMsg string
preRun func(bondId string)
}{
{
"invalid url",
reqURL + badPath,
true,
"",
func(bondId string) {
},
},
{
"valid request",
reqURL,
false,
"",
func(bondId string) {
// creating the record
ets.createRecord(bondId)
},
},
}
for _, tc := range testCases {
ets.Run(tc.name, func() {
tc.preRun(ets.bondId)
tc.url = fmt.Sprintf(reqURL, ets.bondId)
resp, err := testutil.GetRequest(tc.url)
ets.NoError(err)
require := ets.Require()
if tc.expectErr {
require.Contains(string(resp), tc.errorMsg)
} else {
var response registrytypes.QueryRecordsByBondIdResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
sr.NoError(err)
records := response.GetRecords()
sr.NotZero(len(records))
sr.Equal(records[0].GetBondId(), ets.bondId)
}
})
}
}
func (ets *E2ETestSuite) TestGRPCQueryGetRegistryModuleBalance() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := val.APIAddress + "/cerc/registry/v1/balance"
testCases := []struct {
name string
url string
expectErr bool
errorMsg string
preRun func(bondId string)
}{
{
"invalid url",
reqURL + badPath,
true,
"",
func(bondId string) {
},
},
{
"Success",
reqURL,
false,
"",
func(bondId string) {
// creating the record
ets.createRecord(bondId)
},
},
}
for _, tc := range testCases {
ets.Run(tc.name, func() {
tc.preRun(ets.bondId)
resp, err := testutil.GetRequest(tc.url)
ets.NoError(err)
require := ets.Require()
if tc.expectErr {
require.Contains(string(resp), tc.errorMsg)
} else {
var response registrytypes.QueryGetRegistryModuleBalanceResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
sr.NoError(err)
sr.NotZero(len(response.GetBalances()))
}
})
}
}
func (ets *E2ETestSuite) TestGRPCQueryNamesList() {
val := ets.network.Validators[0]
sr := ets.Require()
reqURL := val.APIAddress + "/cerc/registry/v1/names"
testCases := []struct {
name string
url string
expectErr bool
errorMsg string
preRun func(authorityName string)
}{
{
"invalid url",
reqURL + badPath,
true,
"",
func(authorityName string) {
},
},
{
"valid request",
reqURL,
false,
"",
func(authorityName string) {
// create name record
ets.createNameRecord(authorityName)
},
},
}
for _, tc := range testCases {
ets.Run(tc.name, func() {
tc.preRun("ListNameRecords")
resp, err := testutil.GetRequest(tc.url)
ets.NoError(err)
require := ets.Require()
if tc.expectErr {
require.Contains(string(resp), tc.errorMsg)
} else {
var response registrytypes.QueryNameRecordsResponse
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
sr.NoError(err)
sr.NotZero(len(response.GetNames()))
}
})
}
}

View File

@ -2,6 +2,7 @@ package registry
import ( import (
"fmt" "fmt"
"path/filepath"
"time" "time"
"cosmossdk.io/math" "cosmossdk.io/math"
@ -167,6 +168,107 @@ func (ets *E2ETestSuite) reserveName(authorityName string) {
sr.NoError(err) sr.NoError(err)
} }
func (ets *E2ETestSuite) createNameRecord(authorityName string) {
val := ets.network.Validators[0]
sr := ets.Require()
// reserving the name
clientCtx := val.ClientCtx
cmd := cli.GetCmdReserveName()
args := []string{
authorityName,
fmt.Sprintf("--owner=%s", ets.accountAddress),
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=json", flags.FlagOutput),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
}
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
sr.NoError(err)
var d sdk.TxResponse
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
sr.NoError(err)
sr.Zero(d.Code)
err = ets.network.WaitForNextBlock()
sr.NoError(err)
// Get the bond-id
bondId := ets.bondId
// adding bond-id to name authority
args = []string{
authorityName, bondId,
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=json", flags.FlagOutput),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
}
cmd = cli.GetCmdSetAuthorityBond()
out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
sr.NoError(err)
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
sr.NoError(err)
sr.Zero(d.Code)
err = ets.network.WaitForNextBlock()
sr.NoError(err)
args = []string{
fmt.Sprintf("lrn://%s/", authorityName),
"test_hello_cid",
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=json", flags.FlagOutput),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
}
cmd = cli.GetCmdSetName()
out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
sr.NoError(err)
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
sr.NoError(err)
sr.Zero(d.Code)
err = ets.network.WaitForNextBlock()
sr.NoError(err)
}
func (ets *E2ETestSuite) createRecord(bondId string) {
val := ets.network.Validators[0]
sr := ets.Require()
payloadPath := "../../data/examples/service_provider_example.yml"
payloadFilePath, err := filepath.Abs(payloadPath)
sr.NoError(err)
args := []string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=json", flags.FlagOutput),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
}
args = append([]string{payloadFilePath, bondId}, args...)
clientCtx := val.ClientCtx
cmd := cli.GetCmdSetRecord()
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
sr.NoError(err)
var d sdk.TxResponse
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
sr.NoError(err)
sr.Zero(d.Code, d.RawLog)
err = ets.network.WaitForNextBlock()
sr.NoError(err)
}
func (ets *E2ETestSuite) updateParams(params *registrytypes.Params) { func (ets *E2ETestSuite) updateParams(params *registrytypes.Params) {
params.RecordRent = sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(1000)) params.RecordRent = sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(1000))
params.RecordRentDuration = 10 * time.Second params.RecordRentDuration = 10 * time.Second

70
tests/e2e/registry/tx.go Normal file
View File

@ -0,0 +1,70 @@
package registry
import (
"fmt"
"path/filepath"
"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"git.vdb.to/cerc-io/laconic2d/x/registry/client/cli"
)
func (ets *E2ETestSuite) TestGetCmdSetRecord() {
val := ets.network.Validators[0]
sr := ets.Require()
bondId := ets.bondId
payloadPath := "../../data/examples/service_provider_example.yml"
payloadFilePath, err := filepath.Abs(payloadPath)
sr.NoError(err)
testCases := []struct {
name string
args []string
err bool
}{
{
"invalid request without bond id/without payload",
[]string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=json", flags.FlagOutput),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
},
true,
},
{
"success",
[]string{
payloadFilePath, bondId,
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=json", flags.FlagOutput),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
},
false,
},
}
for _, tc := range testCases {
ets.Run(fmt.Sprintf("Case %s", tc.name), func() {
clientCtx := val.ClientCtx
cmd := cli.GetCmdSetRecord()
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)
}
})
}
}

View File

@ -37,9 +37,9 @@ func (kts *KeeperTestSuite) TestGrpcGetRecordLists() {
var recordId string var recordId string
examples := []string{ examples := []string{
"../../data/examples/service_provider_example.yml", "../../../data/examples/service_provider_example.yml",
"../../data/examples/website_registration_example.yml", "../../../data/examples/website_registration_example.yml",
"../../data/examples/general_record_example.yml", "../../../data/examples/general_record_example.yml",
} }
testCases := []struct { testCases := []struct {
msg string msg string
@ -268,7 +268,7 @@ func (kts *KeeperTestSuite) TestGrpcGetRecordLists() {
} }
// Get the records by record id // Get the records by record id
testCasesByBondID := []struct { testCasesByBondId := []struct {
msg string msg string
req *types.QueryRecordsByBondIdRequest req *types.QueryRecordsByBondIdRequest
createRecord bool createRecord bool
@ -292,7 +292,7 @@ func (kts *KeeperTestSuite) TestGrpcGetRecordLists() {
1, 1,
}, },
} }
for _, test := range testCasesByBondID { for _, test := range testCasesByBondId {
kts.Run(fmt.Sprintf("Case %s ", test.msg), func() { kts.Run(fmt.Sprintf("Case %s ", test.msg), func() {
resp, err := queryClient.GetRecordsByBondId(context.Background(), test.req) resp, err := queryClient.GetRecordsByBondId(context.Background(), test.req)
@ -314,8 +314,8 @@ func (kts *KeeperTestSuite) TestGrpcQueryRegistryModuleBalance() {
queryClient, ctx := kts.queryClient, kts.SdkCtx queryClient, ctx := kts.queryClient, kts.SdkCtx
sr := kts.Require() sr := kts.Require()
examples := []string{ examples := []string{
"../../data/examples/service_provider_example.yml", "../../../data/examples/service_provider_example.yml",
"../../data/examples/website_registration_example.yml", "../../../data/examples/website_registration_example.yml",
} }
testCases := []struct { testCases := []struct {
msg string msg string

View File

@ -0,0 +1,58 @@
package cli
import (
"encoding/json"
"fmt"
"strings"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
"github.com/spf13/cobra"
registrytypes "git.vdb.to/cerc-io/laconic2d/x/registry"
)
// GetCmdList queries all records.
func GetCmdList() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List records.",
Long: strings.TrimSpace(
fmt.Sprintf(`Get the records.
Example:
$ %s query %s list
`,
version.AppName, registrytypes.ModuleName,
),
),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := registrytypes.NewQueryClient(clientCtx)
res, err := queryClient.Records(cmd.Context(), &registrytypes.QueryRecordsRequest{})
if err != nil {
return err
}
recordsList := res.GetRecords()
records := make([]registrytypes.ReadableRecord, len(recordsList))
for i, record := range res.GetRecords() {
records[i] = record.ToReadableRecord()
}
bytesResult, err := json.Marshal(records)
if err != nil {
return err
}
return clientCtx.PrintBytes(bytesResult)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

View File

@ -129,3 +129,66 @@ $ %s tx %s reserve-name [name] --owner [ownerAddress]
return cmd return cmd
} }
// GetCmdSetAuthorityBond is the CLI command for associating a bond with an authority.
func GetCmdSetAuthorityBond() *cobra.Command {
cmd := &cobra.Command{
Use: "authority-bond [name] [bond-id]",
Short: "Associate authority with bond.",
Long: strings.TrimSpace(
fmt.Sprintf(`Reserver name with owner address .
Example:
$ %s tx %s authority-bond [name] [bond-id]
`,
version.AppName, registrytypes.ModuleName,
),
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := registrytypes.NewMsgSetAuthorityBond(args[0], args[1], clientCtx.GetFromAddress())
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdSetName is the CLI command for mapping a name to a CID.
func GetCmdSetName() *cobra.Command {
cmd := &cobra.Command{
Use: "set-name [crn] [cid]",
Short: "Set CRN to CID mapping.",
Long: strings.TrimSpace(
fmt.Sprintf(`Set name with crn and cid.
Example:
$ %s tx %s set-name [crn] [cid]
`,
version.AppName, registrytypes.ModuleName,
),
),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := registrytypes.NewMsgSetName(args[0], args[1], clientCtx.GetFromAddress())
err = msg.ValidateBasic()
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}

View File

@ -55,3 +55,38 @@ func (msg MsgReserveAuthority) ValidateBasic() error {
return nil return nil
} }
// NewMsgSetAuthorityBond is the constructor function for MsgSetAuthorityBond.
func NewMsgSetAuthorityBond(name string, bondID string, signer sdk.AccAddress) MsgSetAuthorityBond {
return MsgSetAuthorityBond{
Name: name,
Signer: signer.String(),
BondId: bondID,
}
}
// NewMsgSetName is the constructor function for MsgSetName.
func NewMsgSetName(lrn string, cid string, signer sdk.AccAddress) *MsgSetName {
return &MsgSetName{
Lrn: lrn,
Cid: cid,
Signer: signer.String(),
}
}
// ValidateBasic Implements Msg.
func (msg MsgSetName) ValidateBasic() error {
if msg.Lrn == "" {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "LRN is required.")
}
if msg.Cid == "" {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "CID is required.")
}
if len(msg.Signer) == 0 {
return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "invalid signer")
}
return nil
}