-
Notifications
You must be signed in to change notification settings - Fork 592
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
refactor: acknowledgePacket handling flushing / flush complete state #4412
Changes from 4 commits
f2033ef
0cc8ced
f3cd95b
942ef27
80013f8
417bff3
050ac3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -730,6 +730,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { | |
packet types.Packet | ||
ack = ibcmock.MockAcknowledgement | ||
|
||
assertFn func() | ||
channelCap *capabilitytypes.Capability | ||
expError *errorsmod.Error | ||
Comment on lines
+733
to
735
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this I'd like to refactor these tests to use either I think it would make testing here more flexible, we can do expected error checking in an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the function expResult exactly because of the ability to verify posterior state so ++ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. created #4433 and assigned to myself |
||
) | ||
|
@@ -784,6 +785,90 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { | |
channel.State = types.STATE_FLUSHING | ||
|
||
path.EndpointA.SetChannel(channel) | ||
|
||
counterpartyUpgrade := types.Upgrade{ | ||
Timeout: types.NewTimeout(clienttypes.ZeroHeight(), 0), | ||
} | ||
|
||
path.EndpointA.SetChannelCounterpartyUpgrade(counterpartyUpgrade) | ||
|
||
assertFn = func() { | ||
channel := path.EndpointA.GetChannel() | ||
suite.Require().Equal(types.STATE_FLUSHING, channel.State) | ||
} | ||
}, true}, | ||
{"success on channel in flushing state with valid timeout", func() { | ||
// setup uses an UNORDERED channel | ||
suite.coordinator.Setup(path) | ||
|
||
// create packet commitment | ||
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) | ||
suite.Require().NoError(err) | ||
|
||
// create packet receipt and acknowledgement | ||
packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) | ||
err = path.EndpointB.RecvPacket(packet) | ||
suite.Require().NoError(err) | ||
|
||
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) | ||
|
||
channel := path.EndpointA.GetChannel() | ||
channel.State = types.STATE_FLUSHING | ||
|
||
path.EndpointA.SetChannel(channel) | ||
|
||
counterpartyUpgrade := types.Upgrade{ | ||
Timeout: types.NewTimeout(suite.chainB.GetTimeoutHeight(), 0), | ||
} | ||
|
||
path.EndpointA.SetChannelCounterpartyUpgrade(counterpartyUpgrade) | ||
|
||
assertFn = func() { | ||
channel := path.EndpointA.GetChannel() | ||
suite.Require().Equal(types.STATE_FLUSHCOMPLETE, channel.State) | ||
} | ||
}, true}, | ||
{"success on channel in flushing state with timeout passed", func() { | ||
// setup uses an UNORDERED channel | ||
suite.coordinator.Setup(path) | ||
|
||
// create packet commitment | ||
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) | ||
suite.Require().NoError(err) | ||
|
||
// create packet receipt and acknowledgement | ||
packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) | ||
err = path.EndpointB.RecvPacket(packet) | ||
suite.Require().NoError(err) | ||
|
||
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) | ||
|
||
channel := path.EndpointA.GetChannel() | ||
channel.State = types.STATE_FLUSHING | ||
|
||
path.EndpointA.SetChannel(channel) | ||
|
||
upgrade := types.Upgrade{ | ||
Fields: types.NewUpgradeFields(types.UNORDERED, []string{ibctesting.FirstConnectionID}, ibcmock.UpgradeVersion), | ||
Timeout: types.NewTimeout(clienttypes.ZeroHeight(), 1), | ||
} | ||
|
||
counterpartyUpgrade := types.Upgrade{ | ||
Fields: types.NewUpgradeFields(types.UNORDERED, []string{ibctesting.FirstConnectionID}, ibcmock.UpgradeVersion), | ||
Timeout: types.NewTimeout(clienttypes.ZeroHeight(), 1), | ||
} | ||
|
||
path.EndpointA.SetChannelUpgrade(upgrade) | ||
path.EndpointA.SetChannelCounterpartyUpgrade(counterpartyUpgrade) | ||
|
||
assertFn = func() { | ||
channel := path.EndpointA.GetChannel() | ||
suite.Require().Equal(types.OPEN, channel.State) | ||
|
||
errorReceipt, found := path.EndpointA.Chain.App.GetIBCKeeper().ChannelKeeper.GetUpgradeErrorReceipt(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID) | ||
suite.Require().True(found) | ||
suite.Require().NotEmpty(errorReceipt) | ||
} | ||
}, true}, | ||
{"packet already acknowledged ordered channel (no-op)", func() { | ||
expError = types.ErrNoOpMsg | ||
|
@@ -1040,6 +1125,10 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() { | |
} else { | ||
suite.Require().Equal(uint64(1), sequenceAck, "sequence incremented for UNORDERED channel") | ||
} | ||
|
||
if assertFn != nil { | ||
assertFn() | ||
} | ||
} else { | ||
suite.Error(err) | ||
// only check if expError is set, since not all error codes can be known | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must have slipped in as a typo at some point. I'll create an issue
edit: created #4422