2022-04-05 07:09:27 +00:00
|
|
|
package testutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2022-04-20 07:37:38 +00:00
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2022-12-09 04:17:14 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/registry/client/cli"
|
|
|
|
nstypes "github.com/cerc-io/laconicd/x/registry/types"
|
2022-04-05 07:09:27 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
|
|
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
2022-04-23 15:53:51 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/testutil/rest"
|
2022-04-05 07:09:27 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
tmcli "github.com/tendermint/tendermint/libs/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestGRPCQueryParams() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
2022-12-09 04:17:14 +00:00
|
|
|
reqURL := val.APIAddress + "/vulcanize/registry/v1beta1/params"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectErr bool
|
|
|
|
errorMsg string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid url",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL + "/asdasd",
|
2022-04-05 07:09:27 +00:00
|
|
|
true,
|
|
|
|
"",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL,
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
"",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.name, func() {
|
|
|
|
resp, _ := rest.GetRequest(tc.url)
|
|
|
|
require := s.Require()
|
|
|
|
if tc.expectErr {
|
|
|
|
require.Contains(string(resp), tc.errorMsg)
|
|
|
|
} else {
|
|
|
|
var response nstypes.QueryParamsResponse
|
|
|
|
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
|
|
|
sr.NoError(err)
|
|
|
|
params := nstypes.DefaultParams()
|
|
|
|
params.RecordRent = sdk.NewCoin(s.cfg.BondDenom, nstypes.DefaultRecordRent)
|
2022-04-20 19:15:52 +00:00
|
|
|
params.RecordRentDuration = 10 * time.Second
|
|
|
|
params.AuthorityGracePeriod = 10 * time.Second
|
2022-04-05 07:09:27 +00:00
|
|
|
sr.Equal(response.GetParams().String(), params.String())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-17 06:47:56 +00:00
|
|
|
//nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
func (s *IntegrationTestSuite) TestGRPCQueryWhoIs() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
2022-12-09 04:17:14 +00:00
|
|
|
reqUrl := val.APIAddress + "/vulcanize/registry/v1beta1/whois/%s"
|
2022-10-17 06:47:56 +00:00
|
|
|
authorityName := "QueryWhoIS"
|
2022-04-05 07:09:27 +00:00
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectErr bool
|
|
|
|
errorMsg string
|
|
|
|
preRun func(authorityName string)
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid url",
|
|
|
|
reqUrl + "/asdasd",
|
|
|
|
true,
|
|
|
|
"",
|
|
|
|
func(authorityName string) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
|
|
|
reqUrl,
|
|
|
|
false,
|
|
|
|
"",
|
|
|
|
func(authorityName string) {
|
|
|
|
clientCtx := val.ClientCtx
|
|
|
|
cmd := cli.GetCmdReserveName()
|
|
|
|
args := []string{
|
|
|
|
authorityName,
|
|
|
|
fmt.Sprintf("--owner=%s", accountAddress),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.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)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.name, func() {
|
|
|
|
if !tc.expectErr {
|
|
|
|
tc.preRun(authorityName)
|
|
|
|
tc.url = fmt.Sprintf(tc.url, authorityName)
|
|
|
|
}
|
|
|
|
resp, _ := rest.GetRequest(tc.url)
|
|
|
|
require := s.Require()
|
|
|
|
if tc.expectErr {
|
|
|
|
require.Contains(string(resp), tc.errorMsg)
|
|
|
|
} else {
|
|
|
|
var response nstypes.QueryWhoisResponse
|
|
|
|
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.Equal(nstypes.AuthorityActive, response.GetNameAuthority().Status)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestGRPCQueryLookup() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
2022-12-09 04:17:14 +00:00
|
|
|
reqURL := val.APIAddress + "/vulcanize/registry/v1beta1/lookup?crn=%s"
|
2022-10-17 06:47:56 +00:00
|
|
|
authorityName := "QueryLookUp"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectErr bool
|
|
|
|
errorMsg string
|
|
|
|
preRun func(authorityName string)
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid url",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL + "/asdasd",
|
2022-04-05 07:09:27 +00:00
|
|
|
true,
|
|
|
|
"",
|
|
|
|
func(authorityName string) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL,
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
"",
|
|
|
|
func(authorityName string) {
|
|
|
|
// create name record
|
|
|
|
createNameRecord(authorityName, s)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.name, func() {
|
|
|
|
if !tc.expectErr {
|
|
|
|
tc.preRun(authorityName)
|
2022-10-17 11:03:31 +00:00
|
|
|
tc.url = fmt.Sprintf(reqURL, fmt.Sprintf("crn://%s/", authorityName))
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
resp, _ := rest.GetRequest(tc.url)
|
|
|
|
if tc.expectErr {
|
|
|
|
sr.Contains(string(resp), tc.errorMsg)
|
|
|
|
} else {
|
2022-04-20 07:37:38 +00:00
|
|
|
var response nstypes.QueryLookupCrnResponse
|
2022-04-05 07:09:27 +00:00
|
|
|
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotZero(len(response.Name.Latest.Id))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-17 06:47:56 +00:00
|
|
|
//nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
func (s *IntegrationTestSuite) TestGRPCQueryRecordExpiryQueue() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
2022-12-09 04:17:14 +00:00
|
|
|
reqUrl := val.APIAddress + "/vulcanize/registry/v1beta1/record-expiry"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectErr bool
|
|
|
|
errorMsg string
|
|
|
|
preRun func(bondId string)
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid url",
|
|
|
|
reqUrl + "/asdasd",
|
|
|
|
true,
|
|
|
|
"",
|
|
|
|
func(bondId string) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
|
|
|
reqUrl,
|
|
|
|
false,
|
|
|
|
"",
|
|
|
|
func(bondId string) {
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
sr.NoError(err)
|
2022-11-15 06:21:14 +00:00
|
|
|
payloadPath := dir + "/service_provider_example.yml"
|
2022-04-05 07:09:27 +00:00
|
|
|
args := []string{
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
}
|
|
|
|
args = append([]string{payloadPath, 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)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.name, func() {
|
|
|
|
if !tc.expectErr {
|
2022-10-17 11:03:31 +00:00
|
|
|
tc.preRun(s.bondID)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
2022-04-20 19:15:52 +00:00
|
|
|
// wait 12 seconds for records expires
|
|
|
|
time.Sleep(time.Second * 12)
|
2022-04-05 07:09:27 +00:00
|
|
|
resp, _ := rest.GetRequest(tc.url)
|
|
|
|
require := s.Require()
|
|
|
|
if tc.expectErr {
|
|
|
|
require.Contains(string(resp), tc.errorMsg)
|
|
|
|
} else {
|
|
|
|
var response nstypes.QueryGetRecordExpiryQueueResponse
|
|
|
|
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotZero(len(response.GetRecords()))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-17 06:47:56 +00:00
|
|
|
//nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
func (s *IntegrationTestSuite) TestGRPCQueryAuthorityExpiryQueue() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
2022-12-09 04:17:14 +00:00
|
|
|
reqUrl := val.APIAddress + "/vulcanize/registry/v1beta1/authority-expiry"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectErr bool
|
|
|
|
errorMsg string
|
|
|
|
preRun func(authorityName string)
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid url",
|
|
|
|
reqUrl + "/asdasd",
|
|
|
|
true,
|
|
|
|
"",
|
|
|
|
func(authorityName string) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
|
|
|
reqUrl,
|
|
|
|
false,
|
|
|
|
"",
|
|
|
|
func(authorityName string) {
|
|
|
|
// reserving the name
|
|
|
|
clientCtx := val.ClientCtx
|
|
|
|
cmd := cli.GetCmdReserveName()
|
|
|
|
args := []string{
|
|
|
|
authorityName,
|
|
|
|
fmt.Sprintf("--owner=%s", accountAddress),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.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)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.name, func() {
|
|
|
|
if !tc.expectErr {
|
|
|
|
tc.preRun("QueryAuthorityExpiryQueue")
|
|
|
|
}
|
2022-04-20 19:15:52 +00:00
|
|
|
// wait 12 seconds to name authorites expires
|
|
|
|
time.Sleep(time.Second * 12)
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
resp, _ := rest.GetRequest(tc.url)
|
|
|
|
require := s.Require()
|
|
|
|
if tc.expectErr {
|
|
|
|
require.Contains(string(resp), tc.errorMsg)
|
|
|
|
} else {
|
|
|
|
var response nstypes.QueryGetAuthorityExpiryQueueResponse
|
|
|
|
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
|
|
|
sr.NoError(err)
|
2022-04-20 19:15:52 +00:00
|
|
|
// removed from expiry queue as no bond set
|
|
|
|
sr.Zero(len(response.GetAuthorities()))
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-17 06:47:56 +00:00
|
|
|
//nolint: all
|
2022-04-05 07:09:27 +00:00
|
|
|
func (s *IntegrationTestSuite) TestGRPCQueryListRecords() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
2022-12-09 04:17:14 +00:00
|
|
|
reqUrl := val.APIAddress + "/vulcanize/registry/v1beta1/records"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectErr bool
|
|
|
|
errorMsg string
|
|
|
|
preRun func(bondId string)
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid url",
|
|
|
|
reqUrl + "/asdasd",
|
|
|
|
true,
|
|
|
|
"",
|
|
|
|
func(bondId string) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
|
|
|
reqUrl,
|
|
|
|
false,
|
|
|
|
"",
|
|
|
|
func(bondId string) {
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
sr.NoError(err)
|
2022-11-15 06:21:14 +00:00
|
|
|
payloadPath := dir + "/service_provider_example.yml"
|
2022-04-05 07:09:27 +00:00
|
|
|
args := []string{
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
}
|
|
|
|
args = append([]string{payloadPath, 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)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.name, func() {
|
|
|
|
if !tc.expectErr {
|
2022-10-17 11:03:31 +00:00
|
|
|
tc.preRun(s.bondID)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
resp, _ := rest.GetRequest(tc.url)
|
|
|
|
require := s.Require()
|
|
|
|
if tc.expectErr {
|
|
|
|
require.Contains(string(resp), tc.errorMsg)
|
|
|
|
} else {
|
|
|
|
var response nstypes.QueryListRecordsResponse
|
|
|
|
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotZero(len(response.GetRecords()))
|
2022-10-17 11:03:31 +00:00
|
|
|
sr.Equal(s.bondID, response.GetRecords()[0].GetBondId())
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestGRPCQueryGetRecordByID() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
2022-12-09 04:17:14 +00:00
|
|
|
reqURL := val.APIAddress + "/vulcanize/registry/v1beta1/records/%s"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectErr bool
|
|
|
|
errorMsg string
|
|
|
|
preRun func(bondId string) string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid url",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL + "/asdasd",
|
2022-04-05 07:09:27 +00:00
|
|
|
true,
|
|
|
|
"",
|
|
|
|
func(bondId string) string {
|
|
|
|
return ""
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL,
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
"",
|
|
|
|
func(bondId string) string {
|
|
|
|
// creating the record
|
|
|
|
createRecord(bondId, s)
|
|
|
|
|
|
|
|
// list the records
|
|
|
|
clientCtx := val.ClientCtx
|
|
|
|
cmd := cli.GetCmdList()
|
|
|
|
args := []string{
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
}
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
|
|
|
sr.NoError(err)
|
|
|
|
var records []nstypes.RecordType
|
|
|
|
err = json.Unmarshal(out.Bytes(), &records)
|
|
|
|
sr.NoError(err)
|
2022-10-17 11:03:31 +00:00
|
|
|
return records[0].ID
|
2022-04-05 07:09:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.name, func() {
|
2022-10-17 11:03:31 +00:00
|
|
|
var recordID string
|
2022-04-05 07:09:27 +00:00
|
|
|
if !tc.expectErr {
|
2022-10-17 11:03:31 +00:00
|
|
|
recordID = tc.preRun(s.bondID)
|
|
|
|
tc.url = fmt.Sprintf(reqURL, recordID)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
resp, _ := rest.GetRequest(tc.url)
|
|
|
|
require := s.Require()
|
|
|
|
if tc.expectErr {
|
|
|
|
require.Contains(string(resp), tc.errorMsg)
|
|
|
|
} else {
|
2022-10-17 11:03:31 +00:00
|
|
|
var response nstypes.QueryRecordByIDResponse
|
2022-04-05 07:09:27 +00:00
|
|
|
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
|
|
|
sr.NoError(err)
|
|
|
|
record := response.GetRecord()
|
2022-11-15 06:21:14 +00:00
|
|
|
sr.NotZero(len(record.GetId()))
|
|
|
|
sr.Equal(record.GetId(), recordID)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestGRPCQueryGetRecordByBondID() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
2022-12-09 04:17:14 +00:00
|
|
|
reqURL := val.APIAddress + "/vulcanize/registry/v1beta1/records-by-bond-id/%s"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectErr bool
|
|
|
|
errorMsg string
|
|
|
|
preRun func(bondId string)
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid url",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL + "/asdasd",
|
2022-04-05 07:09:27 +00:00
|
|
|
true,
|
|
|
|
"",
|
|
|
|
func(bondId string) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL,
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
"",
|
|
|
|
func(bondId string) {
|
|
|
|
// creating the record
|
|
|
|
createRecord(bondId, s)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.name, func() {
|
|
|
|
if !tc.expectErr {
|
2022-10-17 11:03:31 +00:00
|
|
|
tc.preRun(s.bondID)
|
|
|
|
tc.url = fmt.Sprintf(reqURL, s.bondID)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
resp, _ := rest.GetRequest(tc.url)
|
|
|
|
require := s.Require()
|
|
|
|
if tc.expectErr {
|
|
|
|
require.Contains(string(resp), tc.errorMsg)
|
|
|
|
} else {
|
2022-10-17 11:03:31 +00:00
|
|
|
var response nstypes.QueryRecordByBondIDResponse
|
2022-04-05 07:09:27 +00:00
|
|
|
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
|
|
|
sr.NoError(err)
|
|
|
|
records := response.GetRecords()
|
|
|
|
sr.NotZero(len(records))
|
2022-10-17 11:03:31 +00:00
|
|
|
sr.Equal(records[0].GetBondId(), s.bondID)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-09 04:17:14 +00:00
|
|
|
func (s *IntegrationTestSuite) TestGRPCQueryGetRegistryModuleBalance() {
|
2022-04-05 07:09:27 +00:00
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
2022-12-09 04:17:14 +00:00
|
|
|
reqURL := val.APIAddress + "/vulcanize/registry/v1beta1/balance"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectErr bool
|
|
|
|
errorMsg string
|
|
|
|
preRun func(bondId string)
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid url",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL + "/asdasd",
|
2022-04-05 07:09:27 +00:00
|
|
|
true,
|
|
|
|
"",
|
|
|
|
func(bondId string) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL,
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
"",
|
|
|
|
func(bondId string) {
|
|
|
|
// creating the record
|
|
|
|
createRecord(bondId, s)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.name, func() {
|
|
|
|
if !tc.expectErr {
|
2022-10-17 11:03:31 +00:00
|
|
|
tc.preRun(s.bondID)
|
2022-04-05 07:09:27 +00:00
|
|
|
}
|
|
|
|
resp, _ := rest.GetRequest(tc.url)
|
|
|
|
require := s.Require()
|
|
|
|
if tc.expectErr {
|
|
|
|
require.Contains(string(resp), tc.errorMsg)
|
|
|
|
} else {
|
2022-12-09 04:17:14 +00:00
|
|
|
var response nstypes.GetRegistryModuleBalanceResponse
|
2022-04-05 07:09:27 +00:00
|
|
|
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotZero(len(response.GetBalances()))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *IntegrationTestSuite) TestGRPCQueryNamesList() {
|
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
2022-12-09 04:17:14 +00:00
|
|
|
reqURL := val.APIAddress + "/vulcanize/registry/v1beta1/names"
|
2022-04-05 07:09:27 +00:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
name string
|
|
|
|
url string
|
|
|
|
expectErr bool
|
|
|
|
errorMsg string
|
|
|
|
preRun func(authorityName string)
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"invalid url",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL + "/asdasd",
|
2022-04-05 07:09:27 +00:00
|
|
|
true,
|
|
|
|
"",
|
|
|
|
func(authorityName string) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"Success",
|
2022-10-17 11:03:31 +00:00
|
|
|
reqURL,
|
2022-04-05 07:09:27 +00:00
|
|
|
false,
|
|
|
|
"",
|
|
|
|
func(authorityName string) {
|
|
|
|
// create name record
|
|
|
|
createNameRecord(authorityName, s)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
s.Run(tc.name, func() {
|
|
|
|
if !tc.expectErr {
|
|
|
|
tc.preRun("ListNameRecords")
|
|
|
|
}
|
|
|
|
resp, _ := rest.GetRequest(tc.url)
|
|
|
|
require := s.Require()
|
|
|
|
if tc.expectErr {
|
|
|
|
require.Contains(string(resp), tc.errorMsg)
|
|
|
|
} else {
|
|
|
|
var response nstypes.QueryListNameRecordsResponse
|
|
|
|
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &response)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.NotZero(len(response.GetNames()))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-17 11:03:31 +00:00
|
|
|
func createRecord(bondID string, s *IntegrationTestSuite) {
|
2022-04-05 07:09:27 +00:00
|
|
|
val := s.network.Validators[0]
|
|
|
|
sr := s.Require()
|
|
|
|
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
sr.NoError(err)
|
2022-11-15 06:21:14 +00:00
|
|
|
payloadPath := dir + "/service_provider_example.yml"
|
2022-04-05 07:09:27 +00:00
|
|
|
args := []string{
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", s.cfg.BondDenom)),
|
|
|
|
}
|
2022-10-17 11:03:31 +00:00
|
|
|
args = append([]string{payloadPath, bondID}, args...)
|
2022-04-05 07:09:27 +00:00
|
|
|
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)
|
|
|
|
}
|