Skip to content

Commit

Permalink
Extra testing for fungible token offers
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 8, 2023
1 parent b56ec6f commit 72eb986
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 4 additions & 4 deletions convex-core/src/main/cvx/convex/asset.cvx
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
(defn get-offer
^{:doc {:description ["Gets the current offer from `sender` to `receiver` for a given asset."
"Returns the quantity representing the current offer. Will be the 'zero' quantity if no open offer exists."]
:examples [{:code "(get-offer asset-address sender receiver)"}]
:signature [{:params [asset-address sender receiver]}]}}
[asset-address sender receiver]
(query (call asset-address
:examples [{:code "(get-offer asset-path sender receiver)"}]
:signature [{:params [asset-path sender receiver]}]}}
[path sender receiver]
(query (call path
(get-offer sender
receiver))))

Expand Down
22 changes: 21 additions & 1 deletion convex-core/src/test/java/convex/lib/AssetTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,30 @@ public static void doFungibleTests (Context ctx, ACell token, Address user) {
assertEquals(0L, evalL(ctx,"(asset/balance token actor)"));
assertTrue(BAL>0,"Should provide a user account with positive balance!");

// New Address gets zero balance
// New Address gets zero offers
{
assertEquals(0L,evalL(ctx,"(asset/balance token (deploy nil))"));
assertEquals(0L,evalL(ctx,"(asset/balance token (create-account *key*))"));
assertEquals(0L,evalL(ctx,"(asset/get-offer token (create-account *key*) (deploy nil))"));
}

// New Address gets zero offers
{
assertEquals(0L,evalL(ctx,"(asset/balance token (deploy nil))"));
assertEquals(0L,evalL(ctx,"(asset/balance token (create-account *key*))"));
assertEquals(0L,evalL(ctx,"(asset/get-offer token (create-account *key*) (deploy nil))"));
}

// New Address offers work
{
Context ctxx = step (ctx,"(do (def a1 (deploy nil)))");
assertEquals(0L,evalL(ctxx,"(asset/get-offer token *address* a1)"));
ctxx = step (ctxx,"(asset/offer a1 token 1000)");
assertCVMEquals(1000L,ctxx.getResult());
assertEquals(1000L,evalL(ctxx,"(asset/get-offer token *address* a1)"));
ctxx = step(ctxx,"(asset/offer a1 [token 0])");
assertCVMEquals(0L,ctxx.getResult());
assertEquals(0L,evalL(ctxx,"(asset/get-offer token *address* a1)"));
}

// transfer all to self, should not affect balance
Expand Down

0 comments on commit 72eb986

Please sign in to comment.