diff --git a/convex-core/src/main/cvx/convex/core.cvx b/convex-core/src/main/cvx/convex/core.cvx index a51a04e3f..0785acf36 100644 --- a/convex-core/src/main/cvx/convex/core.cvx +++ b/convex-core/src/main/cvx/convex/core.cvx @@ -377,11 +377,9 @@ [[sym count] & body] - (let [n (long count) - sym (if (symbol? (unsyntax sym)) - sym - (fail :CAST - "`dotimes` requires a symbol for loop binding"))] + (let [n (long count)] + (or (symbol? (unsyntax sym)) + (fail :CAST "`dotimes` requires a symbol for loop binding")) `(loop [~sym 0] (if (< ~sym ~n) diff --git a/convex-core/src/test/java/convex/actors/CurationMarketTest.java b/convex-core/src/test/java/convex/actors/CurationMarketTest.java index 6a472e07d..4fe940385 100644 --- a/convex-core/src/test/java/convex/actors/CurationMarketTest.java +++ b/convex-core/src/test/java/convex/actors/CurationMarketTest.java @@ -5,9 +5,6 @@ import convex.core.init.InitTest; import convex.core.lang.ACVMTest; import convex.core.lang.Context; -import convex.core.util.Utils; - -import static convex.test.Assertions.*; public class CurationMarketTest extends ACVMTest { diff --git a/convex-core/src/test/java/convex/actors/RegistryTest.java b/convex-core/src/test/java/convex/actors/RegistryTest.java index 3df373a02..56e1ed9d9 100644 --- a/convex-core/src/test/java/convex/actors/RegistryTest.java +++ b/convex-core/src/test/java/convex/actors/RegistryTest.java @@ -96,8 +96,7 @@ public void testRegistryCNSUpdate() throws IOException { Context c=ctx.forkWithAddress(VILLAIN); // VILLAIN shouldn't be able to use update on existing CNS mapping - c=step(c,"(call *registry* (cns-update 'convex.villain *address*))"); - assertNotError(c); + c=exec(c,"(call *registry* (cns-update 'convex.villain *address*))"); // original mapping should be held assertEquals(VILLAIN,eval(c,"(call *registry* (cns-resolve 'convex.villain))")); diff --git a/convex-core/src/test/java/convex/actors/TorusTest.java b/convex-core/src/test/java/convex/actors/TorusTest.java index 66e8c6c33..49be1da9e 100644 --- a/convex-core/src/test/java/convex/actors/TorusTest.java +++ b/convex-core/src/test/java/convex/actors/TorusTest.java @@ -2,7 +2,6 @@ import static convex.test.Assertions.assertCVMEquals; import static convex.test.Assertions.assertError; -import static convex.test.Assertions.assertNotError; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; diff --git a/convex-core/src/test/java/convex/core/lang/ACVMTest.java b/convex-core/src/test/java/convex/core/lang/ACVMTest.java index f6153bb30..e8b07c7c9 100644 --- a/convex-core/src/test/java/convex/core/lang/ACVMTest.java +++ b/convex-core/src/test/java/convex/core/lang/ACVMTest.java @@ -228,7 +228,7 @@ protected Context step(String source) { * @param source Code to execute * @return */ - protected Context exec(Context ctx, String source) { + protected static Context exec(Context ctx, String source) { ctx=step(ctx, source); assertNotError(ctx); return ctx; diff --git a/convex-core/src/test/java/convex/core/lang/CoreTest.java b/convex-core/src/test/java/convex/core/lang/CoreTest.java index f2db88db4..c1008ed87 100644 --- a/convex-core/src/test/java/convex/core/lang/CoreTest.java +++ b/convex-core/src/test/java/convex/core/lang/CoreTest.java @@ -2365,22 +2365,22 @@ public void testImport() { @Test public void testImportCore() { - Context ctx = step("(import convex.core :as cc)"); + Context ctx = exec(context(),"(import convex.core :as cc)"); assertNotError(ctx); assertEquals(eval(ctx,"count"),eval(ctx,"cc/count")); } @Test public void testImportStatic() { - Context ctx = step("(import convex.core :as cc)"); - assertNotError(ctx); + Context ctx = context(); + ctx=exec(ctx,"(import convex.core :as cc)"); + if (Constants.OPT_STATIC) { ACell va=eval(ctx,"(compile 'cc/actor?)"); assertEquals(Lookup.create(Init.CORE_ADDRESS, Symbols.ACTOR_Q),va); ACell vc=eval(ctx,"(compile 'cc/count)"); assertEquals(Constant.of(Core.COUNT),vc); - } } @@ -2607,8 +2607,14 @@ public void testCreateAccount() { assertTrue(evalB("(= (query (create-account *key*)) (query (create-account *key*)))")); // Check multiple create-accounts in same transaction - assertNotError(step("(dotimes [i 100] (create-account *key*))")); - + { + Context c=ctx; + long numAccounts=c.getState().getAccounts().count(); + c=exec(c,"(dotimes [i 100] (create-account *key*))"); + long resultNum=c.getState().getAccounts().count(); + assertEquals(numAccounts+100, resultNum); + } + assertCastError(step("(create-account :foo)")); assertCastError(step("(create-account 1)")); assertCastError(step("(create-account nil)")); diff --git a/convex-core/src/test/java/convex/lib/ShareTest.java b/convex-core/src/test/java/convex/lib/ShareTest.java index feeee6042..3df22f226 100644 --- a/convex-core/src/test/java/convex/lib/ShareTest.java +++ b/convex-core/src/test/java/convex/lib/ShareTest.java @@ -27,30 +27,19 @@ protected ShareTest() { } @Override protected Context buildContext(Context ctx) { - String importS="(import asset.multi-token :as mt)"; - ctx=step(ctx,importS); - assertNotError(ctx); - - String importS2="(import asset.share :as share)"; - ctx=step(ctx,importS2); - assertNotError(ctx); - - ctx=step(ctx,"(import convex.asset :as asset)"); - assertNotError(ctx); - ctx=step(ctx,"(import convex.fungible :as fungible)"); - assertNotError(ctx); - ctx=step(ctx,"(import convex.trust :as trust)"); - assertNotError(ctx); - - // Unerlying - ctx=step(ctx,"(def underlying [mt (call mt (create :USD))])"); - assertNotError(ctx); + ctx=exec(ctx,"(import asset.multi-token :as mt)"); + ctx=step(ctx,"(import asset.share :as share)"); + ctx=exec(ctx,"(import convex.asset :as asset)"); + ctx=exec(ctx,"(import convex.fungible :as fungible)"); + ctx=exec(ctx,"(import convex.trust :as trust)"); + + // Underlying asset + ctx=exec(ctx,"(def underlying [mt (call mt (create :USD))])"); - ctx=step(ctx,"(call underlying (mint 1000000))"); + ctx=exec(ctx,"(call underlying (mint 1000000))"); assertCVMEquals(1000000,ctx.getResult()); - ctx=step(ctx,"(asset/transfer "+InitTest.VILLAIN+" [underlying 400])"); - assertNotError(ctx); + ctx=exec(ctx,"(asset/transfer "+InitTest.VILLAIN+" [underlying 400])"); return ctx; } diff --git a/convex-core/src/test/java/convex/lib/SimpleNFTTest.java b/convex-core/src/test/java/convex/lib/SimpleNFTTest.java index 2874a1b81..433669106 100644 --- a/convex-core/src/test/java/convex/lib/SimpleNFTTest.java +++ b/convex-core/src/test/java/convex/lib/SimpleNFTTest.java @@ -31,11 +31,9 @@ protected SimpleNFTTest() { private static State createState() { Context ctx=TestState.CONTEXT.fork(); - String importS = "(import asset.nft.simple :as nft)"; - ctx=step(ctx,importS); - - ctx=step(ctx,"(import convex.asset :as asset)"); + ctx=exec(ctx,importS); + ctx=exec(ctx,"(import convex.asset :as asset)"); return ctx.getState(); } @@ -48,7 +46,7 @@ private static State createState() { @SuppressWarnings("unchecked") @Test public void testAssetAPI() { Context ctx=context(); - ctx=step(ctx,"(def total (map (fn [v] (call nft (create))) [1 2 3 4]))"); + ctx=exec(ctx,"(def total (map (fn [v] (call nft (create))) [1 2 3 4]))"); AVector v=(AVector) ctx.getResult(); assertEquals(4,v.count()); CVMLong b1=v.get(0); diff --git a/convex-core/src/test/java/convex/lib/TrustActorTest.java b/convex-core/src/test/java/convex/lib/TrustActorTest.java index 92b931316..3a91f92e0 100644 --- a/convex-core/src/test/java/convex/lib/TrustActorTest.java +++ b/convex-core/src/test/java/convex/lib/TrustActorTest.java @@ -28,16 +28,14 @@ protected TrustActorTest() throws IOException { @Override protected Context buildContext(Context ctx) { String importS = "(import convex.trust :as trust)"; - ctx = step(ctx, importS); - assertNotError(ctx); + ctx = exec(ctx, importS); trusted = (Address)ctx.getResult(); return ctx; } @Test public void testDelegate() { - Context ctx=step(context(),"(import convex.trust.delegate :as del)"); - assertNotError(ctx); + Context ctx=exec(context(),"(import convex.trust.delegate :as del)"); Address del=ctx.getResult(); // Unscoped usage @@ -47,20 +45,19 @@ public void testDelegate() { assertFalse(evalB(ctx,"(trust/trusted? [del -1] *address*)")); // Get a monitor - ctx=step(ctx,"(call del (create nil))"); + ctx=exec(ctx,"(call del (create nil))"); ACell id = ctx.getResult(); AVector mon=Vectors.of(del,id); assertFalse(evalB(ctx,"(trust/trusted? "+mon+" *address*)")); // Update monitor to own address - ctx=step(ctx,"(call "+mon+" (update *address*))"); - assertNotError(ctx); + ctx=exec(ctx,"(call "+mon+" (update *address*))"); assertFalse(evalB(ctx,"(trust/trusted? "+mon+" #0)")); assertTrue(evalB(ctx,"(trust/trusted? "+mon+" *address*)")); // Get another monitor - ctx=step(ctx,"(call del (create nil))"); + ctx=exec(ctx,"(call del (create nil))"); ACell newid = ctx.getResult(); assertNotEquals(id,newid); diff --git a/convex-core/src/test/java/convex/lib/TrustTest.java b/convex-core/src/test/java/convex/lib/TrustTest.java index 8d67ba6a0..754ebc8e7 100644 --- a/convex-core/src/test/java/convex/lib/TrustTest.java +++ b/convex-core/src/test/java/convex/lib/TrustTest.java @@ -28,8 +28,7 @@ protected TrustTest() throws IOException { @Override protected Context buildContext(Context ctx) { String importS = "(import convex.trust :as trust)"; - ctx = step(ctx, importS); - assertNotError(ctx); + ctx = exec(ctx, importS); trusted = (Address)ctx.getResult(); return ctx; } @@ -61,19 +60,19 @@ public void testUpgrade() { Context ctx = CONTEXT.fork(); // deploy an actor with upgradable capability - ctx = step(ctx, "(def wlist (deploy (trust/add-trusted-upgrade nil)))"); + ctx = exec(ctx, "(def wlist (deploy (trust/add-trusted-upgrade nil)))"); Address wl = (Address) ctx.getResult(); assertNotNull(wl); // do an upgrade that edits the actor - ctx = step(ctx, "(call wlist (upgrade '(def foo 2)))"); + ctx = exec(ctx, "(call wlist (upgrade '(def foo 2)))"); { // check our villain cannot upgrade the actor! Address a1 = VILLAIN; Context c = ctx.forkWithAddress(a1); - c = step(c, "(do (import " + trusted + " :as trust) (def wlist " + wl + "))"); + c = exec(c, "(do (import " + trusted + " :as trust) (def wlist " + wl + "))"); assertTrustError(step(c, "(call wlist (upgrade '(def foo 3)))")); } @@ -84,8 +83,7 @@ public void testUpgrade() { testChangeControl(ctx,wl); // check we can permanently remove upgradability - ctx = step(ctx, "(trust/remove-upgradability! wlist)"); - assertNotError(ctx); + ctx = exec(ctx, "(trust/remove-upgradability! wlist)"); assertStateError(step(ctx, "(call wlist (upgrade '(do :foo)))")); // actor functionality should still work otherwise diff --git a/convex-core/src/test/java/convex/lib/WrappedCVXTest.java b/convex-core/src/test/java/convex/lib/WrappedCVXTest.java index f8c5a677c..59527c024 100644 --- a/convex-core/src/test/java/convex/lib/WrappedCVXTest.java +++ b/convex-core/src/test/java/convex/lib/WrappedCVXTest.java @@ -32,15 +32,10 @@ protected WrappedCVXTest() { private static State buildState() { Context ctx=TestState.CONTEXT.fork(); String importS="(import convex.fungible :as fungible)"; - ctx=step(ctx,importS); - assertNotError(ctx); - ctx=step(ctx,"(import convex.asset :as asset)"); - assertNotError(ctx); - - ctx=step(ctx,"(import asset.wrap.convex :as wcvx)"); - assertNotError(ctx); - - ctx=step(ctx,"(def token wcvx)"); + ctx=exec(ctx,importS); + ctx=exec(ctx,"(import convex.asset :as asset)"); + ctx=exec(ctx,"(import asset.wrap.convex :as wcvx)"); + ctx=exec(ctx,"(def token wcvx)"); return ctx.getState(); } @@ -56,11 +51,8 @@ private static State buildState() { assertEquals(1000000L,evalL(ctx,"(asset/balance token *address*)")); assertEquals(0L,evalL(ctx,"(asset/balance token *registry*)")); - ctx=step(ctx,"(asset/offer "+VILLAIN+" [token 1000])"); - assertNotError(ctx); - - ctx=step(ctx,"(asset/transfer "+VILLAIN+" [token 2000])"); - assertNotError(ctx); + ctx=exec(ctx,"(asset/offer "+VILLAIN+" [token 1000])"); + ctx=exec(ctx,"(asset/transfer "+VILLAIN+" [token 2000])"); assertEquals(998000L,evalL(ctx,"(asset/balance token *address*)")); assertEquals(2000L,evalL(ctx,"(asset/balance token "+VILLAIN+")")); @@ -83,12 +75,12 @@ private static State buildState() { assertFalse(evalB(ctx,"(asset/owns? "+VILLAIN+" [token 2001])")); // transfer using map argument - ctx=step(ctx,"(asset/transfer "+VILLAIN+" {token 100})"); + ctx=exec(ctx,"(asset/transfer "+VILLAIN+" {token 100})"); assertTrue(ctx.getResult() instanceof AMap); assertTrue(evalB(ctx,"(asset/owns? "+VILLAIN+" [token 2100])")); // test offer - ctx=step(ctx,"(asset/offer "+VILLAIN+" [token 1337])"); + ctx=exec(ctx,"(asset/offer "+VILLAIN+" [token 1337])"); assertEquals(1337L,evalL(ctx,"(asset/get-offer token *address* "+VILLAIN+")")); @@ -98,15 +90,13 @@ private static State buildState() { Context ctx = context(); long BAL= evalL(ctx,"*balance*"); - ctx=step(ctx,"(wcvx/wrap 1000000)"); - assertNotError(ctx); + ctx=exec(ctx,"(wcvx/wrap 1000000)"); assertEquals(1000000,evalL(ctx,"(asset/balance wcvx *address*)")); long NBAL= evalL(ctx,"*balance*"); assertEquals(BAL-1000000,NBAL); - ctx=step(ctx,"(wcvx/unwrap 50000)"); - assertNotError(ctx); + ctx=exec(ctx,"(wcvx/unwrap 50000)"); assertEquals(950000,evalL(ctx,"(fungible/balance wcvx *address*)")); assertEquals(NBAL+50000,evalL(ctx,"*balance*"));