Skip to content

Commit 42dec36

Browse files
committed
Modify get-holding to return null for non-existent accounts
1 parent a174979 commit 42dec36

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

convex-core/src/main/cvx/convex/asset.cvx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
(recur path *address*))
193193

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

198198
(defn burn

convex-core/src/main/java/convex/core/lang/Core.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,8 @@ public Context invoke(Context context, ACell[] args) {
11741174
if (address == null) return context.withCastError(args[0], Types.ADDRESS);
11751175

11761176
AccountStatus as=context.getAccountStatus(address);
1177-
if (as==null) return context.withError(ErrorCodes.NOBODY,"Account "+address+" does not exist to get holdings");
1177+
if (as==null) return context.withResult(Juice.LOOKUP, null);
1178+
11781179
BlobMap<Address,ACell> holdings=as.getHoldings();
11791180

11801181
// we get the target accounts holdings for the currently executing account

convex-core/src/test/java/convex/core/lang/CoreTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4680,7 +4680,9 @@ public void testSpecialEdgeCases() {
46804680
assertNull(eval(ctx,"(get-holding VILLAIN)"));
46814681
assertCastError(step(ctx,"(get-holding :foo)"));
46824682
assertCastError(step(ctx,"(get-holding nil)"));
4683-
assertNobodyError(step(ctx,"(get-holding NOONE)"));
4683+
4684+
// NOTE: holdings are nil for non-existent accounts, better for default behaviour
4685+
assertNull(eval(ctx,"(get-holding NOONE)"));
46844686

46854687
// OK to set holding for a real owner account
46864688
assertEquals(100L,evalL(ctx,"(set-holding VILLAIN 100)"));

convex-core/src/test/java/convex/lib/AssetTester.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public static void doFungibleTests (Context ctx, ACell token, Address user) {
5454
assertEquals(0L,evalL(ctx,"(asset/balance token (deploy nil))"));
5555
assertEquals(0L,evalL(ctx,"(asset/balance token (create-account *key*))"));
5656
assertEquals(0L,evalL(ctx,"(asset/get-offer token (create-account *key*) (deploy nil))"));
57+
assertEquals(0L,evalL(ctx,"(asset/balance token #675475647)"));
5758
}
5859

5960
// New Address gets zero offers

0 commit comments

Comments
 (0)