forked from osmosis-labs/osmosis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make testing suite to ensure queries never alter state (osmosis-labs#…
…3001) * create func to check alter state * add tests * format * Update app/apptesting/test_suite.go Co-authored-by: Roman <roman@osmosis.team> * remove fmt * epochs: try to use Invoke * gamm: use Invoke * incentives: use Invoke * lockup: use Invoke * mint: use Invoke * pool-incentives: use Invoke * superfluid: use Invoke * tokenfactory * txfees * format * fix Co-authored-by: Roman <roman@osmosis.team>
- Loading branch information
1 parent
f431464
commit 91f5b18
Showing
11 changed files
with
918 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package cli_test | ||
|
||
import ( | ||
gocontext "context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/osmosis-labs/osmosis/v12/app/apptesting" | ||
"github.com/osmosis-labs/osmosis/v12/x/epochs/types" | ||
) | ||
|
||
type QueryTestSuite struct { | ||
apptesting.KeeperTestHelper | ||
queryClient types.QueryClient | ||
} | ||
|
||
func (s *QueryTestSuite) SetupSuite() { | ||
s.Setup() | ||
s.queryClient = types.NewQueryClient(s.QueryHelper) | ||
|
||
// add new epoch | ||
epoch := types.EpochInfo{ | ||
Identifier: "weekly", | ||
StartTime: time.Time{}, | ||
Duration: time.Hour, | ||
CurrentEpoch: 0, | ||
CurrentEpochStartHeight: 0, | ||
CurrentEpochStartTime: time.Time{}, | ||
EpochCountingStarted: false, | ||
} | ||
s.App.EpochsKeeper.AddEpochInfo(s.Ctx, epoch) | ||
|
||
s.Commit() | ||
} | ||
|
||
func (s *QueryTestSuite) TestQueriesNeverAlterState() { | ||
testCases := []struct { | ||
name string | ||
query string | ||
input interface{} | ||
output interface{} | ||
}{ | ||
{ | ||
"Query current epoch", | ||
"/osmosis.epochs.v1beta1.Query/CurrentEpoch", | ||
&types.QueryCurrentEpochRequest{Identifier: "weekly"}, | ||
&types.QueryCurrentEpochResponse{}, | ||
}, | ||
{ | ||
"Query epochs info", | ||
"/osmosis.epochs.v1beta1.Query/EpochInfos", | ||
&types.QueryEpochsInfoRequest{}, | ||
&types.QueryEpochsInfoResponse{}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
s.Run(tc.name, func() { | ||
s.SetupSuite() | ||
err := s.QueryHelper.Invoke(gocontext.Background(), tc.query, tc.input, tc.output) | ||
s.Require().NoError(err) | ||
s.StateNotAltered() | ||
}) | ||
} | ||
} | ||
|
||
func TestQueryTestSuite(t *testing.T) { | ||
suite.Run(t, new(QueryTestSuite)) | ||
} |
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,102 @@ | ||
package cli_test | ||
|
||
import ( | ||
gocontext "context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/osmosis-labs/osmosis/v12/app/apptesting" | ||
"github.com/osmosis-labs/osmosis/v12/x/gamm/types" | ||
) | ||
|
||
type QueryTestSuite struct { | ||
apptesting.KeeperTestHelper | ||
queryClient types.QueryClient | ||
} | ||
|
||
func (s *QueryTestSuite) SetupSuite() { | ||
s.Setup() | ||
s.queryClient = types.NewQueryClient(s.QueryHelper) | ||
// create a new pool | ||
s.PrepareBalancerPool() | ||
s.Commit() | ||
} | ||
|
||
func (s *QueryTestSuite) TestQueriesNeverAlterState() { | ||
testCases := []struct { | ||
name string | ||
query string | ||
input interface{} | ||
output interface{} | ||
}{ | ||
{ | ||
"Query pools", | ||
"/osmosis.gamm.v1beta1.Query/Pools", | ||
&types.QueryPoolsRequest{}, | ||
&types.QueryPoolsResponse{}, | ||
}, | ||
{ | ||
"Query single pool", | ||
"/osmosis.gamm.v1beta1.Query/Pool", | ||
&types.QueryPoolRequest{PoolId: 1}, | ||
&types.QueryPoolsResponse{}, | ||
}, | ||
{ | ||
"Query num pools", | ||
"/osmosis.gamm.v1beta1.Query/NumPools", | ||
&types.QueryNumPoolsRequest{}, | ||
&types.QueryNumPoolsResponse{}, | ||
}, | ||
{ | ||
"Query pool params", | ||
"/osmosis.gamm.v1beta1.Query/PoolParams", | ||
&types.QueryPoolParamsRequest{PoolId: 1}, | ||
&types.QueryPoolParamsResponse{}, | ||
}, | ||
{ | ||
"Query pool type", | ||
"/osmosis.gamm.v1beta1.Query/PoolType", | ||
&types.QueryPoolTypeRequest{PoolId: 1}, | ||
&types.QueryPoolTypeResponse{}, | ||
}, | ||
{ | ||
"Query spot price", | ||
"/osmosis.gamm.v1beta1.Query/SpotPrice", | ||
&types.QuerySpotPriceRequest{PoolId: 1, BaseAssetDenom: "foo", QuoteAssetDenom: "bar"}, | ||
&types.QuerySpotPriceResponse{}, | ||
}, | ||
{ | ||
"Query total liquidity", | ||
"/osmosis.gamm.v1beta1.Query/TotalLiquidity", | ||
&types.QueryTotalLiquidityRequest{}, | ||
&types.QueryTotalLiquidityResponse{}, | ||
}, | ||
{ | ||
"Query pool total liquidity", | ||
"/osmosis.gamm.v1beta1.Query/TotalPoolLiquidity", | ||
&types.QueryTotalPoolLiquidityRequest{PoolId: 1}, | ||
&types.QueryTotalPoolLiquidityResponse{}, | ||
}, | ||
{ | ||
"Query total shares", | ||
"/osmosis.gamm.v1beta1.Query/TotalShares", | ||
&types.QueryTotalSharesRequest{PoolId: 1}, | ||
&types.QueryTotalSharesResponse{}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
s.Run(tc.name, func() { | ||
s.SetupSuite() | ||
err := s.QueryHelper.Invoke(gocontext.Background(), tc.query, tc.input, tc.output) | ||
s.Require().NoError(err) | ||
s.StateNotAltered() | ||
}) | ||
} | ||
} | ||
|
||
func TestQueryTestSuite(t *testing.T) { | ||
suite.Run(t, new(QueryTestSuite)) | ||
} |
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,110 @@ | ||
package cli_test | ||
|
||
import ( | ||
gocontext "context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/osmosis-labs/osmosis/v12/app/apptesting" | ||
"github.com/osmosis-labs/osmosis/v12/x/incentives/types" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
type QueryTestSuite struct { | ||
apptesting.KeeperTestHelper | ||
queryClient types.QueryClient | ||
} | ||
|
||
func (s *QueryTestSuite) SetupSuite() { | ||
s.Setup() | ||
s.queryClient = types.NewQueryClient(s.QueryHelper) | ||
|
||
// create a pool | ||
s.PrepareBalancerPool() | ||
// set up lock with id = 1 | ||
s.LockTokens(s.TestAccs[0], sdk.Coins{sdk.NewCoin("gamm/pool/1", sdk.NewInt(1000000))}, time.Hour*24) | ||
|
||
s.Commit() | ||
} | ||
|
||
func (s *QueryTestSuite) TestQueriesNeverAlterState() { | ||
testCases := []struct { | ||
name string | ||
query string | ||
input interface{} | ||
output interface{} | ||
}{ | ||
{ | ||
"Query active gauges", | ||
"/osmosis.incentives.Query/ActiveGauges", | ||
&types.ActiveGaugesRequest{}, | ||
&types.ActiveGaugesResponse{}, | ||
}, | ||
{ | ||
"Query active gauges per denom", | ||
"/osmosis.incentives.Query/ActiveGaugesPerDenom", | ||
&types.ActiveGaugesPerDenomRequest{Denom: "stake"}, | ||
&types.ActiveGaugesPerDenomResponse{}, | ||
}, | ||
{ | ||
"Query gauge by id", | ||
"/osmosis.incentives.Query/GaugeByID", | ||
&types.GaugeByIDRequest{Id: 1}, | ||
&types.GaugeByIDResponse{}, | ||
}, | ||
{ | ||
"Query all gauges", | ||
"/osmosis.incentives.Query/Gauges", | ||
&types.GaugesRequest{}, | ||
&types.GaugesResponse{}, | ||
}, | ||
{ | ||
"Query lockable durations", | ||
"/osmosis.incentives.Query/LockableDurations", | ||
&types.QueryLockableDurationsRequest{}, | ||
&types.QueryLockableDurationsResponse{}, | ||
}, | ||
{ | ||
"Query module to distibute coins", | ||
"/osmosis.incentives.Query/ModuleToDistributeCoins", | ||
&types.ModuleToDistributeCoinsRequest{}, | ||
&types.ModuleToDistributeCoinsResponse{}, | ||
}, | ||
{ | ||
"Query reward estimate", | ||
"/osmosis.incentives.Query/RewardsEst", | ||
&types.RewardsEstRequest{Owner: s.TestAccs[0].String()}, | ||
&types.RewardsEstResponse{}, | ||
}, | ||
{ | ||
"Query upcoming gauges", | ||
"/osmosis.incentives.Query/UpcomingGauges", | ||
&types.UpcomingGaugesRequest{}, | ||
&types.UpcomingGaugesResponse{}, | ||
}, | ||
{ | ||
"Query upcoming gauges", | ||
"/osmosis.incentives.Query/UpcomingGaugesPerDenom", | ||
&types.UpcomingGaugesPerDenomRequest{Denom: "stake"}, | ||
&types.UpcomingGaugesPerDenomResponse{}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
|
||
s.Run(tc.name, func() { | ||
s.SetupSuite() | ||
err := s.QueryHelper.Invoke(gocontext.Background(), tc.query, tc.input, tc.output) | ||
s.Require().NoError(err) | ||
s.StateNotAltered() | ||
}) | ||
} | ||
} | ||
|
||
func TestQueryTestSuite(t *testing.T) { | ||
suite.Run(t, new(QueryTestSuite)) | ||
} |
Oops, something went wrong.