Skip to content

Commit

Permalink
fix(eventindexer): nft indexing fix (#15525)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Jan 19, 2024
1 parent baefaef commit 73ef96d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
11 changes: 6 additions & 5 deletions packages/eventindexer/pkg/repo/nft_balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ func (r *NFTBalanceRepository) IncreaseBalance(
if err != nil {
// allow to be not found, it may be first time this user has this NFT
if err != gorm.ErrRecordNotFound {
// should always be found, since we are subtracting a balance.
// that should be indexed as a positive balance before.
return nil, errors.Wrap(err, "r.db.gormDB.First")
}
}
Expand Down Expand Up @@ -85,9 +83,12 @@ func (r *NFTBalanceRepository) SubtractBalance(
First(b).
Error
if err != nil {
// should always be found, since we are subtracting a balance.
// that should be indexed as a positive balance before.
return nil, errors.Wrap(err, "r.db.gormDB.First")
if err != gorm.ErrRecordNotFound {
return nil, errors.Wrap(err, "r.db.gormDB.First")
} else {
// cant subtract a balance if user never had this balance, indexing issue
return nil, nil
}
}

b.Amount -= opts.Amount
Expand Down
12 changes: 0 additions & 12 deletions packages/eventindexer/pkg/repo/nft_balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,6 @@ func TestIntegration_NFTBalance_Decrease(t *testing.T) {
assert.Equal(t, tt.wantErr, err)
})
}

bal3, err := nftBalanceRepo.SubtractBalance(context.Background(),
eventindexer.UpdateNFTBalanceOpts{
ChainID: 1,
Address: "0x123",
TokenID: 1,
ContractAddress: "0x1234",
ContractType: "ERC721",
Amount: 1,
})
assert.ErrorContains(t, err, "record not found")
assert.Nil(t, bal3)
}

// TODO: fix this test
Expand Down

0 comments on commit 73ef96d

Please sign in to comment.