Skip to content

Commit

Permalink
sean/fix-proto-identified-fee-not-null
Browse files Browse the repository at this point in the history
  • Loading branch information
seantking committed Jan 20, 2022
1 parent 26731ce commit 45b28af
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 75 deletions.
4 changes: 2 additions & 2 deletions modules/apps/29-fee/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (suite *FeeTestSuite) TestOnRecvPacket() {
func (suite *FeeTestSuite) TestOnAcknowledgementPacket() {
var (
ack []byte
identifiedFee *types.IdentifiedPacketFee
identifiedFee types.IdentifiedPacketFee
originalBalance sdk.Coins
expectedBalance sdk.Coins
expectedRelayerBalance sdk.Coins
Expand Down Expand Up @@ -658,7 +658,7 @@ func (suite *FeeTestSuite) TestOnAcknowledgementPacket() {
func (suite *FeeTestSuite) TestOnTimeoutPacket() {
var (
relayerAddr sdk.AccAddress
identifiedFee *types.IdentifiedPacketFee
identifiedFee types.IdentifiedPacketFee
originalBalance sdk.Coins
expectedBalance sdk.Coins
)
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/29-fee/keeper/escrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

// EscrowPacketFee sends the packet fee to the 29-fee module account to hold in escrow
func (k Keeper) EscrowPacketFee(ctx sdk.Context, identifiedFee *types.IdentifiedPacketFee) error {
func (k Keeper) EscrowPacketFee(ctx sdk.Context, identifiedFee types.IdentifiedPacketFee) error {
if !k.IsFeeEnabled(ctx, identifiedFee.PacketId.PortId, identifiedFee.PacketId.ChannelId) {
// users may not escrow fees on this channel. Must send packets without a fee message
return sdkerrors.Wrap(types.ErrFeeNotEnabled, "cannot escrow fee for packet")
Expand Down
30 changes: 15 additions & 15 deletions modules/apps/29-fee/keeper/escrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (suite *KeeperTestSuite) TestEscrowPacketFee() {
AckFee: ackFee,
TimeoutFee: timeoutFee,
}
identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}}
identifiedPacketFee := types.NewIdentifiedPacketFee(packetId, fee, refundAcc.String(), []string{})

// refundAcc balance before escrow
originalBal := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), refundAcc, sdk.DefaultBondDenom)
Expand Down Expand Up @@ -158,7 +158,7 @@ func (suite *KeeperTestSuite) TestDistributeFee() {
// refundAcc balance after escrow
refundAccBal := suite.chainA.GetSimApp().BankKeeper.GetBalance(suite.chainA.GetContext(), refundAcc, sdk.DefaultBondDenom)

suite.chainA.GetSimApp().IBCFeeKeeper.DistributePacketFees(suite.chainA.GetContext(), refundAcc.String(), forwardRelayer, reverseRelayer, *identifiedPacketFee)
suite.chainA.GetSimApp().IBCFeeKeeper.DistributePacketFees(suite.chainA.GetContext(), refundAcc.String(), forwardRelayer, reverseRelayer, identifiedPacketFee)

if tc.expPass {
// there should no longer be a fee in escrow for this packet
Expand Down Expand Up @@ -212,14 +212,14 @@ func (suite *KeeperTestSuite) TestDistributeTimeoutFee() {
}

// escrow the packet fee & store the fee in state
identifiedPacketFee := types.IdentifiedPacketFee{
PacketId: packetId,
Fee: fee,
RefundAddress: refundAcc.String(),
Relayers: []string{},
}
identifiedPacketFee := types.NewIdentifiedPacketFee(
packetId,
fee,
refundAcc.String(),
[]string{},
)

err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), &identifiedPacketFee)
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee)
suite.Require().NoError(err)

// refundAcc balance after escrow
Expand Down Expand Up @@ -261,9 +261,9 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannel() {
TimeoutFee: defaultTimeoutFee,
}

identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}}
identifiedPacketFee := types.NewIdentifiedPacketFee(packetId, fee, refundAcc.String(), []string{})
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, "channel-0")
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), &identifiedPacketFee)
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee)
suite.Require().NoError(err)
}

Expand All @@ -275,9 +275,9 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannel() {
TimeoutFee: defaultTimeoutFee,
}

identifiedPacketFee := types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}}
identifiedPacketFee := types.NewIdentifiedPacketFee(packetId, fee, refundAcc.String(), []string{})
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, "channel-1")
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), &identifiedPacketFee)
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee)
suite.Require().NoError(err)

// check that refunding all fees on channel-0 refunds all fees except for fee on channel-1
Expand All @@ -291,8 +291,8 @@ func (suite *KeeperTestSuite) TestRefundFeesOnChannel() {
// create escrow and then change module account balance to cause error on refund
packetId = channeltypes.NewPacketId("channel-0", transfertypes.PortID, uint64(6))

identifiedPacketFee = types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}}
err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), &identifiedPacketFee)
identifiedPacketFee = types.NewIdentifiedPacketFee(packetId, fee, refundAcc.String(), []string{})
err = suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee)
suite.Require().NoError(err)

suite.chainA.GetSimApp().BankKeeper.SendCoinsFromModuleToAccount(suite.chainA.GetContext(), types.ModuleName, refundAcc, fee.TimeoutFee)
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/29-fee/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
counterparty := suite.chainB.SenderAccount.GetAddress().String()

genesisState := types.GenesisState{
IdentifiedFees: []*types.IdentifiedPacketFee{
IdentifiedFees: []types.IdentifiedPacketFee{
{
PacketId: packetId,
Fee: fee,
Expand All @@ -55,7 +55,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
// check fee
identifiedFee, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), packetId)
suite.Require().True(found)
suite.Require().Equal(genesisState.IdentifiedFees[0], &identifiedFee)
suite.Require().Equal(genesisState.IdentifiedFees[0], identifiedFee)

// check fee is enabled
isEnabled := suite.chainA.GetSimApp().IBCFeeKeeper.IsFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID)
Expand Down Expand Up @@ -84,7 +84,7 @@ func (suite *KeeperTestSuite) TestExportGenesis() {
defaultAckFee,
defaultTimeoutFee,
}
identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}}
identifiedPacketFee := types.NewIdentifiedPacketFee(packetId, fee, refundAcc.String(), []string{})
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee)
suite.Require().NoError(err)

Expand Down
6 changes: 3 additions & 3 deletions modules/apps/29-fee/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPacketI() {
if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(identifiedPacketFee, res.IncentivizedPacket)
suite.Require().Equal(&identifiedPacketFee, res.IncentivizedPacket)
} else {
suite.Require().Error(err)
}
Expand Down Expand Up @@ -120,11 +120,11 @@ func (suite *KeeperTestSuite) TestQueryIncentivizedPackets() {
fee3 := types.NewIdentifiedPacketFee(channeltypes.NewPacketId(ibctesting.FirstChannelID, transfertypes.PortID, 3), fee, refundAcc.String(), []string(nil))

expPackets = []*types.IdentifiedPacketFee{}
expPackets = append(expPackets, fee1, fee2, fee3)
expPackets = append(expPackets, &fee1, &fee2, &fee3)

suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID)
for _, p := range expPackets {
suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), p)
suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), *p)
}

req = &types.QueryIncentivizedPacketsRequest{
Expand Down
10 changes: 5 additions & 5 deletions modules/apps/29-fee/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ func (k Keeper) DeleteForwardRelayerAddress(ctx sdk.Context, packetId channeltyp
}

// Stores a Fee for a given packet in state
func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee *types.IdentifiedPacketFee) {
func (k Keeper) SetFeeInEscrow(ctx sdk.Context, fee types.IdentifiedPacketFee) {
store := ctx.KVStore(k.storeKey)
bz := k.MustMarshalFee(fee)
bz := k.MustMarshalFee(&fee)
store.Set(types.KeyFeeInEscrow(fee.PacketId), bz)
}

Expand Down Expand Up @@ -278,15 +278,15 @@ func (k Keeper) HasFeeInEscrow(ctx sdk.Context, packetId channeltypes.PacketId)
}

// GetAllIdentifiedPacketFees returns a list of all IdentifiedPacketFees that are stored in state
func (k Keeper) GetAllIdentifiedPacketFees(ctx sdk.Context) []*types.IdentifiedPacketFee {
func (k Keeper) GetAllIdentifiedPacketFees(ctx sdk.Context) []types.IdentifiedPacketFee {
store := ctx.KVStore(k.storeKey)
iterator := sdk.KVStorePrefixIterator(store, []byte(types.FeeInEscrowPrefix))
defer iterator.Close()

var identifiedFees []*types.IdentifiedPacketFee
var identifiedFees []types.IdentifiedPacketFee
for ; iterator.Valid(); iterator.Next() {
fee := k.MustUnmarshalFee(iterator.Value())
identifiedFees = append(identifiedFees, &fee)
identifiedFees = append(identifiedFees, fee)
}

return identifiedFees
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/29-fee/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ func (suite *KeeperTestSuite) TestGetAllIdentifiedPacketFees() {
refundAcc := suite.chainA.SenderAccount.GetAddress()
packetId := channeltypes.NewPacketId(suite.path.EndpointA.ChannelID, transfertypes.PortID, uint64(1))
fee := types.Fee{defaultAckFee, defaultReceiveFee, defaultTimeoutFee}
identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}}
identifiedPacketFee := types.NewIdentifiedPacketFee(packetId, fee, refundAcc.String(), []string{})

// escrow the packet fee
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee)
suite.Require().NoError(err)

expectedFees := []*types.IdentifiedPacketFee{
expectedFees := []types.IdentifiedPacketFee{
{
PacketId: packetId,
Fee: fee,
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/29-fee/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (k Keeper) PayPacketFee(goCtx context.Context, msg *types.MsgPayPacketFee)
func (k Keeper) PayPacketFeeAsync(goCtx context.Context, msg *types.MsgPayPacketFeeAsync) (*types.MsgPayPacketFeeAsyncResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

err := k.EscrowPacketFee(ctx, &msg.IdentifiedPacketFee)
err := k.EscrowPacketFee(ctx, msg.IdentifiedPacketFee)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/29-fee/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// NewGenesisState creates a 29-fee GenesisState instance.
func NewGenesisState(identifiedFees []*IdentifiedPacketFee, feeEnabledChannels []*FeeEnabledChannel, registeredRelayers []*RegisteredRelayerAddress) *GenesisState {
func NewGenesisState(identifiedFees []IdentifiedPacketFee, feeEnabledChannels []*FeeEnabledChannel, registeredRelayers []*RegisteredRelayerAddress) *GenesisState {
return &GenesisState{
IdentifiedFees: identifiedFees,
FeeEnabledChannels: feeEnabledChannels,
Expand All @@ -19,7 +19,7 @@ func NewGenesisState(identifiedFees []*IdentifiedPacketFee, feeEnabledChannels [
// DefaultGenesisState returns a GenesisState with "transfer" as the default PortID.
func DefaultGenesisState() *GenesisState {
return &GenesisState{
IdentifiedFees: []*IdentifiedPacketFee{},
IdentifiedFees: []IdentifiedPacketFee{},
FeeEnabledChannels: []*FeeEnabledChannel{},
RegisteredRelayers: []*RegisteredRelayerAddress{},
}
Expand Down
Loading

0 comments on commit 45b28af

Please sign in to comment.