From 9297db06bbf39ca449c1294be7fca3047446e495 Mon Sep 17 00:00:00 2001 From: javiersuweijie Date: Wed, 1 Feb 2023 17:40:08 +0800 Subject: [PATCH] fix: simulation to register interfaces --- app/simulation_test.go | 17 ++++--- x/alliance/keeper/tests/grpc_query_test.go | 53 +++++++++++++++------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/app/simulation_test.go b/app/simulation_test.go index f4a0c144..4bd13192 100644 --- a/app/simulation_test.go +++ b/app/simulation_test.go @@ -15,7 +15,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/terra-money/alliance/app" - "github.com/terra-money/alliance/app/params" ) func init() { @@ -53,9 +52,9 @@ func BenchmarkSimulation(b *testing.B) { require.NoError(b, err) }) - encoding := params.MakeEncodingConfig() + encoding := app.MakeTestEncodingConfig() - app := app.New( + simApp := app.New( logger, db, nil, @@ -71,17 +70,17 @@ func BenchmarkSimulation(b *testing.B) { _, simParams, simErr := simulation.SimulateFromSeed( b, os.Stdout, - app.GetBaseApp(), - simapp.AppStateFn(app.AppCodec(), app.SimulationManager()), + simApp.GetBaseApp(), + simapp.AppStateFn(simApp.AppCodec(), simApp.SimulationManager()), simulationtypes.RandomAccounts, - simapp.SimulationOperations(app, app.AppCodec(), config), - app.ModuleAccountAddrs(), + simapp.SimulationOperations(simApp, simApp.AppCodec(), config), + simApp.ModuleAccountAddrs(), config, - app.AppCodec(), + simApp.AppCodec(), ) // export state and simParams before the simulation error is checked - err = simapp.CheckExportSimulation(app, config, simParams) + err = simapp.CheckExportSimulation(simApp, config, simParams) require.NoError(b, err) require.NoError(b, simErr) diff --git a/x/alliance/keeper/tests/grpc_query_test.go b/x/alliance/keeper/tests/grpc_query_test.go index a1bea0a1..90697829 100644 --- a/x/alliance/keeper/tests/grpc_query_test.go +++ b/x/alliance/keeper/tests/grpc_query_test.go @@ -899,21 +899,42 @@ func TestQueryValidators(t *testing.T) { }) require.NoError(t, queryErr) - require.Equal(t, &types.QueryAllianceValidatorsResponse{ - Validators: []types.QueryAllianceValidatorResponse{ - { - ValidatorAddr: val2.GetOperator().String(), - TotalDelegationShares: sdk.NewDecCoins( - sdk.NewDecCoinFromDec(AllianceDenomTwo, sdk.NewDec(1000000)), - ), - ValidatorShares: sdk.NewDecCoins( - sdk.NewDecCoinFromDec(AllianceDenomTwo, sdk.NewDec(1000000)), - ), - TotalStaked: sdk.NewDecCoins( - sdk.NewDecCoinFromDec(AllianceDenomTwo, sdk.NewDec(1000_000)), - ), + // Order in which validators are returned is not deterministic since we randomly generate validator addresses + if queryVal2.Validators[0].ValidatorAddr == val.GetOperator().String() { + require.Equal(t, &types.QueryAllianceValidatorsResponse{ + Validators: []types.QueryAllianceValidatorResponse{ + { + ValidatorAddr: val.GetOperator().String(), + TotalDelegationShares: sdk.NewDecCoins( + sdk.NewDecCoinFromDec(AllianceDenom, sdk.NewDec(1000000)), + ), + ValidatorShares: sdk.NewDecCoins( + sdk.NewDecCoinFromDec(AllianceDenom, sdk.NewDec(1000000)), + ), + TotalStaked: sdk.NewDecCoins( + sdk.NewDecCoinFromDec(AllianceDenom, sdk.NewDec(1000_000)), + ), + }, }, - }, - Pagination: queryVal2.Pagination, - }, queryVal2) + Pagination: queryVal2.Pagination, + }, queryVal2) + } else { + require.Equal(t, &types.QueryAllianceValidatorsResponse{ + Validators: []types.QueryAllianceValidatorResponse{ + { + ValidatorAddr: val2.GetOperator().String(), + TotalDelegationShares: sdk.NewDecCoins( + sdk.NewDecCoinFromDec(AllianceDenomTwo, sdk.NewDec(1000000)), + ), + ValidatorShares: sdk.NewDecCoins( + sdk.NewDecCoinFromDec(AllianceDenomTwo, sdk.NewDec(1000000)), + ), + TotalStaked: sdk.NewDecCoins( + sdk.NewDecCoinFromDec(AllianceDenomTwo, sdk.NewDec(1000_000)), + ), + }, + }, + Pagination: queryVal2.Pagination, + }, queryVal2) + } }