Skip to content

Commit a5b5b92

Browse files
Merge commit from fork
* v7 patch remove test case * fix test --------- Co-authored-by: Aditya Sripal <[email protected]>
1 parent f45181b commit a5b5b92

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed

modules/apps/transfer/ibc_module_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func (suite *TransferTestSuite) TestOnRecvPacket() {
268268
packet.Data = []byte("invalid data")
269269

270270
},
271-
channeltypes.NewErrorAcknowledgement(ibcerrors.ErrInvalidType),
271+
channeltypes.NewErrorAcknowledgement(sdkerrors.ErrInvalidType),
272272
},
273273
{
274274
"failure: receive disabled",

modules/core/04-channel/keeper/packet.go

+9
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,15 @@ func (k Keeper) AcknowledgePacket(
436436

437437
packetCommitment := types.CommitPacket(k.cdc, packet)
438438

439+
var ack types.Acknowledgement
440+
err := types.SubModuleCdc.UnmarshalJSON(acknowledgement, &ack)
441+
if err == nil {
442+
ackBz := ack.Acknowledgement()
443+
if !bytes.Equal(ackBz, acknowledgement) {
444+
return sdkerrors.Wrap(types.ErrInvalidAcknowledgement, "acknowledgement marshalling error")
445+
}
446+
}
447+
439448
// verify we sent the packet and haven't cleared it out yet
440449
if !bytes.Equal(commitment, packetCommitment) {
441450
return sdkerrors.Wrapf(types.ErrInvalidPacket, "commitment bytes are not equal: got (%v), expected (%v)", packetCommitment, commitment)

modules/core/04-channel/keeper/packet_test.go

+57-5
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
619619
var (
620620
path *ibctesting.Path
621621
packet types.Packet
622-
ack = ibcmock.MockAcknowledgement
622+
ack []byte
623623

624624
channelCap *capabilitytypes.Capability
625625
expError *sdkerrors.Error
@@ -673,7 +673,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
673673

674674
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
675675

676-
err = path.EndpointA.AcknowledgePacket(packet, ack.Acknowledgement())
676+
err = path.EndpointA.AcknowledgePacket(packet, ack)
677677
suite.Require().NoError(err)
678678
}, false},
679679
{"packet already acknowledged unordered channel (no-op)", func() {
@@ -693,9 +693,60 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
693693

694694
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
695695

696-
err = path.EndpointA.AcknowledgePacket(packet, ack.Acknowledgement())
696+
err = path.EndpointA.AcknowledgePacket(packet, ack)
697697
suite.Require().NoError(err)
698698
}, false},
699+
{
700+
"fake acknowledgement",
701+
func() {
702+
// setup uses an UNORDERED channel
703+
suite.coordinator.Setup(path)
704+
705+
// create packet commitment
706+
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
707+
suite.Require().NoError(err)
708+
709+
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
710+
711+
// write packet acknowledgement directly
712+
// Create a valid acknowledgement using deterministic serialization.
713+
ack = types.NewResultAcknowledgement([]byte{byte(1)}).Acknowledgement()
714+
// Introduce non-determinism: insert an extra space after the first character '{'
715+
// This will deserialize correctly but fail to re-serialize to the expected bytes.
716+
if len(ack) > 0 && ack[0] == '{' {
717+
ack = []byte("{ " + string(ack[1:]))
718+
}
719+
path.EndpointB.Chain.Coordinator.UpdateTimeForChain(path.EndpointB.Chain)
720+
721+
path.EndpointB.Chain.App.GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(path.EndpointB.Chain.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sequence, types.CommitAcknowledgement(ack))
722+
723+
path.EndpointB.Chain.NextBlock()
724+
path.EndpointA.UpdateClient()
725+
},
726+
false,
727+
},
728+
{
729+
"non-standard acknowledgement", func() {
730+
// setup uses an UNORDERED channel
731+
suite.coordinator.Setup(path)
732+
733+
// create packet commitment
734+
sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData)
735+
suite.Require().NoError(err)
736+
737+
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
738+
739+
// write packet acknowledgement directly
740+
ack = []byte(`{"somethingelse":"anything"}`)
741+
path.EndpointB.Chain.Coordinator.UpdateTimeForChain(path.EndpointB.Chain)
742+
743+
path.EndpointB.Chain.App.GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(path.EndpointB.Chain.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, sequence, types.CommitAcknowledgement(ack))
744+
745+
path.EndpointB.Chain.NextBlock()
746+
path.EndpointA.UpdateClient()
747+
},
748+
true,
749+
},
699750
{"channel not found", func() {
700751
expError = types.ErrChannelNotFound
701752

@@ -835,7 +886,7 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
835886
suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetPacketCommitment(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, packet.GetSequence(), types.CommitPacket(suite.chainA.App.AppCodec(), packet))
836887

837888
// manually set packet acknowledgement and capability
838-
suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, packet.GetSequence(), types.CommitAcknowledgement(ack.Acknowledgement()))
889+
suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, packet.GetSequence(), types.CommitAcknowledgement(ack))
839890

840891
suite.chainA.CreateChannelCapability(suite.chainA.GetSimApp().ScopedIBCMockKeeper, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
841892
channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
@@ -872,14 +923,15 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {
872923
suite.Run(fmt.Sprintf("Case %s, %d/%d tests", tc.msg, i, len(testCases)), func() {
873924
suite.SetupTest() // reset
874925
expError = nil // must explcitly set error for failed cases
926+
ack = ibcmock.MockAcknowledgement.Acknowledgement()
875927
path = ibctesting.NewPath(suite.chainA, suite.chainB)
876928

877929
tc.malleate()
878930

879931
packetKey := host.PacketAcknowledgementKey(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence())
880932
proof, proofHeight := path.EndpointB.QueryProof(packetKey)
881933

882-
err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.AcknowledgePacket(suite.chainA.GetContext(), channelCap, packet, ack.Acknowledgement(), proof, proofHeight)
934+
err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.AcknowledgePacket(suite.chainA.GetContext(), channelCap, packet, ack, proof, proofHeight)
883935
pc := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetPacketCommitment(suite.chainA.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence())
884936

885937
channelA, _ := suite.chainA.App.GetIBCKeeper().ChannelKeeper.GetChannel(suite.chainA.GetContext(), packet.GetSourcePort(), packet.GetSourceChannel())

0 commit comments

Comments
 (0)