Repository: algorand/indexer (go)

Issue:
Lookup of asset id 0 yields unexpected behavior.
### Subject of the issue

A request like `https://mainnet-idx.algonode.cloud/v2/assets/0`

Will generate the query

```sql
 SELECT index, creator_addr, params, created_at, closed_at, deleted FROM asset a WHERE NOT a.deleted ORDER BY index ASC LIMIT 1
```

Which just returns the first asset it comes across by index since the 0 is omitted from the query parameters.

This is strange behavior and should either be documented or return a 404


### Your environment

Indexer 2.11.1



Pull request:
Fix: Ensure requests for asset/application id 0 check for the correct result


<!--
Thanks for submitting a pull request! We appreciate the time and effort you spent to get this far.

If you haven't already, please make sure that you've reviewed the CONTRIBUTING guide:
https://github.com/algorand/go-algorand/blob/master/CONTRIBUTING.md#code-guidelines
-->

## Summary

Make assetId and applicationId arguments pointers across several indexer queries for assets, apps, and transactions. Meant to resolve #1087, where requesting the 0 indexed asset/application resulted in a search query returning an incorrect creatable.

## Test Plan

Existing tests are updated and passed. Manually tested the problematic queries.


Patch:
diff --git a/api/converter_utils.go b/api/converter_utils.go
index 4bc7041..8b4081a 100644
--- a/api/converter_utils.go
+++ b/api/converter_utils.go
@@ -645,17 +645,17 @@ func (si *ServerImplementation) assetParamsToAssetQuery(params generated.SearchF
 		return idb.AssetsQuery{}, errors.New(errUnableToParseAddress)
 	}
 
-	var assetGreaterThan uint64 = 0
+	var assetGreaterThan *uint64
 	if params.Next != nil {
 		agt, err := strconv.ParseUint(*params.Next, 10, 64)
 		if err != nil {
 			return idb.AssetsQuery{}, fmt.Errorf("%s: %v", errUnableToParseNext, err)
 		}
-		assetGreaterThan = agt
+		assetGreaterThan = &agt
 	}
 
 	query := idb.AssetsQuery{
-		AssetID:            uintOrDefault(params.AssetId),
+		AssetID:            params.AssetId,
 		AssetIDGreaterThan: assetGreaterThan,
 		Creator:            creator,
 		Name:               strOrDefault(params.Name),
@@ -674,17 +674,17 @@ func (si *ServerImplementation) appParamsToApplicationQuery(params generated.Sea
 		return idb.ApplicationQuery{}, errors.New(errUnableToParseAddress)
 	}
 
-	var appGreaterThan uint64 = 0
+	var appGreaterThan *uint64
 	if params.Next != nil {
 		agt, err := strconv.ParseUint(*params.Next, 10, 64)
 		if err != nil {
 			return idb.ApplicationQuery{}, fmt.Errorf("%s: %v", errUnableToParseNext, err)
 		}
-		appGreaterThan = agt
+		appGreaterThan = &agt
 	}
 
 	return idb.ApplicationQuery{
-		ApplicationID:            uintOrDefault(params.ApplicationId),
+		ApplicationID:            params.ApplicationId,
 		ApplicationIDGreaterThan: appGreaterThan,
 		Address:                  addr,
 		IncludeDeleted:           boolOrDefault(params.IncludeAll),
@@ -698,8 +698,8 @@ func (si *ServerImplementation) transactionParamsToTransactionFilter(params gene
 	// Integer
 	filter.MaxRound = uintOrDefault(params.MaxRound)
 	filter.MinRound = uintOrDefault(params.MinRound)
-	filter.AssetID = uintOrDefault(params.AssetId)
-	filter.ApplicationID = uintOrDefault(params.ApplicationId)
+	filter.AssetID = params.AssetId
+	filter.ApplicationID = params.ApplicationId
 	filter.Limit = min(uintOrDefaultValue(params.Limit, si.opts.DefaultTransactionsLimit), si.opts.MaxTransactionsLimit)
 	filter.Round = params.Round
 
@@ -730,7 +730,7 @@ func (si *ServerImplementation) transactionParamsToTransactionFilter(params gene
 	filter.RekeyTo = params.RekeyTo
 
 	// filter Algos or Asset but not both.
-	if filter.AssetID != 0 || filter.TypeEnum == idb.TypeEnumAssetTransfer {
+	if filter.AssetID != nil || filter.TypeEnum == idb.TypeEnumAssetTransfer {
 		filter.AssetAmountLT = params.CurrencyLessThan
 		filter.AssetAmountGT = params.CurrencyGreaterThan
 	} else {
diff --git a/api/handlers.go b/api/handlers.go
index f325e4b..ca13335 100644
--- a/api/handlers.go
+++ b/api/handlers.go
@@ -59,7 +59,8 @@ func validateTransactionFilter(filter *idb.TransactionFilter) error {
 	// Round or application-id or asset-id is greater than math.MaxInt64
 	if filter.MinRound > math.MaxInt64 || filter.MaxRound > math.MaxInt64 ||
 		(filter.Round != nil && *filter.Round > math.MaxInt64) ||
-		filter.AssetID > math.MaxInt64 || filter.ApplicationID > math.MaxInt64 {
+		(filter.AssetID != nil && *filter.AssetID > math.MaxInt64) ||
+		(filter.ApplicationID != nil && *filter.ApplicationID > math.MaxInt64) {
 		errorArr = append(errorArr, errValueExceedingInt64)
 	}
 
@@ -304,18 +305,18 @@ func (si *ServerImplementation) LookupAccountAssets(ctx echo.Context, accountID
 		return badRequest(ctx, errors[0])
 	}
 
-	var assetGreaterThan uint64 = 0
+	var assetGreaterThan *uint64
 	if params.Next != nil {
 		agt, err := strconv.ParseUint(*params.Next, 10, 64)
 		if err != nil {
 			return badRequest(ctx, fmt.Sprintf("%s: %v", errUnableToParseNext, err))
 		}
-		assetGreaterThan = agt
+		assetGreaterThan = &agt
 	}
 
 	query := idb.AssetBalanceQuery{
 		Address:        addr,
-		AssetID:        uintOrDefault(params.AssetId),
+		AssetID:        params.AssetId,
 		AssetIDGT:      assetGreaterThan,
 		IncludeDeleted: boolOrDefault(params.IncludeAll),
 		Limit:          min(uintOrDefaultValue(params.Limit, si.opts.DefaultBalancesLimit), si.opts.MaxBalancesLimit),
@@ -545,7 +546,7 @@ func (si *ServerImplementation) LookupApplicationByID(ctx echo.Context, applicat
 		return notFound(ctx, errValueExceedingInt64)
 	}
 	q := idb.ApplicationQuery{
-		ApplicationID:  applicationID,
+		ApplicationID:  uint64Ptr(applicationID),
 		IncludeDeleted: boolOrDefault(params.IncludeAll),
 		Limit:          1,
 	}
@@ -819,7 +820,7 @@ func (si *ServerImplementation) LookupAssetBalances(ctx echo.Context, assetID ui
 	}
 
 	query := idb.AssetBalanceQuery{
-		AssetID:        assetID,
+		AssetID:        &assetID,
 		AmountGT:       params.CurrencyGreaterThan,
 		AmountLT:       params.CurrencyLessThan,
 		IncludeDeleted: boolOrDefault(params.IncludeAll),
diff --git a/idb/idb.go b/idb/idb.go
index c91b1c0..a4c58c9 100644
--- a/idb/idb.go
+++ b/idb/idb.go
@@ -224,11 +224,11 @@ type TransactionFilter struct {
 	AlgosLT    *uint64
 	RekeyTo    *bool // nil for no filter
 
-	AssetID       uint64 // filter transactions relevant to an asset
+	AssetID       *uint64 // filter transactions relevant to an asset
 	AssetAmountGT *uint64
 	AssetAmountLT *uint64
 
-	ApplicationID uint64 // filter transactions relevant to an application
+	ApplicationID *uint64 // filter transactions relevant to an application
 
 	EffectiveAmountGT *uint64 // Algo: Amount + CloseAmount > x
 	EffectiveAmountLT *uint64 // Algo: Amount + CloseAmount < x
@@ -306,8 +306,8 @@ func (e MaxAPIResourcesPerAccountError) Error() string {
 
 // AssetsQuery is a parameter object with all of the asset filter options.
 type AssetsQuery struct {
-	AssetID            uint64
-	AssetIDGreaterThan uint64
+	AssetID            *uint64
+	AssetIDGreaterThan *uint64
 
 	Creator []byte
 
@@ -338,8 +338,8 @@ type AssetRow struct {
 
 // AssetBalanceQuery is a parameter object with all of the asset balance filter options.
 type AssetBalanceQuery struct {
-	AssetID   uint64
-	AssetIDGT uint64
+	AssetID   *uint64
+	AssetIDGT *uint64
 	AmountGT  *uint64 // only rows > this
 	AmountLT  *uint64 // only rows < this
 
@@ -376,8 +376,8 @@ type ApplicationRow struct {
 // ApplicationQuery is a parameter object used for query local and global application state.
 type ApplicationQuery struct {
 	Address                  []byte
-	ApplicationID            uint64
-	ApplicationIDGreaterThan uint64
+	ApplicationID            *uint64
+	ApplicationIDGreaterThan *uint64
 	IncludeDeleted           bool
 	Limit                    uint64
 }
diff --git a/idb/postgres/postgres.go b/idb/postgres/postgres.go
index 8cad4c4..1a6850c 100644
--- a/idb/postgres/postgres.go
+++ b/idb/postgres/postgres.go
@@ -585,19 +585,17 @@ func buildTransactionQuery(tf idb.TransactionFilter) (query string, whereArgs []
 		whereArgs = append(whereArgs, convertedTime)
 		partNumber++
 	}
-	if tf.AssetID != 0 || tf.ApplicationID != 0 {
+	if tf.AssetID != nil || tf.ApplicationID != nil {
 		var creatableID uint64
-		if tf.AssetID != 0 {
-			creatableID = tf.AssetID
-			if tf.ApplicationID != 0 {
-				if tf.AssetID == tf.ApplicationID {
-					// this is nonsense, but I'll allow it
-				} else {
+		if tf.AssetID != nil {
+			creatableID = *tf.AssetID
+			if tf.ApplicationID != nil {
+				if *tf.AssetID != *tf.ApplicationID {
 					return "", nil, fmt.Errorf("cannot search both assetid and appid")
 				}
 			}
 		} else {
-			creatableID = tf.ApplicationID
+			creatableID = *tf.ApplicationID
 		}
 		whereParts = append(whereParts, fmt.Sprintf("t.asset = $%d", partNumber))
 		whereArgs = append(whereArgs, creatableID)
@@ -1978,14 +1976,14 @@ func (db *IndexerDb) Assets(ctx context.Context, filter idb.AssetsQuery) (<-chan
 	whereParts := make([]string, 0, maxWhereParts)
 	whereArgs := make([]interface{}, 0, maxWhereParts)
 	partNumber := 1
-	if filter.AssetID != 0 {
+	if filter.AssetID != nil {
 		whereParts = append(whereParts, fmt.Sprintf("a.index = $%d", partNumber))
-		whereArgs = append(whereArgs, filter.AssetID)
+		whereArgs = append(whereArgs, *filter.AssetID)
 		partNumber++
 	}
-	if filter.AssetIDGreaterThan != 0 {
+	if filter.AssetIDGreaterThan != nil {
 		whereParts = append(whereParts, fmt.Sprintf("a.index > $%d", partNumber))
-		whereArgs = append(whereArgs, filter.AssetIDGreaterThan)
+		whereArgs = append(whereArgs, *filter.AssetIDGreaterThan)
 		partNumber++
 	}
 	if filter.Creator != nil {
@@ -2107,14 +2105,14 @@ func (db *IndexerDb) AssetBalances(ctx context.Context, abq idb.AssetBalanceQuer
 	whereParts := make([]string, 0, maxWhereParts)
 	whereArgs := make([]interface{}, 0, maxWhereParts)
 	partNumber := 1
-	if abq.AssetID != 0 {
+	if abq.AssetID != nil {
 		whereParts = append(whereParts, fmt.Sprintf("aa.assetid = $%d", partNumber))
-		whereArgs = append(whereArgs, abq.AssetID)
+		whereArgs = append(whereArgs, *abq.AssetID)
 		partNumber++
 	}
-	if abq.AssetIDGT != 0 {
+	if abq.AssetIDGT != nil {
 		whereParts = append(whereParts, fmt.Sprintf("aa.assetid > $%d", partNumber))
-		whereArgs = append(whereArgs, abq.AssetIDGT)
+		whereArgs = append(whereArgs, *abq.AssetIDGT)
 		partNumber++
 	}
 	if abq.Address != nil {
@@ -2234,9 +2232,9 @@ func (db *IndexerDb) Applications(ctx context.Context, filter idb.ApplicationQue
 	whereParts := make([]string, 0, maxWhereParts)
 	whereArgs := make([]interface{}, 0, maxWhereParts)
 	partNumber := 1
-	if filter.ApplicationID != 0 {
+	if filter.ApplicationID != nil {
 		whereParts = append(whereParts, fmt.Sprintf("index = $%d", partNumber))
-		whereArgs = append(whereArgs, filter.ApplicationID)
+		whereArgs = append(whereArgs, *filter.ApplicationID)
 		partNumber++
 	}
 	if filter.Address != nil {
@@ -2244,9 +2242,9 @@ func (db *IndexerDb) Applications(ctx context.Context, filter idb.ApplicationQue
 		whereArgs = append(whereArgs, filter.Address)
 		partNumber++
 	}
-	if filter.ApplicationIDGreaterThan != 0 {
+	if filter.ApplicationIDGreaterThan != nil {
 		whereParts = append(whereParts, fmt.Sprintf("index > $%d", partNumber))
-		whereArgs = append(whereArgs, filter.ApplicationIDGreaterThan)
+		whereArgs = append(whereArgs, *filter.ApplicationIDGreaterThan)
 		partNumber++
 	}
 	if !filter.IncludeDeleted {
@@ -2485,9 +2483,9 @@ func (db *IndexerDb) AppLocalState(ctx context.Context, filter idb.ApplicationQu
 	whereParts := make([]string, 0, maxWhereParts)
 	whereArgs := make([]interface{}, 0, maxWhereParts)
 	partNumber := 1
-	if filter.ApplicationID != 0 {
+	if filter.ApplicationID != nil {
 		whereParts = append(whereParts, fmt.Sprintf("app = $%d", partNumber))
-		whereArgs = append(whereArgs, filter.ApplicationID)
+		whereArgs = append(whereArgs, *filter.ApplicationID)
 		partNumber++
 	}
 	if filter.Address != nil {
@@ -2495,9 +2493,9 @@ func (db *IndexerDb) AppLocalState(ctx context.Context, filter idb.ApplicationQu
 		whereArgs = append(whereArgs, filter.Address)
 		partNumber++
 	}
-	if filter.ApplicationIDGreaterThan != 0 {
+	if filter.ApplicationIDGreaterThan != nil {
 		whereParts = append(whereParts, fmt.Sprintf("app > $%d", partNumber))
-		whereArgs = append(whereArgs, filter.ApplicationIDGreaterThan)
+		whereArgs = append(whereArgs, *filter.ApplicationIDGreaterThan)
 		partNumber++
 	}
 	if !filter.IncludeDeleted {


Test patch:
diff --git a/api/handlers_e2e_test.go b/api/handlers_e2e_test.go
index 70f6ff5..0808b60 100644
--- a/api/handlers_e2e_test.go
+++ b/api/handlers_e2e_test.go
@@ -223,6 +223,28 @@ func TestApplicationHandlers(t *testing.T) {
 			checkAppLocalState(t, &response.AppsLocalStates[0])
 		})
 	}
+
+	t.Run("app-0-query", func(t *testing.T) {
+		//////////
+		// When // We query an app that does not exist
+		//////////
+
+		c, api, rec := setupReq("/v2/applications/:appidx", "appidx", "0")
+		params := generated.LookupApplicationByIDParams{}
+		err = api.LookupApplicationByID(c, 0, params)
+		require.NoError(t, err)
+
+		//////////
+		// Then // The response is 404
+		//////////
+
+		require.Equal(t, http.StatusNotFound, rec.Code, fmt.Sprintf("unexpected return code, body: %s", rec.Body.String()))
+		data := rec.Body.Bytes()
+		var response generated.ErrorResponse
+		err = json.Decode(data, &response)
+		require.NoError(t, err)
+		require.Equal(t, "no application found for application-id: 0", response.Message)
+	})
 }
 
 func TestAccountExcludeParameters(t *testing.T) {
@@ -1930,7 +1952,7 @@ func runBoxCreateMutateDelete(t *testing.T, comparator boxTestComparator) {
 	err = db.AddBlock(&vb1)
 	require.NoError(t, err)
 
-	opts := idb.ApplicationQuery{ApplicationID: uint64(appid)}
+	opts := idb.ApplicationQuery{ApplicationID: uint64Ptr(uint64(appid))}
 
 	rowsCh, round := db.Applications(context.Background(), opts)
 	require.Equal(t, uint64(currentRound), round)
@@ -2524,12 +2546,12 @@ func TestAccounts(t *testing.T) {
 	require.NoError(t, err)
 	stxn, _, err := util.DecodeSignedTxn(vb.Block.BlockHeader, vb.Block.Payset[0])
 	require.NoError(t, err)
-	assetID := crypto.TransactionIDString(stxn.Txn)
+	transactionID := crypto.TransactionIDString(stxn.Txn)
 
 	///////////
 	// When // Look up transaction containing this asset
 	///////////
-	path = fmt.Sprintf("/v2/transactions/%s", assetID)
+	path = fmt.Sprintf("/v2/transactions/%s", transactionID)
 	resp, data = makeRequest(t, listenAddr, path, false)
 	require.Equal(t, http.StatusOK, resp.StatusCode, fmt.Sprintf("unexpected return code, body: %s", string(data)))
 	var txn generated.TransactionResponse
@@ -2552,7 +2574,7 @@ func TestAccounts(t *testing.T) {
 	///////////
 	// When // Look up the asset
 	///////////
-	path = fmt.Sprintf("/v2/assets/%d", 0)
+	path = fmt.Sprintf("/v2/assets/%d", expectedAssetIdx)
 	resp, data = makeRequest(t, listenAddr, path, false)
 	require.Equal(t, http.StatusOK, resp.StatusCode, fmt.Sprintf("unexpected return code, body: %s", string(data)))
 	var asset generated.AssetResponse
diff --git a/api/handlers_test.go b/api/handlers_test.go
index 36459e3..18c1526 100644
--- a/api/handlers_test.go
+++ b/api/handlers_test.go
@@ -55,7 +55,7 @@ func TestTransactionParamToTransactionFilter(t *testing.T) {
 		{
 			"Int field",
 			generated.SearchForTransactionsParams{AssetId: uint64Ptr(1234)},
-			idb.TransactionFilter{AssetID: 1234, Limit: defaultOpts.DefaultTransactionsLimit},
+			idb.TransactionFilter{AssetID: uint64Ptr(1234), Limit: defaultOpts.DefaultTransactionsLimit},
 			nil,
 		},
 		{
@@ -120,7 +120,7 @@ func TestTransactionParamToTransactionFilter(t *testing.T) {
 				Round:             nil,
 				MinRound:          2,
 				MaxRound:          3,
-				AssetID:           4,
+				AssetID:           uint64Ptr(4),
 				BeforeTime:        time.Date(2021, 1, 1, 1, 0, 0, 0, time.FixedZone("UTC", 0)),
 				AfterTime:         time.Date(2022, 2, 2, 2, 0, 0, 0, time.FixedZone("UTC", 0)),
 				AlgosGT:           nil,
@@ -134,7 +134,7 @@ func TestTransactionParamToTransactionFilter(t *testing.T) {
 				Offset:            nil,
 				OffsetLT:          nil,
 				OffsetGT:          nil,
-				ApplicationID:     7,
+				ApplicationID:     uint64Ptr(7),
 			},
 			nil,
 		},
@@ -195,7 +195,7 @@ func TestTransactionParamToTransactionFilter(t *testing.T) {
 		{
 			name:          "Searching by application-id",
 			params:        generated.SearchForTransactionsParams{ApplicationId: uint64Ptr(1234)},
-			filter:        idb.TransactionFilter{ApplicationID: 1234, Limit: defaultOpts.DefaultTransactionsLimit},
+			filter:        idb.TransactionFilter{ApplicationID: uint64Ptr(1234), Limit: defaultOpts.DefaultTransactionsLimit},
 			errorContains: nil,
 		},
 		{
@@ -299,14 +299,14 @@ func TestValidateTransactionFilter(t *testing.T) {
 		{
 			name: "application-id > math.MaxInt64",
 			filter: idb.TransactionFilter{
-				ApplicationID: math.MaxInt64 + 1,
+				ApplicationID: uint64Ptr(math.MaxInt64 + 1),
 			},
 			errorContains: []string{errValueExceedingInt64},
 		},
 		{
 			name: "asset-id > math.MaxInt64",
 			filter: idb.TransactionFilter{
-				AssetID: math.MaxInt64 + 1,
+				AssetID: uint64Ptr(math.MaxInt64 + 1),
 			},
 			errorContains: []string{errValueExceedingInt64},
 		},
diff --git a/cmd/idbtest/idbtest.go b/cmd/idbtest/idbtest.go
index 3307e05..e6a6255 100644
--- a/cmd/idbtest/idbtest.go
+++ b/cmd/idbtest/idbtest.go
@@ -41,8 +41,8 @@ func doAssetQueryTests(db idb.IndexerDb) {
 	printAssetQuery(db, idb.AssetsQuery{Query: "us", Limit: 9})
 	printAssetQuery(db, idb.AssetsQuery{Name: "Tether USDt", Limit: 1})
 	printAssetQuery(db, idb.AssetsQuery{Unit: "USDt", Limit: 2})
-	printAssetQuery(db, idb.AssetsQuery{AssetID: 312769, Limit: 1})
-	printAssetQuery(db, idb.AssetsQuery{AssetIDGreaterThan: 312769, Query: "us", Limit: 2})
+	printAssetQuery(db, idb.AssetsQuery{AssetID: uint64Ptr(312769), Limit: 1})
+	printAssetQuery(db, idb.AssetsQuery{AssetIDGreaterThan: uint64Ptr(312769), Query: "us", Limit: 2})
 	tcreator, err := sdk_types.DecodeAddress("XIU7HGGAJ3QOTATPDSIIHPFVKMICXKHMOR2FJKHTVLII4FAOA3CYZQDLG4")
 	maybeFail(err, "addr decode, %v\n", err)
 	printAssetQuery(db, idb.AssetsQuery{Creator: tcreator[:], Limit: 1})
@@ -171,7 +171,7 @@ func main() {
 		printTxnQuery(db, idb.TransactionFilter{Limit: 2})
 		printTxnQuery(db, idb.TransactionFilter{MinRound: 5000000, Limit: 2})
 		printTxnQuery(db, idb.TransactionFilter{MaxRound: 100000, Limit: 2})
-		printTxnQuery(db, idb.TransactionFilter{AssetID: 604, Limit: 2})
+		printTxnQuery(db, idb.TransactionFilter{AssetID: uint64Ptr(604), Limit: 2})
 		printTxnQuery(db, idb.TransactionFilter{TypeEnum: 2, Limit: 2}) // keyreg
 		offset := uint64(3)
 		printTxnQuery(db, idb.TransactionFilter{Offset: &offset, Limit: 2})
diff --git a/idb/postgres/postgres_boxes_test.go b/idb/postgres/postgres_boxes_test.go
index d601199..3f77d18 100644
--- a/idb/postgres/postgres_boxes_test.go
+++ b/idb/postgres/postgres_boxes_test.go
@@ -124,7 +124,7 @@ func runBoxCreateMutateDelete(t *testing.T, comparator boxTestComparator) {
 	err = db.AddBlock(&vb1)
 	require.NoError(t, err)
 
-	opts := idb.ApplicationQuery{ApplicationID: uint64(appid)}
+	opts := idb.ApplicationQuery{ApplicationID: uint64Ptr(uint64(appid))}
 
 	rowsCh, round := db.Applications(context.Background(), opts)
 	require.Equal(t, uint64(currentRound), round)
diff --git a/idb/postgres/postgres_integration_test.go b/idb/postgres/postgres_integration_test.go
index f1854d0..ac34144 100644
--- a/idb/postgres/postgres_integration_test.go
+++ b/idb/postgres/postgres_integration_test.go
@@ -856,8 +856,8 @@ func TestAppExtraPages(t *testing.T) {
 	require.Equal(t, uint32(1), ap.ExtraProgramPages)
 
 	var filter idb.ApplicationQuery
-	var aidx uint64 = uint64(index)
-	filter.ApplicationID = aidx
+	var aidx = index
+	filter.ApplicationID = uint64Ptr(aidx)
 	appRows, _ := db.Applications(context.Background(), filter)
 	num := 0
 	for row := range appRows {
@@ -938,7 +938,7 @@ func TestLargeAssetAmount(t *testing.T) {
 
 	// txn := test.MakeAssetConfigTxn(
 	//	0, math.MaxUint64, 0, false, "mc", "mycoin", "", test.AccountA)
-	assetid := uint64(1)
+	assetid := uint64Ptr(uint64(1))
 	vb, err := test.ReadValidatedBlockFromFile("test_resources/validated_blocks/LargeAssetAmount.vb")
 	require.NoError(t, err)
 	err = db.AddBlock(&vb)
@@ -1068,7 +1068,7 @@ func TestNonDisplayableUTF8(t *testing.T) {
 		},
 	}
 
-	assetID := uint64(1)
+	assetID := uint64Ptr(uint64(1))
 
 	for _, testcase := range tests {
 		testcase := testcase
@@ -1165,7 +1165,7 @@ func TestReconfigAsset(t *testing.T) {
 	unit := "co\000in"
 	name := "algo"
 	url := "https://algorand.com"
-	assetID := uint64(1)
+	assetID := uint64Ptr(uint64(1))
 
 	// txn := test.MakeAssetConfigTxn(
 	//	0, math.MaxUint64, 0, false, unit, name, url, test.AccountA)
@@ -1406,7 +1406,7 @@ func TestAddBlockCreateDeleteAssetSameRound(t *testing.T) {
 	db, shutdownFunc := setupIdb(t, test.MakeGenesis())
 	defer shutdownFunc()
 
-	assetid := uint64(1)
+	assetid := uint64Ptr(uint64(1))
 	// createTxn := test.MakeAssetConfigTxn(0, 3, 0, false, "", "", "", test.AccountA)
 	// deleteTxn := test.MakeAssetDestroyTxn(assetid, test.AccountA)
 	vb, err := test.ReadValidatedBlockFromFile("test_resources/validated_blocks/AddBlockCreateDeleteAssetSameRound.vb")
@@ -1460,7 +1460,7 @@ func TestAddBlockCreateDeleteAppSameRound(t *testing.T) {
 	db, shutdownFunc := setupIdb(t, test.MakeGenesis())
 	defer shutdownFunc()
 
-	appid := uint64(1)
+	appid := uint64Ptr(uint64(1))
 
 	// createTxn := test.MakeCreateAppTxn(test.AccountA)
 	// deleteTxn := test.MakeAppDestroyTxn(appid, test.AccountA)
@@ -1495,7 +1495,7 @@ func TestAddBlockAppOptInOutSameRound(t *testing.T) {
 	// createTxn := test.MakeCreateAppTxn(test.AccountA)
 	// optInTxn := test.MakeAppOptInTxn(appid, test.AccountB)
 	// optOutTxn := test.MakeAppOptOutTxn(appid, test.AccountB)
-	appid := uint64(1)
+	appid := uint64Ptr(uint64(1))
 	vb, err := test.ReadValidatedBlockFromFile("test_resources/validated_blocks/AddBlockAppOptInOutSameRound.vb")
 	require.NoError(t, err)
 	err = db.AddBlock(&vb)
@@ -1533,7 +1533,7 @@ func TestAddBlockAppOptInOutSameRound(t *testing.T) {
 	require.True(t, ok)
 	require.NoError(t, lsRow.Error)
 	ls := lsRow.AppLocalState
-	require.Equal(t, appid, ls.Id)
+	require.Equal(t, appid, uint64Ptr(ls.Id))
 	require.NotNil(t, ls.Deleted)
 	assert.True(t, *ls.Deleted)
 	require.NotNil(t, ls.OptedInAtRound)