github.com/Finschia/finschia-sdk@v0.48.1/x/collection/client/testutil/query.go (about)

     1  package testutil
     2  
     3  import (
     4  	"fmt"
     5  
     6  	ostcli "github.com/Finschia/ostracon/libs/cli"
     7  	"github.com/gogo/protobuf/proto"
     8  
     9  	"github.com/Finschia/finschia-sdk/client/flags"
    10  	codectypes "github.com/Finschia/finschia-sdk/codec/types"
    11  	clitestutil "github.com/Finschia/finschia-sdk/testutil/cli"
    12  	sdk "github.com/Finschia/finschia-sdk/types"
    13  	"github.com/Finschia/finschia-sdk/types/query"
    14  	"github.com/Finschia/finschia-sdk/x/collection"
    15  	"github.com/Finschia/finschia-sdk/x/collection/client/cli"
    16  )
    17  
    18  func (s *IntegrationTestSuite) TestNewQueryCmdBalance() {
    19  	val := s.network.Validators[0]
    20  	commonArgs := []string{
    21  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
    22  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
    23  	}
    24  
    25  	testCases := map[string]struct {
    26  		args     []string
    27  		valid    bool
    28  		expected proto.Message
    29  	}{
    30  		"valid query": {
    31  			[]string{
    32  				s.contractID,
    33  				s.customer.String(),
    34  				fmt.Sprintf("--%s=%s", cli.FlagTokenID, collection.NewFTID(s.ftClassID)),
    35  			},
    36  			true,
    37  			&collection.QueryBalanceResponse{
    38  				Balance: collection.NewFTCoin(s.ftClassID, s.balance),
    39  			},
    40  		},
    41  		"extra args": {
    42  			[]string{
    43  				s.contractID,
    44  				s.customer.String(),
    45  				"extra",
    46  			},
    47  			false,
    48  			nil,
    49  		},
    50  		"not enough args": {
    51  			[]string{
    52  				s.contractID,
    53  			},
    54  			false,
    55  			nil,
    56  		},
    57  		"invalid address": {
    58  			[]string{
    59  				s.contractID,
    60  				"",
    61  			},
    62  			false,
    63  			nil,
    64  		},
    65  	}
    66  
    67  	for name, tc := range testCases {
    68  		tc := tc
    69  
    70  		s.Run(name, func() {
    71  			cmd := cli.NewQueryCmdBalances()
    72  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
    73  			if !tc.valid {
    74  				s.Require().Error(err)
    75  				return
    76  			}
    77  			s.Require().NoError(err)
    78  
    79  			var actual collection.QueryBalanceResponse
    80  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
    81  			s.Require().Equal(tc.expected, &actual)
    82  		})
    83  	}
    84  }
    85  
    86  func (s *IntegrationTestSuite) TestNewQueryCmdFTSupply() {
    87  	val := s.network.Validators[0]
    88  	commonArgs := []string{
    89  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
    90  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
    91  	}
    92  
    93  	tokenID := collection.NewFTID(s.ftClassID)
    94  	testCases := map[string]struct {
    95  		args     []string
    96  		valid    bool
    97  		expected proto.Message
    98  	}{
    99  		"valid query": {
   100  			[]string{
   101  				s.contractID,
   102  				tokenID,
   103  			},
   104  			true,
   105  			&collection.QueryFTSupplyResponse{
   106  				Supply: s.balance.Mul(sdk.NewInt(4)),
   107  			},
   108  		},
   109  		"extra args": {
   110  			[]string{
   111  				s.contractID,
   112  				tokenID,
   113  				"extra",
   114  			},
   115  			false,
   116  			nil,
   117  		},
   118  		"not enough args": {
   119  			[]string{
   120  				s.contractID,
   121  			},
   122  			false,
   123  			nil,
   124  		},
   125  		"invalid contract id": {
   126  			[]string{
   127  				"",
   128  				tokenID,
   129  			},
   130  			false,
   131  			nil,
   132  		},
   133  		"invalid class id": {
   134  			[]string{
   135  				s.contractID,
   136  				"",
   137  			},
   138  			false,
   139  			nil,
   140  		},
   141  	}
   142  
   143  	for name, tc := range testCases {
   144  		tc := tc
   145  
   146  		s.Run(name, func() {
   147  			cmd := cli.NewQueryCmdFTSupply()
   148  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   149  			if !tc.valid {
   150  				s.Require().Error(err)
   151  				return
   152  			}
   153  			s.Require().NoError(err)
   154  
   155  			var actual collection.QueryFTSupplyResponse
   156  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   157  			s.Require().Equal(tc.expected, &actual)
   158  		})
   159  	}
   160  }
   161  
   162  func (s *IntegrationTestSuite) TestNewQueryCmdFTMinted() {
   163  	val := s.network.Validators[0]
   164  	commonArgs := []string{
   165  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   166  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   167  	}
   168  
   169  	tokenID := collection.NewFTID(s.ftClassID)
   170  	testCases := map[string]struct {
   171  		args     []string
   172  		valid    bool
   173  		expected proto.Message
   174  	}{
   175  		"valid query": {
   176  			[]string{
   177  				s.contractID,
   178  				tokenID,
   179  			},
   180  			true,
   181  			&collection.QueryFTMintedResponse{
   182  				Minted: s.balance.Mul(sdk.NewInt(5)),
   183  			},
   184  		},
   185  		"extra args": {
   186  			[]string{
   187  				s.contractID,
   188  				tokenID,
   189  				"extra",
   190  			},
   191  			false,
   192  			nil,
   193  		},
   194  		"not enough args": {
   195  			[]string{
   196  				s.contractID,
   197  			},
   198  			false,
   199  			nil,
   200  		},
   201  		"invalid contract id": {
   202  			[]string{
   203  				"",
   204  				tokenID,
   205  			},
   206  			false,
   207  			nil,
   208  		},
   209  		"invalid class id": {
   210  			[]string{
   211  				s.contractID,
   212  				"",
   213  			},
   214  			false,
   215  			nil,
   216  		},
   217  	}
   218  
   219  	for name, tc := range testCases {
   220  		tc := tc
   221  
   222  		s.Run(name, func() {
   223  			cmd := cli.NewQueryCmdFTMinted()
   224  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   225  			if !tc.valid {
   226  				s.Require().Error(err)
   227  				return
   228  			}
   229  			s.Require().NoError(err)
   230  
   231  			var actual collection.QueryFTMintedResponse
   232  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   233  			s.Require().Equal(tc.expected, &actual)
   234  		})
   235  	}
   236  }
   237  
   238  func (s *IntegrationTestSuite) TestNewQueryCmdFTBurnt() {
   239  	val := s.network.Validators[0]
   240  	commonArgs := []string{
   241  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   242  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   243  	}
   244  
   245  	tokenID := collection.NewFTID(s.ftClassID)
   246  	testCases := map[string]struct {
   247  		args     []string
   248  		valid    bool
   249  		expected proto.Message
   250  	}{
   251  		"valid query": {
   252  			[]string{
   253  				s.contractID,
   254  				tokenID,
   255  			},
   256  			true,
   257  			&collection.QueryFTBurntResponse{
   258  				Burnt: s.balance,
   259  			},
   260  		},
   261  		"extra args": {
   262  			[]string{
   263  				s.contractID,
   264  				tokenID,
   265  				"extra",
   266  			},
   267  			false,
   268  			nil,
   269  		},
   270  		"not enough args": {
   271  			[]string{
   272  				s.contractID,
   273  			},
   274  			false,
   275  			nil,
   276  		},
   277  		"invalid contract id": {
   278  			[]string{
   279  				"",
   280  				tokenID,
   281  			},
   282  			false,
   283  			nil,
   284  		},
   285  		"invalid class id": {
   286  			[]string{
   287  				s.contractID,
   288  				"",
   289  			},
   290  			false,
   291  			nil,
   292  		},
   293  	}
   294  
   295  	for name, tc := range testCases {
   296  		tc := tc
   297  
   298  		s.Run(name, func() {
   299  			cmd := cli.NewQueryCmdFTBurnt()
   300  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   301  			if !tc.valid {
   302  				s.Require().Error(err)
   303  				return
   304  			}
   305  			s.Require().NoError(err)
   306  
   307  			var actual collection.QueryFTBurntResponse
   308  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   309  			s.Require().Equal(tc.expected, &actual)
   310  		})
   311  	}
   312  }
   313  
   314  func (s *IntegrationTestSuite) TestNewQueryCmdNFTSupply() {
   315  	val := s.network.Validators[0]
   316  	commonArgs := []string{
   317  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   318  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   319  	}
   320  
   321  	testCases := map[string]struct {
   322  		args     []string
   323  		valid    bool
   324  		expected proto.Message
   325  	}{
   326  		"valid query": {
   327  			[]string{
   328  				s.contractID,
   329  				s.nftClassID,
   330  			},
   331  			true,
   332  			&collection.QueryNFTSupplyResponse{
   333  				Supply: sdk.NewInt(24),
   334  			},
   335  		},
   336  		"extra args": {
   337  			[]string{
   338  				s.contractID,
   339  				s.nftClassID,
   340  				"extra",
   341  			},
   342  			false,
   343  			nil,
   344  		},
   345  		"not enough args": {
   346  			[]string{
   347  				s.contractID,
   348  			},
   349  			false,
   350  			nil,
   351  		},
   352  		"invalid contract id": {
   353  			[]string{
   354  				"",
   355  				s.nftClassID,
   356  			},
   357  			false,
   358  			nil,
   359  		},
   360  		"invalid class id": {
   361  			[]string{
   362  				s.contractID,
   363  				"",
   364  			},
   365  			false,
   366  			nil,
   367  		},
   368  	}
   369  
   370  	for name, tc := range testCases {
   371  		tc := tc
   372  
   373  		s.Run(name, func() {
   374  			cmd := cli.NewQueryCmdNFTSupply()
   375  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   376  			if !tc.valid {
   377  				s.Require().Error(err)
   378  				return
   379  			}
   380  			s.Require().NoError(err)
   381  
   382  			var actual collection.QueryNFTSupplyResponse
   383  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   384  			s.Require().Equal(tc.expected, &actual)
   385  		})
   386  	}
   387  }
   388  
   389  func (s *IntegrationTestSuite) TestNewQueryCmdNFTMinted() {
   390  	val := s.network.Validators[0]
   391  	commonArgs := []string{
   392  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   393  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   394  	}
   395  
   396  	testCases := map[string]struct {
   397  		args     []string
   398  		valid    bool
   399  		expected proto.Message
   400  	}{
   401  		"valid query": {
   402  			[]string{
   403  				s.contractID,
   404  				s.nftClassID,
   405  			},
   406  			true,
   407  			&collection.QueryNFTMintedResponse{
   408  				Minted: sdk.NewInt(24),
   409  			},
   410  		},
   411  		"extra args": {
   412  			[]string{
   413  				s.contractID,
   414  				s.nftClassID,
   415  				"extra",
   416  			},
   417  			false,
   418  			nil,
   419  		},
   420  		"not enough args": {
   421  			[]string{
   422  				s.contractID,
   423  			},
   424  			false,
   425  			nil,
   426  		},
   427  		"invalid contract id": {
   428  			[]string{
   429  				"",
   430  				s.nftClassID,
   431  			},
   432  			false,
   433  			nil,
   434  		},
   435  		"invalid class id": {
   436  			[]string{
   437  				s.contractID,
   438  				"",
   439  			},
   440  			false,
   441  			nil,
   442  		},
   443  	}
   444  
   445  	for name, tc := range testCases {
   446  		tc := tc
   447  
   448  		s.Run(name, func() {
   449  			cmd := cli.NewQueryCmdNFTMinted()
   450  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   451  			if !tc.valid {
   452  				s.Require().Error(err)
   453  				return
   454  			}
   455  			s.Require().NoError(err)
   456  
   457  			var actual collection.QueryNFTMintedResponse
   458  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   459  			s.Require().Equal(tc.expected, &actual)
   460  		})
   461  	}
   462  }
   463  
   464  func (s *IntegrationTestSuite) TestNewQueryCmdNFTBurnt() {
   465  	val := s.network.Validators[0]
   466  	commonArgs := []string{
   467  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   468  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   469  	}
   470  
   471  	testCases := map[string]struct {
   472  		args     []string
   473  		valid    bool
   474  		expected proto.Message
   475  	}{
   476  		"valid query": {
   477  			[]string{
   478  				s.contractID,
   479  				s.nftClassID,
   480  			},
   481  			true,
   482  			&collection.QueryNFTBurntResponse{
   483  				Burnt: sdk.ZeroInt(),
   484  			},
   485  		},
   486  		"extra args": {
   487  			[]string{
   488  				s.contractID,
   489  				s.nftClassID,
   490  				"extra",
   491  			},
   492  			false,
   493  			nil,
   494  		},
   495  		"not enough args": {
   496  			[]string{
   497  				s.contractID,
   498  			},
   499  			false,
   500  			nil,
   501  		},
   502  		"invalid contract id": {
   503  			[]string{
   504  				"",
   505  				s.nftClassID,
   506  			},
   507  			false,
   508  			nil,
   509  		},
   510  		"invalid class id": {
   511  			[]string{
   512  				s.contractID,
   513  				"",
   514  			},
   515  			false,
   516  			nil,
   517  		},
   518  	}
   519  
   520  	for name, tc := range testCases {
   521  		tc := tc
   522  
   523  		s.Run(name, func() {
   524  			cmd := cli.NewQueryCmdNFTBurnt()
   525  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   526  			if !tc.valid {
   527  				s.Require().Error(err)
   528  				return
   529  			}
   530  			s.Require().NoError(err)
   531  
   532  			var actual collection.QueryNFTBurntResponse
   533  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   534  			s.Require().Equal(tc.expected, &actual)
   535  		})
   536  	}
   537  }
   538  
   539  func (s *IntegrationTestSuite) TestNewQueryCmdContract() {
   540  	val := s.network.Validators[0]
   541  	commonArgs := []string{
   542  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   543  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   544  	}
   545  
   546  	testCases := map[string]struct {
   547  		args     []string
   548  		valid    bool
   549  		expected proto.Message
   550  	}{
   551  		"valid query": {
   552  			[]string{
   553  				s.contractID,
   554  			},
   555  			true,
   556  			&collection.QueryContractResponse{
   557  				Contract: collection.Contract{Id: s.contractID},
   558  			},
   559  		},
   560  		"extra args": {
   561  			[]string{
   562  				s.contractID,
   563  				"extra",
   564  			},
   565  			false,
   566  			nil,
   567  		},
   568  		"not enough args": {
   569  			[]string{},
   570  			false,
   571  			nil,
   572  		},
   573  	}
   574  
   575  	for name, tc := range testCases {
   576  		tc := tc
   577  
   578  		s.Run(name, func() {
   579  			cmd := cli.NewQueryCmdContract()
   580  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   581  			if !tc.valid {
   582  				s.Require().Error(err)
   583  				return
   584  			}
   585  			s.Require().NoError(err)
   586  
   587  			var actual collection.QueryContractResponse
   588  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   589  			s.Require().Equal(tc.expected, &actual)
   590  		})
   591  	}
   592  }
   593  
   594  func (s *IntegrationTestSuite) TestNewQueryCmdTokenType() {
   595  	val := s.network.Validators[0]
   596  	commonArgs := []string{
   597  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   598  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   599  	}
   600  
   601  	testCases := map[string]struct {
   602  		args     []string
   603  		valid    bool
   604  		expected proto.Message
   605  	}{
   606  		"valid query": {
   607  			[]string{
   608  				s.contractID,
   609  				s.nftClassID,
   610  			},
   611  			true,
   612  			&collection.QueryTokenTypeResponse{
   613  				TokenType: collection.TokenType{
   614  					ContractId: s.contractID,
   615  					TokenType:  s.nftClassID,
   616  				},
   617  			},
   618  		},
   619  		"extra args": {
   620  			[]string{
   621  				s.contractID,
   622  				s.nftClassID,
   623  				"extra",
   624  			},
   625  			false,
   626  			nil,
   627  		},
   628  		"not enough args": {
   629  			[]string{
   630  				s.contractID,
   631  			},
   632  			false,
   633  			nil,
   634  		},
   635  		"token not found": {
   636  			[]string{
   637  				s.contractID,
   638  				"deadbeef",
   639  			},
   640  			false,
   641  			nil,
   642  		},
   643  	}
   644  
   645  	for name, tc := range testCases {
   646  		tc := tc
   647  
   648  		s.Run(name, func() {
   649  			cmd := cli.NewQueryCmdTokenType()
   650  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   651  			if !tc.valid {
   652  				s.Require().Error(err)
   653  				return
   654  			}
   655  			s.Require().NoError(err)
   656  
   657  			var actual collection.QueryTokenTypeResponse
   658  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   659  			s.Require().Equal(tc.expected, &actual)
   660  		})
   661  	}
   662  }
   663  
   664  func (s *IntegrationTestSuite) TestNewQueryCmdToken() {
   665  	val := s.network.Validators[0]
   666  	commonArgs := []string{
   667  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   668  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   669  	}
   670  
   671  	tokenID := collection.NewNFTID(s.nftClassID, 1)
   672  	token, err := codectypes.NewAnyWithValue(&collection.OwnerNFT{
   673  		ContractId: s.contractID,
   674  		TokenId:    tokenID,
   675  		Name:       "arctic fox",
   676  		Owner:      s.customer.String(),
   677  	})
   678  	s.Require().NoError(err)
   679  
   680  	testCases := map[string]struct {
   681  		args     []string
   682  		valid    bool
   683  		expected proto.Message
   684  	}{
   685  		"valid query": {
   686  			[]string{
   687  				s.contractID,
   688  				tokenID,
   689  			},
   690  			true,
   691  			&collection.QueryTokenResponse{
   692  				Token: *token,
   693  			},
   694  		},
   695  		"extra args": {
   696  			[]string{
   697  				s.contractID,
   698  				tokenID,
   699  				"extra",
   700  			},
   701  			false,
   702  			nil,
   703  		},
   704  		"not enough args": {
   705  			[]string{
   706  				s.contractID,
   707  			},
   708  			false,
   709  			nil,
   710  		},
   711  		"token not found": {
   712  			[]string{
   713  				s.contractID,
   714  				collection.NewNFTID("deadbeef", 1),
   715  			},
   716  			false,
   717  			nil,
   718  		},
   719  	}
   720  
   721  	for name, tc := range testCases {
   722  		tc := tc
   723  
   724  		s.Run(name, func() {
   725  			cmd := cli.NewQueryCmdToken()
   726  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   727  			if !tc.valid {
   728  				s.Require().Error(err)
   729  				return
   730  			}
   731  			s.Require().NoError(err)
   732  
   733  			var actual collection.QueryTokenResponse
   734  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   735  			err = collection.TokenUnpackInterfaces(&actual.Token, val.ClientCtx.InterfaceRegistry)
   736  			s.Require().NoError(err)
   737  			s.Require().Equal(tc.expected, &actual)
   738  		})
   739  	}
   740  }
   741  
   742  func (s *IntegrationTestSuite) TestNewQueryCmdRoot() {
   743  	val := s.network.Validators[0]
   744  	commonArgs := []string{
   745  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   746  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   747  	}
   748  
   749  	tokenID := collection.NewNFTID(s.nftClassID, 2)
   750  
   751  	testCases := map[string]struct {
   752  		args     []string
   753  		valid    bool
   754  		expected proto.Message
   755  	}{
   756  		"valid query": {
   757  			[]string{
   758  				s.contractID,
   759  				tokenID,
   760  			},
   761  			true,
   762  			&collection.QueryRootResponse{
   763  				Root: collection.NFT{
   764  					TokenId: collection.NewNFTID(s.nftClassID, 1),
   765  					Name:    "arctic fox",
   766  				},
   767  			},
   768  		},
   769  		"extra args": {
   770  			[]string{
   771  				s.contractID,
   772  				tokenID,
   773  				"extra",
   774  			},
   775  			false,
   776  			nil,
   777  		},
   778  		"not enough args": {
   779  			[]string{
   780  				s.contractID,
   781  			},
   782  			false,
   783  			nil,
   784  		},
   785  		"token not found": {
   786  			[]string{
   787  				s.contractID,
   788  				collection.NewNFTID("deadbeef", 1),
   789  			},
   790  			false,
   791  			nil,
   792  		},
   793  	}
   794  
   795  	for name, tc := range testCases {
   796  		tc := tc
   797  
   798  		s.Run(name, func() {
   799  			cmd := cli.NewQueryCmdRoot()
   800  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   801  			if !tc.valid {
   802  				s.Require().Error(err)
   803  				return
   804  			}
   805  			s.Require().NoError(err)
   806  
   807  			var actual collection.QueryRootResponse
   808  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   809  			s.Require().Equal(tc.expected, &actual)
   810  		})
   811  	}
   812  }
   813  
   814  func (s *IntegrationTestSuite) TestNewQueryCmdParent() {
   815  	val := s.network.Validators[0]
   816  	commonArgs := []string{
   817  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   818  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   819  	}
   820  
   821  	tokenID := collection.NewNFTID(s.nftClassID, 2)
   822  
   823  	testCases := map[string]struct {
   824  		args     []string
   825  		valid    bool
   826  		expected proto.Message
   827  	}{
   828  		"valid query": {
   829  			[]string{
   830  				s.contractID,
   831  				tokenID,
   832  			},
   833  			true,
   834  			&collection.QueryParentResponse{
   835  				Parent: collection.NFT{
   836  					TokenId: collection.NewNFTID(s.nftClassID, 1),
   837  					Name:    "arctic fox",
   838  				},
   839  			},
   840  		},
   841  		"extra args": {
   842  			[]string{
   843  				s.contractID,
   844  				tokenID,
   845  				"extra",
   846  			},
   847  			false,
   848  			nil,
   849  		},
   850  		"not enough args": {
   851  			[]string{
   852  				s.contractID,
   853  			},
   854  			false,
   855  			nil,
   856  		},
   857  		"token not found": {
   858  			[]string{
   859  				s.contractID,
   860  				collection.NewNFTID("deadbeef", 1),
   861  			},
   862  			false,
   863  			nil,
   864  		},
   865  	}
   866  
   867  	for name, tc := range testCases {
   868  		tc := tc
   869  
   870  		s.Run(name, func() {
   871  			cmd := cli.NewQueryCmdParent()
   872  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   873  			if !tc.valid {
   874  				s.Require().Error(err)
   875  				return
   876  			}
   877  			s.Require().NoError(err)
   878  
   879  			var actual collection.QueryParentResponse
   880  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   881  			s.Require().Equal(tc.expected, &actual)
   882  		})
   883  	}
   884  }
   885  
   886  func (s *IntegrationTestSuite) TestNewQueryCmdChildren() {
   887  	val := s.network.Validators[0]
   888  	commonArgs := []string{
   889  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   890  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   891  	}
   892  
   893  	tokenID := collection.NewNFTID(s.nftClassID, 1)
   894  
   895  	testCases := map[string]struct {
   896  		args     []string
   897  		valid    bool
   898  		expected proto.Message
   899  	}{
   900  		"valid query": {
   901  			[]string{
   902  				s.contractID,
   903  				tokenID,
   904  			},
   905  			true,
   906  			&collection.QueryChildrenResponse{
   907  				Children: []collection.NFT{{
   908  					TokenId: collection.NewNFTID(s.nftClassID, 2),
   909  					Name:    "arctic fox",
   910  				}},
   911  				Pagination: &query.PageResponse{},
   912  			},
   913  		},
   914  		"token not found": {
   915  			[]string{
   916  				s.contractID,
   917  				collection.NewNFTID("deadbeef", 1),
   918  			},
   919  			true,
   920  			&collection.QueryChildrenResponse{
   921  				Children:   []collection.NFT{},
   922  				Pagination: &query.PageResponse{},
   923  			},
   924  		},
   925  		"extra args": {
   926  			[]string{
   927  				s.contractID,
   928  				tokenID,
   929  				"extra",
   930  			},
   931  			false,
   932  			nil,
   933  		},
   934  		"not enough args": {
   935  			[]string{
   936  				s.contractID,
   937  			},
   938  			false,
   939  			nil,
   940  		},
   941  	}
   942  
   943  	for name, tc := range testCases {
   944  		tc := tc
   945  
   946  		s.Run(name, func() {
   947  			cmd := cli.NewQueryCmdChildren()
   948  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
   949  			if !tc.valid {
   950  				s.Require().Error(err)
   951  				return
   952  			}
   953  			s.Require().NoError(err)
   954  
   955  			var actual collection.QueryChildrenResponse
   956  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
   957  			s.Require().Equal(tc.expected, &actual)
   958  		})
   959  	}
   960  }
   961  
   962  func (s *IntegrationTestSuite) TestNewQueryCmdGranteeGrants() {
   963  	val := s.network.Validators[0]
   964  	commonArgs := []string{
   965  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
   966  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
   967  	}
   968  
   969  	testCases := map[string]struct {
   970  		args     []string
   971  		valid    bool
   972  		expected proto.Message
   973  	}{
   974  		"valid query": {
   975  			[]string{
   976  				s.contractID,
   977  				s.operator.String(),
   978  			},
   979  			true,
   980  			&collection.QueryGranteeGrantsResponse{
   981  				Grants: []collection.Grant{
   982  					{
   983  						Grantee:    s.operator.String(),
   984  						Permission: collection.PermissionIssue,
   985  					},
   986  					{
   987  						Grantee:    s.operator.String(),
   988  						Permission: collection.PermissionModify,
   989  					},
   990  					{
   991  						Grantee:    s.operator.String(),
   992  						Permission: collection.PermissionMint,
   993  					},
   994  					{
   995  						Grantee:    s.operator.String(),
   996  						Permission: collection.PermissionBurn,
   997  					},
   998  				},
   999  				Pagination: &query.PageResponse{
  1000  					Total: 4,
  1001  				},
  1002  			},
  1003  		},
  1004  		"extra args": {
  1005  			[]string{
  1006  				s.contractID,
  1007  				s.operator.String(),
  1008  				"extra",
  1009  			},
  1010  			false,
  1011  			nil,
  1012  		},
  1013  		"not enough args": {
  1014  			[]string{
  1015  				s.contractID,
  1016  			},
  1017  			false,
  1018  			nil,
  1019  		},
  1020  	}
  1021  
  1022  	for name, tc := range testCases {
  1023  		tc := tc
  1024  
  1025  		s.Run(name, func() {
  1026  			cmd := cli.NewQueryCmdGranteeGrants()
  1027  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
  1028  			if !tc.valid {
  1029  				s.Require().Error(err)
  1030  				return
  1031  			}
  1032  			s.Require().NoError(err)
  1033  
  1034  			var actual collection.QueryGranteeGrantsResponse
  1035  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
  1036  			s.Require().Equal(tc.expected, &actual)
  1037  		})
  1038  	}
  1039  }
  1040  
  1041  func (s *IntegrationTestSuite) TestNewQueryCmdIsOperatorFor() {
  1042  	val := s.network.Validators[0]
  1043  	commonArgs := []string{
  1044  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
  1045  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
  1046  	}
  1047  
  1048  	testCases := map[string]struct {
  1049  		args     []string
  1050  		valid    bool
  1051  		expected proto.Message
  1052  	}{
  1053  		"valid query": {
  1054  			[]string{
  1055  				s.contractID,
  1056  				s.operator.String(),
  1057  				s.customer.String(),
  1058  			},
  1059  			true,
  1060  			&collection.QueryIsOperatorForResponse{
  1061  				Authorized: true,
  1062  			},
  1063  		},
  1064  		"extra args": {
  1065  			[]string{
  1066  				s.contractID,
  1067  				s.operator.String(),
  1068  				s.customer.String(),
  1069  				"extra",
  1070  			},
  1071  			false,
  1072  			nil,
  1073  		},
  1074  		"not enough args": {
  1075  			[]string{
  1076  				s.contractID,
  1077  				s.operator.String(),
  1078  			},
  1079  			false,
  1080  			nil,
  1081  		},
  1082  	}
  1083  
  1084  	for name, tc := range testCases {
  1085  		tc := tc
  1086  
  1087  		s.Run(name, func() {
  1088  			cmd := cli.NewQueryCmdIsOperatorFor()
  1089  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
  1090  			if !tc.valid {
  1091  				s.Require().Error(err)
  1092  				return
  1093  			}
  1094  			s.Require().NoError(err)
  1095  
  1096  			var actual collection.QueryIsOperatorForResponse
  1097  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
  1098  			s.Require().Equal(tc.expected, &actual)
  1099  		})
  1100  	}
  1101  }
  1102  
  1103  func (s *IntegrationTestSuite) TestNewQueryCmdHoldersByOperator() {
  1104  	val := s.network.Validators[0]
  1105  	commonArgs := []string{
  1106  		fmt.Sprintf("--%s=%d", flags.FlagHeight, s.setupHeight),
  1107  		fmt.Sprintf("--%s=json", ostcli.OutputFlag),
  1108  	}
  1109  
  1110  	testCases := map[string]struct {
  1111  		args     []string
  1112  		valid    bool
  1113  		expected proto.Message
  1114  	}{
  1115  		"valid query": {
  1116  			[]string{
  1117  				s.contractID,
  1118  				s.vendor.String(),
  1119  			},
  1120  			true,
  1121  			&collection.QueryHoldersByOperatorResponse{
  1122  				Holders:    []string{s.operator.String()},
  1123  				Pagination: &query.PageResponse{},
  1124  			},
  1125  		},
  1126  		"extra args": {
  1127  			[]string{
  1128  				s.contractID,
  1129  				s.vendor.String(),
  1130  				"extra",
  1131  			},
  1132  			false,
  1133  			nil,
  1134  		},
  1135  		"not enough args": {
  1136  			[]string{
  1137  				s.contractID,
  1138  			},
  1139  			false,
  1140  			nil,
  1141  		},
  1142  	}
  1143  
  1144  	for name, tc := range testCases {
  1145  		tc := tc
  1146  
  1147  		s.Run(name, func() {
  1148  			cmd := cli.NewQueryCmdHoldersByOperator()
  1149  			out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, append(tc.args, commonArgs...))
  1150  			if !tc.valid {
  1151  				s.Require().Error(err)
  1152  				return
  1153  			}
  1154  			s.Require().NoError(err)
  1155  
  1156  			var actual collection.QueryHoldersByOperatorResponse
  1157  			s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &actual), out.String())
  1158  			s.Require().Equal(tc.expected, &actual)
  1159  		})
  1160  	}
  1161  }