diff --git a/convex-core/src/main/cvx/asset/share.cvx b/convex-core/src/main/cvx/asset/share.cvx index e7c5b26a7..8aee42447 100644 --- a/convex-core/src/main/cvx/asset/share.cvx +++ b/convex-core/src/main/cvx/asset/share.cvx @@ -145,8 +145,8 @@ rec (get hs id)] (if rec (let [os (nth rec 1) ;; offers map - off (or (get os receiver) (fail "No offer to receiver")) - _ (cond (< off quantity) (fail "insufficient offer")) + off (or (get os receiver) (fail :STATE "No offer to receiver")) + _ (cond (< off quantity) (fail :STATE "insufficient offer")) bal (nth rec 0) nbal (- bal quantity) _ (cond (< nbal 0) (fail "insufficent balance to accept")) diff --git a/convex-core/src/main/cvx/convex/fungible.cvx b/convex-core/src/main/cvx/convex/fungible.cvx index b6bf0e637..b2c00cb3f 100644 --- a/convex-core/src/main/cvx/convex/fungible.cvx +++ b/convex-core/src/main/cvx/convex/fungible.cvx @@ -127,7 +127,7 @@ (< offer quantity) - (fail "Offer is insufficient") + (fail :STATE "Offer is insufficient") (< sendbal quantity) diff --git a/convex-core/src/test/java/convex/lib/AssetTester.java b/convex-core/src/test/java/convex/lib/AssetTester.java index e66cdaa9c..e21c358cb 100644 --- a/convex-core/src/test/java/convex/lib/AssetTester.java +++ b/convex-core/src/test/java/convex/lib/AssetTester.java @@ -88,15 +88,17 @@ public static void doFungibleTests (Context ctx, ACell token, Address user) { assertCVMEquals(BAL,evalL(ctxx,"(asset/balance token)")); // accepting one more token at this point should be error - assertError(step(ctxx,"(asset/accept *address* [token 1])")); + assertStateError(step(ctxx,"(asset/accept *address* [token 1])")); - ctxx = step (ctxx,"(asset/offer *address* token BAL)"); - assertCVMEquals(BAL,ctxx.getResult()); + // Offer / accept of half balance should work + ctxx = step (ctxx,"(asset/offer *address* token (div BAL 2))"); + assertCVMEquals(BAL/2,ctxx.getResult()); + assertStateError(step(ctxx,"(asset/accept *address* [token (inc (div BAL 2))])")); ctxx=step(ctxx,"(asset/accept *address* token (div BAL 2))"); assertCVMEquals(BAL/2,ctxx.getResult()); assertCVMEquals(BAL,evalL(ctxx,"(asset/balance token)")); - + // Set back to zero offer ctxx = step(ctxx,"(asset/offer *address* [token 0])"); assertCVMEquals(0L,ctxx.getResult()); assertEquals(0L,evalL(ctxx,"(asset/get-offer token *address* *address*)"));