Skip to content

Commit

Permalink
Merge branch 'main' into dong/TestRemoveZoneAndAssociatedRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Nov 1, 2023
2 parents d5a9140 + 1399c5e commit 247617b
Show file tree
Hide file tree
Showing 31 changed files with 1,342 additions and 826 deletions.
6 changes: 2 additions & 4 deletions icq-relayer/cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ const (
defaultCoinType uint32 = sdk.CoinType
)

var (
// FlagAccountPrefix allows the user to override the prefix for a given account
FlagAccountPrefix = ""
)
// FlagAccountPrefix allows the user to override the prefix for a given account
var FlagAccountPrefix = ""

// keysCmd represents the keys command
func keysCmd() *cobra.Command {
Expand Down
16 changes: 6 additions & 10 deletions icq-relayer/pkg/runner/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ type Query struct {
}

func handleHistoricRequests(queries []qstypes.Query, sourceChainId string, logger log.Logger, metrics prommetrics.Metrics) {

metrics.HistoricQueries.WithLabelValues("historic-queries").Set(float64(len(queries)))

if len(queries) == 0 {
Expand Down Expand Up @@ -363,7 +362,6 @@ func handleEvent(event coretypes.ResultEvent, logger log.Logger, metrics prommet
}

func RunGRPCQuery(ctx context.Context, client *lensclient.ChainClient, method string, reqBz []byte, md metadata.MD, metrics prommetrics.Metrics) (abcitypes.ResponseQuery, metadata.MD, error) {

// parse height header
height, err := lensclient.GetHeightFromMetadata(md)
if err != nil {
Expand Down Expand Up @@ -420,6 +418,7 @@ func retryLightblock(ctx context.Context, client *lensclient.ChainClient, height
}
return lightBlock.(*tmtypes.LightBlock), err
}

func doRequestWithMetrics(query Query, logger log.Logger, metrics prommetrics.Metrics) {
startTime := time.Now()
metrics.Requests.WithLabelValues("requests", query.Type).Inc()
Expand Down Expand Up @@ -609,7 +608,6 @@ func getHeader(ctx context.Context, client, submitClient *lensclient.ChainClient
clientHeight, ok := trustedHeight.(clienttypes.Height)
if !ok {
return nil, fmt.Errorf("error: Could coerce trusted height")

}

if !historicOk && clientHeight.RevisionHeight >= uint64(requestHeight+1) {
Expand Down Expand Up @@ -649,7 +647,6 @@ func getHeader(ctx context.Context, client, submitClient *lensclient.ChainClient
}

func getBlocksForTxResults(node rpcclient.Client, resTxs []*coretypes.ResultTx) (map[int64]*coretypes.ResultBlock, error) {

resBlocks := make(map[int64]*coretypes.ResultBlock)

for _, resTx := range resTxs {
Expand Down Expand Up @@ -721,26 +718,26 @@ func flush(chainId string, toSend []sdk.Msg, logger log.Logger, metrics prommetr
resp, err := chainClient.SendMsgs(ctx, msgs, VERSION)
if err != nil {
if resp != nil && resp.Code == 19 && resp.Codespace == "sdk" {
//if err.Error() == "transaction failed with code: 19" {
// if err.Error() == "transaction failed with code: 19" {
_ = logger.Log("msg", "Tx already in mempool")
} else if resp != nil && resp.Code == 12 && resp.Codespace == "sdk" {
//if err.Error() == "transaction failed with code: 19" {
// if err.Error() == "transaction failed with code: 19" {
_ = logger.Log("msg", "Not enough gas")
} else if err.Error() == "context deadline exceeded" {
_ = logger.Log("msg", "Failed to submit in time, retrying")
resp, err := chainClient.SendMsgs(ctx, msgs, VERSION)
if err != nil {
if resp != nil && resp.Code == 19 && resp.Codespace == "sdk" {
//if err.Error() == "transaction failed with code: 19" {
// if err.Error() == "transaction failed with code: 19" {
_ = logger.Log("msg", "Tx already in mempool")
} else if resp != nil && resp.Code == 12 && resp.Codespace == "sdk" {
//if err.Error() == "transaction failed with code: 19" {
// if err.Error() == "transaction failed with code: 19" {
_ = logger.Log("msg", "Not enough gas")
} else if err.Error() == "context deadline exceeded" {
_ = logger.Log("msg", "Failed to submit in time, bailing")
return
} else {
//panic(fmt.Sprintf("panic(1): %v", err))
// panic(fmt.Sprintf("panic(1): %v", err))
_ = logger.Log("msg", "Failed to submit after retry; nevermind, we'll try again!", "err", err)
metrics.FailedTxs.WithLabelValues("failed_txs").Inc()
}
Expand Down Expand Up @@ -789,7 +786,6 @@ func unique(msgSlice []sdk.Msg, logger log.Logger) []sdk.Msg {
}

func Close() error {

query := tmquery.MustParse(fmt.Sprintf("message.module='%s'", "interchainquery"))

for _, chainClient := range globalCfg.Cl {
Expand Down
70 changes: 35 additions & 35 deletions x/airdrop/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,40 +58,40 @@ func (*KeeperTestSuite) GetQuicksilverApp(chain *ibctesting.TestChain) *app.Quic
}

// SetupTest creates a coordinator with 2 test chains.
func (s *KeeperTestSuite) SetupTest() {
s.coordinator = ibctesting.NewCoordinator(s.T(), 2) // initializes 2 test chains
s.chainA = s.coordinator.GetChain(ibctesting.GetChainID(1)) // convenience and readability
s.chainB = s.coordinator.GetChain(ibctesting.GetChainID(2)) // convenience and readability
func (suite *KeeperTestSuite) SetupTest() {
suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) // initializes 2 test chains
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) // convenience and readability
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) // convenience and readability

s.path = newQuicksilverPath(s.chainA, s.chainB)
s.coordinator.SetupConnections(s.path)
suite.path = newQuicksilverPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(suite.path)

s.coordinator.CurrentTime = time.Now().UTC()
s.coordinator.UpdateTime()
suite.coordinator.CurrentTime = time.Now().UTC()
suite.coordinator.UpdateTime()

s.initTestZone()
suite.initTestZone()

s.coordinator.CommitNBlocks(s.chainA, 10)
s.coordinator.CommitNBlocks(s.chainB, 10)
suite.coordinator.CommitNBlocks(suite.chainA, 10)
suite.coordinator.CommitNBlocks(suite.chainB, 10)
}

func (s *KeeperTestSuite) initTestZone() {
func (suite *KeeperTestSuite) initTestZone() {
// test zone
zone := icstypes.Zone{
ConnectionId: s.path.EndpointB.ConnectionID,
ChainId: s.chainB.ChainID,
ConnectionId: suite.path.EndpointB.ConnectionID,
ChainId: suite.chainB.ChainID,
AccountPrefix: "cosmos",
LocalDenom: "uqatom",
BaseDenom: "uatom",
Is_118: true,
}

s.GetQuicksilverApp(s.chainA).InterchainstakingKeeper.SetZone(s.chainA.GetContext(), &zone)
suite.GetQuicksilverApp(suite.chainA).InterchainstakingKeeper.SetZone(suite.chainA.GetContext(), &zone)
}

func (s *KeeperTestSuite) getZoneDrop() types.ZoneDrop {
func (suite *KeeperTestSuite) getZoneDrop() types.ZoneDrop {
zd := types.ZoneDrop{
ChainId: s.chainB.ChainID,
ChainId: suite.chainB.ChainID,
StartTime: time.Now().Add(-5 * time.Minute),
Duration: time.Hour,
Decay: 30 * time.Minute,
Expand All @@ -115,32 +115,32 @@ func (s *KeeperTestSuite) getZoneDrop() types.ZoneDrop {
return zd
}

func (s *KeeperTestSuite) compressClaimRecords(crs []types.ClaimRecord) []byte {
s.T().Helper()
func (suite *KeeperTestSuite) compressClaimRecords(crs []types.ClaimRecord) []byte {
suite.T().Helper()

bz, err := json.Marshal(&crs)
s.Require().NoError(err)
suite.Require().NoError(err)

var buf bytes.Buffer
zw := zlib.NewWriter(&buf)
_, err = zw.Write(bz)
s.Require().NoError(err)
suite.Require().NoError(err)

err = zw.Close()
s.Require().NoError(err)
suite.Require().NoError(err)

return buf.Bytes()
}

func (s *KeeperTestSuite) initTestZoneDrop() {
zd := s.getZoneDrop()
s.GetQuicksilverApp(s.chainA).AirdropKeeper.SetZoneDrop(s.chainA.GetContext(), zd)
s.fundZoneDrop(zd.ChainId, zd.Allocation)
func (suite *KeeperTestSuite) initTestZoneDrop() {
zd := suite.getZoneDrop()
suite.GetQuicksilverApp(suite.chainA).AirdropKeeper.SetZoneDrop(suite.chainA.GetContext(), zd)
suite.fundZoneDrop(zd.ChainId, zd.Allocation)
}

func (s *KeeperTestSuite) fundZoneDrop(chainID string, amount uint64) {
quicksilver := s.GetQuicksilverApp(s.chainA)
ctx := s.chainA.GetContext()
func (suite *KeeperTestSuite) fundZoneDrop(chainID string, amount uint64) {
quicksilver := suite.GetQuicksilverApp(suite.chainA)
ctx := suite.chainA.GetContext()
coins := sdk.NewCoins(
sdk.NewCoin(
quicksilver.StakingKeeper.BondDenom(ctx),
Expand All @@ -151,16 +151,16 @@ func (s *KeeperTestSuite) fundZoneDrop(chainID string, amount uint64) {
zdacc := quicksilver.AirdropKeeper.GetZoneDropAccountAddress(chainID)

err := quicksilver.MintKeeper.MintCoins(ctx, coins)
s.Require().NoError(err)
suite.Require().NoError(err)

err = quicksilver.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, zdacc, coins)
s.Require().NoError(err)
suite.Require().NoError(err)
}

func (s *KeeperTestSuite) setClaimRecord(cr types.ClaimRecord) {
err := s.GetQuicksilverApp(s.chainA).AirdropKeeper.SetClaimRecord(s.chainA.GetContext(), cr)
func (suite *KeeperTestSuite) setClaimRecord(cr types.ClaimRecord) {
err := suite.GetQuicksilverApp(suite.chainA).AirdropKeeper.SetClaimRecord(suite.chainA.GetContext(), cr)
if err != nil {
s.T().Logf("setClaimRecord error: %v", err)
suite.T().Logf("setClaimRecord error: %v", err)
}
s.Require().NoError(err)
suite.Require().NoError(err)
}
Loading

0 comments on commit 247617b

Please sign in to comment.