diff --git a/go.mod b/go.mod index 0751e2896..81c516b52 100644 --- a/go.mod +++ b/go.mod @@ -6,15 +6,18 @@ toolchain go1.22.0 require ( cosmossdk.io/api v0.7.5 + cosmossdk.io/client/v2 v2.0.0-beta.2 + cosmossdk.io/core v0.11.0 cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.3.1 cosmossdk.io/math v1.3.0 cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d cosmossdk.io/store v1.1.0 - cosmossdk.io/tools/confix v0.1.0 - cosmossdk.io/x/evidence v0.1.0 - cosmossdk.io/x/feegrant v0.1.0 - cosmossdk.io/x/upgrade v0.1.1 + cosmossdk.io/tools/confix v0.1.1 + cosmossdk.io/x/evidence v0.1.1 + cosmossdk.io/x/feegrant v0.1.1 + cosmossdk.io/x/tx v0.13.3 + cosmossdk.io/x/upgrade v0.1.2 github.com/cometbft/cometbft v0.38.10 github.com/cosmos/cosmos-db v1.0.3-0.20240408151834-e75f6e4b28d8 github.com/cosmos/cosmos-proto v1.0.0-beta.5 @@ -37,6 +40,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.9.0 + github.com/tidwall/gjson v1.14.0 google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de google.golang.org/grpc v1.63.2 google.golang.org/protobuf v1.33.0 @@ -49,11 +53,10 @@ require ( cloud.google.com/go/compute/metadata v0.2.3 // indirect cloud.google.com/go/iam v1.1.6 // indirect cloud.google.com/go/storage v1.36.0 // indirect - cosmossdk.io/client/v2 v2.0.0-beta.2 // indirect cosmossdk.io/collections v0.4.0 // indirect - cosmossdk.io/core v0.11.0 // indirect cosmossdk.io/depinject v1.0.0-alpha.4 // indirect - cosmossdk.io/x/tx v0.13.3 // indirect + cosmossdk.io/x/circuit v0.1.1 // indirect + cosmossdk.io/x/nft v0.1.1 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect @@ -179,7 +182,6 @@ require ( github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect github.com/tidwall/btree v1.7.0 // indirect - github.com/tidwall/gjson v1.14.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect github.com/tidwall/tinylru v1.1.0 // indirect @@ -220,6 +222,7 @@ require ( // release/v0.50.x replace ( cosmossdk.io/client/v2 => github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240716063309-c47504d189d4 + cosmossdk.io/simapp => github.com/crypto-org-chain/cosmos-sdk/simapp v0.0.0-20240716063309-c47504d189d4 cosmossdk.io/store => github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240716063309-c47504d189d4 cosmossdk.io/x/tx => github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240716063309-c47504d189d4 github.com/cosmos/cosmos-sdk => github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240716063309-c47504d189d4 diff --git a/go.sum b/go.sum index 4dfa1ff04..251aa5467 100644 --- a/go.sum +++ b/go.sum @@ -202,18 +202,18 @@ cosmossdk.io/log v1.3.1 h1:UZx8nWIkfbbNEWusZqzAx3ZGvu54TZacWib3EzUYmGI= cosmossdk.io/log v1.3.1/go.mod h1:2/dIomt8mKdk6vl3OWJcPk2be3pGOS8OQaLUM/3/tCM= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= cosmossdk.io/math v1.3.0/go.mod h1:vnRTxewy+M7BtXBNFybkuhSH4WfedVAAnERHgVFhp3k= -cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d h1:E/8y0oG3u9hBR8l4F9MtC0LdZIamPCUwUoLlrHrX86I= -cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d/go.mod h1:xbjky3L3DJEylaho6gXplkrMvJ5sFgv+qNX+Nn47bzY= -cosmossdk.io/tools/confix v0.1.0 h1:2OOZTtQsDT5e7P3FM5xqM0bPfluAxZlAwxqaDmYBE+E= -cosmossdk.io/tools/confix v0.1.0/go.mod h1:TdXKVYs4gEayav5wM+JHT+kTU2J7fozFNqoVaN+8CdY= -cosmossdk.io/x/circuit v0.1.0 h1:IAej8aRYeuOMritczqTlljbUVHq1E85CpBqaCTwYgXs= -cosmossdk.io/x/circuit v0.1.0/go.mod h1:YDzblVE8+E+urPYQq5kq5foRY/IzhXovSYXb4nwd39w= -cosmossdk.io/x/evidence v0.1.0 h1:J6OEyDl1rbykksdGynzPKG5R/zm6TacwW2fbLTW4nCk= -cosmossdk.io/x/evidence v0.1.0/go.mod h1:hTaiiXsoiJ3InMz1uptgF0BnGqROllAN8mwisOMMsfw= -cosmossdk.io/x/feegrant v0.1.0 h1:c7s3oAq/8/UO0EiN1H5BIjwVntujVTkYs35YPvvrdQk= -cosmossdk.io/x/feegrant v0.1.0/go.mod h1:4r+FsViJRpcZif/yhTn+E0E6OFfg4n0Lx+6cCtnZElU= -cosmossdk.io/x/upgrade v0.1.1 h1:aoPe2gNvH+Gwt/Pgq3dOxxQVU3j5P6Xf+DaUJTDZATc= -cosmossdk.io/x/upgrade v0.1.1/go.mod h1:MNLptLPcIFK9CWt7Ra//8WUZAxweyRDNcbs5nkOcQy0= +cosmossdk.io/tools/confix v0.1.1 h1:aexyRv9+y15veH3Qw16lxQwo+ki7r2I+g0yNTEFEQM8= +cosmossdk.io/tools/confix v0.1.1/go.mod h1:nQVvP1tHsGXS83PonPVWJtSbddIqyjEw99L4M3rPJyQ= +cosmossdk.io/x/circuit v0.1.1 h1:KPJCnLChWrxD4jLwUiuQaf5mFD/1m7Omyo7oooefBVQ= +cosmossdk.io/x/circuit v0.1.1/go.mod h1:B6f/urRuQH8gjt4eLIXfZJucrbreuYrKh5CSjaOxr+Q= +cosmossdk.io/x/evidence v0.1.1 h1:Ks+BLTa3uftFpElLTDp9L76t2b58htjVbSZ86aoK/E4= +cosmossdk.io/x/evidence v0.1.1/go.mod h1:OoDsWlbtuyqS70LY51aX8FBTvguQqvFrt78qL7UzeNc= +cosmossdk.io/x/feegrant v0.1.1 h1:EKFWOeo/pup0yF0svDisWWKAA9Zags6Zd0P3nRvVvw8= +cosmossdk.io/x/feegrant v0.1.1/go.mod h1:2GjVVxX6G2fta8LWj7pC/ytHjryA6MHAJroBWHFNiEQ= +cosmossdk.io/x/nft v0.1.1 h1:pslAVS8P5NkW080+LWOamInjDcq+v2GSCo+BjN9sxZ8= +cosmossdk.io/x/nft v0.1.1/go.mod h1:Kac6F6y2gsKvoxU+fy8uvxRTi4BIhLOor2zgCNQwVgY= +cosmossdk.io/x/upgrade v0.1.2 h1:O2FGb0mVSXl7P6BQm9uV3hRVKom1zBLDGhd4G8jysJg= +cosmossdk.io/x/upgrade v0.1.2/go.mod h1:P+e4/ZNd8km7lTAX5hC2pXz/042YDcB7gzKTHuY53nc= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= @@ -448,6 +448,8 @@ github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240716063309-c47504d189d4 h1: github.com/crypto-org-chain/cosmos-sdk v0.50.6-0.20240716063309-c47504d189d4/go.mod h1:Rb43DdB0i/rKcCN69Tg2X3+zA4WhJ7MC8K3a6Ezh38E= github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240716063309-c47504d189d4 h1:CdzO51wAov8N3jpw77AY6T4LuZfp5DXco8ynyUe0z8k= github.com/crypto-org-chain/cosmos-sdk/client/v2 v2.0.0-20240716063309-c47504d189d4/go.mod h1:W5sR4asmVDUhJpEmuXTUBkk/yEefKlXTjVWcNciVSR0= +github.com/crypto-org-chain/cosmos-sdk/simapp v0.0.0-20240716063309-c47504d189d4 h1:rQqUFQFTSEbAFc3KD1TqIBxN+xsVnOtI5W7cRIMK0Y0= +github.com/crypto-org-chain/cosmos-sdk/simapp v0.0.0-20240716063309-c47504d189d4/go.mod h1:wkn2mL8skyC8wgO9iPhuBNZ2hCz3mjyAe9fHfXQNq2g= github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240716063309-c47504d189d4 h1:h27ED0uoWeHZZhWw1GYqtaf9Vl3fG86eOyF8Ifss2M4= github.com/crypto-org-chain/cosmos-sdk/store v0.0.0-20240716063309-c47504d189d4/go.mod h1:gjE3DZe4t/+VeIk6CmrouyqiuDbZ7QOVDDq3nLqBTpg= github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240716063309-c47504d189d4 h1:BfeHnfEVkVQlXWvFqw2kWuhgmujCqdImgiCyIoZ2c9A= diff --git a/gomod2nix.toml b/gomod2nix.toml index 79f283c59..365c4863e 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -42,28 +42,35 @@ schema = 3 version = "v1.3.0" hash = "sha256-EEFK43Cr0g0ndhQhkIKher0FqV3mvkmE9z0sP7uVSHg=" [mod."cosmossdk.io/simapp"] - version = "v0.0.0-20230608160436-666c345ad23d" - hash = "sha256-6BMBA98BpK3jG6++ZE4LdPQwwpS+lZ0GLMRF1fO4UfM=" + version = "v0.0.0-20240716063309-c47504d189d4" + hash = "sha256-f7M7boC76frRltU/0Hhml1pV5IYhYF8WnexGn3yV9Ro=" + replaced = "github.com/crypto-org-chain/cosmos-sdk/simapp" [mod."cosmossdk.io/store"] version = "v0.0.0-20240716063309-c47504d189d4" hash = "sha256-zne7cIFs9WLg11pIr9VLBBc+G+kZfKLn8UU1mP4w6BM=" replaced = "github.com/crypto-org-chain/cosmos-sdk/store" [mod."cosmossdk.io/tools/confix"] - version = "v0.1.0" - hash = "sha256-PvIYbcjsATI+gP0+efJZjlGhaClx4SNfadlVY3Ok9TE=" + version = "v0.1.1" + hash = "sha256-/Et2FFhb4XfakbLFvGQK3QxN5Y7alzO+DGfi2/EWbxo=" + [mod."cosmossdk.io/x/circuit"] + version = "v0.1.1" + hash = "sha256-MGeCCqyF1IS/QqaMRDol9+JHjdPgQVj9weIN8o3aAIU=" [mod."cosmossdk.io/x/evidence"] - version = "v0.1.0" - hash = "sha256-ZhVrmCGOzx2yODpcgvM9c48jkqz37NwU2ln/uVuCEfc=" + version = "v0.1.1" + hash = "sha256-iSjMwFPu1InR6weF/m4hGHP+StsudOCqeDZefGPTfxw=" [mod."cosmossdk.io/x/feegrant"] - version = "v0.1.0" - hash = "sha256-/gWvrqvy6bW90+NU66T+9QysYgvG1VbwfYJZ8tkqpeA=" + version = "v0.1.1" + hash = "sha256-aps3LfnQau1TYeccGwtqHQvy1Rudc9+O+iVAwXBKyDw=" + [mod."cosmossdk.io/x/nft"] + version = "v0.1.1" + hash = "sha256-6Nbgmpwx70Jr3S8f4A6imCsdEAxPdVQpmJQTW2RuzKo=" [mod."cosmossdk.io/x/tx"] version = "v0.0.0-20240716063309-c47504d189d4" hash = "sha256-xT5IdapEx1h46ofBpxcBQfzGF2EntmC8xZl7aym/6xE=" replaced = "github.com/crypto-org-chain/cosmos-sdk/x/tx" [mod."cosmossdk.io/x/upgrade"] - version = "v0.1.1" - hash = "sha256-bM9ybpaibMH7k4M6/QAXCZ3fJcADfJHxvMgp4AVUihs=" + version = "v0.1.2" + hash = "sha256-rNOuZBlR4rfxka2XBJ4LRRnJ+pnADojDzb1o2m4YulU=" [mod."filippo.io/edwards25519"] version = "v1.0.0" hash = "sha256-APnPAcmItvtJ5Zsy863lzR2TjEBF9Y66TY1e4M1ap98=" diff --git a/x/nft/client/cli/cli_test.go b/x/nft/client/cli/cli_test.go new file mode 100644 index 000000000..03c514fbe --- /dev/null +++ b/x/nft/client/cli/cli_test.go @@ -0,0 +1,318 @@ +// Copyright (c) 2016-2021 Shanghai Bianjie AI Technology Inc. (licensed under the Apache License, Version 2.0) +// Modifications Copyright (c) 2021-present Crypto.org (licensed under the Apache License, Version 2.0) +package cli_test + +import ( + "fmt" + "testing" + + "github.com/gogo/protobuf/proto" + "github.com/stretchr/testify/suite" + + sdkmath "cosmossdk.io/math" + "cosmossdk.io/simapp" + "github.com/cometbft/cometbft/crypto" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/rpc" + clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" + "github.com/cosmos/cosmos-sdk/testutil/network" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/crypto-org-chain/chain-main/v4/app" + "github.com/crypto-org-chain/chain-main/v4/testutil" + nftcli "github.com/crypto-org-chain/chain-main/v4/x/nft/client/cli" + nfttestutil "github.com/crypto-org-chain/chain-main/v4/x/nft/client/testutil" + nfttypes "github.com/crypto-org-chain/chain-main/v4/x/nft/types" +) + +type IntegrationTestSuite struct { + suite.Suite + + cfg network.Config + network *network.Network +} + +func (s *IntegrationTestSuite) SetupSuite() { + var err error + s.T().Log("setting up integration test suite") + + cfg := network.DefaultConfig(simapp.NewTestNetworkFixture) + cfg.ChainID = testutil.ChainID + cfg.AppConstructor = nfttestutil.GetApp + cfg.NumValidators = 2 + + encCfg := app.MakeEncodingConfig() + cfg.GenesisState = app.NewDefaultGenesisState(encCfg.Marshaler) + + s.cfg = cfg + s.network, err = network.New(s.T(), s.T().TempDir(), cfg) + s.Require().NoError(err) + + _, 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 TestIntegrationTestSuite(t *testing.T) { + suite.Run(t, new(IntegrationTestSuite)) +} + +func (s *IntegrationTestSuite) eventQueryTxFor(val *network.Validator, hash string) *sdk.TxResponse { + bz, err := clitestutil.ExecTestCLICmd(val.ClientCtx, rpc.QueryEventForTxCmd(), []string{hash, fmt.Sprintf("--%s=json", flags.FlagOutput)}) + s.Require().NoError(err) + respType := proto.Message(&sdk.TxResponse{}) + fmt.Println("mm-bz", bz.String()) + fmt.Println("mm-respType", respType) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) + return respType.(*sdk.TxResponse) +} + +func (s *IntegrationTestSuite) TestNft() { + val := s.network.Validators[0] + val2 := s.network.Validators[1] + + // --------------------------------------------------------------------------- + + from := val.Address + tokenName := "Kitty Token" + tokenURI := "uri" + tokenData := "data" + tokenID := "kitty" + // owner := "owner" + denomName := "name" + denom := "denom" + schema := "schema" + + //------test GetCmdIssueDenom()------------- + args := []string{ + fmt.Sprintf("--%s=%s", nftcli.FlagDenomName, denomName), + fmt.Sprintf("--%s=%s", nftcli.FlagSchema, schema), + + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + } + + respType := proto.Message(&sdk.TxResponse{}) + expectedCode := uint32(0) + + bz, err := nfttestutil.IssueDenomExec(val.ClientCtx, from.String(), denom, args...) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) + txResp := respType.(*sdk.TxResponse) + + s.Require().Equal(expectedCode, txResp.Code) + txResp = s.eventQueryTxFor(val, txResp.TxHash) + + var denomID string + for _, evt := range txResp.Events { + if evt.Type == "issue_denom" { + for _, attr := range evt.Attributes { + if attr.Key == "denom_id" { + denomID = attr.Value + break + } + } + } + } + //------test GetCmdQueryDenom()------------- + respType = proto.Message(&nfttypes.Denom{}) + bz, err = nfttestutil.QueryDenomExec(val.ClientCtx, denomID) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + denomItem := respType.(*nfttypes.Denom) + s.Require().Equal(denomName, denomItem.Name) + s.Require().Equal(schema, denomItem.Schema) + + //------test GetCmdQueryDenomByName()------------- + respType = proto.Message(&nfttypes.Denom{}) + bz, err = nfttestutil.QueryDenomByNameExec(val.ClientCtx, denomName) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + denomItem = respType.(*nfttypes.Denom) + s.Require().Equal(denomName, denomItem.Name) + s.Require().Equal(denomID, denomItem.Id) + s.Require().Equal(schema, denomItem.Schema) + + //------test GetCmdQueryDenoms()------------- + respType = proto.Message(&nfttypes.QueryDenomsResponse{}) + bz, err = nfttestutil.QueryDenomsExec(val.ClientCtx) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + denomsResp := respType.(*nfttypes.QueryDenomsResponse) + s.Require().Equal(1, len(denomsResp.Denoms)) + s.Require().Equal(denomID, denomsResp.Denoms[0].Id) + + //------test GetCmdMintNFT()------------- + args = []string{ + fmt.Sprintf("--%s=%s", nftcli.FlagTokenData, tokenData), + fmt.Sprintf("--%s=%s", nftcli.FlagRecipient, from.String()), + fmt.Sprintf("--%s=%s", nftcli.FlagTokenURI, tokenURI), + fmt.Sprintf("--%s=%s", nftcli.FlagTokenName, tokenName), + + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + } + + respType = proto.Message(&sdk.TxResponse{}) + + bz, err = nfttestutil.MintNFTExec(val.ClientCtx, from.String(), denomID, tokenID, args...) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) + txResp = respType.(*sdk.TxResponse) + s.Require().Equal(expectedCode, txResp.Code) + s.eventQueryTxFor(val, txResp.TxHash) + + //------test GetCmdQuerySupply()------------- + respType = proto.Message(&nfttypes.QuerySupplyResponse{}) + bz, err = nfttestutil.QuerySupplyExec(val.ClientCtx, denomID) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + supplyResp := respType.(*nfttypes.QuerySupplyResponse) + s.Require().Equal(uint64(1), supplyResp.Amount) + + //------test GetCmdQueryNFT()------------- + respType = proto.Message(&nfttypes.BaseNFT{}) + bz, err = nfttestutil.QueryNFTExec(val.ClientCtx, denomID, tokenID) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + nftItem := respType.(*nfttypes.BaseNFT) + s.Require().Equal(tokenID, nftItem.Id) + s.Require().Equal(tokenName, nftItem.Name) + s.Require().Equal(tokenURI, nftItem.URI) + s.Require().Equal(tokenData, nftItem.Data) + s.Require().Equal(from.String(), nftItem.Owner) + + //------test GetCmdQueryOwner()------------- + respType = proto.Message(&nfttypes.QueryOwnerResponse{}) + bz, err = nfttestutil.QueryOwnerExec(val.ClientCtx, from.String()) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + ownerResp := respType.(*nfttypes.QueryOwnerResponse) + s.Require().Equal(from.String(), ownerResp.Owner.Address) + s.Require().Equal(denom, ownerResp.Owner.IDCollections[0].DenomId) + s.Require().Equal(tokenID, ownerResp.Owner.IDCollections[0].TokenIds[0]) + + //------test GetCmdQueryCollection()------------- + respType = proto.Message(&nfttypes.QueryCollectionResponse{}) + bz, err = nfttestutil.QueryCollectionExec(val.ClientCtx, denomID) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + collectionItem := respType.(*nfttypes.QueryCollectionResponse) + s.Require().Equal(1, len(collectionItem.Collection.NFTs)) + + //------test GetCmdEditNFT()------------- + newTokenData := "newdata" + newTokenURI := "newuri" + newTokenName := "new Kitty Token" + args = []string{ + fmt.Sprintf("--%s=%s", nftcli.FlagTokenData, newTokenData), + fmt.Sprintf("--%s=%s", nftcli.FlagTokenURI, newTokenURI), + fmt.Sprintf("--%s=%s", nftcli.FlagTokenName, newTokenName), + + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + } + + respType = proto.Message(&sdk.TxResponse{}) + + bz, err = nfttestutil.EditNFTExec(val.ClientCtx, from.String(), denomID, tokenID, args...) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) + txResp = respType.(*sdk.TxResponse) + s.Require().Equal(expectedCode, txResp.Code) + s.eventQueryTxFor(val, txResp.TxHash) + + respType = proto.Message(&nfttypes.BaseNFT{}) + bz, err = nfttestutil.QueryNFTExec(val.ClientCtx, denomID, tokenID) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + newNftItem := respType.(*nfttypes.BaseNFT) + s.Require().Equal(newTokenName, newNftItem.Name) + s.Require().Equal(newTokenURI, newNftItem.URI) + s.Require().Equal(newTokenData, newNftItem.Data) + + //------test GetCmdTransferNFT()------------- + recipient := sdk.AccAddress(crypto.AddressHash([]byte("dgsbl"))) + + args = []string{ + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + } + + respType = proto.Message(&sdk.TxResponse{}) + + bz, err = nfttestutil.TransferNFTExec(val.ClientCtx, from.String(), recipient.String(), denomID, tokenID, args...) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) + txResp = respType.(*sdk.TxResponse) + s.Require().Equal(expectedCode, txResp.Code) + s.eventQueryTxFor(val, txResp.TxHash) + + respType = proto.Message(&nfttypes.BaseNFT{}) + bz, err = nfttestutil.QueryNFTExec(val.ClientCtx, denomID, tokenID) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + nftItem = respType.(*nfttypes.BaseNFT) + s.Require().Equal(tokenID, nftItem.Id) + s.Require().Equal(newTokenName, nftItem.Name) + s.Require().Equal(newTokenURI, nftItem.URI) + s.Require().Equal(newTokenData, nftItem.Data) + s.Require().Equal(recipient.String(), nftItem.Owner) + + //------test GetCmdBurnNFT()------------- + newTokenID := "dgsbl" + args = []string{ + fmt.Sprintf("--%s=%s", nftcli.FlagTokenData, newTokenData), + fmt.Sprintf("--%s=%s", nftcli.FlagRecipient, from.String()), + fmt.Sprintf("--%s=%s", nftcli.FlagTokenURI, newTokenURI), + fmt.Sprintf("--%s=%s", nftcli.FlagTokenName, newTokenName), + + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + } + + respType = proto.Message(&sdk.TxResponse{}) + + bz, err = nfttestutil.MintNFTExec(val.ClientCtx, from.String(), denomID, newTokenID, args...) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) + txResp = respType.(*sdk.TxResponse) + s.Require().Equal(expectedCode, txResp.Code) + s.eventQueryTxFor(val, txResp.TxHash) + + respType = proto.Message(&nfttypes.QuerySupplyResponse{}) + bz, err = nfttestutil.QuerySupplyExec(val.ClientCtx, denomID) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + supplyResp = respType.(*nfttypes.QuerySupplyResponse) + s.Require().Equal(uint64(2), supplyResp.Amount) + + args = []string{ + fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), + fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdkmath.NewInt(10))).String()), + } + respType = proto.Message(&sdk.TxResponse{}) + bz, err = nfttestutil.BurnNFTExec(val.ClientCtx, from.String(), denomID, newTokenID, args...) + s.Require().NoError(err) + s.Require().NoError(val2.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType), bz.String()) + txResp = respType.(*sdk.TxResponse) + s.Require().Equal(expectedCode, txResp.Code) + s.eventQueryTxFor(val, txResp.TxHash) + + respType = proto.Message(&nfttypes.QuerySupplyResponse{}) + bz, err = nfttestutil.QuerySupplyExec(val.ClientCtx, denomID) + s.Require().NoError(err) + s.Require().NoError(val.ClientCtx.Codec.UnmarshalJSON(bz.Bytes(), respType)) + supplyResp = respType.(*nfttypes.QuerySupplyResponse) + s.Require().Equal(uint64(1), supplyResp.Amount) +} diff --git a/x/nft/client/testutil/test_helpers.go b/x/nft/client/testutil/test_helpers.go index d8a7ec2c5..19cb25219 100644 --- a/x/nft/client/testutil/test_helpers.go +++ b/x/nft/client/testutil/test_helpers.go @@ -21,10 +21,9 @@ import ( pruningtypes "cosmossdk.io/store/pruning/types" dbm "github.com/cosmos/cosmos-db" servertypes "github.com/cosmos/cosmos-sdk/server/types" + apptestutil "github.com/crypto-org-chain/chain-main/v4/testutil" ) -const TestAppChainID = "chainmain-1" - func GetApp(val network.ValidatorI) servertypes.Application { ctx := val.GetCtx() appConfig := val.GetAppConfig() @@ -33,7 +32,7 @@ func GetApp(val network.ValidatorI) servertypes.Application { simtestutil.EmptyAppOptions{}, baseapp.SetPruning(pruningtypes.NewPruningOptionsFromString(appConfig.Pruning)), baseapp.SetMinGasPrices(appConfig.MinGasPrices), - baseapp.SetChainID(TestAppChainID), + baseapp.SetChainID(apptestutil.ChainID), ) } diff --git a/x/nft/keeper/keeper_test.go b/x/nft/keeper/keeper_test.go index 301c82c31..edfc8bd38 100644 --- a/x/nft/keeper/keeper_test.go +++ b/x/nft/keeper/keeper_test.go @@ -60,13 +60,11 @@ type KeeperSuite struct { queryClient types.QueryClient } -const TestAppChainID = "chainmain-1" - func (suite *KeeperSuite) SetupTest() { a := testutil.Setup(isCheckTx, nil) suite.app = a suite.legacyAmino = a.LegacyAmino() - suite.ctx = a.BaseApp.NewContext(isCheckTx).WithBlockHeader(tmproto.Header{ChainID: TestAppChainID}) + suite.ctx = a.BaseApp.NewContext(isCheckTx).WithBlockHeader(tmproto.Header{ChainID: testutil.ChainID}) suite.keeper = a.NFTKeeper queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, a.InterfaceRegistry())