diff --git a/x/ecocredit/server/basket/invariants.go b/x/ecocredit/server/basket/invariants.go index 61d7d18fdb..dab6893b7a 100644 --- a/x/ecocredit/server/basket/invariants.go +++ b/x/ecocredit/server/basket/invariants.go @@ -80,6 +80,7 @@ func (k Keeper) computeBasketBalances(ctx context.Context) (map[uint64]math.Dec, if err != nil { return nil, fmt.Errorf("can't create basket balance iterator, %w", err) } + defer it.Close() balances := map[uint64]math.Dec{} for it.Next() { b, err := it.Value() diff --git a/x/ecocredit/server/core/query_balances.go b/x/ecocredit/server/core/query_balances.go index 14f9103293..03e3a3d46e 100644 --- a/x/ecocredit/server/core/query_balances.go +++ b/x/ecocredit/server/core/query_balances.go @@ -26,6 +26,7 @@ func (k Keeper) Balances(ctx context.Context, req *core.QueryBalancesRequest) (* if err != nil { return nil, err } + defer it.Close() balances := make([]*core.BatchBalanceInfo, 0, 8) // pre-allocate some cap space for it.Next() { diff --git a/x/ecocredit/server/core/query_batches_by_class.go b/x/ecocredit/server/core/query_batches_by_class.go index f9284bab3a..6777ca747f 100644 --- a/x/ecocredit/server/core/query_batches_by_class.go +++ b/x/ecocredit/server/core/query_batches_by_class.go @@ -29,6 +29,7 @@ func (k Keeper) BatchesByClass(ctx context.Context, request *core.QueryBatchesBy if err != nil { return nil, err } + defer it.Close() batches := make([]*core.BatchInfo, 0, 10) for it.Next() { diff --git a/x/ecocredit/server/core/query_batches_by_issuer.go b/x/ecocredit/server/core/query_batches_by_issuer.go index dce5fdb733..5037d06281 100644 --- a/x/ecocredit/server/core/query_batches_by_issuer.go +++ b/x/ecocredit/server/core/query_batches_by_issuer.go @@ -29,6 +29,7 @@ func (k Keeper) BatchesByIssuer(ctx context.Context, req *core.QueryBatchesByIss if err != nil { return nil, err } + defer it.Close() batches := make([]*core.BatchInfo, 0, 8) diff --git a/x/ecocredit/server/core/query_class_issuers.go b/x/ecocredit/server/core/query_class_issuers.go index 42e61a3fa1..4727c3ffd1 100644 --- a/x/ecocredit/server/core/query_class_issuers.go +++ b/x/ecocredit/server/core/query_class_issuers.go @@ -27,6 +27,7 @@ func (k Keeper) ClassIssuers(ctx context.Context, request *core.QueryClassIssuer if err != nil { return nil, err } + defer it.Close() issuers := make([]string, 0) for it.Next() { diff --git a/x/ecocredit/server/core/query_classes.go b/x/ecocredit/server/core/query_classes.go index f85b9fd540..750a45eedd 100644 --- a/x/ecocredit/server/core/query_classes.go +++ b/x/ecocredit/server/core/query_classes.go @@ -22,6 +22,7 @@ func (k Keeper) Classes(ctx context.Context, request *core.QueryClassesRequest) if err != nil { return nil, err } + defer it.Close() classes := make([]*core.ClassInfo, 0) for it.Next() { diff --git a/x/ecocredit/server/core/query_classes_by_admin.go b/x/ecocredit/server/core/query_classes_by_admin.go index b70b16f23a..38fbc4d007 100644 --- a/x/ecocredit/server/core/query_classes_by_admin.go +++ b/x/ecocredit/server/core/query_classes_by_admin.go @@ -28,6 +28,7 @@ func (k Keeper) ClassesByAdmin(ctx context.Context, req *core.QueryClassesByAdmi if err != nil { return nil, err } + defer it.Close() adminString := admin.String() classes := make([]*core.ClassInfo, 0) diff --git a/x/ecocredit/server/core/query_projects.go b/x/ecocredit/server/core/query_projects.go index a33d0760da..1ec0cbabfb 100644 --- a/x/ecocredit/server/core/query_projects.go +++ b/x/ecocredit/server/core/query_projects.go @@ -27,6 +27,7 @@ func (k Keeper) Projects(ctx context.Context, request *core.QueryProjectsRequest if err != nil { return nil, err } + defer it.Close() projects := make([]*core.ProjectInfo, 0) for it.Next() { diff --git a/x/ecocredit/server/core/query_projects_by_reference_id.go b/x/ecocredit/server/core/query_projects_by_reference_id.go index 64b7b4e1de..5a6d332edc 100644 --- a/x/ecocredit/server/core/query_projects_by_reference_id.go +++ b/x/ecocredit/server/core/query_projects_by_reference_id.go @@ -28,6 +28,7 @@ func (k Keeper) ProjectsByReferenceId(ctx context.Context, req *core.QueryProjec if err != nil { return nil, err } + defer it.Close() projects := make([]*core.ProjectInfo, 0) for it.Next() { diff --git a/x/ecocredit/server/core/update_class_test.go b/x/ecocredit/server/core/update_class_test.go index 5bac447616..400c91cbed 100644 --- a/x/ecocredit/server/core/update_class_test.go +++ b/x/ecocredit/server/core/update_class_test.go @@ -115,6 +115,7 @@ func TestUpdateClass_Issuers(t *testing.T) { for it.Next() { count++ } + it.Close() assert.Equal(t, len(addrs)+len(newAddrs), count, "expected to get %d address matches, got %d", len(addrs)+len(newAddrs), count) // remove the original addrs @@ -142,6 +143,7 @@ func TestUpdateClass_Issuers(t *testing.T) { assert.Check(t, !addr.Equals(rmAddr), "%s was supposed to be deleted", rmAddr.String()) } } + it.Close() } func TestUpdateClass_IssuersErrs(t *testing.T) { diff --git a/x/ecocredit/server/marketplace/query_allowed_denoms.go b/x/ecocredit/server/marketplace/query_allowed_denoms.go index b5f89e3174..0f18895725 100644 --- a/x/ecocredit/server/marketplace/query_allowed_denoms.go +++ b/x/ecocredit/server/marketplace/query_allowed_denoms.go @@ -17,6 +17,9 @@ func (k Keeper) AllowedDenoms(ctx context.Context, req *marketplace.QueryAllowed } it, err := k.stateStore.AllowedDenomTable().List(ctx, &marketplacev1.AllowedDenomPrimaryKey{}, ormlist.Paginate(pg)) + if err != nil { + return nil, err + } defer it.Close() allowedDenoms := make([]*marketplace.AllowedDenom, 0)