Skip to content

Commit

Permalink
fix some test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Oct 14, 2024
1 parent 28829ed commit c6b54b0
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 17 deletions.
5 changes: 3 additions & 2 deletions app/sim_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/ignite/network/app"
networktypes "github.com/ignite/network/pkg/types"
)

// Profile with:
Expand Down Expand Up @@ -45,7 +46,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {

bApp, err := app.New(logger, db, nil, true, appOptions, interBlockCacheOpt())
require.NoError(b, err)
require.Equal(b, app.Name, bApp.Name())
require.Equal(b, networktypes.Name, bApp.Name())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down Expand Up @@ -102,7 +103,7 @@ func BenchmarkInvariants(b *testing.B) {

bApp, err := app.New(logger, db, nil, true, appOptions, interBlockCacheOpt())
require.NoError(b, err)
require.Equal(b, app.Name, bApp.Name())
require.Equal(b, networktypes.Name, bApp.Name())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down
11 changes: 6 additions & 5 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/ignite/network/app"
networktypes "github.com/ignite/network/pkg/types"
)

const (
Expand Down Expand Up @@ -89,7 +90,7 @@ func BenchmarkSimulation(b *testing.B) {

bApp, err := app.New(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.NoError(b, err)
require.Equal(b, app.Name, bApp.Name())
require.Equal(b, networktypes.Name, bApp.Name())

// run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down Expand Up @@ -135,7 +136,7 @@ func TestAppImportExport(t *testing.T) {

bApp, err := app.New(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.NoError(t, err)
require.Equal(t, app.Name, bApp.Name())
require.Equal(t, networktypes.Name, bApp.Name())

// Run randomized simulation
_, simParams, simErr := simulation.SimulateFromSeed(
Expand Down Expand Up @@ -176,7 +177,7 @@ func TestAppImportExport(t *testing.T) {

newApp, err := app.New(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.NoError(t, err)
require.Equal(t, app.Name, newApp.Name())
require.Equal(t, networktypes.Name, newApp.Name())

var genesisState app.GenesisState
err = json.Unmarshal(exported.AppState, &genesisState)
Expand Down Expand Up @@ -254,7 +255,7 @@ func TestAppSimulationAfterImport(t *testing.T) {

bApp, err := app.New(logger, db, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.NoError(t, err)
require.Equal(t, app.Name, bApp.Name())
require.Equal(t, networktypes.Name, bApp.Name())

// Run randomized simulation
stopEarly, simParams, simErr := simulation.SimulateFromSeed(
Expand Down Expand Up @@ -300,7 +301,7 @@ func TestAppSimulationAfterImport(t *testing.T) {

newApp, err := app.New(log.NewNopLogger(), newDB, nil, true, appOptions, fauxMerkleModeOpt, baseapp.SetChainID(SimAppChainID))
require.NoError(t, err)
require.Equal(t, app.Name, newApp.Name())
require.Equal(t, networktypes.Name, newApp.Name())

_, err = newApp.InitChain(&abci.RequestInitChain{
AppStateBytes: exported.AppState,
Expand Down
2 changes: 1 addition & 1 deletion x/launch/keeper/query_genesis_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (q queryServer) GetGenesisAccount(ctx context.Context, req *types.QueryGetG

address, err := q.k.addressCodec.StringToBytes(req.Address)
if err != nil {
return nil, status.Error(codes.Internal, "internal error")
return nil, status.Error(codes.InvalidArgument, "invalid address")
}

val, err := q.k.GenesisAccount.Get(ctx, collections.Join(req.LaunchID, sdk.AccAddress(address)))
Expand Down
2 changes: 1 addition & 1 deletion x/launch/keeper/query_genesis_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (q queryServer) GetGenesisValidator(ctx context.Context, req *types.QueryGe

address, err := q.k.addressCodec.StringToBytes(req.Address)
if err != nil {
return nil, status.Error(codes.Internal, "internal error")
return nil, status.Error(codes.InvalidArgument, "invalid address")
}

val, err := q.k.GenesisValidator.Get(ctx, collections.Join(req.LaunchID, sdk.AccAddress(address)))
Expand Down
2 changes: 1 addition & 1 deletion x/launch/keeper/query_vesting_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (q queryServer) GetVestingAccount(ctx context.Context, req *types.QueryGetV

address, err := q.k.addressCodec.StringToBytes(req.Address)
if err != nil {
return nil, status.Error(codes.Internal, "internal error")
return nil, status.Error(codes.InvalidArgument, "invalid address")
}

val, err := q.k.VestingAccount.Get(ctx, collections.Join(req.LaunchID, sdk.AccAddress(address)))
Expand Down
6 changes: 5 additions & 1 deletion x/participation/keeper/msg_update_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ func TestMsgUpdateParams(t *testing.T) {
name: "send enabled param",
input: &types.MsgUpdateParams{
Authority: k.GetAuthority(),
Params: types.Params{},
Params: types.Params{
AllocationPrice: types.DefaultAllocationPrice,
RegistrationPeriod: types.DefaultRegistrationPeriod,
WithdrawalDelay: types.DefaultWithdrawalDelay,
},
},
expErr: false,
},
Expand Down
2 changes: 1 addition & 1 deletion x/participation/keeper/query_auction_used_allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (q queryServer) GetAuctionUsedAllocations(ctx context.Context, req *types.Q

address, err := q.k.addressCodec.StringToBytes(req.Address)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
return nil, status.Error(codes.InvalidArgument, "invalid address")
}

val, err := q.k.AuctionUsedAllocations.Get(ctx, collections.Join(sdk.AccAddress(address), req.AuctionID))
Expand Down
19 changes: 15 additions & 4 deletions x/participation/keeper/query_auction_used_allocations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (

func createNAuctionUsedAllocations(keeper keeper.Keeper, ctx context.Context, n int) []types.AuctionUsedAllocations {
items := make([]types.AuctionUsedAllocations, n)
auctionID := uint64(0)
for i := range items {
address := sample.AccAddress(r)
auctionID := uint64(i)
items[i].Address = address.String()
items[i].AuctionID = auctionID
items[i].NumAllocations = sample.Int(r)
Expand All @@ -45,24 +45,35 @@ func TestAuctionUsedAllocationsQuerySingle(t *testing.T) {
{
desc: "First",
request: &types.QueryGetAuctionUsedAllocationsRequest{
Address: msgs[0].Address,
AuctionID: msgs[0].AuctionID,
Address: msgs[0].Address,
},
response: &types.QueryGetAuctionUsedAllocationsResponse{AuctionUsedAllocations: msgs[0]},
},
{
desc: "Second",
request: &types.QueryGetAuctionUsedAllocationsRequest{
Address: msgs[1].Address,
AuctionID: msgs[1].AuctionID,
Address: msgs[1].Address,
},
response: &types.QueryGetAuctionUsedAllocationsResponse{AuctionUsedAllocations: msgs[1]},
},
{
desc: "KeyNotFound",
request: &types.QueryGetAuctionUsedAllocationsRequest{
Address: strconv.Itoa(100000),
AuctionID: 100,
Address: sample.Address(r),
},
err: status.Error(codes.NotFound, "not found"),
},
{
desc: "InvalidAddress",
request: &types.QueryGetAuctionUsedAllocationsRequest{
AuctionID: 100,
Address: strconv.Itoa(100000),
},
err: status.Error(codes.InvalidArgument, "invalid address"),
},
{
desc: "InvalidRequest",
err: status.Error(codes.InvalidArgument, "invalid request"),
Expand Down
2 changes: 2 additions & 0 deletions x/participation/keeper/query_used_allocations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

keepertest "github.com/ignite/network/testutil/keeper"
"github.com/ignite/network/testutil/nullify"
"github.com/ignite/network/testutil/sample"
"github.com/ignite/network/x/participation/keeper"
"github.com/ignite/network/x/participation/types"
)
Expand All @@ -20,6 +21,7 @@ func createNUsedAllocations(keeper keeper.Keeper, ctx context.Context, n int) []
items := make([]types.UsedAllocations, n)
for i := range items {
items[i].Address = strconv.Itoa(i)
items[i].NumAllocations = sample.Int(r)

_ = keeper.UsedAllocations.Set(ctx, items[i].Address, items[i])
}
Expand Down
2 changes: 1 addition & 1 deletion x/profile/keeper/query_coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (q queryServer) GetCoordinatorByAddress(ctx context.Context, req *types.Que

address, err := q.k.addressCodec.StringToBytes(req.Address)
if err != nil {
return nil, status.Error(codes.Internal, "internal error")
return nil, status.Error(codes.InvalidArgument, "invalid address")
}

coordinatorByAddress, err := q.k.CoordinatorByAddress.Get(ctx, address)
Expand Down

0 comments on commit c6b54b0

Please sign in to comment.