Skip to content

Commit

Permalink
prove 17
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorTrustyDev committed Sep 26, 2024
1 parent e2bdcaa commit 1057f08
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions x/dymns/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"fmt"
"reflect"
"sort"
"testing"
"time"

"github.com/stretchr/testify/require"

sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -3461,3 +3464,34 @@ func (s *KeeperTestSuite) Test_queryServer_Aliases() {
s.Require().Contains(err.Error(), "invalid request")
})
}

func Benchmark_queryServer_Aliases(b *testing.B) {
b.StopTimer()

s := new(KeeperTestSuite)
s.SetT(&testing.T{})
s.SetupTest()

// restore params which was previously cleared by test suite setup
err := s.dymNsKeeper.SetParams(s.ctx, dymnstypes.DefaultParams())
require.NoError(b, err)

// create large amount of RollApps
const rollAppCounts = 100_000
for id := 1; id <= rollAppCounts; id++ {
rollApp := newRollApp(fmt.Sprintf("rollapp_%d-1", id)).WithOwner(testAddr(1).bech32()).WithAlias(fmt.Sprintf("alias%d", id))
s.persistRollApp(*rollApp)
}

// benchmark
for i := 0; i < b.N; i++ {
resp, err := func() (*dymnstypes.QueryAliasesResponse, error) {
b.StartTimer()
defer b.StopTimer()
return dymnskeeper.NewQueryServerImpl(s.dymNsKeeper).Aliases(sdk.WrapSDKContext(s.ctx), &dymnstypes.QueryAliasesRequest{})
}()
require.NoError(b, err)
require.NotNil(b, resp)
require.GreaterOrEqual(b, len(resp.AliasesByChainId), rollAppCounts)
}
}

0 comments on commit 1057f08

Please sign in to comment.