From 49da1795c9839d1f64e85380de10e8501ef10b4c Mon Sep 17 00:00:00 2001 From: mikera Date: Fri, 20 Dec 2024 21:37:29 +0000 Subject: [PATCH] Extra tests --- .../src/test/java/convex/core/data/IndexTest.java | 8 ++++++++ .../src/test/java/convex/core/data/SetsTest.java | 14 ++++++++++++++ .../src/test/java/convex/lib/AssetTester.java | 1 + 3 files changed, 23 insertions(+) diff --git a/convex-core/src/test/java/convex/core/data/IndexTest.java b/convex-core/src/test/java/convex/core/data/IndexTest.java index 7b5ebdbd7..8653ffb58 100644 --- a/convex-core/src/test/java/convex/core/data/IndexTest.java +++ b/convex-core/src/test/java/convex/core/data/IndexTest.java @@ -21,6 +21,7 @@ import convex.core.data.prim.CVMDouble; import convex.core.data.prim.CVMLong; import convex.core.data.type.Types; +import convex.core.exceptions.BadFormatException; import convex.core.exceptions.InvalidDataException; import convex.core.init.InitTest; import convex.core.lang.RT; @@ -132,6 +133,13 @@ public void testIndexConstruction() throws InvalidDataException { } assertSame(Index.none(), m); } + + @Test public void testIndexEncode() throws BadFormatException { + Index m = Index.of(Address.ZERO,Samples.IPSUM); + + Blob enc=m.getEncoding(); + assertEquals(m,Format.read(enc)); + } @Test public void testIndexRandomConstruction() throws InvalidDataException { diff --git a/convex-core/src/test/java/convex/core/data/SetsTest.java b/convex-core/src/test/java/convex/core/data/SetsTest.java index 5074e6b0a..47745292d 100644 --- a/convex-core/src/test/java/convex/core/data/SetsTest.java +++ b/convex-core/src/test/java/convex/core/data/SetsTest.java @@ -7,8 +7,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.IOException; + import org.junit.jupiter.api.Test; +import convex.core.cvm.Address; import convex.core.data.prim.CVMDouble; import convex.core.data.prim.CVMLong; import convex.core.exceptions.BadFormatException; @@ -51,6 +54,17 @@ public void testIncludeExclude() { assertSame(Sets.empty(),s); } + @Test public void testSetEncodeRegression() throws BadFormatException, IOException { + // This failed once in generative tests, checking just in case + ASet s = Sets.of(Address.ZERO,Samples.IPSUM); + Ref pref = Ref.get(Cells.persist(s)); // ensure persisted + + Blob enc=s.getEncoding(); + assertEquals(s,Format.read(enc)); + + assertEquals(s,pref.getValue()); + } + @Test public void testSetEncoding() { // Set should be encoded as a map with different tag and extra value Ref(s) diff --git a/convex-core/src/test/java/convex/lib/AssetTester.java b/convex-core/src/test/java/convex/lib/AssetTester.java index a730dbcda..10fd04148 100644 --- a/convex-core/src/test/java/convex/lib/AssetTester.java +++ b/convex-core/src/test/java/convex/lib/AssetTester.java @@ -133,6 +133,7 @@ public static void doFungibleTests(Context ctx, ACell token, Address user) { 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()); + assertStateError(step(ctxx, "(asset/accept *address* [token 1])")); // should fail, no offer left assertCVMEquals(BAL, evalL(ctxx, "(asset/balance token)")); // Offer / accept of more than balance should fail with :FUNDS