Skip to content

Commit

Permalink
Merge branch 'main' into jim/internal-telemetry-core
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim authored Jul 8, 2024
2 parents 1260f26 + 45342f2 commit f3066ef
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 125 deletions.
80 changes: 49 additions & 31 deletions modules/apps/29-fee/keeper/escrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,18 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() {
expEscrowBal sdk.Coins
expRefundBal sdk.Coins
refundAcc sdk.AccAddress
fee types.Fee
)

fee := types.Fee{
RecvFee: defaultRecvFee,
AckFee: defaultAckFee,
TimeoutFee: defaultTimeoutFee,
}

testCases := []struct {
name string
malleate func()
locked bool
name string
malleate func()
expResult func(originalRefundBal, originalEscrowBal, refundBal, escrowBal sdk.Coins)
}{
{
"success", func() {
Expand All @@ -420,7 +425,12 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() {
err := suite.chainA.GetSimApp().BankKeeper.SendCoinsFromAccountToModule(suite.chainA.GetContext(), refundAcc, types.ModuleName, fee.Total())
suite.Require().NoError(err)
}
}, false,
}, func(_, _, refundBal, escrowBal sdk.Coins) {
suite.Require().False(suite.chainA.GetSimApp().IBCFeeKeeper.IsLocked(suite.chainA.GetContext()))
suite.Require().Empty(suite.chainA.GetSimApp().IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID))
suite.Require().Empty(escrowBal)
suite.Require().Equal(expRefundBal, refundBal)
},
},
{
"success with undistributed packet fees on a different channel", func() {
Expand All @@ -445,7 +455,12 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() {

expEscrowBal = fee.Total()
expRefundBal = expRefundBal.Sub(fee.Total()...)
}, false,
}, func(_, _, refundBal, escrowBal sdk.Coins) {
suite.Require().False(suite.chainA.GetSimApp().IBCFeeKeeper.IsLocked(suite.chainA.GetContext()))
suite.Require().Empty(suite.chainA.GetSimApp().IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID))
suite.Require().Equal(expEscrowBal, escrowBal)
suite.Require().Equal(expRefundBal, refundBal)
},
},
{
"escrow account empty, module should become locked", func() {
Expand All @@ -457,7 +472,12 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() {
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeesInEscrow(suite.chainA.GetContext(), packetID, packetFees)

expIdentifiedPacketFees = []types.IdentifiedPacketFees{identifiedPacketFees}
}, true,
}, func(originalRefundBal, originalEscrowBal, refundBal, escrowBal sdk.Coins) {
suite.Require().True(suite.chainA.GetSimApp().IBCFeeKeeper.IsLocked(suite.chainA.GetContext()))
suite.Require().Equal(expIdentifiedPacketFees, suite.chainA.GetSimApp().IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID))
suite.Require().Equal(originalRefundBal, refundBal)
suite.Require().Equal(originalEscrowBal, escrowBal)
},
},
{
"escrow account goes negative on second packet, module should become locked", func() {
Expand All @@ -476,7 +496,12 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() {
suite.Require().NoError(err)

expIdentifiedPacketFees = []types.IdentifiedPacketFees{identifiedPacketFee1, identifiedPacketFee2}
}, true,
}, func(originalRefundBal, originalEscrowBal, refundBal, escrowBal sdk.Coins) {
suite.Require().True(suite.chainA.GetSimApp().IBCFeeKeeper.IsLocked(suite.chainA.GetContext()))
suite.Require().Equal(expIdentifiedPacketFees, suite.chainA.GetSimApp().IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID))
suite.Require().Equal(originalRefundBal, refundBal)
suite.Require().Equal(originalEscrowBal, escrowBal)
},
},
{
"invalid refund acc address", func() {
Expand All @@ -497,7 +522,12 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() {

expEscrowBal = fee.Total()
expRefundBal = expRefundBal.Sub(fee.Total()...)
}, false,
}, func(_, _, refundBal, escrowBal sdk.Coins) {
suite.Require().False(suite.chainA.GetSimApp().IBCFeeKeeper.IsLocked(suite.chainA.GetContext()))
suite.Require().Equal(expIdentifiedPacketFees, suite.chainA.GetSimApp().IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID))
suite.Require().Equal(expEscrowBal, escrowBal)
suite.Require().Equal(expRefundBal, refundBal)
},
},
{
"distributing to blocked address is skipped", func() {
Expand All @@ -520,7 +550,12 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() {

expEscrowBal = fee.Total()
expRefundBal = expRefundBal.Sub(fee.Total()...)
}, false,
}, func(_, _, refundBal, escrowBal sdk.Coins) {
suite.Require().False(suite.chainA.GetSimApp().IBCFeeKeeper.IsLocked(suite.chainA.GetContext()))
suite.Require().Equal(expIdentifiedPacketFees, suite.chainA.GetSimApp().IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID))
suite.Require().Equal(expEscrowBal, escrowBal)
suite.Require().Equal(expRefundBal, refundBal)
},
},
}

Expand All @@ -531,46 +566,29 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannelClosure() {
suite.SetupTest() // reset
suite.path.Setup() // setup channel
expIdentifiedPacketFees = []types.IdentifiedPacketFees(nil)
expEscrowBal = sdk.Coins{}

// setup
refundAcc = suite.chainA.SenderAccount.GetAddress()
moduleAcc := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeModuleAddress()

// expected refund balance if the refunds are successful
// NOTE: tc.malleate() should transfer from refund balance to correctly set the escrow balance
expRefundBal = suite.chainA.GetSimApp().BankKeeper.GetAllBalances(suite.chainA.GetContext(), refundAcc)

fee = types.Fee{
RecvFee: defaultRecvFee,
AckFee: defaultAckFee,
TimeoutFee: defaultTimeoutFee,
}

tc.malleate()

// refundAcc balance before distribution
// original balance before RefundFeesOnChannelClosure
originalRefundBal := suite.chainA.GetSimApp().BankKeeper.GetAllBalances(suite.chainA.GetContext(), refundAcc)
originalEscrowBal := suite.chainA.GetSimApp().BankKeeper.GetAllBalances(suite.chainA.GetContext(), moduleAcc)

// perform refund fees on channel closure
err := suite.chainA.GetSimApp().IBCFeeKeeper.RefundFeesOnChannelClosure(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID)
suite.Require().NoError(err)
suite.NoError(err)

// refundAcc balance after RefundFeesOnChannelClosure
refundBal := suite.chainA.GetSimApp().BankKeeper.GetAllBalances(suite.chainA.GetContext(), refundAcc)
escrowBal := suite.chainA.GetSimApp().BankKeeper.GetAllBalances(suite.chainA.GetContext(), moduleAcc)

suite.Require().Equal(tc.locked, suite.chainA.GetSimApp().IBCFeeKeeper.IsLocked(suite.chainA.GetContext()))
suite.Require().Equal(expIdentifiedPacketFees, suite.chainA.GetSimApp().IBCFeeKeeper.GetIdentifiedPacketFeesForChannel(suite.chainA.GetContext(), suite.path.EndpointA.ChannelConfig.PortID, suite.path.EndpointA.ChannelID))

if tc.locked {
// refund account and escrow account balances should remain unchanged
suite.Require().Equal(originalRefundBal, refundBal)
suite.Require().Equal(originalEscrowBal, escrowBal)
} else {
suite.Require().Equal(expEscrowBal, escrowBal) // escrow balance should be empty
suite.Require().Equal(expRefundBal, refundBal) // all packets should have been refunded
}
tc.expResult(originalRefundBal, originalEscrowBal, refundBal, escrowBal)
})
}
}
12 changes: 5 additions & 7 deletions modules/apps/callbacks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
ibcmock "github.com/cosmos/ibc-go/v8/testing/mock"
)

var emptyForwardingPacketData = transfertypes.ForwardingPacketData{}

func (s *CallbacksTestSuite) TestNewIBCMiddleware() {
testCases := []struct {
name string
Expand Down Expand Up @@ -189,7 +187,7 @@ func (s *CallbacksTestSuite) TestSendPacket() {
ibctesting.TestAccAddress,
ibctesting.TestAccAddress,
fmt.Sprintf(`{"src_callback": {"address": "%s"}}`, simapp.SuccessContract),
emptyForwardingPacketData,
ibctesting.EmptyForwardingPacketData,
)

chanCap := s.path.EndpointA.Chain.GetChannelCapability(s.path.EndpointA.ChannelConfig.PortID, s.path.EndpointA.ChannelID)
Expand Down Expand Up @@ -331,7 +329,7 @@ func (s *CallbacksTestSuite) TestOnAcknowledgementPacket() {
ibctesting.TestAccAddress,
ibctesting.TestAccAddress,
fmt.Sprintf(`{"src_callback": {"address":"%s", "gas_limit":"%d"}}`, simapp.SuccessContract, userGasLimit),
emptyForwardingPacketData,
ibctesting.EmptyForwardingPacketData,
)

packet = channeltypes.Packet{
Expand Down Expand Up @@ -665,7 +663,7 @@ func (s *CallbacksTestSuite) TestOnRecvPacket() {
ibctesting.TestAccAddress,
s.chainB.SenderAccount.GetAddress().String(),
fmt.Sprintf(`{"dest_callback": {"address":"%s", "gas_limit":"%d"}}`, ibctesting.TestAccAddress, userGasLimit),
emptyForwardingPacketData,
ibctesting.EmptyForwardingPacketData,
)

packet = channeltypes.Packet{
Expand Down Expand Up @@ -797,7 +795,7 @@ func (s *CallbacksTestSuite) TestWriteAcknowledgement() {
ibctesting.TestAccAddress,
s.chainB.SenderAccount.GetAddress().String(),
fmt.Sprintf(`{"dest_callback": {"address":"%s", "gas_limit":"600000"}}`, ibctesting.TestAccAddress),
emptyForwardingPacketData,
ibctesting.EmptyForwardingPacketData,
)

packet = channeltypes.Packet{
Expand Down Expand Up @@ -1021,7 +1019,7 @@ func (s *CallbacksTestSuite) TestUnmarshalPacketDataV1() {
Sender: ibctesting.TestAccAddress,
Receiver: ibctesting.TestAccAddress,
Memo: fmt.Sprintf(`{"src_callback": {"address": "%s"}, "dest_callback": {"address":"%s"}}`, ibctesting.TestAccAddress, ibctesting.TestAccAddress),
Forwarding: emptyForwardingPacketData,
Forwarding: ibctesting.EmptyForwardingPacketData,
}

portID := s.path.EndpointA.ChannelConfig.PortID
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func (suite *TransferTestSuite) TestOnRecvPacket() {
suite.chainA.SenderAccount.GetAddress().String(),
suite.chainB.SenderAccount.GetAddress().String(),
"",
types.ForwardingPacketData{},
ibctesting.EmptyForwardingPacketData,
)

tokensBz, err := json.Marshal(packetData.Tokens)
Expand Down
20 changes: 9 additions & 11 deletions modules/apps/transfer/internal/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const (
receiver = "receiver"
)

var emptyForwardingPacketData = types.ForwardingPacketData{}

func TestUnmarshalPacketData(t *testing.T) {
var (
packetDataBz []byte
Expand All @@ -43,7 +41,7 @@ func TestUnmarshalPacketData(t *testing.T) {
Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData)
}, sender, receiver, "", types.ForwardingPacketData{})

packetDataBz = packetData.GetBytes()
version = types.V2
Expand Down Expand Up @@ -115,7 +113,7 @@ func TestV2ForwardsCompatibilityFails(t *testing.T) {
Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")),
Amount: "1000",
},
}, "sender", "receiver", "", emptyForwardingPacketData,
}, "sender", "receiver", "", types.ForwardingPacketData{},
)

packetDataBz = packet.GetBytes()
Expand Down Expand Up @@ -155,7 +153,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
}, sender, receiver, "", types.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -167,7 +165,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
Denom: types.NewDenom("atom"),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
}, sender, receiver, "", types.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -179,7 +177,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
Denom: types.NewDenom("atom/withslash", types.NewHop("transfer", "channel-0")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
}, sender, receiver, "", types.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -191,7 +189,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
Denom: types.NewDenom("atom/", types.NewHop("transfer", "channel-0")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
}, sender, receiver, "", types.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -203,7 +201,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
Denom: types.NewDenom("atom/pool", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
}, sender, receiver, "", types.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -215,7 +213,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1"), types.NewHop("transfer-custom", "channel-2")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
}, sender, receiver, "", types.ForwardingPacketData{}),
nil,
},
{
Expand All @@ -227,7 +225,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
Denom: types.NewDenom("atom/pool", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1"), types.NewHop("transfer-custom", "channel-2")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
}, sender, receiver, "", types.ForwardingPacketData{}),
nil,
},
{
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/mbt_relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func FungibleTokenPacketFromTla(packet TlaFungibleTokenPacket) FungibleTokenPack
AddressFromString(packet.Data.Sender),
AddressFromString(packet.Data.Receiver),
"",
types.ForwardingPacketData{},
ibctesting.EmptyForwardingPacketData,
),
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/relay_forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketForwarding() {
},
address,
receiver.GetAddress().String(),
"", types.ForwardingPacketData{},
"", ibctesting.EmptyForwardingPacketData,
)

packet = channeltypes.NewPacket(
Expand Down
Loading

0 comments on commit f3066ef

Please sign in to comment.