Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestMsgServerCreateCollection suggestion #202

Open
giorgionocera opened this issue Oct 1, 2022 · 0 comments
Open

TestMsgServerCreateCollection suggestion #202

giorgionocera opened this issue Oct 1, 2022 · 0 comments
Labels

Comments

@giorgionocera
Copy link
Contributor

In the nft module, in the nft/keeper/msg_server_test.go file, lays the TestMsgServerCreateCollection method. This method implements the tests for creating new collections on the system

I suggest creating multiple tests and here pass the arguments for the MsgCreateCollection, instead of a single test. By doing so, it is possible to verify the module behavior with the wrong arguments (a reference to #193)

func (suite *KeeperTestSuite) TestMsgServerCreateCollection() {
tests := []struct {
testCase string
expectPass bool
expectedCollectionId uint64
}{
{
"create a collection",
true,
1,
},
}
for _, tc := range tests {
creator := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes())
msgServer := keeper.NewMsgServerImpl(suite.app.NFTKeeper)
resp, err := msgServer.CreateCollection(sdk.WrapSDKContext(suite.ctx), types.NewMsgCreateCollection(
creator, "PUNK", "Punk Collection", "punk.com", creator.String(), false,
))
if tc.expectPass {
suite.Require().NoError(err)
// test response is correct
suite.Require().Equal(resp.Id, tc.expectedCollectionId)
// test last collectionId id updated correctly
lastCollectionId := suite.app.NFTKeeper.GetLastCollectionId(suite.ctx)
suite.Require().Equal(lastCollectionId, tc.expectedCollectionId)
// test collection is set correctly
collection, err := suite.app.NFTKeeper.GetCollectionById(suite.ctx, resp.Id)
suite.Require().NoError(err)
suite.Require().Equal(collection.Id, tc.expectedCollectionId)
suite.Require().Equal(collection.UpdateAuthority, creator.String())
} else {
suite.Require().Error(err)
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant