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

tests: fix ProvideCounterparty test. #7501

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 37 additions & 29 deletions modules/core/04-channel/v2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,58 +272,66 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
},
nil,
},
{
"failure: creator not set",
func() {
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeleteCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID)
},
ibcerrors.ErrUnauthorized,
},
{
"failure: signer does not match creator",
func() {
msg.Signer = path.EndpointB.Chain.SenderAccount.GetAddress().String()
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID, ibctesting.TestAccAddress)
},
ibcerrors.ErrUnauthorized,
},
/* // Account sequence mismatch, expected 5, got 6. :thinking:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the morning thinking vibes

ac43edd0c63cbdb4be6b5b333df29db9

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahahha

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could because the suite.Run was missing and thus maybe the test suite setup code wasn't being rerun per test case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly! thankfully didn't take too much time out of my life to figure out

{
"failure: counterparty does not already exists",
"failure: channel must already exist",
func() {
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.ChannelStore(suite.chainA.GetContext(), path.EndpointA.ChannelID).Delete([]byte(channeltypesv2.ChannelKey))
},
channeltypesv2.ErrInvalidChannel,
},
*/
}

for _, tc := range cases {
tc := tc
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupClients()
suite.Run(tc.name, func() {
suite.SetupTest()

suite.Require().NoError(path.EndpointA.CreateChannel())
suite.Require().NoError(path.EndpointB.CreateChannel())
path = ibctesting.NewPath(suite.chainA, suite.chainB)
path.SetupClients()

signer := path.EndpointA.Chain.SenderAccount.GetAddress().String()
msg = channeltypesv2.NewMsgProvideCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, signer)
suite.Require().NoError(path.EndpointA.CreateChannel())
suite.Require().NoError(path.EndpointB.CreateChannel())

tc.malleate()
signer := path.EndpointA.Chain.SenderAccount.GetAddress().String()
msg = channeltypesv2.NewMsgProvideCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, signer)

res, err := path.EndpointA.Chain.SendMsgs(msg)
tc.malleate()

res, err := path.EndpointA.Chain.SendMsgs(msg)

expPass := tc.expError == nil
if expPass {
suite.Require().NotNil(res)
suite.Require().Nil(err)
expPass := tc.expError == nil
if expPass {
suite.Require().NotNil(res)
suite.Require().Nil(err)

// Assert counterparty channel id filled in and creator deleted
channel, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(channel.CounterpartyChannelId, path.EndpointB.ChannelID)
// Assert counterparty channel id filled in and creator deleted
channel, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetChannel(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(channel.CounterpartyChannelId, path.EndpointB.ChannelID)

_, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().False(found)
_, found = suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().False(found)

seq, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(seq, uint64(1))
} else {
suite.Require().Error(err)
}
seq, found := suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.GetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.Require().True(found)
suite.Require().Equal(seq, uint64(1))
} else {
ibctesting.RequireErrorIsOrContains(suite.T(), err, tc.expError, "expected error %q, got %q instead", tc.expError, err)
}
})
}
}

Expand Down
Loading