Skip to content

Commit

Permalink
More testing for insufficient offers with :STATE error
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 8, 2023
1 parent 363a1be commit b6a1f50
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions convex-core/src/main/cvx/asset/share.cvx
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion convex-core/src/main/cvx/convex/fungible.cvx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@

(< offer
quantity)
(fail "Offer is insufficient")
(fail :STATE "Offer is insufficient")

(< sendbal
quantity)
Expand Down
10 changes: 6 additions & 4 deletions convex-core/src/test/java/convex/lib/AssetTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -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*)"));
Expand Down

0 comments on commit b6a1f50

Please sign in to comment.