diff --git a/convex-core/src/main/cvx/asset/share.cvx b/convex-core/src/main/cvx/asset/share.cvx index 8aee42447..8dae17188 100644 --- a/convex-core/src/main/cvx/asset/share.cvx +++ b/convex-core/src/main/cvx/asset/share.cvx @@ -149,7 +149,7 @@ _ (cond (< off quantity) (fail :STATE "insufficient offer")) bal (nth rec 0) nbal (- bal quantity) - _ (cond (< nbal 0) (fail "insufficent balance to accept")) + _ (cond (< nbal 0) (fail :FUNDS "insufficent balance to accept")) noff (- off quantity) nos (cond (<= noff 0) (dissoc os receiver) (assoc os receiver noff)) nrec [nbal nos]] diff --git a/convex-core/src/main/cvx/convex/asset.cvx b/convex-core/src/main/cvx/convex/asset.cvx index 2096e64f1..5b9a8a6bb 100644 --- a/convex-core/src/main/cvx/convex/asset.cvx +++ b/convex-core/src/main/cvx/convex/asset.cvx @@ -42,7 +42,9 @@ "If asset contains multiple assets, accepts each in turn. MUST fail if the asset cannot be accepted."] :examples [{:code "(accept sender [fungible-token-address 1000])"}] :signature [{:params [sender asset]} - {:params [sender asset-path quantity]}]}} + {:params [sender asset-path quantity]}] + :errors {:STATE "If there is no sufficient offer to accept." + :FUNDS "If sender has insufficient balance."}}} ([sender asset] (cond diff --git a/convex-core/src/main/cvx/convex/fungible.cvx b/convex-core/src/main/cvx/convex/fungible.cvx index b2c00cb3f..a8c7c5a61 100644 --- a/convex-core/src/main/cvx/convex/fungible.cvx +++ b/convex-core/src/main/cvx/convex/fungible.cvx @@ -131,7 +131,7 @@ (< sendbal quantity) - (fail "Sender token balance is insufficient") + (fail :FUNDS "Sender token balance is insufficient") (let [new-offer (- offer quantity)] diff --git a/convex-core/src/test/java/convex/lib/AssetTester.java b/convex-core/src/test/java/convex/lib/AssetTester.java index e21c358cb..9fded922c 100644 --- a/convex-core/src/test/java/convex/lib/AssetTester.java +++ b/convex-core/src/test/java/convex/lib/AssetTester.java @@ -80,14 +80,14 @@ public static void doFungibleTests (Context ctx, ACell token, Address user) { assertCVMEquals(BAL,ctxx.getResult()); assertEquals(BAL,evalL(ctxx,"(asset/get-offer token *address* *address*)")); - // accepting one more token than offered at this point should be error + // accepting one more token than offered at this point should be :STATE error assertError(step(ctxx,"(asset/accept *address* [token (inc BAL)])")); ctxx=step(ctxx,"(asset/accept *address* token BAL)"); assertCVMEquals(BAL,ctxx.getResult()); assertCVMEquals(BAL,evalL(ctxx,"(asset/balance token)")); - // accepting one more token at this point should be error + // accepting one more token at this point should be :STATE error assertStateError(step(ctxx,"(asset/accept *address* [token 1])")); // Offer / accept of half balance should work @@ -97,6 +97,11 @@ public static void doFungibleTests (Context ctx, ACell token, Address user) { ctxx=step(ctxx,"(asset/accept *address* token (div BAL 2))"); assertCVMEquals(BAL/2,ctxx.getResult()); assertCVMEquals(BAL,evalL(ctxx,"(asset/balance token)")); + + // Offer / accept of more than balance should fail with :FUNDS + ctxx = step (ctxx,"(asset/offer *address* token (inc BAL))"); + assertCVMEquals(BAL+1,ctxx.getResult()); + assertFundsError(step(ctxx,"(asset/accept *address* [token (inc BAL)])")); // Set back to zero offer ctxx = step(ctxx,"(asset/offer *address* [token 0])");