Skip to content

Commit

Permalink
update interchain-test and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
anhductn2001 committed Jul 20, 2023
1 parent 4210bd0 commit 88dbcbc
Show file tree
Hide file tree
Showing 37 changed files with 434 additions and 438 deletions.
16 changes: 8 additions & 8 deletions proto/centauri/ratelimit/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ service Query {
option (google.api.http).get =
"/centauri/ratelimit/ratelimit/{channel_id}/by_denom";
}
rpc RateLimitsByChainId(QueryRateLimitsByChainIdRequest)
returns (QueryRateLimitsByChainIdResponse) {
rpc RateLimitsByChainID(QueryRateLimitsByChainIDRequest)
returns (QueryRateLimitsByChainIDResponse) {
option (google.api.http).get = "/centauri/ratelimit/ratelimits/{chain_id}";
}
rpc RateLimitsByChannelId(QueryRateLimitsByChannelIdRequest)
returns (QueryRateLimitsByChannelIdResponse) {
rpc RateLimitsByChannelID(QueryRateLimitsByChannelIDRequest)
returns (QueryRateLimitsByChannelIDResponse) {
option (google.api.http).get =
"/centauri/ratelimit/ratelimits/{channel_id}";
}
Expand All @@ -43,13 +43,13 @@ message QueryRateLimitRequest {
}
message QueryRateLimitResponse { RateLimit rate_limit = 1; }

message QueryRateLimitsByChainIdRequest { string chain_id = 1; }
message QueryRateLimitsByChainIdResponse {
message QueryRateLimitsByChainIDRequest { string chain_id = 1; }
message QueryRateLimitsByChainIDResponse {
repeated RateLimit rate_limits = 1 [ (gogoproto.nullable) = false ];
}

message QueryRateLimitsByChannelIdRequest { string channel_id = 1; }
message QueryRateLimitsByChannelIdResponse {
message QueryRateLimitsByChannelIDRequest { string channel_id = 1; }
message QueryRateLimitsByChannelIDResponse {
repeated RateLimit rate_limits = 1 [ (gogoproto.nullable) = false ];
}

Expand Down
8 changes: 4 additions & 4 deletions tests/interchaintest/polkadot_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func TestPolkadotComposableChainStart(t *testing.T) {
ChainID: "rococo-local",
Images: []ibc.DockerImage{
{
Repository: "seunlanlege/centauri-polkadot",
Version: "v0.9.27",
Repository: "parity/polkadot",
Version: "v0.9.39",
UidGid: "1000:1000",
},
{
Repository: "seunlanlege/centauri-parachain",
Version: "v0.9.27",
Repository: "composablefi/parachain-node",
Version: "13f3db34-1688755040",
// UidGid: "1025:1025",
},
},
Expand Down
4 changes: 2 additions & 2 deletions tests/interchaintest/upgrade_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (

func TestCentauriUpgrade(t *testing.T) {
repo, version := GetDockerImageInfo()
CosmosChainUpgradeTest(t, repo, version, "reward")
CosmosChainUpgradeTest(t, repo, version, "v4")
}

func CosmosChainUpgradeTest(t *testing.T, upgradeContainerRepo, upgradeVersion, upgradeName string) {
Expand All @@ -39,7 +39,7 @@ func CosmosChainUpgradeTest(t *testing.T, upgradeContainerRepo, upgradeVersion,
Images: []ibc.DockerImage{
{
Repository: "ghcr.io/notional-labs/centauri",
Version: "3.1.2",
Version: "3.2.3",
UidGid: "1025:1025",
},
},
Expand Down
2 changes: 1 addition & 1 deletion x/ratelimit/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (k Keeper) BeginBlocker(ctx sdk.Context) {
logger.Info(fmt.Sprintf("Starting new epoch with identifier %s epoch number %d", epochInfo.Identifier, epochInfo.CurrentEpoch))
} else {
k.AfterEpochEnd(ctx, epochInfo)
epochInfo.CurrentEpoch += 1
epochInfo.CurrentEpoch++
epochInfo.CurrentEpochStartTime = epochInfo.CurrentEpochStartTime.Add(epochInfo.Duration)
logger.Info(fmt.Sprintf("Starting epoch with identifier %s epoch number %d", epochInfo.Identifier, epochInfo.CurrentEpoch))
}
Expand Down
6 changes: 3 additions & 3 deletions x/ratelimit/keeper/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ func (k Keeper) NumBlocksSinceEpochStart(ctx sdk.Context, identifier string) (in
}

func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochInfo types.EpochInfo) {
if epochInfo.Identifier == types.DAY_EPOCH {
if epochInfo.Identifier == types.DayEpoch {
epochHour := uint64(epochInfo.CurrentEpoch)

for _, rateLimit := range k.GetAllRateLimits(ctx) {
if epochHour%rateLimit.Quota.DurationHours == 0 {
err := k.ResetRateLimit(ctx, rateLimit.Path.Denom, rateLimit.Path.ChannelId)
err := k.ResetRateLimit(ctx, rateLimit.Path.Denom, rateLimit.Path.ChannelID)
if err != nil {
k.Logger(ctx).Error(fmt.Sprintf("Unable to reset quota for Denom: %s, ChannelId: %s", rateLimit.Path.Denom, rateLimit.Path.ChannelId))
k.Logger(ctx).Error(fmt.Sprintf("Unable to reset quota for Denom: %s, ChannelID: %s", rateLimit.Path.Denom, rateLimit.Path.ChannelID))
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions x/ratelimit/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
for _, addressPair := range genState.WhitelistedAddressPairs {
k.SetWhitelistedAddressPair(ctx, addressPair)
}
for _, pendingPacketId := range genState.PendingSendPacketSequenceNumbers {
splits := strings.Split(pendingPacketId, "/")
for _, pendingPacketID := range genState.PendingSendPacketSequenceNumbers {
splits := strings.Split(pendingPacketID, "/")
if len(splits) != 2 {
panic("Invalid pending send packet, must be of form: {channelId}/{sequenceNumber}")
panic("Invalid pending send packet, must be of form: {channelID}/{sequenceNumber}")
}
channelId := splits[0]
channelID := splits[0]
sequence, err := strconv.ParseUint(splits[1], 10, 64)
if err != nil {
panic(err)
}
k.SetPendingSendPacket(ctx, channelId, sequence)
k.SetPendingSendPacket(ctx, channelID, sequence)
}
for _, epoch := range genState.Epochs {
err := k.AddEpochInfo(ctx, epoch)
Expand Down
24 changes: 12 additions & 12 deletions x/ratelimit/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@ import (
var _ types.QueryServer = Keeper{}

// Query all rate limits
func (k Keeper) AllRateLimits(goCtx context.Context, req *types.QueryAllRateLimitsRequest) (*types.QueryAllRateLimitsResponse, error) {
func (k Keeper) AllRateLimits(goCtx context.Context, _ *types.QueryAllRateLimitsRequest) (*types.QueryAllRateLimitsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
rateLimits := k.GetAllRateLimits(ctx)
return &types.QueryAllRateLimitsResponse{RateLimits: rateLimits}, nil
}

// Query a rate limit by denom and channelId
// Query a rate limit by denom and channelID
func (k Keeper) RateLimit(goCtx context.Context, req *types.QueryRateLimitRequest) (*types.QueryRateLimitResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
rateLimit, found := k.GetRateLimit(ctx, req.Denom, req.ChannelId)
rateLimit, found := k.GetRateLimit(ctx, req.Denom, req.ChannelID)
if !found {
return &types.QueryRateLimitResponse{}, nil
}
return &types.QueryRateLimitResponse{RateLimit: &rateLimit}, nil
}

// Query all rate limits for a given chain
func (k Keeper) RateLimitsByChainId(goCtx context.Context, req *types.QueryRateLimitsByChainIdRequest) (*types.QueryRateLimitsByChainIdResponse, error) {
func (k Keeper) RateLimitsByChainID(goCtx context.Context, req *types.QueryRateLimitsByChainIDRequest) (*types.QueryRateLimitsByChainIDResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

rateLimits := []types.RateLimit{}
for _, rateLimit := range k.GetAllRateLimits(ctx) {

// Determine the client state from the channel Id
_, clientState, err := k.channelKeeper.GetChannelClientState(ctx, transfertypes.PortID, rateLimit.Path.ChannelId)
_, clientState, err := k.channelKeeper.GetChannelClientState(ctx, transfertypes.PortID, rateLimit.Path.ChannelID)
if err != nil {
return &types.QueryRateLimitsByChainIdResponse{}, errorsmod.Wrapf(types.ErrInvalidClientState, "Unable to fetch client state from channelId")
return &types.QueryRateLimitsByChainIDResponse{}, errorsmod.Wrapf(types.ErrInvalidClientState, "Unable to fetch client state from channelID")
}
client, ok := clientState.(*ibctmtypes.ClientState)
if !ok {
return &types.QueryRateLimitsByChainIdResponse{}, errorsmod.Wrapf(types.ErrInvalidClientState, "Client state is not tendermint")
return &types.QueryRateLimitsByChainIDResponse{}, errorsmod.Wrapf(types.ErrInvalidClientState, "Client state is not tendermint")
}

// If the chain ID matches, add the rate limit to the returned list
Expand All @@ -52,26 +52,26 @@ func (k Keeper) RateLimitsByChainId(goCtx context.Context, req *types.QueryRateL
}
}

return &types.QueryRateLimitsByChainIdResponse{RateLimits: rateLimits}, nil
return &types.QueryRateLimitsByChainIDResponse{RateLimits: rateLimits}, nil
}

// Query all rate limits for a given channel
func (k Keeper) RateLimitsByChannelId(goCtx context.Context, req *types.QueryRateLimitsByChannelIdRequest) (*types.QueryRateLimitsByChannelIdResponse, error) {
func (k Keeper) RateLimitsByChannelID(goCtx context.Context, req *types.QueryRateLimitsByChannelIDRequest) (*types.QueryRateLimitsByChannelIDResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

rateLimits := []types.RateLimit{}
for _, rateLimit := range k.GetAllRateLimits(ctx) {
// If the channel ID matches, add the rate limit to the returned list
if rateLimit.Path.ChannelId == req.ChannelId {
if rateLimit.Path.ChannelID == req.ChannelID {
rateLimits = append(rateLimits, rateLimit)
}
}

return &types.QueryRateLimitsByChannelIdResponse{RateLimits: rateLimits}, nil
return &types.QueryRateLimitsByChannelIDResponse{RateLimits: rateLimits}, nil
}

// Query all whitelisted addresses
func (k Keeper) AllWhitelistedAddresses(goCtx context.Context, req *types.QueryAllWhitelistedAddressesRequest) (*types.QueryAllWhitelistedAddressesResponse, error) {
func (k Keeper) AllWhitelistedAddresses(goCtx context.Context, _ *types.QueryAllWhitelistedAddressesRequest) (*types.QueryAllWhitelistedAddressesResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
whitelistedAddresses := k.GetAllWhitelistedAddressPairs(ctx)
return &types.QueryAllWhitelistedAddressesResponse{AddressPairs: whitelistedAddresses}, nil
Expand Down
2 changes: 1 addition & 1 deletion x/ratelimit/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
}

// GetParams get all parameters as types.Params
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
func (k Keeper) GetParams(_ sdk.Context) types.Params {
return types.NewParams()
}

Expand Down
4 changes: 2 additions & 2 deletions x/ratelimit/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (k Keeper) RemoveTransferRateLimit(goCtx context.Context, msg *types.MsgRem
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}

err := k.RemoveRateLimit(ctx, msg.Denom, msg.ChannelId)
err := k.RemoveRateLimit(ctx, msg.Denom, msg.ChannelID)
if err != nil {
return nil, err
}
Expand All @@ -75,7 +75,7 @@ func (k Keeper) ResetTransferRateLimit(goCtx context.Context, msg *types.MsgRese
return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority)
}

err := k.ResetRateLimit(ctx, msg.Denom, msg.ChannelId)
err := k.ResetRateLimit(ctx, msg.Denom, msg.ChannelID)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions x/ratelimit/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (k Keeper) ParseDenomFromRecvPacket(packet channeltypes.Packet, packetData
return denom
}

// Parses the sender and channelId and denom for the corresponding RateLimit object, and
// Parses the sender and channelID and denom for the corresponding RateLimit object, and
// the sender/receiver/transfer amount
//
// The Stride channelID should always be used as the key for the RateLimit object (not the counterparty channelID)
Expand Down Expand Up @@ -190,7 +190,7 @@ func (k Keeper) ReceiveRateLimitedPacket(ctx sdk.Context, packet channeltypes.Pa
// Middleware implementation for OnAckPacket with rate limiting
// If the packet failed, we should decrement the Outflow
func (k Keeper) AcknowledgeRateLimitedPacket(ctx sdk.Context, packet channeltypes.Packet, ack []byte) error {
// Parse the denom, channelId, and amount from the packet
// Parse the denom, channelID, and amount from the packet
packetInfo, err := k.ParsePacketInfo(packet, types.PACKET_SEND)
if err != nil {
return err
Expand Down
Loading

0 comments on commit 88dbcbc

Please sign in to comment.