Skip to content

Commit

Permalink
refactor: add Denom type and embed into Token (#6409)
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner authored May 28, 2024
1 parent 534f8a4 commit a4511a7
Show file tree
Hide file tree
Showing 14 changed files with 1,159 additions and 455 deletions.
36 changes: 24 additions & 12 deletions modules/apps/callbacks/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ func (s *CallbacksTestSuite) TestSendPacket() {
packetData = transfertypes.NewFungibleTokenPacketDataV2(
[]transfertypes.Token{
{
Denom: ibctesting.TestCoin.GetDenom(),
Denom: transfertypes.Denom{
Base: ibctesting.TestCoin.GetDenom(),
Trace: []string{},
},
Amount: ibctesting.TestCoin.Amount.String(),
Trace: []string{},
},
},
ibctesting.TestAccAddress,
Expand Down Expand Up @@ -309,9 +311,11 @@ func (s *CallbacksTestSuite) TestOnAcknowledgementPacket() {
packetData = transfertypes.NewFungibleTokenPacketDataV2(
[]transfertypes.Token{
{
Denom: ibctesting.TestCoin.GetDenom(),
Denom: transfertypes.Denom{
Base: ibctesting.TestCoin.GetDenom(),
Trace: []string{},
},
Amount: ibctesting.TestCoin.Amount.String(),
Trace: []string{},
},
},
ibctesting.TestAccAddress,
Expand Down Expand Up @@ -642,9 +646,11 @@ func (s *CallbacksTestSuite) TestOnRecvPacket() {
packetData = transfertypes.NewFungibleTokenPacketDataV2(
[]transfertypes.Token{
{
Denom: ibctesting.TestCoin.GetDenom(),
Denom: transfertypes.Denom{
Base: ibctesting.TestCoin.GetDenom(),
Trace: []string{},
},
Amount: ibctesting.TestCoin.Amount.String(),
Trace: []string{},
},
},
ibctesting.TestAccAddress,
Expand Down Expand Up @@ -774,9 +780,11 @@ func (s *CallbacksTestSuite) TestWriteAcknowledgement() {
packetData = transfertypes.NewFungibleTokenPacketDataV2(
[]transfertypes.Token{
{
Denom: ibctesting.TestCoin.GetDenom(),
Denom: transfertypes.Denom{
Base: ibctesting.TestCoin.GetDenom(),
Trace: []string{},
},
Amount: ibctesting.TestCoin.Amount.String(),
Trace: []string{},
},
},
ibctesting.TestAccAddress,
Expand Down Expand Up @@ -998,9 +1006,11 @@ func (s *CallbacksTestSuite) TestUnmarshalPacketDataV1() {
expPacketDataICS20V2 := transfertypes.FungibleTokenPacketDataV2{
Tokens: []transfertypes.Token{
{
Denom: ibctesting.TestCoin.Denom,
Denom: transfertypes.Denom{
Base: ibctesting.TestCoin.Denom,
Trace: nil,
},
Amount: ibctesting.TestCoin.Amount.String(),
Trace: nil,
},
},
Sender: ibctesting.TestAccAddress,
Expand Down Expand Up @@ -1032,9 +1042,11 @@ func (s *CallbacksTestSuite) TestUnmarshalPacketDataV2() {
expPacketDataICS20V2 := transfertypes.FungibleTokenPacketDataV2{
Tokens: []transfertypes.Token{
{
Denom: ibctesting.TestCoin.Denom,
Denom: transfertypes.Denom{
Base: ibctesting.TestCoin.Denom,
Trace: nil,
},
Amount: ibctesting.TestCoin.Amount.String(),
Trace: nil,
},
},
Sender: ibctesting.TestAccAddress,
Expand Down
18 changes: 12 additions & 6 deletions modules/apps/transfer/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,11 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() {
initialPacketData = types.FungibleTokenPacketDataV2{
Tokens: []types.Token{
{
Denom: "atom",
Denom: types.Denom{
Base: "atom",
Trace: []string{"transfer/channel-0"},
},
Amount: ibctesting.TestCoin.Amount.String(),
Trace: []string{"transfer/channel-0"},
},
},
Sender: sender,
Expand All @@ -576,9 +578,11 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() {
initialPacketData = types.FungibleTokenPacketDataV2{
Tokens: []types.Token{
{
Denom: ibctesting.TestCoin.Denom,
Denom: types.Denom{
Base: ibctesting.TestCoin.Denom,
Trace: nil,
},
Amount: ibctesting.TestCoin.Amount.String(),
Trace: nil,
},
},
Sender: sender,
Expand All @@ -597,9 +601,11 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() {
initialPacketData = types.FungibleTokenPacketDataV2{
Tokens: []types.Token{
{
Denom: ibctesting.TestCoin.Denom,
Denom: types.Denom{
Base: ibctesting.TestCoin.Denom,
Trace: []string{""},
},
Amount: ibctesting.TestCoin.Amount.String(),
Trace: []string{""},
},
},
Sender: sender,
Expand Down
6 changes: 4 additions & 2 deletions modules/apps/transfer/internal/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ func PacketDataV1ToV2(packetData types.FungibleTokenPacketData) types.FungibleTo
return types.FungibleTokenPacketDataV2{
Tokens: []types.Token{
{
Denom: v2Denom,
Denom: types.Denom{
Base: v2Denom,
Trace: trace,
},
Amount: packetData.Amount,
Trace: trace,
},
},
Sender: packetData.Sender,
Expand Down
42 changes: 28 additions & 14 deletions modules/apps/transfer/internal/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ func TestConvertPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: "atom",
Denom: types.Denom{
Base: "atom",
Trace: []string{"transfer/channel-0"},
},
Amount: "1000",
Trace: []string{"transfer/channel-0"},
},
}, sender, receiver, ""),
nil,
Expand All @@ -41,9 +43,11 @@ func TestConvertPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: "atom",
Denom: types.Denom{
Base: "atom",
Trace: nil,
},
Amount: "1000",
Trace: nil,
},
}, sender, receiver, ""),
nil,
Expand All @@ -54,9 +58,11 @@ func TestConvertPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: "atom/withslash",
Denom: types.Denom{
Base: "atom/withslash",
Trace: []string{"transfer/channel-0"},
},
Amount: "1000",
Trace: []string{"transfer/channel-0"},
},
}, sender, receiver, ""),
nil,
Expand All @@ -67,9 +73,11 @@ func TestConvertPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: "atom/",
Denom: types.Denom{
Base: "atom/",
Trace: []string{"transfer/channel-0"},
},
Amount: "1000",
Trace: []string{"transfer/channel-0"},
},
}, sender, receiver, ""),
nil,
Expand All @@ -80,9 +88,11 @@ func TestConvertPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: "atom/pool",
Denom: types.Denom{
Base: "atom/pool",
Trace: []string{"transfer/channel-0", "transfer/channel-1"},
},
Amount: "1000",
Trace: []string{"transfer/channel-0", "transfer/channel-1"},
},
}, sender, receiver, ""),
nil,
Expand All @@ -93,9 +103,11 @@ func TestConvertPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: "atom",
Denom: types.Denom{
Base: "atom",
Trace: []string{"transfer/channel-0", "transfer/channel-1", "transfer-custom/channel-2"},
},
Amount: "1000",
Trace: []string{"transfer/channel-0", "transfer/channel-1", "transfer-custom/channel-2"},
},
}, sender, receiver, ""),
nil,
Expand All @@ -106,9 +118,11 @@ func TestConvertPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: "atom/pool",
Denom: types.Denom{
Base: "atom/pool",
Trace: []string{"transfer/channel-0", "transfer/channel-1", "transfer-custom/channel-2"},
},
Amount: "1000",
Trace: []string{"transfer/channel-0", "transfer/channel-1", "transfer-custom/channel-2"},
},
}, sender, receiver, ""),
nil,
Expand Down
6 changes: 4 additions & 2 deletions modules/apps/transfer/keeper/mbt_relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ func FungibleTokenPacketFromTla(packet TlaFungibleTokenPacket) FungibleTokenPack
Data: types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: denom,
Denom: types.Denom{
Base: denom,
Trace: trace,
},
Amount: packet.Data.Amount,
Trace: trace,
},
},
AddressFromString(packet.Data.Sender),
Expand Down
6 changes: 4 additions & 2 deletions modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ func (k Keeper) sendTransfer(

denom, trace := convertinternal.ExtractDenomAndTraceFromV1Denom(fullDenomPath)
token := types.Token{
Denom: denom,
Denom: types.Denom{
Base: denom,
Trace: trace,
},
Amount: coin.Amount.String(),
Trace: trace,
}
tokens = append(tokens, token)
}
Expand Down
42 changes: 28 additions & 14 deletions modules/apps/transfer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,11 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsNotSource() {
data := types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: sdk.DefaultBondDenom,
Denom: types.Denom{
Base: sdk.DefaultBondDenom,
Trace: []string{},
},
Amount: amount.String(),
Trace: []string{},
},
}, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo)
packet := channeltypes.NewPacket(data.GetBytes(), seq, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0)
Expand Down Expand Up @@ -510,9 +512,11 @@ func (suite *KeeperTestSuite) TestOnRecvPacket_ReceiverIsSource() {
data := types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: denom,
Denom: types.Denom{
Base: denom,
Trace: trace,
},
Amount: amount.String(),
Trace: trace,
},
}, suite.chainA.SenderAccount.GetAddress().String(), receiver, memo)
packet = channeltypes.NewPacket(data.GetBytes(), seq, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0)
Expand Down Expand Up @@ -589,9 +593,11 @@ func (suite *KeeperTestSuite) TestOnRecvPacketSetsTotalEscrowAmountForSourceIBCT
data := types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: denom,
Denom: types.Denom{
Base: denom,
Trace: trace,
},
Amount: amount.String(),
Trace: trace,
},
}, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "")
packet := channeltypes.NewPacket(
Expand Down Expand Up @@ -721,9 +727,11 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacket() {
data := types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: denom,
Denom: types.Denom{
Base: denom,
Trace: trace,
},
Amount: amount.String(),
Trace: trace,
},
}, suite.chainA.SenderAccount.GetAddress().String(), suite.chainB.SenderAccount.GetAddress().String(), "")
packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0)
Expand Down Expand Up @@ -816,9 +824,11 @@ func (suite *KeeperTestSuite) TestOnAcknowledgementPacketSetsTotalEscrowAmountFo
data := types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: denom,
Denom: types.Denom{
Base: denom,
Trace: trace,
},
Amount: amount.String(),
Trace: trace,
},
},
suite.chainB.SenderAccount.GetAddress().String(),
Expand Down Expand Up @@ -945,9 +955,11 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacket() {
data := types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: denom,
Denom: types.Denom{
Base: denom,
Trace: trace,
},
Amount: amount.String(),
Trace: trace,
},
}, sender, suite.chainB.SenderAccount.GetAddress().String(), "")
packet := channeltypes.NewPacket(data.GetBytes(), 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0)
Expand Down Expand Up @@ -1033,9 +1045,11 @@ func (suite *KeeperTestSuite) TestOnTimeoutPacketSetsTotalEscrowAmountForSourceI
data := types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: denom,
Denom: types.Denom{
Base: denom,
Trace: trace,
},
Amount: amount.String(),
Trace: trace,
},
}, suite.chainB.SenderAccount.GetAddress().String(), suite.chainA.SenderAccount.GetAddress().String(), "")
packet := channeltypes.NewPacket(
Expand Down
Loading

0 comments on commit a4511a7

Please sign in to comment.