Skip to content

Commit

Permalink
More Archon updates and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Aug 13, 2024
1 parent 332e5a2 commit b0de5d7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
5 changes: 3 additions & 2 deletions convex-core/src/main/cvx/asset/nft/basic.cvx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"Follows the interface described in `convex.asset`."]
:name "Basic NFT creation and management"}))

(declare balance)

;;;;;;;;;; Values

(define counter
Expand All @@ -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."}
Expand Down
9 changes: 5 additions & 4 deletions convex-core/src/main/cvx/lab/archon.cvx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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."}
Expand Down Expand Up @@ -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")]
{
Expand Down
8 changes: 4 additions & 4 deletions convex-core/src/test/java/convex/core/lang/ACVMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
20 changes: 19 additions & 1 deletion convex-core/src/test/java/lab/ArchonTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -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<AString,ACell> 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() {
Expand Down

0 comments on commit b0de5d7

Please sign in to comment.