From b0de5d7d469344c1235972ff40adf08f52a5a66a Mon Sep 17 00:00:00 2001 From: mikera Date: Tue, 13 Aug 2024 12:15:00 +0100 Subject: [PATCH] More Archon updates and tests --- convex-core/src/main/cvx/asset/nft/basic.cvx | 5 +++-- convex-core/src/main/cvx/lab/archon.cvx | 9 +++++---- .../test/java/convex/core/lang/ACVMTest.java | 8 ++++---- convex-core/src/test/java/lab/ArchonTest.java | 20 ++++++++++++++++++- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/convex-core/src/main/cvx/asset/nft/basic.cvx b/convex-core/src/main/cvx/asset/nft/basic.cvx index f7a29504a..57044b3a2 100644 --- a/convex-core/src/main/cvx/asset/nft/basic.cvx +++ b/convex-core/src/main/cvx/asset/nft/basic.cvx @@ -6,8 +6,6 @@ "Follows the interface described in `convex.asset`."] :name "Basic NFT creation and management"})) -(declare balance) - ;;;;;;;;;; Values (define counter @@ -23,6 +21,9 @@ {}) ;;;;;;;;;; Implementation of `convex.asset` interface +;; These functions provide full CAD19 asset functionality +;; + (defn -qc ^{:doc {:description "Checks a basic NFT quantity."} diff --git a/convex-core/src/main/cvx/lab/archon.cvx b/convex-core/src/main/cvx/lab/archon.cvx index a45f95d03..0423249cd 100644 --- a/convex-core/src/main/cvx/lab/archon.cvx +++ b/convex-core/src/main/cvx/lab/archon.cvx @@ -1,11 +1,9 @@ 'archon (call *registry* - (register {:description ["Actor for the Archon NFT collection."] + (register {:description ["Archon NFT collection actor."] :name "Archon Actor"})) -(declare balance) - ;;;;;;;;;; Governance ;; We set a controller with upgrade and access rights. This can be removed / modified later ;; Use the current controller, or the geneses peer account #12 if unspecified @@ -55,6 +53,9 @@ ;;;;;;;;;; Implementation of `convex.asset` interface +;; These functions provide full CAD19 asset functionality +;; + (defn -qc ^{:doc {:description "Checks a basic NFT quantity."} @@ -162,7 +163,7 @@ {:params [id]}]}} ([] (recur *scope*)) ([id] - (or (valid-id? id) nil) + (or (valid-id? id) (return nil)) (let [hex (str id) img (str base-url hex ".png")] { 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 1ea175ef6..2f546c062 100644 --- a/convex-core/src/test/java/convex/core/lang/ACVMTest.java +++ b/convex-core/src/test/java/convex/core/lang/ACVMTest.java @@ -52,15 +52,15 @@ public abstract class ACVMTest { */ protected ACVMTest(State genesis) { Context c = Context.createFake(genesis, Init.GENESIS_ADDRESS); - c=buildContext(c); - this.INITIAL=c.getState(); - this.CONTEXT=c; HERO = BaseTest.HERO; VILLAIN = BaseTest.VILLAIN; - c=c.withJuice(0); // reset juice used INITIAL_JUICE = c.getJuiceAvailable(); HERO_BALANCE = c.getAccountStatus(HERO).getBalance(); VILLAIN_BALANCE = c.getAccountStatus(VILLAIN).getBalance(); + c=buildContext(c); + c=c.withJuice(0); // reset juice used + this.INITIAL=c.getState(); + this.CONTEXT=c; } /** diff --git a/convex-core/src/test/java/lab/ArchonTest.java b/convex-core/src/test/java/lab/ArchonTest.java index a32b56e53..c4ca1184d 100644 --- a/convex-core/src/test/java/lab/ArchonTest.java +++ b/convex-core/src/test/java/lab/ArchonTest.java @@ -1,12 +1,19 @@ package lab; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import org.junit.jupiter.api.Test; +import convex.core.data.ACell; +import convex.core.data.AHashMap; +import convex.core.data.AString; import convex.core.data.Address; +import convex.core.data.Strings; import convex.core.lang.ACVMTest; import convex.core.lang.Context; import convex.core.lang.TestState; @@ -23,7 +30,11 @@ public class ArchonTest extends ACVMTest { ctx=exec(ctx,"(import convex.asset :as asset)"); ctx=exec(ctx,"(import convex.trust :as trust)"); - ctx=exec(ctx,"(def archon (deploy '(set-controller *caller*) *address*))"); + // User accounts for testing + ctx=exec(ctx,"(def HERO *address*)"); + ctx=exec(ctx,"(def VILLAIN "+VILLAIN+")"); + + ctx=exec(ctx,"(def archon (deploy '(set-controller *caller*)))"); ARCHON=ctx.getResult(); try { @@ -45,6 +56,13 @@ public class ArchonTest extends ACVMTest { assertEquals(ARCHON,archon); assertEquals(1024,evalL(ctx,"(count (asset/balance archon))")); + + // Metadata should work and have an image + AHashMap meta=eval(ctx,"(call archon (get-metadata 0x0123))"); + assertFalse(meta.isEmpty()); + assertTrue(meta.containsKey(Strings.create("image"))); + + assertNull(eval(ctx,"(call archon (get-metadata :not-a-valid-id))")); } @Test public void testArchonNFTs() {