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