Skip to content

Commit

Permalink
fix farm error
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamer committed Jun 28, 2023
1 parent 2f7e5e2 commit 56deb97
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 11 deletions.
3 changes: 3 additions & 0 deletions modules/farm/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")

s.network = simapp.SetupNetwork(s.T())
sdk.SetCoinDenomRegex(func() string {
return `[a-zA-Z][a-zA-Z0-9/\-]{2,127}`
})
}

func (s *IntegrationTestSuite) TearDownSuite() {
Expand Down
59 changes: 57 additions & 2 deletions modules/farm/client/testutil/grpc_query_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package testutil_test

import (
"context"
"fmt"
"testing"
"time"

"github.com/cosmos/gogoproto/proto"
"github.com/stretchr/testify/suite"
Expand All @@ -11,9 +13,11 @@ import (
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"

coinswaptypes "github.com/irisnet/irismod/modules/coinswap/types"
farmcli "github.com/irisnet/irismod/modules/farm/client/cli"
farmtestutil "github.com/irisnet/irismod/modules/farm/client/testutil"
farmtypes "github.com/irisnet/irismod/modules/farm/types"
tokentypes "github.com/irisnet/irismod/modules/token/types/v1"
"github.com/irisnet/irismod/simapp"
)

Expand All @@ -27,6 +31,9 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.T().Log("setting up integration test suite")

s.network = simapp.SetupNetwork(s.T())
sdk.SetCoinDenomRegex(func() string {
return `[a-zA-Z][a-zA-Z0-9/\-]{2,127}`
})
}

func (s *IntegrationTestSuite) TearDownSuite() {
Expand All @@ -43,13 +50,15 @@ func (s *IntegrationTestSuite) TestRest() {
clientCtx := val.ClientCtx
baseURL := val.APIAddress

s.Init()

// ---------------------------------------------------------------------------

creator := val.Address
description := "iris-atom farm pool"
startHeight := s.LatestHeight() + 1
rewardPerBlock := sdk.NewCoins(sdk.NewCoin(s.network.BondDenom, sdk.NewInt(10)))
lpTokenDenom := s.network.BondDenom
lpTokenDenom := "lpt-1"
totalReward := sdk.NewCoins(sdk.NewCoin(s.network.BondDenom, sdk.NewInt(1000)))
editable := true

Expand Down Expand Up @@ -80,6 +89,7 @@ func (s *IntegrationTestSuite) TestRest() {
creator.String(),
args...,
)
s.Require().EqualValues(txResult.Code, 0, txResult.Log)

poolId := s.network.GetAttribute(
farmtypes.EventTypeCreatePool,
Expand Down Expand Up @@ -113,7 +123,7 @@ func (s *IntegrationTestSuite) TestRest() {
s.Require().NoError(err)
s.network.WaitForNextBlock()

lpToken := sdk.NewCoin(s.network.BondDenom, sdk.NewInt(100))
lpToken := sdk.NewCoin(lpTokenDenom, sdk.NewInt(100))
txResult = farmtestutil.StakeExec(
s.T(),
s.network,
Expand All @@ -123,6 +133,7 @@ func (s *IntegrationTestSuite) TestRest() {
lpToken.String(),
globalFlags...,
)
s.Require().Equal(uint32(0), txResult.Code, txResult.Log)

expectFarmer := farmtypes.LockedInfo{
PoolId: poolId,
Expand Down Expand Up @@ -150,3 +161,47 @@ func (s *IntegrationTestSuite) LatestHeight() int64 {
s.Require().NoError(err)
return height
}

func (s *IntegrationTestSuite) Init() {

val := s.network.Validators[0]
clientCtx := val.ClientCtx

from := val.Address
symbol := "kitty"
name := "Kitty Token"
minUnit := "kitty"
scale := uint32(0)
initialSupply := uint64(100000000)
maxSupply := uint64(200000000)
mintable := true

// issue token
msgIssueToken := &tokentypes.MsgIssueToken{
Symbol: symbol,
Name: name,
Scale: scale,
MinUnit: minUnit,
InitialSupply: initialSupply,
MaxSupply: maxSupply,
Mintable: mintable,
Owner: from.String(),
}
res := s.network.BlockSendMsgs(s.T(), msgIssueToken)
s.Require().Equal(uint32(0), res.Code, res.Log)

// add liquidity
status, err := clientCtx.Client.Status(context.Background())
s.Require().NoError(err)
deadline := status.SyncInfo.LatestBlockTime.Add(time.Minute)

msgAddLiquidity := &coinswaptypes.MsgAddLiquidity{
MaxToken: sdk.NewCoin(symbol, sdk.NewInt(1000)),
ExactStandardAmt: sdk.NewInt(1000),
MinLiquidity: sdk.NewInt(1000),
Deadline: deadline.Unix(),
Sender: val.Address.String(),
}
res = s.network.BlockSendMsgs(s.T(), msgAddLiquidity)
s.Require().Equal(uint32(0), res.Code, res.Log)
}
48 changes: 40 additions & 8 deletions modules/random/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ func (s *IntegrationTestSuite) TestRandom() {

fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.network.BondDenom, sdk.NewInt(10))).String()),
fmt.Sprintf(
"--%s=%s",
flags.FlagFees,
sdk.NewCoins(sdk.NewCoin(s.network.BondDenom, sdk.NewInt(10))).String(),
),
}

txResult := servicetestutil.BindServiceExec(s.T(), s.network, clientCtx, provider.String(), args...)
txResult := servicetestutil.BindServiceExec(
s.T(),
s.network,
clientCtx,
provider.String(),
args...)
s.Require().Equal(expectedCode, txResult.Code)

// ------test GetCmdRequestRandom()-------------
Expand All @@ -90,7 +99,11 @@ func (s *IntegrationTestSuite) TestRandom() {

fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.network.BondDenom, sdk.NewInt(10))).String()),
fmt.Sprintf(
"--%s=%s",
flags.FlagFees,
sdk.NewCoins(sdk.NewCoin(s.network.BondDenom, sdk.NewInt(10))).String(),
),
}

txResult = randomtestutil.RequestRandomExec(s.T(), s.network, clientCtx, from.String(), args...)
Expand All @@ -100,12 +113,20 @@ func (s *IntegrationTestSuite) TestRandom() {
requestHeight := gjson.Get(txResult.Log, "0.events.1.attributes.2.value").Int()

// ------test GetCmdQueryRandomRequestQueue()-------------
qrrResp := randomtestutil.QueryRandomRequestQueueExec(s.T(), s.network, clientCtx, fmt.Sprintf("%d", requestHeight))
qrrResp := randomtestutil.QueryRandomRequestQueueExec(
s.T(),
s.network,
clientCtx,
fmt.Sprintf("%d", requestHeight),
)
s.Require().Len(qrrResp.Requests, 1)

// ------get service request-------------
requestHeight = requestHeight + 1
_, err := s.network.WaitForHeightWithTimeout(requestHeight, time.Duration(int64(blockInterval+2)*int64(s.network.TimeoutCommit)))
_, err := s.network.WaitForHeightWithTimeout(
requestHeight,
time.Duration(int64(blockInterval+5)*int64(s.network.TimeoutCommit)),
)
s.Require().NoError(err)

blockResult, err := val.RPCClient.BlockResults(context.Background(), &requestHeight)
Expand Down Expand Up @@ -141,10 +162,19 @@ func (s *IntegrationTestSuite) TestRandom() {

fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.network.BondDenom, sdk.NewInt(10))).String()),
fmt.Sprintf(
"--%s=%s",
flags.FlagFees,
sdk.NewCoins(sdk.NewCoin(s.network.BondDenom, sdk.NewInt(10))).String(),
),
}

txResult = servicetestutil.RespondServiceExec(s.T(), s.network, clientCtx, provider.String(), args...)
txResult = servicetestutil.RespondServiceExec(
s.T(),
s.network,
clientCtx,
provider.String(),
args...)
s.Require().Equal(expectedCode, txResult.Code)

generateHeight := txResult.Height
Expand All @@ -157,6 +187,8 @@ func (s *IntegrationTestSuite) TestRandom() {
s.Require().NoError(err)
seed, err := hex.DecodeString(seedStr)
s.Require().NoError(err)
random := randomtypes.MakePRNG(generateBLock.Block.LastBlockID.Hash, generateBLock.Block.Header.Time.Unix(), from, seed, true).GetRand().FloatString(randomtypes.RandPrec)
random := randomtypes.MakePRNG(generateBLock.Block.LastBlockID.Hash, generateBLock.Block.Header.Time.Unix(), from, seed, true).
GetRand().
FloatString(randomtypes.RandPrec)
s.Require().Equal(random, randomResp.Value)
}
2 changes: 1 addition & 1 deletion simapp/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ modules:
- name: service
config:
"@type": irismod.service.module.v1.Module
fee_collector_name: "fee_collector"
fee_collector_name: "service_fee_collector"

- name: token
config:
Expand Down

0 comments on commit 56deb97

Please sign in to comment.