Skip to content

Commit de59235

Browse files
committed
Assert :FUNDS error if sender balance is insufficient for token offer
1 parent b6a1f50 commit de59235

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
_ (cond (< off quantity) (fail :STATE "insufficient offer"))
150150
bal (nth rec 0)
151151
nbal (- bal quantity)
152-
_ (cond (< nbal 0) (fail "insufficent balance to accept"))
152+
_ (cond (< nbal 0) (fail :FUNDS "insufficent balance to accept"))
153153
noff (- off quantity)
154154
nos (cond (<= noff 0) (dissoc os receiver) (assoc os receiver noff))
155155
nrec [nbal nos]]

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
"If asset contains multiple assets, accepts each in turn. MUST fail if the asset cannot be accepted."]
4343
:examples [{:code "(accept sender [fungible-token-address 1000])"}]
4444
:signature [{:params [sender asset]}
45-
{:params [sender asset-path quantity]}]}}
45+
{:params [sender asset-path quantity]}]
46+
:errors {:STATE "If there is no sufficient offer to accept."
47+
:FUNDS "If sender has insufficient balance."}}}
4648

4749
([sender asset]
4850
(cond

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131

132132
(< sendbal
133133
quantity)
134-
(fail "Sender token balance is insufficient")
134+
(fail :FUNDS "Sender token balance is insufficient")
135135

136136
(let [new-offer (- offer
137137
quantity)]

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ public static void doFungibleTests (Context ctx, ACell token, Address user) {
8080
assertCVMEquals(BAL,ctxx.getResult());
8181
assertEquals(BAL,evalL(ctxx,"(asset/get-offer token *address* *address*)"));
8282

83-
// accepting one more token than offered at this point should be error
83+
// accepting one more token than offered at this point should be :STATE error
8484
assertError(step(ctxx,"(asset/accept *address* [token (inc BAL)])"));
8585

8686
ctxx=step(ctxx,"(asset/accept *address* token BAL)");
8787
assertCVMEquals(BAL,ctxx.getResult());
8888
assertCVMEquals(BAL,evalL(ctxx,"(asset/balance token)"));
8989

90-
// accepting one more token at this point should be error
90+
// accepting one more token at this point should be :STATE error
9191
assertStateError(step(ctxx,"(asset/accept *address* [token 1])"));
9292

9393
// Offer / accept of half balance should work
@@ -97,6 +97,11 @@ public static void doFungibleTests (Context ctx, ACell token, Address user) {
9797
ctxx=step(ctxx,"(asset/accept *address* token (div BAL 2))");
9898
assertCVMEquals(BAL/2,ctxx.getResult());
9999
assertCVMEquals(BAL,evalL(ctxx,"(asset/balance token)"));
100+
101+
// Offer / accept of more than balance should fail with :FUNDS
102+
ctxx = step (ctxx,"(asset/offer *address* token (inc BAL))");
103+
assertCVMEquals(BAL+1,ctxx.getResult());
104+
assertFundsError(step(ctxx,"(asset/accept *address* [token (inc BAL)])"));
100105

101106
// Set back to zero offer
102107
ctxx = step(ctxx,"(asset/offer *address* [token 0])");

0 commit comments

Comments
 (0)