Skip to content

Commit

Permalink
Extra tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 20, 2024
1 parent 2d42120 commit 49da179
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions convex-core/src/test/java/convex/core/data/IndexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,6 +133,13 @@ public void testIndexConstruction() throws InvalidDataException {
}
assertSame(Index.none(), m);
}

@Test public void testIndexEncode() throws BadFormatException {
Index<ABlob, CVMLong> m = Index.of(Address.ZERO,Samples.IPSUM);

Blob enc=m.getEncoding();
assertEquals(m,Format.read(enc));
}

@Test
public void testIndexRandomConstruction() throws InvalidDataException {
Expand Down
14 changes: 14 additions & 0 deletions convex-core/src/test/java/convex/core/data/SetsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ACell> s = Sets.of(Address.ZERO,Samples.IPSUM);
Ref<ACell> 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)
Expand Down
1 change: 1 addition & 0 deletions convex-core/src/test/java/convex/lib/AssetTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 49da179

Please sign in to comment.