-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* proto: adding genesis state * feat: add GetAllIdentifiedPacketFees * feat: adding genesis.go & updating proto + app.go * fix: removing PortId from genesis * feat: adding GetAll for relayer addr/fee enabled chan + update genesis * test: TestExportGenesis * feat: update type + hook up to module.go * fix: remove PortKey * fix: imports + remove scoped keeper * nit: using NewPacketId helper and updating helper def to have correct params
- Loading branch information
Showing
14 changed files
with
1,019 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
package keeper | ||
|
||
/* | ||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/modules/apps/29-fee/types" | ||
) | ||
|
||
// InitGenesis | ||
func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { | ||
for _, fee := range state.IdentifiedFees { | ||
k.SetFeeInEscrow(ctx, fee) | ||
} | ||
|
||
for _, addr := range state.RegisteredRelayers { | ||
k.SetCounterpartyAddress(ctx, addr.Address, addr.CounterpartyAddress) | ||
} | ||
|
||
for _, enabledChan := range state.FeeEnabledChannels { | ||
k.SetFeeEnabled(ctx, enabledChan.PortId, enabledChan.ChannelId) | ||
} | ||
} | ||
|
||
// ExportGenesis | ||
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { | ||
return &types.GenesisState{} | ||
return &types.GenesisState{ | ||
IdentifiedFees: k.GetAllIdentifiedPacketFees(ctx), | ||
FeeEnabledChannels: k.GetAllFeeEnabledChannels(ctx), | ||
RegisteredRelayers: k.GetAllRelayerAddresses(ctx), | ||
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"github.com/cosmos/ibc-go/modules/apps/29-fee/types" | ||
transfertypes "github.com/cosmos/ibc-go/modules/apps/transfer/types" | ||
ibctesting "github.com/cosmos/ibc-go/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestInitGenesis() { | ||
suite.SetupTest() | ||
|
||
// build PacketId & Fee | ||
refundAcc := suite.chainA.SenderAccount.GetAddress() | ||
packetId := types.NewPacketId( | ||
ibctesting.FirstChannelID, | ||
types.PortID, | ||
uint64(1), | ||
) | ||
fee := types.Fee{ | ||
validCoins, | ||
validCoins2, | ||
validCoins3, | ||
} | ||
|
||
// relayer addresses | ||
sender := suite.chainA.SenderAccount.GetAddress().String() | ||
counterparty := suite.chainB.SenderAccount.GetAddress().String() | ||
|
||
genesisState := types.GenesisState{ | ||
IdentifiedFees: []*types.IdentifiedPacketFee{ | ||
{ | ||
PacketId: packetId, | ||
Fee: fee, | ||
RefundAddress: refundAcc.String(), | ||
Relayers: nil, | ||
}, | ||
}, | ||
FeeEnabledChannels: []*types.FeeEnabledChannel{ | ||
{ | ||
PortId: transfertypes.PortID, | ||
ChannelId: ibctesting.FirstChannelID, | ||
}, | ||
}, | ||
RegisteredRelayers: []*types.RegisteredRelayerAddress{ | ||
{ | ||
Address: sender, | ||
CounterpartyAddress: counterparty, | ||
}, | ||
}, | ||
} | ||
|
||
suite.chainA.GetSimApp().IBCFeeKeeper.InitGenesis(suite.chainA.GetContext(), genesisState) | ||
|
||
// check fee | ||
identifiedFee, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetFeeInEscrow(suite.chainA.GetContext(), packetId) | ||
suite.Require().True(found) | ||
suite.Require().Equal(genesisState.IdentifiedFees[0], &identifiedFee) | ||
|
||
// check fee is enabled | ||
isEnabled := suite.chainA.GetSimApp().IBCFeeKeeper.IsFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID) | ||
suite.Require().True(isEnabled) | ||
|
||
// check relayers | ||
addr, found := suite.chainA.GetSimApp().IBCFeeKeeper.GetCounterpartyAddress(suite.chainA.GetContext(), sender) | ||
suite.Require().True(found) | ||
suite.Require().Equal(genesisState.RegisteredRelayers[0].CounterpartyAddress, addr) | ||
} | ||
|
||
func (suite *KeeperTestSuite) TestExportGenesis() { | ||
suite.SetupTest() | ||
// set fee enabled | ||
suite.chainA.GetSimApp().IBCFeeKeeper.SetFeeEnabled(suite.chainA.GetContext(), transfertypes.PortID, ibctesting.FirstChannelID) | ||
|
||
// setup & escrow the packet fee | ||
refundAcc := suite.chainA.SenderAccount.GetAddress() | ||
packetId := types.NewPacketId( | ||
ibctesting.FirstChannelID, | ||
types.PortID, | ||
uint64(1), | ||
) | ||
fee := types.Fee{ | ||
validCoins, | ||
validCoins2, | ||
validCoins3, | ||
} | ||
identifiedPacketFee := &types.IdentifiedPacketFee{PacketId: packetId, Fee: fee, RefundAddress: refundAcc.String(), Relayers: []string{}} | ||
err := suite.chainA.GetSimApp().IBCFeeKeeper.EscrowPacketFee(suite.chainA.GetContext(), identifiedPacketFee) | ||
suite.Require().NoError(err) | ||
|
||
// relayer addresses | ||
sender := suite.chainA.SenderAccount.GetAddress().String() | ||
counterparty := suite.chainB.SenderAccount.GetAddress().String() | ||
// set counterparty address | ||
suite.chainA.GetSimApp().IBCFeeKeeper.SetCounterpartyAddress(suite.chainA.GetContext(), sender, counterparty) | ||
|
||
// export genesis | ||
genesisState := suite.chainA.GetSimApp().IBCFeeKeeper.ExportGenesis(suite.chainA.GetContext()) | ||
|
||
// check fee enabled | ||
suite.Require().Equal(ibctesting.FirstChannelID, genesisState.FeeEnabledChannels[0].ChannelId) | ||
suite.Require().Equal(transfertypes.PortID, genesisState.FeeEnabledChannels[0].PortId) | ||
|
||
// check fee | ||
suite.Require().Equal(packetId, genesisState.IdentifiedFees[0].PacketId) | ||
suite.Require().Equal(fee, genesisState.IdentifiedFees[0].Fee) | ||
suite.Require().Equal(refundAcc.String(), genesisState.IdentifiedFees[0].RefundAddress) | ||
suite.Require().Equal([]string(nil), genesisState.IdentifiedFees[0].Relayers) | ||
|
||
// check registered relayer addresses | ||
suite.Require().Equal(sender, genesisState.RegisteredRelayers[0].Address) | ||
suite.Require().Equal(counterparty, genesisState.RegisteredRelayers[0].CounterpartyAddress) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.