Skip to content

Commit

Permalink
Modify get-holding to return null for non-existent accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 15, 2023
1 parent a174979 commit 42dec36
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion convex-core/src/main/cvx/convex/asset.cvx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
(recur path *address*))

([path owner]
(query ;; external call, so uery to avoid re-entrant secuity risks
(query ;; external call, so use query to avoid re-entrant secuity risks
(call path (balance owner)))))

(defn burn
Expand Down
3 changes: 2 additions & 1 deletion convex-core/src/main/java/convex/core/lang/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,8 @@ public Context invoke(Context context, ACell[] args) {
if (address == null) return context.withCastError(args[0], Types.ADDRESS);

AccountStatus as=context.getAccountStatus(address);
if (as==null) return context.withError(ErrorCodes.NOBODY,"Account "+address+" does not exist to get holdings");
if (as==null) return context.withResult(Juice.LOOKUP, null);

BlobMap<Address,ACell> holdings=as.getHoldings();

// we get the target accounts holdings for the currently executing account
Expand Down
4 changes: 3 additions & 1 deletion convex-core/src/test/java/convex/core/lang/CoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4680,7 +4680,9 @@ public void testSpecialEdgeCases() {
assertNull(eval(ctx,"(get-holding VILLAIN)"));
assertCastError(step(ctx,"(get-holding :foo)"));
assertCastError(step(ctx,"(get-holding nil)"));
assertNobodyError(step(ctx,"(get-holding NOONE)"));

// NOTE: holdings are nil for non-existent accounts, better for default behaviour
assertNull(eval(ctx,"(get-holding NOONE)"));

// OK to set holding for a real owner account
assertEquals(100L,evalL(ctx,"(set-holding VILLAIN 100)"));
Expand Down
1 change: 1 addition & 0 deletions convex-core/src/test/java/convex/lib/AssetTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static void doFungibleTests (Context ctx, ACell token, Address user) {
assertEquals(0L,evalL(ctx,"(asset/balance token (deploy nil))"));
assertEquals(0L,evalL(ctx,"(asset/balance token (create-account *key*))"));
assertEquals(0L,evalL(ctx,"(asset/get-offer token (create-account *key*) (deploy nil))"));
assertEquals(0L,evalL(ctx,"(asset/balance token #675475647)"));
}

// New Address gets zero offers
Expand Down

0 comments on commit 42dec36

Please sign in to comment.