From fad6e90d27cc5c38bfc247f861999fa57f7d6639 Mon Sep 17 00:00:00 2001 From: Senna46 <29295263+Senna46@users.noreply.github.com> Date: Wed, 9 Aug 2023 00:35:01 +0900 Subject: [PATCH 1/5] feat: enable test --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d9e08082b..c2a97aec7 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -17,4 +17,4 @@ jobs: run: go build -v ./... - name: Test - run: go test -v `go list ./... | grep -v -E 'deprecated/|x/ecosystemincentive/|x/nftfactory/'` + run: go build -v ./... From 837a2f340df56074f25a2c6ab8bc156fe195ec3b Mon Sep 17 00:00:00 2001 From: Senna46 <29295263+Senna46@users.noreply.github.com> Date: Wed, 9 Aug 2023 00:59:54 +0900 Subject: [PATCH 2/5] fix: workflow --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c2a97aec7..f1e587c8b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -17,4 +17,4 @@ jobs: run: go build -v ./... - name: Test - run: go build -v ./... + run: go test -v `go list ./... | grep -v -E 'x/ecosystemincentive/'` From 3710d216eae0bf13b87e1af912129d3e2093af80 Mon Sep 17 00:00:00 2001 From: Senna46 <29295263+Senna46@users.noreply.github.com> Date: Wed, 9 Aug 2023 01:35:34 +0900 Subject: [PATCH 3/5] fix: setup test --- x/nftfactory/keeper/keeper_test.go | 143 ++++++----------------------- 1 file changed, 28 insertions(+), 115 deletions(-) diff --git a/x/nftfactory/keeper/keeper_test.go b/x/nftfactory/keeper/keeper_test.go index b698323a8..9caac1d75 100644 --- a/x/nftfactory/keeper/keeper_test.go +++ b/x/nftfactory/keeper/keeper_test.go @@ -5,23 +5,18 @@ import ( "github.com/CosmWasm/wasmd/x/wasm" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - tmtime "github.com/cometbft/cometbft/types/time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/suite" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + + nftkeeper "github.com/UnUniFi/chain/x/nft/keeper" + "github.com/UnUniFi/chain/x/nftfactory/keeper" - "github.com/UnUniFi/chain/x/nftfactory/types" - sdktestutil "github.com/cosmos/cosmos-sdk/testutil" "github.com/cosmos/cosmos-sdk/x/nft" - "github.com/cosmos/cosmos-sdk/x/nft/module" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" - moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - - // nfttestutil "github.com/cosmos/cosmos-sdk/x/nft/testutil" - "github.com/UnUniFi/chain/x/nftfactory/types/testutil" + "github.com/cosmos/cosmos-sdk/baseapp" simapp "github.com/UnUniFi/chain/app" ) @@ -29,113 +24,31 @@ import ( type KeeperTestSuite struct { suite.Suite - ctx sdk.Context - addrs []sdk.AccAddress - // queryClient nft.QueryClient - // nftKeeper nftkeeper.Keeper - nftKeeper *testutil.MockNftKeeper - nftmintKeeper keeper.Keeper - // accountKeeper *nfttestutil.MockAccountKeeper - accountKeeper *testutil.MockAccountKeeper - - encCfg moduletestutil.TestEncodingConfig + ctx sdk.Context + app *simapp.App + addrs []sdk.AccAddress + queryClient nft.QueryClient + keeper keeper.Keeper + nftKeeper nftkeeper.Keeper + accountKeeper authkeeper.AccountKeeper } -func (s *KeeperTestSuite) SetupTest() { - // s.addrs = simtestutil.CreateIncrementalAccounts(3) - // s.encCfg = moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) - - // key := sdk.NewKVStoreKey(nft.StoreKey) - // testCtx := sdktestutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) - // ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) - - // // gomock initializations - // ctrl := gomock.NewController(s.T()) - // accountKeeper := testutil.NewMockAccountKeeper(ctrl) - // bankKeeper := testutil.NewMockBankKeeper(ctrl) - // xbankKeeper := testutil.NewMockNftKeeper(ctrl) - // accountKeeper.EXPECT().GetModuleAddress("nft").Return(s.addrs[0]).AnyTimes() - - // nftKeeper := nftkeeper.NewKeeper(key, s.encCfg.Codec, accountKeeper, bankKeeper) - // queryHelper := baseapp.NewQueryServerTestHelper(ctx, s.encCfg.InterfaceRegistry) - // nft.RegisterQueryServer(queryHelper, nftKeeper) - - // storeKey := sdk.NewKVStoreKey(types.StoreKey) - // memKey := sdk.NewKVStoreKey(types.MemStoreKey) - // app := simapp.Setup(s.T(), ([]wasm.Option{})...) - // // encodingConfig := appparams.MakeEncodingConfig() - // // appCodec := s.encCfg.Marshaler - // nftmintKeeper := keeper.NewKeeper( - // s.encCfg.Codec, - // storeKey, - // memKey, - // app.GetSubspace(types.ModuleName), - // accountKeeper, - // nftKeeper, - // ) - - // s.nftKeeper = nftKeeper - // s.nftmintKeeper = nftmintKeeper - // s.queryClient = nft.NewQueryClient(queryHelper) - // s.ctx = ctx - - s.addrs = simtestutil.CreateIncrementalAccounts(3) - s.encCfg = moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) - - key := sdk.NewKVStoreKey(nft.StoreKey) - testCtx := sdktestutil.DefaultContextWithDB(s.T(), key, sdk.NewTransientStoreKey("transient_test")) - ctx := testCtx.Ctx.WithBlockHeader(tmproto.Header{Time: tmtime.Now()}) - - // gomock initializations - ctrl := gomock.NewController(s.T()) - defer ctrl.Finish() - accountKeeper := testutil.NewMockAccountKeeper(ctrl) - nftKeeper := testutil.NewMockNftKeeper(ctrl) - // uint64c := make(chan uint64) - // errorc := make(chan error) - // fmt.Println("s.addrs[0]") - // fmt.Println(s.addrs[0]) - // accountKeeper.EXPECT().GetSequence(gomock.Any(), uint(1)).Return(uint64(1), nil).AnyTimes() - - // loop addrs length - numIncrements := 5 - // for i := 0; i < len(s.addrs); i++ { - // for j := 0; j <= numIncrements; j++ { - // // mockCounter.EXPECT().Increment().Return(i) - // // accountKeeper.EXPECT().GetSequence(ctx, s.addrs[0]).Return(uint64(1), nil).AnyTimes() - // accountKeeper.EXPECT().GetSequence(ctx, s.addrs[i]).Return(uint64(j), nil) - // } - // } - for j := 0; j <= numIncrements; j++ { - accountKeeper.EXPECT().GetSequence(ctx, s.addrs[0]).Return(uint64(j), nil).Times(j).AnyTimes() - } - - // accountKeeper.EXPECT().GetSequence(ctx, s.addrs[0]).Return(uint64(1), nil).AnyTimes() - // accountKeeper.EXPECT().GetSequence(ctx,s.addrs[0]).Return(s.addrs[0]).AnyTimes() - - // nftKeeper := nftkeeper.NewKeeper(key, s.encCfg.Codec, accountKeeper, bankKeeper) - // queryHelper := baseapp.NewQueryServerTestHelper(ctx, s.encCfg.InterfaceRegistry) - // nft.RegisterQueryServer(queryHelper, nftKeeper) - - storeKey := sdk.NewKVStoreKey(types.StoreKey) - memKey := sdk.NewKVStoreKey(types.MemStoreKey) - app := simapp.Setup(s.T(), ([]wasm.Option{})...) - // encodingConfig := appparams.MakeEncodingConfig() - // appCodec := s.encCfg.Marshaler - nftmintKeeper := keeper.NewKeeper( - s.encCfg.Codec, - storeKey, - memKey, - app.GetSubspace(types.ModuleName), - accountKeeper, - nftKeeper, - ) - - s.nftKeeper = nftKeeper - s.nftmintKeeper = nftmintKeeper - s.accountKeeper = accountKeeper - // s.queryClient = nft.NewQueryClient(queryHelper) - s.ctx = ctx +func (suite *KeeperTestSuite) SetupTest() { + isCheckTx := false + + app := simapp.Setup(suite.T(), ([]wasm.Option{})...) + + suite.ctx = app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) + suite.app = app + suite.addrs = simapp.AddTestAddrsIncremental(app, suite.ctx, 3, sdk.NewInt(30000000)) + + queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, app.InterfaceRegistry()) + nft.RegisterQueryServer(queryHelper, app.UnUniFiNFTKeeper) + suite.queryClient = nft.NewQueryClient(queryHelper) + + suite.keeper = app.NftfactoryKeeper + suite.nftKeeper = app.UnUniFiNFTKeeper + suite.accountKeeper = app.AccountKeeper } func TestKeeperSuite(t *testing.T) { From a868e2bc408b281bdfcae7da16016cc897d354e2 Mon Sep 17 00:00:00 2001 From: Senna46 <29295263+Senna46@users.noreply.github.com> Date: Wed, 9 Aug 2023 01:35:56 +0900 Subject: [PATCH 4/5] fix: address test --- x/nftfactory/keeper/class_test.go | 68 +++++++++++++++---------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/x/nftfactory/keeper/class_test.go b/x/nftfactory/keeper/class_test.go index db016ecd4..a6e1e78fc 100644 --- a/x/nftfactory/keeper/class_test.go +++ b/x/nftfactory/keeper/class_test.go @@ -32,10 +32,10 @@ func (suite *KeeperTestSuite) TestNftMintClassBasics() { ClassId: classId, } // check setting ClassAttributes function - err := suite.nftmintKeeper.SetClassAttributes(suite.ctx, classAttributes) + err := suite.keeper.SetClassAttributes(suite.ctx, classAttributes) suite.Require().NoError(err) // check getting ClassAttributes function - gotClassAttributes, exists := suite.nftmintKeeper.GetClassAttributes(suite.ctx, classAttributes.ClassId) + gotClassAttributes, exists := suite.keeper.GetClassAttributes(suite.ctx, classAttributes.ClassId) suite.Require().True(exists) suite.Require().Equal(classAttributes, gotClassAttributes) @@ -47,10 +47,10 @@ func (suite *KeeperTestSuite) TestNftMintClassBasics() { ClassId: classIdList, } // check setting OwningClassIdList function - err = suite.nftmintKeeper.SetOwningClassIdList(suite.ctx, owningClassIdList) + err = suite.keeper.SetOwningClassIdList(suite.ctx, owningClassIdList) suite.Require().NoError(err) // check getting OwningClassIdList function - gotOwningClassIdList, exists := suite.nftmintKeeper.GetOwningClassIdList(suite.ctx, owner) + gotOwningClassIdList, exists := suite.keeper.GetOwningClassIdList(suite.ctx, owner) suite.Require().True(exists) suite.Require().Equal(owningClassIdList, gotOwningClassIdList) @@ -61,10 +61,10 @@ func (suite *KeeperTestSuite) TestNftMintClassBasics() { ClassId: classIdList, } // check setting ClassNameIdList function - err = suite.nftmintKeeper.SetClassNameIdList(suite.ctx, classNameIdList) + err = suite.keeper.SetClassNameIdList(suite.ctx, classNameIdList) suite.Require().NoError(err) // check getting ClassNameIdList function - gotClassNameIdList, exists := suite.nftmintKeeper.GetClassNameIdList(suite.ctx, testClassName) + gotClassNameIdList, exists := suite.keeper.GetClassNameIdList(suite.ctx, testClassName) suite.Require().True(exists) suite.Require().Equal(classNameIdList, gotClassNameIdList) } @@ -103,7 +103,7 @@ func (suite *KeeperTestSuite) TestCreateClass() { suite.Require().Equal(class, expectedClass) // check if ClassAttributes is set - classAttributes, exists := suite.nftmintKeeper.GetClassAttributes(suite.ctx, classId) + classAttributes, exists := suite.keeper.GetClassAttributes(suite.ctx, classId) suite.Require().True(exists) expectedClassAttributes := types.ClassAttributes{ ClassId: classId, @@ -115,7 +115,7 @@ func (suite *KeeperTestSuite) TestCreateClass() { suite.Require().Equal(classAttributes, expectedClassAttributes) // check if OwningClassIdList is set - owningClassIdList, exists := suite.nftmintKeeper.GetOwningClassIdList(suite.ctx, sender) + owningClassIdList, exists := suite.keeper.GetOwningClassIdList(suite.ctx, sender) suite.Require().True(exists) var classIdList []string classIdList = append(classIdList, classId) @@ -126,7 +126,7 @@ func (suite *KeeperTestSuite) TestCreateClass() { suite.Require().Equal(owningClassIdList, expectedOwningClassIdList) // check if ClassNameIdList is set - classNameIdList, exists := suite.nftmintKeeper.GetClassNameIdList(suite.ctx, testName) + classNameIdList, exists := suite.keeper.GetClassNameIdList(suite.ctx, testName) suite.Require().True(exists) expectedClassNameIdList := types.ClassNameIdList{ ClassName: testName, @@ -145,17 +145,17 @@ func (suite *KeeperTestSuite) TestCreateClass() { TokenSupplyCap: testTokenSupplyCap, MintingPermission: testMintingPermission, } - err = suite.nftmintKeeper.CreateClass(suite.ctx, classIdInInvalidCase, &testMsgCreateClassInvalidName) + err = suite.keeper.CreateClass(suite.ctx, classIdInInvalidCase, &testMsgCreateClassInvalidName) suite.Require().Error(err) // check if data objects aren't set exists = suite.nftKeeper.HasClass(suite.ctx, classIdInInvalidCase) suite.Require().False(exists) - _, exists = suite.nftmintKeeper.GetClassAttributes(suite.ctx, classIdInInvalidCase) + _, exists = suite.keeper.GetClassAttributes(suite.ctx, classIdInInvalidCase) suite.Require().False(exists) - _, exists = suite.nftmintKeeper.GetOwningClassIdList(suite.ctx, senderInInvalidCase) + _, exists = suite.keeper.GetOwningClassIdList(suite.ctx, senderInInvalidCase) suite.Require().False(exists) - _, exists = suite.nftmintKeeper.GetClassNameIdList(suite.ctx, testMsgCreateClassInvalidName.Name) + _, exists = suite.keeper.GetClassNameIdList(suite.ctx, testMsgCreateClassInvalidName.Name) suite.Require().False(exists) // in case which contains the invalid uri @@ -166,7 +166,7 @@ func (suite *KeeperTestSuite) TestCreateClass() { TokenSupplyCap: testTokenSupplyCap, MintingPermission: testMintingPermission, } - err = suite.nftmintKeeper.CreateClass(suite.ctx, classIdInInvalidCase, &testMsgCreateClassInvalidUri) + err = suite.keeper.CreateClass(suite.ctx, classIdInInvalidCase, &testMsgCreateClassInvalidUri) suite.Require().Error(err) // in case which contains the invalid token supply cap @@ -177,7 +177,7 @@ func (suite *KeeperTestSuite) TestCreateClass() { TokenSupplyCap: 10000000, // bigger than the token supply cap MintingPermission: 0, } - err = suite.nftmintKeeper.CreateClass(suite.ctx, classIdInInvalidCase, &testMsgCreateClassInvalidTokenSupplyCap) + err = suite.keeper.CreateClass(suite.ctx, classIdInInvalidCase, &testMsgCreateClassInvalidTokenSupplyCap) suite.Require().Error(err) // in case which contains the invalid minting permission @@ -188,7 +188,7 @@ func (suite *KeeperTestSuite) TestCreateClass() { TokenSupplyCap: 10000, MintingPermission: 10, // not allowed minting permission option } - err = suite.nftmintKeeper.CreateClass(suite.ctx, classIdInInvalidCase, &testMsgCreateClassInvalidMintingPermission) + err = suite.keeper.CreateClass(suite.ctx, classIdInInvalidCase, &testMsgCreateClassInvalidMintingPermission) suite.Require().Error(err) } @@ -206,12 +206,12 @@ func (suite *KeeperTestSuite) TestSendClassOwnership() { ClassId: classId, Recipient: recipient.String(), } - err := suite.nftmintKeeper.SendClassOwnership(suite.ctx, &testMsgSendClassOwnership) + err := suite.keeper.SendClassOwnership(suite.ctx, &testMsgSendClassOwnership) suite.Require().NoError(err) // check if recipient address becomes new owner of class - classAttributes, exists := suite.nftmintKeeper.GetClassAttributes(suite.ctx, classId) + classAttributes, exists := suite.keeper.GetClassAttributes(suite.ctx, classId) suite.Require().True(exists) - expectedOwner := recipient + expectedOwner := recipient.String() suite.Require().Equal(expectedOwner, classAttributes.Owner) // invalid sender of MsgSendClassOwnership @@ -222,7 +222,7 @@ func (suite *KeeperTestSuite) TestSendClassOwnership() { ClassId: classId, Recipient: recipient.String(), } - err = suite.nftmintKeeper.SendClassOwnership(suite.ctx, &testMsgSendClassOwnershipInvalidSender) + err = suite.keeper.SendClassOwnership(suite.ctx, &testMsgSendClassOwnershipInvalidSender) suite.Require().Error(err) // invalid class id specification @@ -232,7 +232,7 @@ func (suite *KeeperTestSuite) TestSendClassOwnership() { ClassId: invalidClassId, // non-existant class Recipient: recipient.String(), } - err = suite.nftmintKeeper.SendClassOwnership(suite.ctx, &testMsgCreateClassInvalidClassId) + err = suite.keeper.SendClassOwnership(suite.ctx, &testMsgCreateClassInvalidClassId) suite.Require().Error(err) } @@ -249,9 +249,9 @@ func (suite *KeeperTestSuite) TestUpdateTokenSupplyCap() { ClassId: classId, TokenSupplyCap: updatingTokenSupplyCap, } - err := suite.nftmintKeeper.UpdateTokenSupplyCap(suite.ctx, &testMsgUpdateTokenSupplyCap) + err := suite.keeper.UpdateTokenSupplyCap(suite.ctx, &testMsgUpdateTokenSupplyCap) suite.Require().NoError(err) - classAttributes, exists := suite.nftmintKeeper.GetClassAttributes(suite.ctx, classId) + classAttributes, exists := suite.keeper.GetClassAttributes(suite.ctx, classId) suite.Require().True(exists) expectedTokenSupplyCap := updatingTokenSupplyCap suite.Require().Equal(expectedTokenSupplyCap, classAttributes.TokenSupplyCap) @@ -264,7 +264,7 @@ func (suite *KeeperTestSuite) TestUpdateTokenSupplyCap() { ClassId: classId, TokenSupplyCap: 100, } - err = suite.nftmintKeeper.UpdateTokenSupplyCap(suite.ctx, &testMsgUpdateTokenSupplyCapInvalidSender) + err = suite.keeper.UpdateTokenSupplyCap(suite.ctx, &testMsgUpdateTokenSupplyCapInvalidSender) suite.Require().Error(err) // invalid token supply cap specification @@ -273,7 +273,7 @@ func (suite *KeeperTestSuite) TestUpdateTokenSupplyCap() { ClassId: classId, TokenSupplyCap: 1000000, // bigger than the maximum token supply cap on UnUniFi } - err = suite.nftmintKeeper.UpdateTokenSupplyCap(suite.ctx, &testMsgUpdateTokenSupplyCapInvalidCap) + err = suite.keeper.UpdateTokenSupplyCap(suite.ctx, &testMsgUpdateTokenSupplyCapInvalidCap) suite.Require().Error(err) // invalid case which current token supply is bigger than the updating supply cap @@ -284,7 +284,7 @@ func (suite *KeeperTestSuite) TestUpdateTokenSupplyCap() { ClassId: classId, TokenSupplyCap: 1, // smaller than the current token supply 2 of the specified class } - err = suite.nftmintKeeper.UpdateTokenSupplyCap(suite.ctx, &testMsgUpdateTokenSupplyCapSmaller) + err = suite.keeper.UpdateTokenSupplyCap(suite.ctx, &testMsgUpdateTokenSupplyCapSmaller) suite.Require().Error(err) } @@ -351,12 +351,12 @@ func (suite *KeeperTestSuite) TestUpdateBaseTokenUri() { } for _, tc := range tests { - err := suite.nftmintKeeper.UpdateBaseTokenUri(suite.ctx, &tc.msg) + err := suite.keeper.UpdateBaseTokenUri(suite.ctx, &tc.msg) // invalid cases if !tc.validSender || !tc.validBaseTokenUir { suite.Require().Error(err) - gotClassAttributes, _ := suite.nftmintKeeper.GetClassAttributes(suite.ctx, classId) + gotClassAttributes, _ := suite.keeper.GetClassAttributes(suite.ctx, classId) suite.Require().Equal(testBaseTokenUri, gotClassAttributes.BaseTokenUri) nft, _ := suite.nftKeeper.GetNFT(suite.ctx, classId, testNftID) expectedNFTUri := testBaseTokenUri + testNFTId @@ -366,7 +366,7 @@ func (suite *KeeperTestSuite) TestUpdateBaseTokenUri() { // valid case if tc.validSender && tc.validBaseTokenUir { suite.Require().NoError(err) - gotClassAttributes, _ := suite.nftmintKeeper.GetClassAttributes(suite.ctx, classId) + gotClassAttributes, _ := suite.keeper.GetClassAttributes(suite.ctx, classId) suite.Require().Equal(tc.msg.BaseTokenUri, gotClassAttributes.BaseTokenUri) nft, _ := suite.nftKeeper.GetNFT(suite.ctx, classId, testNftID) expectedNFTUri := tc.msg.BaseTokenUri + testNftID @@ -385,7 +385,7 @@ func (suite *KeeperTestSuite) CreateClass(ctx sdk.Context, classID string, sende MintingPermission: testMintingPermission, } - err := suite.nftmintKeeper.CreateClass(ctx, classID, &testMsgCreateClass) + err := suite.keeper.CreateClass(ctx, classID, &testMsgCreateClass) return err } @@ -413,7 +413,7 @@ func (suite *KeeperTestSuite) TestGetClassAttributes() { }, } for _, tc := range tests { - res, valid := suite.nftmintKeeper.GetClassAttributes(suite.ctx, tc.classId) + res, valid := suite.keeper.GetClassAttributes(suite.ctx, tc.classId) // invalid cases if !tc.validClass { @@ -456,7 +456,7 @@ func (suite *KeeperTestSuite) TestGetOwningClassIdList() { }, } for _, tc := range tests { - res, valid := suite.nftmintKeeper.GetOwningClassIdList(suite.ctx, tc.ownerAddress) + res, valid := suite.keeper.GetOwningClassIdList(suite.ctx, tc.ownerAddress) // invalid cases if !tc.validOwner { @@ -467,7 +467,7 @@ func (suite *KeeperTestSuite) TestGetOwningClassIdList() { // valid case if tc.validOwner { suite.Require().True(valid) - suite.Require().Equal(res.Owner, tc.ownerAddress) + suite.Require().Equal(res.Owner, tc.ownerAddress.String()) suite.Require().Equal(res.ClassId[0], classId) } } @@ -497,7 +497,7 @@ func (suite *KeeperTestSuite) TestGetClassNameIdList() { }, } for _, tc := range tests { - res, valid := suite.nftmintKeeper.GetClassNameIdList(suite.ctx, tc.className) + res, valid := suite.keeper.GetClassNameIdList(suite.ctx, tc.className) // invalid cases if !tc.validClass { From 3df8cfdfc8e53f65f24853d345a9d678441078db Mon Sep 17 00:00:00 2001 From: Senna46 <29295263+Senna46@users.noreply.github.com> Date: Wed, 9 Aug 2023 01:36:06 +0900 Subject: [PATCH 5/5] fix: keeper --- x/nftfactory/keeper/grpc_query_test.go | 10 +++++----- x/nftfactory/keeper/nft_test.go | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/x/nftfactory/keeper/grpc_query_test.go b/x/nftfactory/keeper/grpc_query_test.go index a32f45a64..c73710496 100644 --- a/x/nftfactory/keeper/grpc_query_test.go +++ b/x/nftfactory/keeper/grpc_query_test.go @@ -17,7 +17,7 @@ func (suite *KeeperTestSuite) TestQueryClassAttributes() { req := types.QueryClassAttributesRequest{ ClassId: classId, } - res, err := suite.nftmintKeeper.ClassAttributes(suite.ctx, &req) + res, err := suite.keeper.ClassAttributes(suite.ctx, &req) suite.Require().NoError(err) suite.Require().Equal(classId, res.ClassAttributes.ClassId) suite.Require().Equal(testBaseTokenUri, res.ClassAttributes.BaseTokenUri) @@ -25,7 +25,7 @@ func (suite *KeeperTestSuite) TestQueryClassAttributes() { invalidReq := types.QueryClassAttributesRequest{ ClassId: "invalidClassId", } - _, err = suite.nftmintKeeper.ClassAttributes(suite.ctx, &invalidReq) + _, err = suite.keeper.ClassAttributes(suite.ctx, &invalidReq) suite.Require().Error(err) } @@ -40,7 +40,7 @@ func (suite *KeeperTestSuite) TestQueryNftMinter() { ClassId: classId, NftId: testNFTId, } - res, err := suite.nftmintKeeper.NFTMinter(suite.ctx, &req) + res, err := suite.keeper.NFTMinter(suite.ctx, &req) suite.Require().NoError(err) suite.Require().Equal(sender.String(), res.Minter) } @@ -55,7 +55,7 @@ func (suite *KeeperTestSuite) TestQueryClassIdsByOwner() { req := types.QueryClassIdsByOwnerRequest{ Owner: sender.String(), } - res, err := suite.nftmintKeeper.ClassIdsByOwner(suite.ctx, &req) + res, err := suite.keeper.ClassIdsByOwner(suite.ctx, &req) suite.Require().NoError(err) var classIds []string classIds = append(classIds, classId) @@ -76,7 +76,7 @@ func (suite *KeeperTestSuite) TestQueryIdsByName() { req := types.QueryClassIdsByNameRequest{ ClassName: testName, } - res, err := suite.nftmintKeeper.ClassIdsByName(suite.ctx, &req) + res, err := suite.keeper.ClassIdsByName(suite.ctx, &req) suite.Require().NoError(err) var classIds []string classIds = append(classIds, classId) diff --git a/x/nftfactory/keeper/nft_test.go b/x/nftfactory/keeper/nft_test.go index 69795a2b2..50f64e8a1 100644 --- a/x/nftfactory/keeper/nft_test.go +++ b/x/nftfactory/keeper/nft_test.go @@ -31,14 +31,14 @@ func (suite *KeeperTestSuite) TestMintNFT() { NftId: testNFTId, Recipient: recipient.String(), } - err := suite.nftmintKeeper.MintNFT(suite.ctx, &testMsgMintNFT) + err := suite.keeper.MintNFT(suite.ctx, &testMsgMintNFT) suite.Require().NoError(err) // check owner owner := suite.nftKeeper.GetOwner(suite.ctx, classId, testNFTId) expectedOwner := recipient suite.Require().Equal(expectedOwner, owner) // check minter - minter, exists := suite.nftmintKeeper.GetNFTMinter(suite.ctx, classId, testNFTId) + minter, exists := suite.keeper.GetNFTMinter(suite.ctx, classId, testNFTId) suite.Require().True(exists) expectedMinter := sender suite.Require().Equal(expectedMinter, minter) @@ -54,7 +54,7 @@ func (suite *KeeperTestSuite) TestMintNFT() { NftId: invalidNFTIdUri, Recipient: recipient.String(), } - err = suite.nftmintKeeper.MintNFT(suite.ctx, &testMsgMintNFTInvalidNftIdUri) + err = suite.keeper.MintNFT(suite.ctx, &testMsgMintNFTInvalidNftIdUri) suite.Require().Error(err) exists = suite.nftKeeper.HasNFT(suite.ctx, classId, invalidNFTIdUri) suite.Require().False(exists) @@ -67,7 +67,7 @@ func (suite *KeeperTestSuite) TestMintNFT() { NftId: invalidNFTId, Recipient: recipient.String(), } - err = suite.nftmintKeeper.MintNFT(suite.ctx, &testMsgMintNFTInvalidNftId) + err = suite.keeper.MintNFT(suite.ctx, &testMsgMintNFTInvalidNftId) suite.Require().Error(err) exists = suite.nftKeeper.HasNFT(suite.ctx, classId, invalidNFTId) suite.Require().False(exists) @@ -82,7 +82,7 @@ func (suite *KeeperTestSuite) TestMintNFT() { NftId: testNFTId2, Recipient: recipient.String(), } - err = suite.nftmintKeeper.MintNFT(suite.ctx, &testMsgMintNFTInvalidMinter) + err = suite.keeper.MintNFT(suite.ctx, &testMsgMintNFTInvalidMinter) suite.Require().Error(err) exists = suite.nftKeeper.HasNFT(suite.ctx, classId, testNFTId2) suite.Require().False(exists) @@ -96,7 +96,7 @@ func (suite *KeeperTestSuite) TestMintNFT() { TokenSupplyCap: 1, MintingPermission: 0, } - _ = suite.nftmintKeeper.CreateClass(suite.ctx, classId, &testMsgCreateClass) + _ = suite.keeper.CreateClass(suite.ctx, classId, &testMsgCreateClass) _ = suite.nftKeeper.Mint(suite.ctx, nfttypes.NFT{ClassId: classId, Id: testNFTId}, sender) testMsgMintNFTOverCap := types.MsgMintNFT{ Sender: sender.String(), @@ -104,7 +104,7 @@ func (suite *KeeperTestSuite) TestMintNFT() { NftId: testNFTId2, Recipient: sender.String(), } - err = suite.nftmintKeeper.MintNFT(suite.ctx, &testMsgMintNFTOverCap) + err = suite.keeper.MintNFT(suite.ctx, &testMsgMintNFTOverCap) suite.Require().Error(err) exists = suite.nftKeeper.HasNFT(suite.ctx, classId, testNFTId2) suite.Require().False(exists) @@ -129,7 +129,7 @@ func (suite *KeeperTestSuite) TestBurnNFT() { ClassId: classId, NftId: testNFTId, } - err := suite.nftmintKeeper.BurnNFT(suite.ctx, &testMsgBurnNFT) + err := suite.keeper.BurnNFT(suite.ctx, &testMsgBurnNFT) suite.Require().NoError(err) // check if burned successfully exists := suite.nftKeeper.HasNFT(suite.ctx, classId, testNFTId) @@ -143,7 +143,7 @@ func (suite *KeeperTestSuite) TestBurnNFT() { ClassId: classId, NftId: testNFTId, } - err = suite.nftmintKeeper.BurnNFT(suite.ctx, &testMsgBurnNFTInvalidSender) + err = suite.keeper.BurnNFT(suite.ctx, &testMsgBurnNFTInvalidSender) suite.Require().Error(err) // check if not burned as intended exists = suite.nftKeeper.HasNFT(suite.ctx, classId, testNFTId) @@ -159,7 +159,7 @@ func (suite *KeeperTestSuite) TestUpdateNFTUri() { _ = suite.MintNFT(suite.ctx, classId, testNFTId, sender) updatingBaseTokenUri := "ipfs://test-latest/" - err := suite.nftmintKeeper.UpdateNFTUri(suite.ctx, classId, updatingBaseTokenUri) + err := suite.keeper.UpdateNFTUri(suite.ctx, classId, updatingBaseTokenUri) suite.Require().NoError(err) nft, _ := suite.nftKeeper.GetNFT(suite.ctx, classId, testNFTId) expectedNFTUri := updatingBaseTokenUri + testNFTId @@ -170,7 +170,7 @@ func (suite *KeeperTestSuite) TestUpdateNFTUri() { for i := 0; i < types.DefaultMaxUriLen; i++ { invalidBaseTokenUri += "a" } - err = suite.nftmintKeeper.UpdateNFTUri(suite.ctx, classId, invalidBaseTokenUri) + err = suite.keeper.UpdateNFTUri(suite.ctx, classId, invalidBaseTokenUri) suite.Require().Error(err) // check if nft uri doesn't change after updating nft, _ = suite.nftKeeper.GetNFT(suite.ctx, classId, testNFTId) @@ -188,6 +188,6 @@ func (suite *KeeperTestSuite) MintNFT(ctx sdk.Context, classID, nftID string, se NftId: nftID, Recipient: sender.String(), } - err := suite.nftmintKeeper.MintNFT(suite.ctx, &testMsgMintNFT) + err := suite.keeper.MintNFT(suite.ctx, &testMsgMintNFT) return err }