refactor(nft): CLI tests using Tendermint Mock (#13256)
* wip: move nft cli tests to e2e tests * wip: add cli tests using Tendermint Mock * cleanup genutil test file * remove unncessary test cases * address review comments Co-authored-by: Julien Robert <julien@rbrt.fr> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
co-authored by
Julien Robert
Marko
Aleksandr Bezobchuk
parent
7252f4a758
commit
7ebbfa0b30
@@ -1,7 +1,7 @@
|
||||
//go:build e2e
|
||||
// +build e2e
|
||||
|
||||
package testutil
|
||||
package nft
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"cosmossdk.io/simapp"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
clienttestutil "github.com/cosmos/cosmos-sdk/x/nft/client/testutil"
|
||||
)
|
||||
|
||||
func TestIntegrationTestSuite(t *testing.T) {
|
||||
cfg := network.DefaultConfig(simapp.NewTestNetworkFixture)
|
||||
cfg.NumValidators = 1
|
||||
suite.Run(t, clienttestutil.NewIntegrationTestSuite(cfg))
|
||||
suite.Run(t, NewIntegrationTestSuite(cfg))
|
||||
}
|
||||
@@ -0,0 +1,476 @@
|
||||
package nft
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/rest"
|
||||
"github.com/cosmos/cosmos-sdk/x/nft"
|
||||
)
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryBalanceGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}
|
||||
expectErr bool
|
||||
errMsg string
|
||||
expectValue uint64
|
||||
}{
|
||||
{
|
||||
name: "fail not exist class id",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: "invalid_class_id",
|
||||
Owner: s.owner.String(),
|
||||
},
|
||||
expectErr: true,
|
||||
errMsg: "invalid class id",
|
||||
expectValue: 0,
|
||||
},
|
||||
{
|
||||
name: "fail not exist owner",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
Owner: s.owner.String(),
|
||||
},
|
||||
expectErr: false,
|
||||
expectValue: 0,
|
||||
},
|
||||
{
|
||||
name: "success",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
Owner: val.Address.String(),
|
||||
},
|
||||
expectErr: false,
|
||||
expectValue: 1,
|
||||
},
|
||||
}
|
||||
balanceURL := val.APIAddress + "/cosmos/nft/v1beta1/balance/%s/%s"
|
||||
for _, tc := range testCases {
|
||||
uri := fmt.Sprintf(balanceURL, tc.args.Owner, tc.args.ClassID)
|
||||
s.Run(tc.name, func() {
|
||||
resp, _ := rest.GetRequest(uri)
|
||||
if tc.expectErr {
|
||||
s.Require().Contains(string(resp), tc.errMsg)
|
||||
} else {
|
||||
var g nft.QueryBalanceResponse
|
||||
err := val.ClientCtx.Codec.UnmarshalJSON(resp, &g)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(tc.expectValue, g.Amount)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryOwnerGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}
|
||||
expectErr bool
|
||||
errMsg string
|
||||
expectResult string
|
||||
}{
|
||||
{
|
||||
name: "class id is invalid",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: "invalid_class_id",
|
||||
ID: ExpNFT.Id,
|
||||
},
|
||||
expectErr: true,
|
||||
errMsg: "invalid class id",
|
||||
expectResult: "",
|
||||
},
|
||||
{
|
||||
name: "class id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: "class-id",
|
||||
ID: ExpNFT.Id,
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: "",
|
||||
},
|
||||
{
|
||||
name: "nft id is invalid",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
ID: "invalid_nft_id",
|
||||
},
|
||||
expectErr: true,
|
||||
expectResult: "",
|
||||
},
|
||||
{
|
||||
name: "nft id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
ID: "nft-id",
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: "",
|
||||
},
|
||||
{
|
||||
name: "nft exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
ID: ExpNFT.Id,
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: val.Address.String(),
|
||||
},
|
||||
}
|
||||
ownerURL := val.APIAddress + "/cosmos/nft/v1beta1/owner/%s/%s"
|
||||
for _, tc := range testCases {
|
||||
uri := fmt.Sprintf(ownerURL, tc.args.ClassID, tc.args.ID)
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := rest.GetRequest(uri)
|
||||
if tc.expectErr {
|
||||
s.Require().Contains(string(resp), tc.errMsg)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryOwnerResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(tc.expectResult, result.Owner)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQuerySupplyGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
}
|
||||
expectErr bool
|
||||
errMsg string
|
||||
expectResult uint64
|
||||
}{
|
||||
{
|
||||
name: "class id is invalid",
|
||||
args: struct {
|
||||
ClassID string
|
||||
}{
|
||||
ClassID: "invalid_class_id",
|
||||
},
|
||||
expectErr: true,
|
||||
errMsg: "invalid class id",
|
||||
expectResult: 0,
|
||||
},
|
||||
{
|
||||
name: "class id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
}{
|
||||
ClassID: "class-id",
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: 0,
|
||||
},
|
||||
{
|
||||
name: "class id exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: 1,
|
||||
},
|
||||
}
|
||||
supplyURL := val.APIAddress + "/cosmos/nft/v1beta1/supply/%s"
|
||||
for _, tc := range testCases {
|
||||
uri := fmt.Sprintf(supplyURL, tc.args.ClassID)
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := rest.GetRequest(uri)
|
||||
if tc.expectErr {
|
||||
s.Require().Contains(string(resp), tc.errMsg)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QuerySupplyResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(tc.expectResult, result.Amount)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryNFTsGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
expectResult []*nft.NFT
|
||||
}{
|
||||
{
|
||||
name: "classID and owner are both empty",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{},
|
||||
errorMsg: "must provide at least one of classID or owner",
|
||||
expectErr: true,
|
||||
expectResult: []*nft.NFT{},
|
||||
},
|
||||
{
|
||||
name: "classID is invalid",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: "invalid_class_id",
|
||||
},
|
||||
expectErr: true,
|
||||
expectResult: []*nft.NFT{},
|
||||
},
|
||||
{
|
||||
name: "classID does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: "class-id",
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: []*nft.NFT{},
|
||||
},
|
||||
{
|
||||
name: "success query by classID",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: []*nft.NFT{&ExpNFT},
|
||||
},
|
||||
{
|
||||
name: "success query by owner",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
Owner: val.Address.String(),
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: []*nft.NFT{&ExpNFT},
|
||||
},
|
||||
{
|
||||
name: "success query by owner and classID",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
Owner: val.Address.String(),
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: []*nft.NFT{&ExpNFT},
|
||||
},
|
||||
}
|
||||
nftsOfClassURL := val.APIAddress + "/cosmos/nft/v1beta1/nfts?class_id=%s&owner=%s"
|
||||
for _, tc := range testCases {
|
||||
uri := fmt.Sprintf(nftsOfClassURL, tc.args.ClassID, tc.args.Owner)
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := rest.GetRequest(uri)
|
||||
if tc.expectErr {
|
||||
s.Require().Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryNFTsResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(tc.expectResult, result.Nfts)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryNFTGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
}{
|
||||
{
|
||||
name: "class id is invalid",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: "invalid_class_id",
|
||||
ID: ExpNFT.Id,
|
||||
},
|
||||
expectErr: true,
|
||||
errorMsg: "invalid class id",
|
||||
},
|
||||
{
|
||||
name: "class id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: "class",
|
||||
ID: ExpNFT.Id,
|
||||
},
|
||||
expectErr: true,
|
||||
errorMsg: "not found nft",
|
||||
},
|
||||
{
|
||||
name: "nft id is invalid",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
ID: "invalid_nft_id",
|
||||
},
|
||||
expectErr: true,
|
||||
errorMsg: "invalid nft id",
|
||||
},
|
||||
{
|
||||
name: "nft id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
ID: "nft-id",
|
||||
},
|
||||
expectErr: true,
|
||||
errorMsg: "not found nft",
|
||||
},
|
||||
{
|
||||
name: "exist nft",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
ID: ExpNFT.Id,
|
||||
},
|
||||
expectErr: false,
|
||||
},
|
||||
}
|
||||
nftURL := val.APIAddress + "/cosmos/nft/v1beta1/nfts/%s/%s"
|
||||
for _, tc := range testCases {
|
||||
uri := fmt.Sprintf(nftURL, tc.args.ClassID, tc.args.ID)
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := rest.GetRequest(uri)
|
||||
if tc.expectErr {
|
||||
s.Require().Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryNFTResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(ExpNFT, *result.Nft)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryClassGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
}
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
}{
|
||||
{
|
||||
name: "class id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
}{
|
||||
ClassID: "class-id",
|
||||
},
|
||||
expectErr: true,
|
||||
errorMsg: "not found class",
|
||||
},
|
||||
{
|
||||
name: "class id exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
}{
|
||||
ClassID: ExpNFT.ClassId,
|
||||
},
|
||||
expectErr: false,
|
||||
},
|
||||
}
|
||||
classURL := val.APIAddress + "/cosmos/nft/v1beta1/classes/%s"
|
||||
for _, tc := range testCases {
|
||||
uri := fmt.Sprintf(classURL, tc.args.ClassID)
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := rest.GetRequest(uri)
|
||||
if tc.expectErr {
|
||||
s.Require().Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryClassResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(ExpClass, *result.Class)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryClassesGRPC() {
|
||||
val := s.network.Validators[0]
|
||||
classURL := val.APIAddress + "/cosmos/nft/v1beta1/classes"
|
||||
resp, err := rest.GetRequest(classURL)
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryClassesResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp, &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(result.Classes, 1)
|
||||
s.Require().EqualValues(ExpClass, *result.Classes[0])
|
||||
}
|
||||
@@ -0,0 +1,437 @@
|
||||
package nft
|
||||
|
||||
import (
|
||||
"github.com/cosmos/cosmos-sdk/x/nft"
|
||||
)
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryClass() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
}
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
name: "class id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
}{
|
||||
ClassID: "class",
|
||||
},
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "class id exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
},
|
||||
expectErr: false,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := ExecQueryClass(val, tc.args.ClassID)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryClassResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(ExpClass, *result.Class)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryClasses() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
name: "no params",
|
||||
expectErr: false,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := ExecQueryClasses(val)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryClassesResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().Len(result.Classes, 1)
|
||||
s.Require().EqualValues(ExpClass, *result.Classes[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryNFT() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
name: "class id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: "class",
|
||||
ID: testID,
|
||||
},
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "nft id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
ID: "id",
|
||||
},
|
||||
expectErr: true,
|
||||
},
|
||||
{
|
||||
name: "exist nft",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
ID: testID,
|
||||
},
|
||||
expectErr: false,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := ExecQueryNFT(val, tc.args.ClassID, tc.args.ID)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryNFTResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(ExpNFT, *result.Nft)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryNFTs() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}
|
||||
expectErr bool
|
||||
expectResult []*nft.NFT
|
||||
}{
|
||||
{
|
||||
name: "class id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: "class",
|
||||
Owner: val.Address.String(),
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: []*nft.NFT{},
|
||||
},
|
||||
{
|
||||
name: "owner does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
Owner: s.owner.String(),
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: []*nft.NFT{},
|
||||
},
|
||||
{
|
||||
name: "class id and owner both does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{},
|
||||
expectErr: true,
|
||||
expectResult: []*nft.NFT{},
|
||||
},
|
||||
{
|
||||
name: "nft exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
Owner: val.Address.String(),
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: []*nft.NFT{&ExpNFT},
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := ExecQueryNFTs(val, tc.args.ClassID, tc.args.Owner)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryNFTsResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(tc.expectResult, result.Nfts)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryOwner() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
expectResult string
|
||||
}{
|
||||
{
|
||||
name: "class id is invalid",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: "invalid_class_id",
|
||||
ID: testID,
|
||||
},
|
||||
expectErr: true,
|
||||
errorMsg: "invalid class id",
|
||||
expectResult: "",
|
||||
},
|
||||
{
|
||||
name: "class id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: "class",
|
||||
ID: testID,
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: "",
|
||||
},
|
||||
{
|
||||
name: "nft id is invalid",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
ID: "invalid_nft_id",
|
||||
},
|
||||
expectErr: true,
|
||||
expectResult: "",
|
||||
},
|
||||
{
|
||||
name: "nft id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
ID: "nft-id",
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: "",
|
||||
},
|
||||
{
|
||||
name: "nft exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
ID string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
ID: testID,
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: val.Address.String(),
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := ExecQueryOwner(val, tc.args.ClassID, tc.args.ID)
|
||||
if tc.expectErr {
|
||||
s.Require().Contains(string(resp.Bytes()), tc.errorMsg)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryOwnerResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(tc.expectResult, result.Owner)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQueryBalance() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
expectResult uint64
|
||||
}{
|
||||
{
|
||||
name: "class id is invalid",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: "invalid_class_id",
|
||||
Owner: val.Address.String(),
|
||||
},
|
||||
expectErr: true,
|
||||
errorMsg: "invalid class id",
|
||||
expectResult: 0,
|
||||
},
|
||||
{
|
||||
name: "class id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: "class",
|
||||
Owner: val.Address.String(),
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: 0,
|
||||
},
|
||||
{
|
||||
name: "owner does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
Owner: s.owner.String(),
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: 0,
|
||||
},
|
||||
{
|
||||
name: "nft exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
Owner string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
Owner: val.Address.String(),
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: 1,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := ExecQueryBalance(val, tc.args.ClassID, tc.args.Owner)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QueryBalanceResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(tc.expectResult, result.Amount)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestQuerySupply() {
|
||||
val := s.network.Validators[0]
|
||||
testCases := []struct {
|
||||
name string
|
||||
args struct {
|
||||
ClassID string
|
||||
}
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
expectResult uint64
|
||||
}{
|
||||
{
|
||||
name: "class id is invalid",
|
||||
args: struct {
|
||||
ClassID string
|
||||
}{
|
||||
ClassID: "invalid_class_id",
|
||||
},
|
||||
expectErr: true,
|
||||
errorMsg: "invalid class id",
|
||||
expectResult: 0,
|
||||
},
|
||||
{
|
||||
name: "class id does not exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
}{
|
||||
ClassID: "class",
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: 0,
|
||||
},
|
||||
{
|
||||
name: "class id exist",
|
||||
args: struct {
|
||||
ClassID string
|
||||
}{
|
||||
ClassID: testClassID,
|
||||
},
|
||||
expectErr: false,
|
||||
expectResult: 1,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
s.Run(tc.name, func() {
|
||||
resp, err := ExecQuerySupply(val, tc.args.ClassID)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
s.Require().NoError(err)
|
||||
var result nft.QuerySupplyResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &result)
|
||||
s.Require().NoError(err)
|
||||
s.Require().EqualValues(tc.expectResult, result.Amount)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package nft
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/cosmos/cosmos-sdk/x/nft/client/cli"
|
||||
)
|
||||
|
||||
func ExecSend(val *network.Validator, args []string) (testutil.BufferWriter, error) {
|
||||
cmd := cli.NewCmdSend()
|
||||
return clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||
}
|
||||
|
||||
func ExecQueryClass(val *network.Validator, classID string) (testutil.BufferWriter, error) {
|
||||
cmd := cli.GetCmdQueryClass()
|
||||
var args []string
|
||||
args = append(args, classID)
|
||||
args = append(args, fmt.Sprintf("--%s=json", tmcli.OutputFlag))
|
||||
return clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||
}
|
||||
|
||||
func ExecQueryClasses(val *network.Validator) (testutil.BufferWriter, error) {
|
||||
cmd := cli.GetCmdQueryClasses()
|
||||
var args []string
|
||||
args = append(args, fmt.Sprintf("--%s=json", tmcli.OutputFlag))
|
||||
return clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||
}
|
||||
|
||||
func ExecQueryNFT(val *network.Validator, classID, nftID string) (testutil.BufferWriter, error) {
|
||||
cmd := cli.GetCmdQueryNFT()
|
||||
var args []string
|
||||
args = append(args, classID)
|
||||
args = append(args, nftID)
|
||||
args = append(args, fmt.Sprintf("--%s=json", tmcli.OutputFlag))
|
||||
return clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||
}
|
||||
|
||||
func ExecQueryNFTs(val *network.Validator, classID, owner string) (testutil.BufferWriter, error) {
|
||||
cmd := cli.GetCmdQueryNFTs()
|
||||
var args []string
|
||||
args = append(args, fmt.Sprintf("--%s=%s", cli.FlagClassID, classID))
|
||||
args = append(args, fmt.Sprintf("--%s=%s", cli.FlagOwner, owner))
|
||||
args = append(args, fmt.Sprintf("--%s=json", tmcli.OutputFlag))
|
||||
return clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||
}
|
||||
|
||||
func ExecQueryOwner(val *network.Validator, classID, nftID string) (testutil.BufferWriter, error) {
|
||||
cmd := cli.GetCmdQueryOwner()
|
||||
var args []string
|
||||
args = append(args, classID)
|
||||
args = append(args, nftID)
|
||||
args = append(args, fmt.Sprintf("--%s=json", tmcli.OutputFlag))
|
||||
return clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||
}
|
||||
|
||||
func ExecQueryBalance(val *network.Validator, classID, owner string) (testutil.BufferWriter, error) {
|
||||
cmd := cli.GetCmdQueryBalance()
|
||||
var args []string
|
||||
args = append(args, owner)
|
||||
args = append(args, classID)
|
||||
args = append(args, fmt.Sprintf("--%s=json", tmcli.OutputFlag))
|
||||
return clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||
}
|
||||
|
||||
func ExecQuerySupply(val *network.Validator, classID string) (testutil.BufferWriter, error) {
|
||||
cmd := cli.GetCmdQuerySupply()
|
||||
var args []string
|
||||
args = append(args, classID)
|
||||
args = append(args, fmt.Sprintf("--%s=json", tmcli.OutputFlag))
|
||||
return clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args)
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package nft
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/nft"
|
||||
)
|
||||
|
||||
const (
|
||||
OwnerName = "owner"
|
||||
Owner = "cosmos1kznrznww4pd6gx0zwrpthjk68fdmqypjpkj5hp"
|
||||
OwnerArmor = `-----BEGIN TENDERMINT PRIVATE KEY-----
|
||||
salt: C3586B75587D2824187D2CDA22B6AFB6
|
||||
type: secp256k1
|
||||
kdf: bcrypt
|
||||
|
||||
1+15OrCKgjnwym1zO3cjo/SGe3PPqAYChQ5wMHjdUbTZM7mWsH3/ueL6swgjzI3b
|
||||
DDzEQAPXBQflzNW6wbne9IfT651zCSm+j1MWaGk=
|
||||
=wEHs
|
||||
-----END TENDERMINT PRIVATE KEY-----`
|
||||
|
||||
testClassID = "kitty"
|
||||
testClassName = "Crypto Kitty"
|
||||
testClassSymbol = "kitty"
|
||||
testClassDescription = "Crypto Kitty"
|
||||
testClassURI = "class uri"
|
||||
testID = "kitty1"
|
||||
testURI = "kitty uri"
|
||||
)
|
||||
|
||||
var (
|
||||
ExpClass = nft.Class{
|
||||
Id: testClassID,
|
||||
Name: testClassName,
|
||||
Symbol: testClassSymbol,
|
||||
Description: testClassDescription,
|
||||
Uri: testClassURI,
|
||||
}
|
||||
|
||||
ExpNFT = nft.NFT{
|
||||
ClassId: testClassID,
|
||||
Id: testID,
|
||||
Uri: testURI,
|
||||
}
|
||||
)
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cfg network.Config
|
||||
network *network.Network
|
||||
owner sdk.AccAddress
|
||||
}
|
||||
|
||||
func NewIntegrationTestSuite(cfg network.Config) *IntegrationTestSuite {
|
||||
return &IntegrationTestSuite{cfg: cfg}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) SetupSuite() {
|
||||
s.T().Log("setting up integration test suite")
|
||||
|
||||
genesisState := s.cfg.GenesisState
|
||||
nftGenesis := nft.GenesisState{
|
||||
Classes: []*nft.Class{&ExpClass},
|
||||
Entries: []*nft.Entry{{
|
||||
Owner: Owner,
|
||||
Nfts: []*nft.NFT{&ExpNFT},
|
||||
}},
|
||||
}
|
||||
|
||||
nftDataBz, err := s.cfg.Codec.MarshalJSON(&nftGenesis)
|
||||
s.Require().NoError(err)
|
||||
genesisState[nft.ModuleName] = nftDataBz
|
||||
s.cfg.GenesisState = genesisState
|
||||
s.network, err = network.New(s.T(), s.T().TempDir(), s.cfg)
|
||||
s.Require().NoError(err)
|
||||
|
||||
_, err = s.network.WaitForHeight(1)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.initAccount()
|
||||
_, err = s.network.WaitForHeight(1)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down integration test suite")
|
||||
s.network.Cleanup()
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) TestCLITxSend() {
|
||||
val := s.network.Validators[0]
|
||||
args := []string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, OwnerName),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
}
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
expectedCode uint32
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
"valid transaction",
|
||||
[]string{
|
||||
testClassID,
|
||||
testID,
|
||||
val.Address.String(),
|
||||
},
|
||||
0,
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
s.Run(tc.name, func() {
|
||||
clientCtx := val.ClientCtx
|
||||
args = append(args, tc.args...)
|
||||
out, err := ExecSend(
|
||||
val,
|
||||
args,
|
||||
)
|
||||
if tc.expectErr {
|
||||
s.Require().Error(err)
|
||||
} else {
|
||||
var txResp sdk.TxResponse
|
||||
s.Require().NoError(err)
|
||||
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &txResp), out.String())
|
||||
s.Require().Equal(tc.expectedCode, txResp.Code, out.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *IntegrationTestSuite) initAccount() {
|
||||
val := s.network.Validators[0]
|
||||
ctx := val.ClientCtx
|
||||
err := ctx.Keyring.ImportPrivKey(OwnerName, OwnerArmor, "1234567890")
|
||||
s.Require().NoError(err)
|
||||
|
||||
keyinfo, err := ctx.Keyring.Key(OwnerName)
|
||||
s.Require().NoError(err)
|
||||
|
||||
args := []string{
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
|
||||
}
|
||||
|
||||
s.owner, err = keyinfo.GetAddress()
|
||||
s.Require().NoError(err)
|
||||
|
||||
amount := sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(200)))
|
||||
_, err = clitestutil.MsgSendExec(ctx, val.Address, s.owner, amount, args...)
|
||||
s.Require().NoError(err)
|
||||
}
|
||||
Reference in New Issue
Block a user