From 92ac6e0a5841a5d46bf82d27a2aae1e989c094a9 Mon Sep 17 00:00:00 2001 From: Jayden Lee <41176085+tkxkd0159@users.noreply.github.com> Date: Wed, 28 Feb 2024 00:17:52 +0900 Subject: [PATCH] Remove `AccAddress.String()` --- tests/e2e/collection/grpc.go | 16 +- tests/e2e/collection/suite.go | 51 +++--- tests/e2e/collection/tx.go | 154 ++++++++--------- x/collection/client/cli/tx_test.go | 152 ++++++++--------- x/collection/genesis_test.go | 22 +-- x/collection/keeper/alias.go | 14 +- x/collection/keeper/genesis.go | 6 +- x/collection/keeper/grpc_query.go | 4 +- x/collection/keeper/grpc_query_test.go | 14 +- x/collection/keeper/keeper_test.go | 12 +- x/collection/keeper/msg_server_test.go | 224 ++++++++++++------------- x/collection/keeper/send.go | 4 +- x/collection/keeper/send_test.go | 12 +- x/collection/keeper/supply.go | 10 +- x/collection/keeper/supply_test.go | 2 +- x/collection/msgs_test.go | 72 ++++---- 16 files changed, 393 insertions(+), 376 deletions(-) diff --git a/tests/e2e/collection/grpc.go b/tests/e2e/collection/grpc.go index 61067b949d..6af9c164c1 100644 --- a/tests/e2e/collection/grpc.go +++ b/tests/e2e/collection/grpc.go @@ -28,7 +28,7 @@ func (s *E2ETestSuite) TestBalanceGRPC() { }{ { "valid request", - fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s/%s", val.APIAddress, s.contractID, s.customer.String(), tokenID), + fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s/%s", val.APIAddress, s.contractID, s.customer, tokenID), false, &collection.QueryBalanceResponse{}, &collection.QueryBalanceResponse{ @@ -37,7 +37,7 @@ func (s *E2ETestSuite) TestBalanceGRPC() { }, { "not own NFT", - fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s/%s", val.APIAddress, s.contractID, s.stranger.String(), tokenID), + fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s/%s", val.APIAddress, s.contractID, s.stranger, tokenID), false, &collection.QueryBalanceResponse{}, &collection.QueryBalanceResponse{ @@ -46,14 +46,14 @@ func (s *E2ETestSuite) TestBalanceGRPC() { }, { "invalid contract ID", - fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s/%s", val.APIAddress, "wrong id", s.customer.String(), tokenID), + fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s/%s", val.APIAddress, "wrong id", s.customer, tokenID), true, &collection.QueryBalanceResponse{}, &collection.QueryBalanceResponse{}, }, { "invalid token ID", - fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s/%s", val.APIAddress, s.contractID, s.customer.String(), "wrong id"), + fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s/%s", val.APIAddress, s.contractID, s.customer, "wrong id"), true, &collection.QueryBalanceResponse{}, &collection.QueryBalanceResponse{}, @@ -97,13 +97,13 @@ func (s *E2ETestSuite) TestBalancesGRPC() { }{ { "valid request", - fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s", val.APIAddress, s.contractID, s.vendor.String()), + fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s", val.APIAddress, s.contractID, s.vendor), false, &collection.QueryAllBalancesResponse{}, }, { "invalid contract ID", - fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s/%s", val.APIAddress, "wrong id", s.vendor.String(), tokenID), + fmt.Sprintf("%s/lbm/collection/v1/contracts/%s/balances/%s/%s", val.APIAddress, "wrong id", s.vendor, tokenID), true, &collection.QueryAllBalancesResponse{}, }, @@ -430,7 +430,7 @@ func (s *E2ETestSuite) TestTokenGRPC() { &collection.OwnerNFT{ ContractId: s.contractID, TokenId: tokenID, - Owner: s.vendor.String(), + Owner: s.vendor, Name: "arctic fox", Meta: "", }, @@ -505,7 +505,7 @@ func (s *E2ETestSuite) TestGranteeGrantsGRPC() { &collection.QueryGranteeGrantsResponse{ Grants: []collection.Grant{ { - Grantee: s.stranger.String(), + Grantee: s.stranger, Permission: collection.PermissionIssue, }, }, diff --git a/tests/e2e/collection/suite.go b/tests/e2e/collection/suite.go index 207d2698d9..8b42e6846b 100644 --- a/tests/e2e/collection/suite.go +++ b/tests/e2e/collection/suite.go @@ -32,10 +32,10 @@ type E2ETestSuite struct { commonArgs []string - vendor sdk.AccAddress - operator sdk.AccAddress - customer sdk.AccAddress - stranger sdk.AccAddress + vendor string + operator string + customer string + stranger string contractID string nftClassID string tokenIDs map[string]string @@ -63,7 +63,8 @@ func (s *E2ETestSuite) SetupSuite() { fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, cmath.NewInt(100))).String()), } - s.vendor = s.network.Validators[0].Address + s.vendor, err = s.ac.BytesToString(s.network.Validators[0].Address) + s.Require().NoError(err) s.operator = s.createAccount("operator") s.customer = s.createAccount("customer") s.stranger = s.createAccount("stranger") @@ -74,8 +75,8 @@ func (s *E2ETestSuite) SetupSuite() { // mint nfts s.tokenIDs = make(map[string]string, 4) - for _, to := range []sdk.AccAddress{s.customer, s.operator, s.vendor, s.stranger} { - s.tokenIDs[to.String()] = s.mintNFT(s.contractID, s.vendor, to, s.nftClassID) + for _, to := range []string{s.customer, s.operator, s.vendor, s.stranger} { + s.tokenIDs[to] = s.mintNFT(s.contractID, s.vendor, to, s.nftClassID) } // grant all the permissions to operator @@ -103,10 +104,10 @@ func (s *E2ETestSuite) TearDownSuite() { s.network.Cleanup() } -func (s *E2ETestSuite) createContract(creator sdk.AccAddress) string { +func (s *E2ETestSuite) createContract(creator string) string { val := s.network.Validators[0] args := append([]string{ - creator.String(), + creator, }, s.commonArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewTxCmdCreateContract(), args) @@ -119,11 +120,11 @@ func (s *E2ETestSuite) createContract(creator sdk.AccAddress) string { return event.ContractId } -func (s *E2ETestSuite) createNFTClass(contractID string, operator sdk.AccAddress) string { +func (s *E2ETestSuite) createNFTClass(contractID, operator string) string { val := s.network.Validators[0] args := append([]string{ contractID, - operator.String(), + operator, }, s.commonArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewTxCmdIssueNFT(), args) @@ -136,12 +137,12 @@ func (s *E2ETestSuite) createNFTClass(contractID string, operator sdk.AccAddress return event.TokenType } -func (s *E2ETestSuite) mintNFT(contractID string, operator, to sdk.AccAddress, classID string) string { +func (s *E2ETestSuite) mintNFT(contractID, operator, to, classID string) string { val := s.network.Validators[0] args := append([]string{ contractID, - operator.String(), - to.String(), + operator, + to, classID, fmt.Sprintf("--%s=%s", cli.FlagName, "arctic fox"), }, s.commonArgs...) @@ -158,11 +159,11 @@ func (s *E2ETestSuite) mintNFT(contractID string, operator, to sdk.AccAddress, c return event.Tokens[0].TokenId } -func (s *E2ETestSuite) burnNFT(contractID string, operator sdk.AccAddress, tokenID string) collection.Coins { +func (s *E2ETestSuite) burnNFT(contractID, operator, tokenID string) collection.Coins { val := s.network.Validators[0] args := append([]string{ contractID, - operator.String(), + operator, tokenID, }, s.commonArgs...) @@ -178,12 +179,12 @@ func (s *E2ETestSuite) burnNFT(contractID string, operator sdk.AccAddress, token return event.Amount } -func (s *E2ETestSuite) grant(contractID string, granter, grantee sdk.AccAddress, permission collection.Permission) { +func (s *E2ETestSuite) grant(contractID, granter, grantee string, permission collection.Permission) { val := s.network.Validators[0] args := append([]string{ contractID, - granter.String(), - grantee.String(), + granter, + grantee, collection.LegacyPermission(permission).String(), }, s.commonArgs...) @@ -192,12 +193,12 @@ func (s *E2ETestSuite) grant(contractID string, granter, grantee sdk.AccAddress, _ = s.getTxResp(out, 0) } -func (s *E2ETestSuite) authorizeOperator(contractID string, holder, operator sdk.AccAddress) { +func (s *E2ETestSuite) authorizeOperator(contractID, holder, operator string) { val := s.network.Validators[0] args := append([]string{ contractID, - holder.String(), - operator.String(), + holder, + operator, }, s.commonArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.NewTxCmdAuthorizeOperator(s.ac), args) @@ -220,7 +221,7 @@ func (s *E2ETestSuite) pickEvent(events []abci.Event, event proto.Message, fn fu } // creates an account and send some coins to it for the future transactions. -func (s *E2ETestSuite) createAccount(uid string) sdk.AccAddress { +func (s *E2ETestSuite) createAccount(uid string) string { val := s.network.Validators[0] keyInfo, _, err := val.ClientCtx.Keyring.NewMnemonic(uid, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1) s.Require().NoError(err) @@ -230,7 +231,9 @@ func (s *E2ETestSuite) createAccount(uid string) sdk.AccAddress { out, err := clitestutil.MsgSendExec(val.ClientCtx, val.Address, addr, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, cmath.NewInt(1000000))), s.ac, s.commonArgs...) s.Require().NoError(err) s.getTxResp(out, 0) - return addr + a, err := s.ac.BytesToString(addr) + s.Require().NoError(err) + return a } func (s *E2ETestSuite) getTxResp(out testutil.BufferWriter, expectedCode uint32) sdk.TxResponse { diff --git a/tests/e2e/collection/tx.go b/tests/e2e/collection/tx.go index 63314030cb..6e732f7d9d 100644 --- a/tests/e2e/collection/tx.go +++ b/tests/e2e/collection/tx.go @@ -11,7 +11,7 @@ import ( func (s *E2ETestSuite) TestNewTxCmdSendNFT() { val := s.network.Validators[0] - tokenID := s.tokenIDs[s.stranger.String()] + tokenID := s.tokenIDs[s.stranger] testCases := map[string]struct { args []string @@ -20,8 +20,8 @@ func (s *E2ETestSuite) TestNewTxCmdSendNFT() { "valid transaction": { []string{ s.contractID, - s.stranger.String(), - s.customer.String(), + s.stranger, + s.customer, tokenID, }, true, @@ -29,8 +29,8 @@ func (s *E2ETestSuite) TestNewTxCmdSendNFT() { "extra args": { []string{ s.contractID, - s.stranger.String(), - s.customer.String(), + s.stranger, + s.customer, tokenID, "extra", }, @@ -39,16 +39,16 @@ func (s *E2ETestSuite) TestNewTxCmdSendNFT() { "not enough args": { []string{ s.contractID, - s.stranger.String(), - s.customer.String(), + s.stranger, + s.customer, }, false, }, "invalid contract id": { []string{ "", - s.stranger.String(), - s.customer.String(), + s.stranger, + s.customer, tokenID, }, false, @@ -73,7 +73,7 @@ func (s *E2ETestSuite) TestNewTxCmdSendNFT() { func (s *E2ETestSuite) TestNewTxCmdOperatorSendNFT() { val := s.network.Validators[0] - tokenID := s.tokenIDs[s.customer.String()] + tokenID := s.tokenIDs[s.customer] testCases := map[string]struct { args []string @@ -83,9 +83,9 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorSendNFT() { "valid transaction": { []string{ s.contractID, - s.operator.String(), - s.customer.String(), - s.vendor.String(), + s.operator, + s.customer, + s.vendor, tokenID, }, true, @@ -94,9 +94,9 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorSendNFT() { "extra args": { []string{ s.contractID, - s.operator.String(), - s.customer.String(), - s.vendor.String(), + s.operator, + s.customer, + s.vendor, tokenID, "extra", }, @@ -106,9 +106,9 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorSendNFT() { "not enough args": { []string{ s.contractID, - s.operator.String(), - s.customer.String(), - s.vendor.String(), + s.operator, + s.customer, + s.vendor, }, false, false, @@ -116,9 +116,9 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorSendNFT() { "invalid contract id": { []string{ "", - s.operator.String(), - s.customer.String(), - s.vendor.String(), + s.operator, + s.customer, + s.vendor, tokenID, }, false, @@ -127,9 +127,9 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorSendNFT() { "invalid operator": { []string{ s.contractID, - s.stranger.String(), - s.customer.String(), - s.vendor.String(), + s.stranger, + s.customer, + s.vendor, tokenID, }, true, @@ -166,13 +166,13 @@ func (s *E2ETestSuite) TestNewTxCmdCreateContract() { }{ "valid transaction": { []string{ - s.vendor.String(), + s.vendor, }, true, }, "extra args": { []string{ - s.vendor.String(), + s.vendor, "extra", }, false, @@ -215,14 +215,14 @@ func (s *E2ETestSuite) TestNewTxCmdIssueNFT() { "valid transaction": { []string{ s.contractID, - s.operator.String(), + s.operator, }, true, }, "extra args": { []string{ s.contractID, - s.operator.String(), + s.operator, "extra", }, false, @@ -236,7 +236,7 @@ func (s *E2ETestSuite) TestNewTxCmdIssueNFT() { "invalid contract id": { []string{ "", - s.operator.String(), + s.operator, }, false, }, @@ -268,8 +268,8 @@ func (s *E2ETestSuite) TestNewTxCmdMintNFT() { "valid transaction": { []string{ s.contractID, - s.operator.String(), - s.customer.String(), + s.operator, + s.customer, s.nftClassID, fmt.Sprintf("--%s=%s", cli.FlagName, "arctic fox"), }, @@ -278,8 +278,8 @@ func (s *E2ETestSuite) TestNewTxCmdMintNFT() { "extra args": { []string{ s.contractID, - s.operator.String(), - s.customer.String(), + s.operator, + s.customer, s.nftClassID, "extra", }, @@ -288,16 +288,16 @@ func (s *E2ETestSuite) TestNewTxCmdMintNFT() { "not enough args": { []string{ s.contractID, - s.operator.String(), - s.customer.String(), + s.operator, + s.customer, }, false, }, "invalid contract id": { []string{ "", - s.operator.String(), - s.customer.String(), + s.operator, + s.customer, s.nftClassID, }, false, @@ -322,7 +322,7 @@ func (s *E2ETestSuite) TestNewTxCmdMintNFT() { func (s *E2ETestSuite) TestNewTxCmdBurnNFT() { val := s.network.Validators[0] - tokenID := s.tokenIDs[s.operator.String()] + tokenID := s.tokenIDs[s.operator] testCases := map[string]struct { args []string @@ -331,7 +331,7 @@ func (s *E2ETestSuite) TestNewTxCmdBurnNFT() { "valid transaction": { []string{ s.contractID, - s.operator.String(), + s.operator, tokenID, }, true, @@ -339,7 +339,7 @@ func (s *E2ETestSuite) TestNewTxCmdBurnNFT() { "extra args": { []string{ s.contractID, - s.operator.String(), + s.operator, tokenID, "extra", }, @@ -348,14 +348,14 @@ func (s *E2ETestSuite) TestNewTxCmdBurnNFT() { "not enough args": { []string{ s.contractID, - s.operator.String(), + s.operator, }, false, }, "invalid contract id": { []string{ "", - s.operator.String(), + s.operator, tokenID, }, false, @@ -380,7 +380,7 @@ func (s *E2ETestSuite) TestNewTxCmdBurnNFT() { func (s *E2ETestSuite) TestNewTxCmdOperatorOperatorBurnNFT() { val := s.network.Validators[0] - tokenID := s.tokenIDs[s.vendor.String()] + tokenID := s.tokenIDs[s.vendor] testCases := map[string]struct { args []string @@ -390,8 +390,8 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorOperatorBurnNFT() { "valid transaction": { []string{ s.contractID, - s.operator.String(), - s.vendor.String(), + s.operator, + s.vendor, tokenID, }, true, @@ -400,8 +400,8 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorOperatorBurnNFT() { "extra args": { []string{ s.contractID, - s.operator.String(), - s.vendor.String(), + s.operator, + s.vendor, tokenID, "extra", }, @@ -411,8 +411,8 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorOperatorBurnNFT() { "not enough args": { []string{ s.contractID, - s.operator.String(), - s.vendor.String(), + s.operator, + s.vendor, }, false, false, @@ -420,8 +420,8 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorOperatorBurnNFT() { "invalid contract id": { []string{ "", - s.operator.String(), - s.vendor.String(), + s.operator, + s.vendor, tokenID, }, false, @@ -430,8 +430,8 @@ func (s *E2ETestSuite) TestNewTxCmdOperatorOperatorBurnNFT() { "invalid operator": { []string{ s.contractID, - s.stranger.String(), - s.vendor.String(), + s.stranger, + s.vendor, tokenID, }, true, @@ -469,7 +469,7 @@ func (s *E2ETestSuite) TestNewTxCmdModify() { "valid transaction": { []string{ s.contractID, - s.operator.String(), + s.operator, s.nftClassID, "", collection.AttributeKeyName.String(), @@ -480,7 +480,7 @@ func (s *E2ETestSuite) TestNewTxCmdModify() { "extra args": { []string{ s.contractID, - s.operator.String(), + s.operator, s.nftClassID, "", collection.AttributeKeyName.String(), @@ -492,7 +492,7 @@ func (s *E2ETestSuite) TestNewTxCmdModify() { "not enough args": { []string{ s.contractID, - s.operator.String(), + s.operator, s.nftClassID, "", collection.AttributeKeyName.String(), @@ -502,7 +502,7 @@ func (s *E2ETestSuite) TestNewTxCmdModify() { "invalid contract id": { []string{ "", - s.operator.String(), + s.operator, s.nftClassID, "", collection.AttributeKeyName.String(), @@ -538,8 +538,8 @@ func (s *E2ETestSuite) TestNewTxCmdGrantPermission() { "valid transaction": { []string{ s.contractID, - s.operator.String(), - s.customer.String(), + s.operator, + s.customer, collection.LegacyPermissionMint.String(), }, true, @@ -547,8 +547,8 @@ func (s *E2ETestSuite) TestNewTxCmdGrantPermission() { "extra args": { []string{ s.contractID, - s.operator.String(), - s.customer.String(), + s.operator, + s.customer, collection.LegacyPermissionMint.String(), "extra", }, @@ -557,8 +557,8 @@ func (s *E2ETestSuite) TestNewTxCmdGrantPermission() { "not enough args": { []string{ s.contractID, - s.operator.String(), - s.customer.String(), + s.operator, + s.customer, }, false, }, @@ -590,7 +590,7 @@ func (s *E2ETestSuite) TestNewTxCmdRevokePermission() { "valid transaction": { []string{ s.contractID, - s.vendor.String(), + s.vendor, collection.LegacyPermissionModify.String(), }, true, @@ -598,7 +598,7 @@ func (s *E2ETestSuite) TestNewTxCmdRevokePermission() { "extra args": { []string{ s.contractID, - s.vendor.String(), + s.vendor, collection.LegacyPermissionModify.String(), "extra", }, @@ -607,7 +607,7 @@ func (s *E2ETestSuite) TestNewTxCmdRevokePermission() { "not enough args": { []string{ s.contractID, - s.vendor.String(), + s.vendor, }, false, }, @@ -639,16 +639,16 @@ func (s *E2ETestSuite) TestNewTxCmdAuthorizeOperator() { "valid transaction": { []string{ s.contractID, - s.vendor.String(), - s.customer.String(), + s.vendor, + s.customer, }, true, }, "extra args": { []string{ s.contractID, - s.vendor.String(), - s.customer.String(), + s.vendor, + s.customer, "extra", }, false, @@ -656,7 +656,7 @@ func (s *E2ETestSuite) TestNewTxCmdAuthorizeOperator() { "not enough args": { []string{ s.contractID, - s.vendor.String(), + s.vendor, }, false, }, @@ -688,16 +688,16 @@ func (s *E2ETestSuite) TestNewTxCmdRevokeOperator() { "valid transaction": { []string{ s.contractID, - s.operator.String(), - s.vendor.String(), + s.operator, + s.vendor, }, true, }, "extra args": { []string{ s.contractID, - s.operator.String(), - s.vendor.String(), + s.operator, + s.vendor, "extra", }, false, @@ -705,7 +705,7 @@ func (s *E2ETestSuite) TestNewTxCmdRevokeOperator() { "not enough args": { []string{ s.contractID, - s.operator.String(), + s.operator, }, false, }, diff --git a/x/collection/client/cli/tx_test.go b/x/collection/client/cli/tx_test.go index 7da796f888..5376e56e94 100644 --- a/x/collection/client/cli/tx_test.go +++ b/x/collection/client/cli/tx_test.go @@ -35,10 +35,10 @@ type CLITestSuite struct { clientCtx client.Context commonFlags []string - vendor testutil.TestAccount - operator testutil.TestAccount - customer testutil.TestAccount - stranger testutil.TestAccount + vendor string + operator string + customer string + stranger string contractID string classID string @@ -79,10 +79,10 @@ func (s *CLITestSuite) SetupSuite() { } val := testutil.CreateKeyringAccounts(s.T(), s.kr, 4) - s.vendor = val[0] - s.operator = val[1] - s.customer = val[2] - s.stranger = val[3] + s.vendor, _ = s.ac.BytesToString(val[0].Address) + s.operator, _ = s.ac.BytesToString(val[1].Address) + s.customer, _ = s.ac.BytesToString(val[2].Address) + s.stranger, _ = s.ac.BytesToString(val[3].Address) s.contractID = "678c146a" s.classID = "10000001" @@ -98,8 +98,8 @@ func (s *CLITestSuite) TestNewTxCmdSendNFT() { "valid transaction": { []string{ s.contractID, - s.vendor.Address.String(), - s.customer.Address.String(), + s.vendor, + s.customer, tokenID, }, true, @@ -107,8 +107,8 @@ func (s *CLITestSuite) TestNewTxCmdSendNFT() { "extra args": { []string{ s.contractID, - s.stranger.Address.String(), - s.customer.Address.String(), + s.stranger, + s.customer, tokenID, "extra", }, @@ -117,16 +117,16 @@ func (s *CLITestSuite) TestNewTxCmdSendNFT() { "not enough args": { []string{ s.contractID, - s.stranger.Address.String(), - s.customer.Address.String(), + s.stranger, + s.customer, }, false, }, "invalid contract id": { []string{ "", - s.stranger.Address.String(), - s.customer.Address.String(), + s.stranger, + s.customer, tokenID, }, false, @@ -160,9 +160,9 @@ func (s *CLITestSuite) TestNewTxCmdOperatorSendNFT() { "valid transaction": { []string{ s.contractID, - s.operator.Address.String(), - s.vendor.Address.String(), - s.customer.Address.String(), + s.operator, + s.vendor, + s.customer, tokenID, }, true, @@ -170,9 +170,9 @@ func (s *CLITestSuite) TestNewTxCmdOperatorSendNFT() { "extra args": { []string{ s.contractID, - s.operator.Address.String(), - s.vendor.Address.String(), - s.customer.Address.String(), + s.operator, + s.vendor, + s.customer, tokenID, "extra", }, @@ -181,18 +181,18 @@ func (s *CLITestSuite) TestNewTxCmdOperatorSendNFT() { "not enough args": { []string{ s.contractID, - s.operator.Address.String(), - s.vendor.Address.String(), - s.customer.Address.String(), + s.operator, + s.vendor, + s.customer, }, false, }, "invalid contract id": { []string{ "", - s.operator.Address.String(), - s.vendor.Address.String(), - s.customer.Address.String(), + s.operator, + s.vendor, + s.customer, tokenID, }, false, @@ -224,7 +224,7 @@ func (s *CLITestSuite) TestNewTxCmdCreateContract() { }{ "valid transaction": { []string{ - s.vendor.Address.String(), + s.vendor, fmt.Sprintf("--%s=%s", cli.FlagName, "arctic fox"), fmt.Sprintf("--%s=%s", cli.FlagMeta, "nft metadata"), fmt.Sprintf("--%s=%s", cli.FlagBaseImgURI, "contract base img uri"), @@ -233,7 +233,7 @@ func (s *CLITestSuite) TestNewTxCmdCreateContract() { }, "extra args": { []string{ - s.vendor.Address.String(), + s.vendor, "extra", }, false, @@ -276,14 +276,14 @@ func (s *CLITestSuite) TestNewTxCmdIssueNFT() { "valid transaction": { []string{ s.contractID, - s.vendor.Address.String(), + s.vendor, }, true, }, "extra args": { []string{ s.contractID, - s.vendor.Address.String(), + s.vendor, "extra", }, false, @@ -297,7 +297,7 @@ func (s *CLITestSuite) TestNewTxCmdIssueNFT() { "invalid contract id": { []string{ "", - s.vendor.Address.String(), + s.vendor, }, false, }, @@ -329,8 +329,8 @@ func (s *CLITestSuite) TestNewTxCmdMintNFT() { "valid transaction": { []string{ s.contractID, - s.vendor.Address.String(), - s.customer.Address.String(), + s.vendor, + s.customer, s.classID, fmt.Sprintf("--%s=%s", cli.FlagName, "arctic fox"), fmt.Sprintf("--%s=%s", cli.FlagMeta, "nft metadata"), @@ -340,8 +340,8 @@ func (s *CLITestSuite) TestNewTxCmdMintNFT() { "extra args": { []string{ s.contractID, - s.vendor.Address.String(), - s.customer.Address.String(), + s.vendor, + s.customer, s.classID, "extra", }, @@ -350,16 +350,16 @@ func (s *CLITestSuite) TestNewTxCmdMintNFT() { "not enough args": { []string{ s.contractID, - s.vendor.Address.String(), - s.customer.Address.String(), + s.vendor, + s.customer, }, false, }, "invalid contract id": { []string{ "", - s.vendor.Address.String(), - s.customer.Address.String(), + s.vendor, + s.customer, s.classID, }, false, @@ -393,7 +393,7 @@ func (s *CLITestSuite) TestNewTxCmdBurnNFT() { "valid transaction": { []string{ s.contractID, - s.customer.Address.String(), + s.customer, tokenID, }, true, @@ -401,7 +401,7 @@ func (s *CLITestSuite) TestNewTxCmdBurnNFT() { "extra args": { []string{ s.contractID, - s.customer.Address.String(), + s.customer, tokenID, "extra", }, @@ -410,14 +410,14 @@ func (s *CLITestSuite) TestNewTxCmdBurnNFT() { "not enough args": { []string{ s.contractID, - s.customer.Address.String(), + s.customer, }, false, }, "invalid contract id": { []string{ "", - s.customer.Address.String(), + s.customer, tokenID, }, false, @@ -451,8 +451,8 @@ func (s *CLITestSuite) TestNewTxCmdOperatorOperatorBurnNFT() { "valid transaction": { []string{ s.contractID, - s.operator.Address.String(), - s.customer.Address.String(), + s.operator, + s.customer, tokenID, }, true, @@ -460,8 +460,8 @@ func (s *CLITestSuite) TestNewTxCmdOperatorOperatorBurnNFT() { "extra args": { []string{ s.contractID, - s.operator.Address.String(), - s.customer.Address.String(), + s.operator, + s.customer, tokenID, "extra", }, @@ -470,16 +470,16 @@ func (s *CLITestSuite) TestNewTxCmdOperatorOperatorBurnNFT() { "not enough args": { []string{ s.contractID, - s.operator.Address.String(), - s.customer.Address.String(), + s.operator, + s.customer, }, false, }, "invalid contract id": { []string{ "", - s.operator.Address.String(), - s.customer.Address.String(), + s.operator, + s.customer, tokenID, }, false, @@ -512,7 +512,7 @@ func (s *CLITestSuite) TestNewTxCmdModify() { "valid transaction": { []string{ s.contractID, - s.operator.Address.String(), + s.operator, s.classID, s.tokenIdx, collection.AttributeKeyName.String(), @@ -523,7 +523,7 @@ func (s *CLITestSuite) TestNewTxCmdModify() { "extra args": { []string{ s.contractID, - s.operator.Address.String(), + s.operator, s.classID, s.tokenIdx, collection.AttributeKeyName.String(), @@ -535,7 +535,7 @@ func (s *CLITestSuite) TestNewTxCmdModify() { "not enough args": { []string{ s.contractID, - s.operator.Address.String(), + s.operator, s.classID, s.tokenIdx, collection.AttributeKeyName.String(), @@ -545,7 +545,7 @@ func (s *CLITestSuite) TestNewTxCmdModify() { "invalid contract id": { []string{ "", - s.operator.Address.String(), + s.operator, s.classID, s.tokenIdx, collection.AttributeKeyName.String(), @@ -581,8 +581,8 @@ func (s *CLITestSuite) TestNewTxCmdGrantPermission() { "valid transaction": { []string{ s.contractID, - s.operator.Address.String(), - s.vendor.Address.String(), + s.operator, + s.vendor, collection.LegacyPermissionMint.String(), }, true, @@ -590,8 +590,8 @@ func (s *CLITestSuite) TestNewTxCmdGrantPermission() { "extra args": { []string{ s.contractID, - s.operator.Address.String(), - s.vendor.Address.String(), + s.operator, + s.vendor, collection.LegacyPermissionMint.String(), "extra", }, @@ -600,8 +600,8 @@ func (s *CLITestSuite) TestNewTxCmdGrantPermission() { "not enough args": { []string{ s.contractID, - s.operator.Address.String(), - s.vendor.Address.String(), + s.operator, + s.vendor, }, false, }, @@ -633,7 +633,7 @@ func (s *CLITestSuite) TestNewTxCmdRevokePermission() { "valid transaction": { []string{ s.contractID, - s.vendor.Address.String(), + s.vendor, collection.LegacyPermissionModify.String(), }, true, @@ -641,7 +641,7 @@ func (s *CLITestSuite) TestNewTxCmdRevokePermission() { "extra args": { []string{ s.contractID, - s.vendor.Address.String(), + s.vendor, collection.LegacyPermissionModify.String(), "extra", }, @@ -650,7 +650,7 @@ func (s *CLITestSuite) TestNewTxCmdRevokePermission() { "not enough args": { []string{ s.contractID, - s.vendor.Address.String(), + s.vendor, }, false, }, @@ -682,16 +682,16 @@ func (s *CLITestSuite) TestNewTxCmdAuthorizeOperator() { "valid transaction": { []string{ s.contractID, - s.customer.Address.String(), - s.operator.Address.String(), + s.customer, + s.operator, }, true, }, "extra args": { []string{ s.contractID, - s.customer.Address.String(), - s.operator.Address.String(), + s.customer, + s.operator, "extra", }, false, @@ -699,7 +699,7 @@ func (s *CLITestSuite) TestNewTxCmdAuthorizeOperator() { "not enough args": { []string{ s.contractID, - s.customer.Address.String(), + s.customer, }, false, }, @@ -731,16 +731,16 @@ func (s *CLITestSuite) TestNewTxCmdRevokeOperator() { "valid transaction": { []string{ s.contractID, - s.customer.Address.String(), - s.operator.Address.String(), + s.customer, + s.operator, }, true, }, "extra args": { []string{ s.contractID, - s.customer.Address.String(), - s.operator.Address.String(), + s.customer, + s.operator, "extra", }, false, @@ -748,7 +748,7 @@ func (s *CLITestSuite) TestNewTxCmdRevokeOperator() { "not enough args": { []string{ s.contractID, - s.customer.Address.String(), + s.customer, }, false, }, diff --git a/x/collection/genesis_test.go b/x/collection/genesis_test.go index c65d92b308..94fee13b8a 100644 --- a/x/collection/genesis_test.go +++ b/x/collection/genesis_test.go @@ -9,15 +9,15 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" "github.com/Finschia/finschia-sdk/x/collection" ) func TestValidateGenesis(t *testing.T) { - addr := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - ac := authcodec.NewBech32Codec("cosmos") + ac := authcodec.NewBech32Codec("link") + addr, err := ac.BytesToString(secp256k1.GenPrivKey().PubKey().Address()) + require.NoError(t, err) testCases := map[string]struct { gs *collection.GenesisState valid bool @@ -147,7 +147,7 @@ func TestValidateGenesis(t *testing.T) { &collection.GenesisState{ Balances: []collection.ContractBalances{{ Balances: []collection.Balance{{ - Address: addr.String(), + Address: addr, Amount: collection.NewCoins(collection.NewNFTCoin("00bab10c", 1)), }}, }}, @@ -178,7 +178,7 @@ func TestValidateGenesis(t *testing.T) { Balances: []collection.ContractBalances{{ ContractId: "deadbeef", Balances: []collection.Balance{{ - Address: addr.String(), + Address: addr, }}, }}, }, @@ -246,8 +246,8 @@ func TestValidateGenesis(t *testing.T) { &collection.GenesisState{ Authorizations: []collection.ContractAuthorizations{{ Authorizations: []collection.Authorization{{ - Holder: addr.String(), - Operator: addr.String(), + Holder: addr, + Operator: addr, }}, }}, }, @@ -266,7 +266,7 @@ func TestValidateGenesis(t *testing.T) { Authorizations: []collection.ContractAuthorizations{{ ContractId: "deadbeef", Authorizations: []collection.Authorization{{ - Operator: addr.String(), + Operator: addr, }}, }}, }, @@ -277,7 +277,7 @@ func TestValidateGenesis(t *testing.T) { Authorizations: []collection.ContractAuthorizations{{ ContractId: "deadbeef", Authorizations: []collection.Authorization{{ - Holder: addr.String(), + Holder: addr, }}, }}, }, @@ -287,7 +287,7 @@ func TestValidateGenesis(t *testing.T) { &collection.GenesisState{ Grants: []collection.ContractGrants{{ Grants: []collection.Grant{{ - Grantee: addr.String(), + Grantee: addr, Permission: collection.PermissionMint, }}, }}, @@ -318,7 +318,7 @@ func TestValidateGenesis(t *testing.T) { Grants: []collection.ContractGrants{{ ContractId: "deadbeef", Grants: []collection.Grant{{ - Grantee: addr.String(), + Grantee: addr, }}, }}, }, diff --git a/x/collection/keeper/alias.go b/x/collection/keeper/alias.go index 59dc45cafd..7f97dad057 100644 --- a/x/collection/keeper/alias.go +++ b/x/collection/keeper/alias.go @@ -94,7 +94,7 @@ func (k Keeper) iterateGrantsImpl(ctx sdk.Context, prefix []byte, fn func(contra for ; iterator.Valid(); iterator.Next() { contractID, grantee, permission := splitGrantKey(iterator.Key()) grant := collection.Grant{ - Grantee: grantee.String(), + Grantee: k.bytesToString(grantee), Permission: permission, } @@ -118,8 +118,8 @@ func (k Keeper) iterateAuthorizationsImpl(ctx sdk.Context, prefix []byte, fn fun for ; iterator.Valid(); iterator.Next() { contractID, operator, holder := splitAuthorizationKey(iterator.Key()) authorization := collection.Authorization{ - Holder: holder.String(), - Operator: operator.String(), + Holder: k.bytesToString(holder), + Operator: k.bytesToString(operator), } stop := fn(contractID, authorization) @@ -243,3 +243,11 @@ func (k Keeper) iterateClassStoreIDs(ctx sdk.Context, fn func(id string) (stop b } } } + +func (k Keeper) bytesToString(addressBytes []byte) string { + addr, err := k.addressCodec.BytesToString(addressBytes) + if err != nil { + panic(err) + } + return addr +} diff --git a/x/collection/keeper/genesis.go b/x/collection/keeper/genesis.go index ea1c859b69..ab494b1ce4 100644 --- a/x/collection/keeper/genesis.go +++ b/x/collection/keeper/genesis.go @@ -300,18 +300,18 @@ func (k Keeper) getContractBalances(ctx sdk.Context, contractID string) []collec addressToBalanceIndex := make(map[string]int) k.iterateContractBalances(ctx, contractID, func(address sdk.AccAddress, balance collection.Coin) (stop bool) { - index, ok := addressToBalanceIndex[address.String()] + index, ok := addressToBalanceIndex[k.bytesToString(address)] if ok { balances[index].Amount = append(balances[index].Amount, balance) return false } accountBalance := collection.Balance{ - Address: address.String(), + Address: k.bytesToString(address), Amount: collection.Coins{balance}, } balances = append(balances, accountBalance) - addressToBalanceIndex[address.String()] = len(balances) - 1 + addressToBalanceIndex[k.bytesToString(address)] = len(balances) - 1 return false }) diff --git a/x/collection/keeper/grpc_query.go b/x/collection/keeper/grpc_query.go index 042e24f32e..635c2cb067 100644 --- a/x/collection/keeper/grpc_query.go +++ b/x/collection/keeper/grpc_query.go @@ -290,7 +290,7 @@ func (s queryServer) getToken(ctx sdk.Context, contractID, tokenID string) (coll TokenId: token.TokenId, Name: token.Name, Meta: token.Meta, - Owner: owner.String(), + Owner: s.keeper.bytesToString(owner), }, nil default: panic("cannot reach here: token must be nft") @@ -404,7 +404,7 @@ func (s queryServer) HoldersByOperator(c context.Context, req *collection.QueryH var holders []string pageRes, err := query.Paginate(authorizationStore, req.Pagination, func(key, value []byte) error { holder := sdk.AccAddress(key) - holders = append(holders, holder.String()) + holders = append(holders, s.keeper.bytesToString(holder)) return nil }) if err != nil { diff --git a/x/collection/keeper/grpc_query_test.go b/x/collection/keeper/grpc_query_test.go index 7f952ce3a4..f3f233e5d4 100644 --- a/x/collection/keeper/grpc_query_test.go +++ b/x/collection/keeper/grpc_query_test.go @@ -18,7 +18,7 @@ func (s *KeeperTestSuite) TestQueryBalance() { _, err := s.queryServer.Balance(s.ctx, nil) s.Require().Error(err) - tokenID := s.issuedNFTs[s.customer.String()][0].TokenId + tokenID := s.issuedNFTs[s.bytesToString(s.customer)][0].TokenId testCases := map[string]struct { contractID string address sdk.AccAddress @@ -71,7 +71,7 @@ func (s *KeeperTestSuite) TestQueryBalance() { s.Run(name, func() { req := &collection.QueryBalanceRequest{ ContractId: tc.contractID, - Address: tc.address.String(), + Address: s.bytesToString(tc.address), TokenId: tc.tokenID, } res, err := s.queryServer.Balance(s.ctx, req) @@ -131,7 +131,7 @@ func (s *KeeperTestSuite) TestQueryAllBalances() { } req := &collection.QueryAllBalancesRequest{ ContractId: tc.contractID, - Address: tc.address.String(), + Address: s.bytesToString(tc.address), Pagination: pageReq, } res, err := s.queryServer.AllBalances(s.ctx, req) @@ -574,7 +574,7 @@ func (s *KeeperTestSuite) TestQueryGranteeGrants() { s.Run(name, func() { req := &collection.QueryGranteeGrantsRequest{ ContractId: tc.contractID, - Grantee: tc.grantee.String(), + Grantee: s.bytesToString(tc.grantee), } res, err := s.queryServer.GranteeGrants(s.ctx, req) if !tc.valid { @@ -636,8 +636,8 @@ func (s *KeeperTestSuite) TestQueryIsOperatorFor() { s.Run(name, func() { req := &collection.QueryIsOperatorForRequest{ ContractId: tc.contractID, - Operator: tc.operator.String(), - Holder: tc.holder.String(), + Operator: s.bytesToString(tc.operator), + Holder: s.bytesToString(tc.holder), } res, err := s.queryServer.IsOperatorFor(s.ctx, req) if !tc.valid { @@ -704,7 +704,7 @@ func (s *KeeperTestSuite) TestQueryHoldersByOperator() { } req := &collection.QueryHoldersByOperatorRequest{ ContractId: tc.contractID, - Operator: tc.operator.String(), + Operator: s.bytesToString(tc.operator), Pagination: pageReq, } res, err := s.queryServer.HoldersByOperator(s.ctx, req) diff --git a/x/collection/keeper/keeper_test.go b/x/collection/keeper/keeper_test.go index a60d5ba89d..38791ca26b 100644 --- a/x/collection/keeper/keeper_test.go +++ b/x/collection/keeper/keeper_test.go @@ -56,8 +56,8 @@ func (s *KeeperTestSuite) createRandomAccounts(accNum int) []sdk.AccAddress { for { pk := secp256k1.GenPrivKey().PubKey() addr = sdk.AccAddress(pk.Address()) - if !seenAddresses[addr.String()] { - seenAddresses[addr.String()] = true + if !seenAddresses[s.bytesToString(addr)] { + seenAddresses[s.bytesToString(addr)] = true break } } @@ -102,7 +102,7 @@ func (s *KeeperTestSuite) SetupTest() { s.issuedNFTs = make(map[string][]collection.NFT) for _, to := range []sdk.AccAddress{s.customer, s.operator, s.vendor} { nfts, err := s.keeper.MintNFT(s.ctx, s.contractID, to, newParams(s.nftClassID, s.numNFTs)) - s.issuedNFTs[to.String()] = nfts + s.issuedNFTs[s.bytesToString(to)] = nfts s.Require().NoError(err) } @@ -168,6 +168,12 @@ func (s *KeeperTestSuite) prepareInitialSetup() { } } +func (s *KeeperTestSuite) bytesToString(address []byte) string { + addr, err := s.addressCodec.BytesToString(address) + s.Require().NoError(err) + return addr +} + func TestKeeperTestSuite(t *testing.T) { suite.Run(t, new(KeeperTestSuite)) } diff --git a/x/collection/keeper/msg_server_test.go b/x/collection/keeper/msg_server_test.go index b7b9802f4a..72a6f4760e 100644 --- a/x/collection/keeper/msg_server_test.go +++ b/x/collection/keeper/msg_server_test.go @@ -41,25 +41,25 @@ func (s *KeeperTestSuite) TestMsgSendNFT() { testCases := map[string]struct { contractID string tokenID string - from string - to string + from sdk.AccAddress + to sdk.AccAddress err error events sdk.Events }{ "valid request": { contractID: s.contractID, tokenID: rootNFTID, - from: s.customer.String(), - to: s.vendor.String(), + from: s.customer, + to: s.vendor, events: sdk.Events{ sdk.Event{ Type: "lbm.collection.v1.EventSent", Attributes: []abci.EventAttribute{ {Key: "amount", Value: mustJSONMarshal(collection.NewCoins(collection.Coin{TokenId: rootNFTID, Amount: math.OneInt()})), Index: false}, {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "from", Value: w(s.customer.String()), Index: false}, - {Key: "operator", Value: w(s.customer.String()), Index: false}, - {Key: "to", Value: w(s.vendor.String()), Index: false}, + {Key: "from", Value: w(s.bytesToString(s.customer)), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.customer)), Index: false}, + {Key: "to", Value: w(s.bytesToString(s.vendor)), Index: false}, }, }, }, @@ -67,53 +67,53 @@ func (s *KeeperTestSuite) TestMsgSendNFT() { "contract not found": { contractID: "deadbeef", tokenID: collection.NewNFTID(s.nftClassID, 1), - from: s.customer.String(), - to: s.vendor.String(), + from: s.customer, + to: s.vendor, err: collection.ErrContractNotExist, }, "NFT not found": { contractID: s.contractID, tokenID: collection.NewNFTID("deadbeef", 1), - from: s.customer.String(), - to: s.vendor.String(), + from: s.customer, + to: s.vendor, err: collection.ErrTokenNotExist, }, "not owned by": { contractID: s.contractID, tokenID: collection.NewNFTID(s.nftClassID, s.numNFTs+1), - from: s.customer.String(), - to: s.vendor.String(), + from: s.customer, + to: s.vendor, err: collection.ErrTokenNotOwnedBy, }, "invalid from": { contractID: s.contractID, tokenID: rootNFTID, - to: s.vendor.String(), + to: s.vendor, err: sdkerrors.ErrInvalidAddress, }, "invalid contract id": { tokenID: rootNFTID, - from: s.customer.String(), - to: s.vendor.String(), + from: s.customer, + to: s.vendor, err: collection.ErrInvalidContractID, }, "invalid to": { contractID: s.contractID, tokenID: rootNFTID, - from: s.customer.String(), + from: s.customer, err: sdkerrors.ErrInvalidAddress, }, "empty token ids": { contractID: s.contractID, - from: s.customer.String(), - to: s.vendor.String(), + from: s.customer, + to: s.vendor, err: collection.ErrEmptyField, }, "invalid token ids": { contractID: s.contractID, tokenID: "null", - from: s.customer.String(), - to: s.vendor.String(), + from: s.customer, + to: s.vendor, err: collection.ErrInvalidTokenID, }, } @@ -126,14 +126,14 @@ func (s *KeeperTestSuite) TestMsgSendNFT() { if tc.tokenID == "" { req = &collection.MsgSendNFT{ ContractId: tc.contractID, - From: tc.from, - To: tc.to, + From: s.bytesToString(tc.from), + To: s.bytesToString(tc.to), } } else { req = &collection.MsgSendNFT{ ContractId: tc.contractID, - From: tc.from, - To: tc.to, + From: s.bytesToString(tc.from), + To: s.bytesToString(tc.to), TokenIds: []string{tc.tokenID}, } } @@ -154,18 +154,18 @@ func (s *KeeperTestSuite) TestMsgOperatorSendNFT() { testCases := map[string]struct { contractID string - operator string - from string - to string + operator sdk.AccAddress + from sdk.AccAddress + to sdk.AccAddress tokenID string err error events sdk.Events }{ "valid request": { contractID: s.contractID, - operator: s.operator.String(), - from: s.customer.String(), - to: s.vendor.String(), + operator: s.operator, + from: s.customer, + to: s.vendor, tokenID: rootNFTID, events: sdk.Events{ sdk.Event{ @@ -173,85 +173,85 @@ func (s *KeeperTestSuite) TestMsgOperatorSendNFT() { Attributes: []abci.EventAttribute{ {Key: "amount", Value: mustJSONMarshal(collection.NewCoins(collection.Coin{TokenId: rootNFTID, Amount: math.OneInt()})), Index: false}, {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "from", Value: w(s.customer.String()), Index: false}, - {Key: "operator", Value: w(s.operator.String()), Index: false}, - {Key: "to", Value: w(s.vendor.String()), Index: false}, + {Key: "from", Value: w(s.bytesToString(s.customer)), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.operator)), Index: false}, + {Key: "to", Value: w(s.bytesToString(s.vendor)), Index: false}, }, }, }, }, "contract not found": { contractID: "deadbeef", - operator: s.operator.String(), - from: s.customer.String(), - to: s.vendor.String(), + operator: s.operator, + from: s.customer, + to: s.vendor, tokenID: rootNFTID, err: collection.ErrContractNotExist, }, "not approved": { contractID: s.contractID, - operator: s.vendor.String(), - from: s.customer.String(), - to: s.vendor.String(), + operator: s.vendor, + from: s.customer, + to: s.vendor, tokenID: rootNFTID, err: collection.ErrCollectionNotApproved, }, "NFT not found": { contractID: s.contractID, - operator: s.operator.String(), - from: s.customer.String(), - to: s.vendor.String(), + operator: s.operator, + from: s.customer, + to: s.vendor, tokenID: collection.NewNFTID("deadbeef", 1), err: collection.ErrTokenNotExist, }, "not owned by": { contractID: s.contractID, - operator: s.operator.String(), - from: s.customer.String(), - to: s.vendor.String(), + operator: s.operator, + from: s.customer, + to: s.vendor, tokenID: collection.NewNFTID(s.nftClassID, s.numNFTs+1), err: collection.ErrTokenNotOwnedBy, }, "invalid operator": { contractID: s.contractID, - from: s.customer.String(), - to: s.vendor.String(), + from: s.customer, + to: s.vendor, tokenID: rootNFTID, err: sdkerrors.ErrInvalidAddress, }, "invalid contract id": { - operator: s.operator.String(), - from: s.customer.String(), - to: s.vendor.String(), + operator: s.operator, + from: s.customer, + to: s.vendor, tokenID: rootNFTID, err: collection.ErrInvalidContractID, }, "invalid from": { contractID: s.contractID, - operator: s.operator.String(), - to: s.vendor.String(), + operator: s.operator, + to: s.vendor, tokenID: rootNFTID, err: sdkerrors.ErrInvalidAddress, }, "invalid to": { contractID: s.contractID, - operator: s.operator.String(), - from: s.customer.String(), + operator: s.operator, + from: s.customer, tokenID: rootNFTID, err: sdkerrors.ErrInvalidAddress, }, "empty ids": { contractID: s.contractID, - operator: s.operator.String(), - from: s.customer.String(), - to: s.vendor.String(), + operator: s.operator, + from: s.customer, + to: s.vendor, err: collection.ErrEmptyField, }, "invalid id": { contractID: s.contractID, - operator: s.operator.String(), - from: s.customer.String(), - to: s.vendor.String(), + operator: s.operator, + from: s.customer, + to: s.vendor, tokenID: "null", err: collection.ErrInvalidTokenID, }, @@ -265,16 +265,16 @@ func (s *KeeperTestSuite) TestMsgOperatorSendNFT() { if tc.tokenID == "" { req = &collection.MsgOperatorSendNFT{ ContractId: tc.contractID, - Operator: tc.operator, - From: tc.from, - To: tc.to, + Operator: s.bytesToString(tc.operator), + From: s.bytesToString(tc.from), + To: s.bytesToString(tc.to), } } else { req = &collection.MsgOperatorSendNFT{ ContractId: tc.contractID, - Operator: tc.operator, - From: tc.from, - To: tc.to, + Operator: s.bytesToString(tc.operator), + From: s.bytesToString(tc.from), + To: s.bytesToString(tc.to), TokenIds: []string{tc.tokenID}, } } @@ -306,8 +306,8 @@ func (s *KeeperTestSuite) TestMsgAuthorizeOperator() { Type: "lbm.collection.v1.EventAuthorizedOperator", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "holder", Value: w(s.customer.String()), Index: false}, - {Key: "operator", Value: w(s.vendor.String()), Index: false}, + {Key: "holder", Value: w(s.bytesToString(s.customer)), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.vendor)), Index: false}, }, }}, }, @@ -349,8 +349,8 @@ func (s *KeeperTestSuite) TestMsgAuthorizeOperator() { // Act req := &collection.MsgAuthorizeOperator{ ContractId: tc.contractID, - Holder: tc.holder.String(), - Operator: tc.operator.String(), + Holder: s.bytesToString(tc.holder), + Operator: s.bytesToString(tc.operator), } res, err := s.msgServer.AuthorizeOperator(ctx, req) if tc.err != nil { @@ -389,8 +389,8 @@ func (s *KeeperTestSuite) TestMsgRevokeOperator() { Type: "lbm.collection.v1.EventRevokedOperator", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "holder", Value: w(s.customer.String()), Index: false}, - {Key: "operator", Value: w(s.operator.String()), Index: false}, + {Key: "holder", Value: w(s.bytesToString(s.customer)), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.operator)), Index: false}, }, }}, }, @@ -432,8 +432,8 @@ func (s *KeeperTestSuite) TestMsgRevokeOperator() { // Act req := &collection.MsgRevokeOperator{ ContractId: tc.contractID, - Holder: tc.holder.String(), - Operator: tc.operator.String(), + Holder: s.bytesToString(tc.holder), + Operator: s.bytesToString(tc.operator), } res, err := s.msgServer.RevokeOperator(ctx, req) if tc.err != nil { @@ -445,12 +445,8 @@ func (s *KeeperTestSuite) TestMsgRevokeOperator() { s.Require().Equal(tc.events, ctx.EventManager().Events()) s.Require().NotNil(prevAuth) - h, err := s.addressCodec.BytesToString(tc.holder.Bytes()) - s.Require().NoError(err) - s.Require().Equal(h, prevAuth.Holder) - o, err := s.addressCodec.BytesToString(tc.operator.Bytes()) - s.Require().NoError(err) - s.Require().Equal(o, prevAuth.Operator) + s.Require().Equal(s.bytesToString(tc.holder), prevAuth.Holder) + s.Require().Equal(s.bytesToString(tc.operator), prevAuth.Operator) curAuth, err := s.keeper.GetAuthorization(ctx, tc.contractID, tc.holder, tc.operator) s.Require().ErrorIs(err, collection.ErrCollectionNotApproved) s.Require().Nil(curAuth) @@ -475,7 +471,7 @@ func (s *KeeperTestSuite) TestMsgCreateContract() { Type: "lbm.collection.v1.EventCreatedContract", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(expectedNewContractID), Index: false}, - {Key: "creator", Value: w(s.vendor.String()), Index: false}, + {Key: "creator", Value: w(s.bytesToString(s.vendor)), Index: false}, {Key: "meta", Value: w(""), Index: false}, {Key: "name", Value: w(""), Index: false}, {Key: "uri", Value: w(""), Index: false}, @@ -485,7 +481,7 @@ func (s *KeeperTestSuite) TestMsgCreateContract() { Type: "lbm.collection.v1.EventGranted", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(expectedNewContractID), Index: false}, - {Key: "grantee", Value: w(s.vendor.String()), Index: false}, + {Key: "grantee", Value: w(s.bytesToString(s.vendor)), Index: false}, {Key: "granter", Value: w(""), Index: false}, {Key: "permission", Value: w(collection.Permission(collection.LegacyPermissionIssue).String()), Index: false}, }, @@ -494,7 +490,7 @@ func (s *KeeperTestSuite) TestMsgCreateContract() { Type: "lbm.collection.v1.EventGranted", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(expectedNewContractID), Index: false}, - {Key: "grantee", Value: w(s.vendor.String()), Index: false}, + {Key: "grantee", Value: w(s.bytesToString(s.vendor)), Index: false}, {Key: "granter", Value: w(""), Index: false}, {Key: "permission", Value: w(collection.Permission(collection.LegacyPermissionModify).String()), Index: false}, }, @@ -503,7 +499,7 @@ func (s *KeeperTestSuite) TestMsgCreateContract() { Type: "lbm.collection.v1.EventGranted", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(expectedNewContractID), Index: false}, - {Key: "grantee", Value: w(s.vendor.String()), Index: false}, + {Key: "grantee", Value: w(s.bytesToString(s.vendor)), Index: false}, {Key: "granter", Value: w(""), Index: false}, {Key: "permission", Value: w(collection.Permission(collection.LegacyPermissionMint).String()), Index: false}, }, @@ -512,7 +508,7 @@ func (s *KeeperTestSuite) TestMsgCreateContract() { Type: "lbm.collection.v1.EventGranted", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(expectedNewContractID), Index: false}, - {Key: "grantee", Value: w(s.vendor.String()), Index: false}, + {Key: "grantee", Value: w(s.bytesToString(s.vendor)), Index: false}, {Key: "granter", Value: w(""), Index: false}, {Key: "permission", Value: w(collection.Permission(collection.LegacyPermissionBurn).String()), Index: false}, }, @@ -553,7 +549,7 @@ func (s *KeeperTestSuite) TestMsgCreateContract() { ctx, _ := s.ctx.CacheContext() req := &collection.MsgCreateContract{ - Owner: tc.owner.String(), + Owner: s.bytesToString(tc.owner), Name: tc.name, Uri: tc.uri, Meta: tc.meta, @@ -592,7 +588,7 @@ func (s *KeeperTestSuite) TestMsgIssueNFT() { {Key: "contract_id", Value: w(s.contractID), Index: false}, {Key: "meta", Value: w(""), Index: false}, {Key: "name", Value: w(""), Index: false}, - {Key: "operator", Value: w(s.vendor.String()), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.vendor)), Index: false}, {Key: "token_type", Value: w(expectedTokenType), Index: false}, }, }, @@ -600,7 +596,7 @@ func (s *KeeperTestSuite) TestMsgIssueNFT() { Type: "lbm.collection.v1.EventGranted", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "grantee", Value: w(s.vendor.String()), Index: false}, + {Key: "grantee", Value: w(s.bytesToString(s.vendor)), Index: false}, {Key: "granter", Value: w(""), Index: false}, {Key: "permission", Value: w(collection.Permission(collection.LegacyPermissionMint).String()), Index: false}, }, @@ -609,7 +605,7 @@ func (s *KeeperTestSuite) TestMsgIssueNFT() { Type: "lbm.collection.v1.EventGranted", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "grantee", Value: w(s.vendor.String()), Index: false}, + {Key: "grantee", Value: w(s.bytesToString(s.vendor)), Index: false}, {Key: "granter", Value: w(""), Index: false}, {Key: "permission", Value: w(collection.Permission(collection.LegacyPermissionBurn).String()), Index: false}, }, @@ -660,7 +656,7 @@ func (s *KeeperTestSuite) TestMsgIssueNFT() { req := &collection.MsgIssueNFT{ ContractId: tc.contractID, - Owner: tc.owner.String(), + Owner: s.bytesToString(tc.owner), Name: tc.name, Meta: tc.meta, } @@ -708,8 +704,8 @@ func (s *KeeperTestSuite) TestMsgMintNFT() { Type: "lbm.collection.v1.EventMintedNFT", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "operator", Value: w(s.vendor.String()), Index: false}, - {Key: "to", Value: w(s.customer.String()), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.vendor)), Index: false}, + {Key: "to", Value: w(s.bytesToString(s.customer)), Index: false}, {Key: "tokens", Value: mustJSONMarshal(expectedTokens), Index: false}, }, }, @@ -810,8 +806,8 @@ func (s *KeeperTestSuite) TestMsgMintNFT() { req := &collection.MsgMintNFT{ ContractId: tc.contractID, - From: tc.from.String(), - To: tc.to.String(), + From: s.bytesToString(tc.from), + To: s.bytesToString(tc.to), Params: tc.params, } res, err := s.msgServer.MintNFT(ctx, req) @@ -847,8 +843,8 @@ func (s *KeeperTestSuite) TestMsgBurnNFT() { Attributes: []abci.EventAttribute{ {Key: "amount", Value: mustJSONMarshal(coins), Index: false}, {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "from", Value: w(s.vendor.String()), Index: false}, - {Key: "operator", Value: w(s.vendor.String()), Index: false}, + {Key: "from", Value: w(s.bytesToString(s.vendor)), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.vendor)), Index: false}, }, }, }, @@ -910,7 +906,7 @@ func (s *KeeperTestSuite) TestMsgBurnNFT() { req := &collection.MsgBurnNFT{ ContractId: tc.contractID, - From: tc.from.String(), + From: s.bytesToString(tc.from), TokenIds: tc.tokenIDs, } res, err := s.msgServer.BurnNFT(ctx, req) @@ -948,8 +944,8 @@ func (s *KeeperTestSuite) TestMsgOperatorBurnNFT() { Attributes: []abci.EventAttribute{ {Key: "amount", Value: mustJSONMarshal(coins), Index: false}, {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "from", Value: w(s.customer.String()), Index: false}, - {Key: "operator", Value: w(s.operator.String()), Index: false}, + {Key: "from", Value: w(s.bytesToString(s.customer)), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.operator)), Index: false}, }, }, }, @@ -1032,8 +1028,8 @@ func (s *KeeperTestSuite) TestMsgOperatorBurnNFT() { req := &collection.MsgOperatorBurnNFT{ ContractId: tc.contractID, - Operator: tc.operator.String(), - From: tc.from.String(), + Operator: s.bytesToString(tc.operator), + From: s.bytesToString(tc.from), TokenIds: tc.tokenIDs, } res, err := s.msgServer.OperatorBurnNFT(ctx, req) @@ -1074,7 +1070,7 @@ func (s *KeeperTestSuite) TestMsgModify() { Attributes: []abci.EventAttribute{ {Key: "changes", Value: mustJSONMarshal(validChanges), Index: false}, {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "operator", Value: w(s.vendor.String()), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.vendor)), Index: false}, }, }, }, @@ -1090,7 +1086,7 @@ func (s *KeeperTestSuite) TestMsgModify() { Attributes: []abci.EventAttribute{ {Key: "changes", Value: mustJSONMarshal(validChanges), Index: false}, {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "operator", Value: w(s.vendor.String()), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.vendor)), Index: false}, {Key: "token_type", Value: w(s.nftClassID), Index: false}, {Key: "type_name", Value: w(proto.MessageName(&collection.NFTClass{})), Index: false}, }, @@ -1101,7 +1097,7 @@ func (s *KeeperTestSuite) TestMsgModify() { contractID: s.contractID, operator: s.vendor, tokenType: s.nftClassID, - tokenIndex: s.issuedNFTs[s.vendor.String()][0].TokenId[8:], + tokenIndex: s.issuedNFTs[s.bytesToString(s.vendor)][0].TokenId[8:], changes: validChanges, events: sdk.Events{ sdk.Event{ @@ -1109,8 +1105,8 @@ func (s *KeeperTestSuite) TestMsgModify() { Attributes: []abci.EventAttribute{ {Key: "changes", Value: mustJSONMarshal(validChanges), Index: false}, {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "operator", Value: w(s.vendor.String()), Index: false}, - {Key: "token_id", Value: w(s.issuedNFTs[s.vendor.String()][0].TokenId), Index: false}, + {Key: "operator", Value: w(s.bytesToString(s.vendor)), Index: false}, + {Key: "token_id", Value: w(s.issuedNFTs[s.bytesToString(s.vendor)][0].TokenId), Index: false}, }, }, }, @@ -1193,7 +1189,7 @@ func (s *KeeperTestSuite) TestMsgModify() { ctx, _ := s.ctx.CacheContext() req := &collection.MsgModify{ ContractId: tc.contractID, - Owner: tc.operator.String(), + Owner: s.bytesToString(tc.operator), TokenType: tc.tokenType, TokenIndex: tc.tokenIndex, Changes: tc.changes, @@ -1229,8 +1225,8 @@ func (s *KeeperTestSuite) TestMsgGrantPermission() { Type: "lbm.collection.v1.EventGranted", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "grantee", Value: w(s.operator.String()), Index: false}, - {Key: "granter", Value: w(s.vendor.String()), Index: false}, + {Key: "grantee", Value: w(s.bytesToString(s.operator)), Index: false}, + {Key: "granter", Value: w(s.bytesToString(s.vendor)), Index: false}, {Key: "permission", Value: w(collection.Permission(collection.LegacyPermissionModify).String()), Index: false}, }, }, @@ -1282,8 +1278,8 @@ func (s *KeeperTestSuite) TestMsgGrantPermission() { req := &collection.MsgGrantPermission{ ContractId: tc.contractID, - From: tc.granter.String(), - To: tc.grantee.String(), + From: s.bytesToString(tc.granter), + To: s.bytesToString(tc.grantee), Permission: tc.permission, } res, err := s.msgServer.GrantPermission(ctx, req) @@ -1315,7 +1311,7 @@ func (s *KeeperTestSuite) TestMsgRevokePermission() { Type: "lbm.collection.v1.EventRenounced", Attributes: []abci.EventAttribute{ {Key: "contract_id", Value: w(s.contractID), Index: false}, - {Key: "grantee", Value: w(s.operator.String()), Index: false}, + {Key: "grantee", Value: w(s.bytesToString(s.operator)), Index: false}, {Key: "permission", Value: w(collection.Permission(collection.LegacyPermissionMint).String()), Index: false}, }, }, @@ -1356,7 +1352,7 @@ func (s *KeeperTestSuite) TestMsgRevokePermission() { req := &collection.MsgRevokePermission{ ContractId: tc.contractID, - From: tc.from.String(), + From: s.bytesToString(tc.from), Permission: tc.permission, } res, err := s.msgServer.RevokePermission(ctx, req) diff --git a/x/collection/keeper/send.go b/x/collection/keeper/send.go index d6282316b0..0ab7125725 100644 --- a/x/collection/keeper/send.go +++ b/x/collection/keeper/send.go @@ -102,8 +102,8 @@ func (k Keeper) GetAuthorization(ctx sdk.Context, contractID string, holder, ope store := k.storeService.OpenKVStore(ctx) if ok, _ := store.Has(authorizationKey(contractID, operator, holder)); ok { return &collection.Authorization{ - Holder: holder.String(), - Operator: operator.String(), + Holder: k.bytesToString(holder), + Operator: k.bytesToString(operator), }, nil } return nil, collection.ErrCollectionNotApproved.Wrapf("no authorization by %s to %s", holder, operator) diff --git a/x/collection/keeper/send_test.go b/x/collection/keeper/send_test.go index 739a0dd86b..16b01912ee 100644 --- a/x/collection/keeper/send_test.go +++ b/x/collection/keeper/send_test.go @@ -44,9 +44,9 @@ func (s *KeeperTestSuite) TestSendCoins() { func (s *KeeperTestSuite) TestAuthorizeOperator() { userDescriptions := map[string]string{ - s.vendor.String(): "vendor", - s.operator.String(): "operator", - s.customer.String(): "customer", + s.bytesToString(s.vendor): "vendor", + s.bytesToString(s.operator): "operator", + s.bytesToString(s.customer): "customer", } for operator, operatorDesc := range userDescriptions { for from, fromDesc := range userDescriptions { @@ -76,9 +76,9 @@ func (s *KeeperTestSuite) TestAuthorizeOperator() { func (s *KeeperTestSuite) TestRevokeOperator() { userDescriptions := map[string]string{ - s.vendor.String(): "vendor", - s.operator.String(): "operator", - s.customer.String(): "customer", + s.bytesToString(s.vendor): "vendor", + s.bytesToString(s.operator): "operator", + s.bytesToString(s.customer): "customer", } for operator, operatorDesc := range userDescriptions { for from, fromDesc := range userDescriptions { diff --git a/x/collection/keeper/supply.go b/x/collection/keeper/supply.go index 070636185f..e9f1cf9f3a 100644 --- a/x/collection/keeper/supply.go +++ b/x/collection/keeper/supply.go @@ -13,7 +13,7 @@ func (k Keeper) CreateContract(ctx sdk.Context, creator sdk.AccAddress, contract contractID := k.createContract(ctx, contract) event := collection.EventCreatedContract{ - Creator: creator.String(), + Creator: k.bytesToString(creator), ContractId: contractID, Name: contract.Name, Meta: contract.Meta, @@ -333,8 +333,8 @@ func (k Keeper) Grant(ctx sdk.Context, contractID string, granter, grantee sdk.A event := collection.EventGranted{ ContractId: contractID, - Granter: granter.String(), - Grantee: grantee.String(), + Granter: k.bytesToString(granter), + Grantee: k.bytesToString(grantee), Permission: permission, } if err := ctx.EventManager().EmitTypedEvent(&event); err != nil { @@ -351,7 +351,7 @@ func (k Keeper) Abandon(ctx sdk.Context, contractID string, grantee sdk.AccAddre event := collection.EventRenounced{ ContractId: contractID, - Grantee: grantee.String(), + Grantee: k.bytesToString(grantee), Permission: permission, } if err := ctx.EventManager().EmitTypedEvent(&event); err != nil { @@ -363,7 +363,7 @@ func (k Keeper) GetGrant(ctx sdk.Context, contractID string, grantee sdk.AccAddr store := k.storeService.OpenKVStore(ctx) if ok, _ := store.Has(grantKey(contractID, grantee, permission)); ok { return &collection.Grant{ - Grantee: grantee.String(), + Grantee: k.bytesToString(grantee), Permission: permission, }, nil } diff --git a/x/collection/keeper/supply_test.go b/x/collection/keeper/supply_test.go index ad7dcb0249..bd48dd26e5 100644 --- a/x/collection/keeper/supply_test.go +++ b/x/collection/keeper/supply_test.go @@ -109,7 +109,7 @@ func (s *KeeperTestSuite) TestMintNFT() { } func (s *KeeperTestSuite) TestBurnCoins() { - targetTokenID := s.issuedNFTs[s.customer.String()][0].TokenId + targetTokenID := s.issuedNFTs[s.bytesToString(s.customer)][0].TokenId testCases := map[string]struct { contractID string amount collection.Coin diff --git a/x/collection/msgs_test.go b/x/collection/msgs_test.go index eeb6bdb9e1..cd64df459f 100644 --- a/x/collection/msgs_test.go +++ b/x/collection/msgs_test.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" + authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/Finschia/finschia-sdk/x/collection" @@ -19,10 +20,13 @@ func TestAminoJSON(t *testing.T) { legacyAmino := codec.NewLegacyAmino() collection.RegisterLegacyAminoCodec(legacyAmino) legacytx.RegressionTestingAminoCodec = legacyAmino + ac := authcodec.NewBech32Codec("link") - addrs := make([]sdk.AccAddress, 3) + addrs := make([]string, 3) for i := range addrs { - addrs[i] = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) + addr, err := ac.BytesToString(secp256k1.GenPrivKey().PubKey().Address()) + require.NoError(t, err) + addrs[i] = addr } tokenIds := []string{collection.NewNFTID(contractID, 1)} @@ -41,120 +45,120 @@ func TestAminoJSON(t *testing.T) { "MsgSendNFT": { &collection.MsgSendNFT{ ContractId: contractID, - From: addrs[0].String(), - To: addrs[1].String(), + From: addrs[0], + To: addrs[1], TokenIds: tokenIds, }, "/lbm.collection.v1.MsgSendNFT", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgSendNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"to\":\"%s\",\"token_ids\":[\"deadbeef00000001\"]}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String(), addrs[1].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgSendNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"to\":\"%s\",\"token_ids\":[\"deadbeef00000001\"]}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0], addrs[1]), }, "MsgOperatorSendNFT": { &collection.MsgOperatorSendNFT{ ContractId: contractID, - Operator: addrs[0].String(), - From: addrs[1].String(), - To: addrs[2].String(), + Operator: addrs[0], + From: addrs[1], + To: addrs[2], TokenIds: tokenIds, }, "/lbm.collection.v1.MsgOperatorSendNFT", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgOperatorSendNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"operator\":\"%s\",\"to\":\"%s\",\"token_ids\":[\"deadbeef00000001\"]}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[1].String(), addrs[0].String(), addrs[2].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgOperatorSendNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"operator\":\"%s\",\"to\":\"%s\",\"token_ids\":[\"deadbeef00000001\"]}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[1], addrs[0], addrs[2]), }, "MsgAuthorizeOperator": { &collection.MsgAuthorizeOperator{ ContractId: contractID, - Holder: addrs[0].String(), - Operator: addrs[1].String(), + Holder: addrs[0], + Operator: addrs[1], }, "/lbm.collection.v1.MsgAuthorizeOperator", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/collection/MsgAuthorizeOperator\",\"value\":{\"contract_id\":\"deadbeef\",\"holder\":\"%s\",\"operator\":\"%s\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String(), addrs[1].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/collection/MsgAuthorizeOperator\",\"value\":{\"contract_id\":\"deadbeef\",\"holder\":\"%s\",\"operator\":\"%s\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0], addrs[1]), }, "MsgRevokeOperator": { &collection.MsgRevokeOperator{ ContractId: contractID, - Holder: addrs[0].String(), - Operator: addrs[1].String(), + Holder: addrs[0], + Operator: addrs[1], }, "/lbm.collection.v1.MsgRevokeOperator", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/collection/MsgRevokeOperator\",\"value\":{\"contract_id\":\"deadbeef\",\"holder\":\"%s\",\"operator\":\"%s\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String(), addrs[1].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/collection/MsgRevokeOperator\",\"value\":{\"contract_id\":\"deadbeef\",\"holder\":\"%s\",\"operator\":\"%s\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0], addrs[1]), }, "MsgCreateContract": { &collection.MsgCreateContract{ - Owner: addrs[0].String(), + Owner: addrs[0], Name: "Test Contract", Uri: "http://image.url", Meta: "This is test", }, "/lbm.collection.v1.MsgCreateContract", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgCreateContract\",\"value\":{\"meta\":\"This is test\",\"name\":\"Test Contract\",\"owner\":\"%s\",\"uri\":\"http://image.url\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgCreateContract\",\"value\":{\"meta\":\"This is test\",\"name\":\"Test Contract\",\"owner\":\"%s\",\"uri\":\"http://image.url\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0]), }, "MsgIssueNFT": { &collection.MsgIssueNFT{ ContractId: contractID, Name: "Test NFT", Meta: "This is NFT Meta", - Owner: addrs[0].String(), + Owner: addrs[0], }, "/lbm.collection.v1.MsgIssueNFT", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgIssueNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"meta\":\"This is NFT Meta\",\"name\":\"Test NFT\",\"owner\":\"%s\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgIssueNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"meta\":\"This is NFT Meta\",\"name\":\"Test NFT\",\"owner\":\"%s\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0]), }, "MsgMintNFT": { &collection.MsgMintNFT{ ContractId: contractID, - From: addrs[0].String(), - To: addrs[1].String(), + From: addrs[0], + To: addrs[1], Params: nftParams, }, "/lbm.collection.v1.MsgMintNFT", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgMintNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"params\":[{\"meta\":\"Tibetian Fox\",\"name\":\"tibetian fox\",\"token_type\":\"deadbeef\"}],\"to\":\"%s\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String(), addrs[1].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgMintNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"params\":[{\"meta\":\"Tibetian Fox\",\"name\":\"tibetian fox\",\"token_type\":\"deadbeef\"}],\"to\":\"%s\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0], addrs[1]), }, "MsgBurnNFT": { &collection.MsgBurnNFT{ ContractId: contractID, - From: addrs[0].String(), + From: addrs[0], TokenIds: tokenIds, }, "/lbm.collection.v1.MsgBurnNFT", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgBurnNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"token_ids\":[\"deadbeef00000001\"]}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgBurnNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"token_ids\":[\"deadbeef00000001\"]}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0]), }, "MsgOperatorBurnNFT": { &collection.MsgOperatorBurnNFT{ ContractId: contractID, - Operator: addrs[0].String(), - From: addrs[1].String(), + Operator: addrs[0], + From: addrs[1], TokenIds: tokenIds, }, "/lbm.collection.v1.MsgOperatorBurnNFT", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgOperatorBurnNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"operator\":\"%s\",\"token_ids\":[\"deadbeef00000001\"]}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[1].String(), addrs[0].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/MsgOperatorBurnNFT\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"operator\":\"%s\",\"token_ids\":[\"deadbeef00000001\"]}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[1], addrs[0]), }, "MsgModify": { &collection.MsgModify{ ContractId: contractID, - Owner: addrs[0].String(), + Owner: addrs[0], TokenType: "NewType", TokenIndex: contractID, Changes: []collection.Attribute{{Key: "name", Value: "New test"}}, }, "/lbm.collection.v1.MsgModify", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/collection/MsgModify\",\"value\":{\"changes\":[{\"key\":\"name\",\"value\":\"New test\"}],\"contract_id\":\"deadbeef\",\"owner\":\"%s\",\"token_index\":\"deadbeef\",\"token_type\":\"NewType\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/collection/MsgModify\",\"value\":{\"changes\":[{\"key\":\"name\",\"value\":\"New test\"}],\"contract_id\":\"deadbeef\",\"owner\":\"%s\",\"token_index\":\"deadbeef\",\"token_type\":\"NewType\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0]), }, "MsgGrantPermission": { &collection.MsgGrantPermission{ ContractId: contractID, - From: addrs[0].String(), - To: addrs[1].String(), + To: addrs[1], + From: addrs[0], Permission: collection.LegacyPermissionMint.String(), }, "/lbm.collection.v1.MsgGrantPermission", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/collection/MsgGrantPermission\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"permission\":\"mint\",\"to\":\"%s\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String(), addrs[1].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/collection/MsgGrantPermission\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"permission\":\"mint\",\"to\":\"%s\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0], addrs[1]), }, "MsgRevokePermission": { &collection.MsgRevokePermission{ ContractId: contractID, - From: addrs[0].String(), + From: addrs[0], Permission: collection.LegacyPermissionMint.String(), }, "/lbm.collection.v1.MsgRevokePermission", - fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/collection/MsgRevokePermission\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"permission\":\"mint\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0].String()), + fmt.Sprintf("{\"account_number\":\"1\",\"chain_id\":\"foo\",\"fee\":{\"amount\":[],\"gas\":\"0\"},\"memo\":\"memo\",\"msgs\":[{\"type\":\"lbm-sdk/collection/MsgRevokePermission\",\"value\":{\"contract_id\":\"deadbeef\",\"from\":\"%s\",\"permission\":\"mint\"}}],\"sequence\":\"1\",\"timeout_height\":\"1\"}", addrs[0]), }, }