Skip to content

Commit

Permalink
Add genesis test, edits for Archon example code
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Dec 28, 2024
1 parent df7145e commit 0493b41
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions convex-cli/GENESIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ alias convex="java -jar ~/convex.jar"

Genesis/Admin Key: `0xc1d3b0104d55ddf7680181a46e93422e49e2ea9298e37794860f1ef1128427f7`
Governance key: `0x12EF73ee900eD1FE78A188f59bF8CedE467bAA66f5b60368aFAaA3B9521aB94d`
Genesis Peer key: `0x12EF73ee900eD1FE78A188f59bF8CedE467bAA66f5b60368aFAaA3B9521aB94d`
mikera key: `0x89b5142678bfef7a2245af5ae5b9ab1e10c282b375fa297c5aaeccc48ac97cac`


Expand Down
17 changes: 12 additions & 5 deletions convex-core/src/main/cvx/convex/lab/archon.cvx
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,22 @@
;; These functions provide full CAD19 asset functionality
;;

;; Quanity check
;; Quanity check, enforces use as a set
(defn -qc
[q]
(cond
(set? q) q ;; base case, quantity should always be a Set
(valid-id? q) #{q} ;; we allow a blob ID to be used as a quanitity if valid
(valid-id? q) #{q} ;; we allow an ID to be used as a quanitity if valid
(nil? q) #{}
(fail :ARGUMENT "Invalid NFT quantity")))

(defn -direct-transfer
^{:private? true}
;; Used internally by [[accept]] and [[direct-transfer]].
[sender receiver quantity]
([sender receiver quqnitity]
(recur sender receiver quanity nil))

([sender receiver quantity data]
(let [q (-qc quantity)
receiver (address receiver)
sender-balance (or (get-holding sender)
Expand All @@ -81,7 +84,10 @@
new-receiver-balance (union receiver-balance q)]
(set-holding sender new-sender-balance)
(set-holding receiver new-receiver-balance)
quantity))
(for [tok q]
(log "NTR" sender receiver tok data))

quantity)))


(defn accept
Expand Down Expand Up @@ -124,7 +130,8 @@
[receiver quantity data]
(-direct-transfer *caller*
receiver
quantity))
quantity
data))

(defn offer
^{:callable true}
Expand Down
4 changes: 3 additions & 1 deletion convex-core/src/main/java/convex/core/init/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public class Init {
private static final long GENESIS_COINS=1000000*Coin.GOLD;

public static final AccountKey DEFAULT_GOV_KEY = AccountKey.fromHex("12EF73ee900eD1FE78A188f59bF8CedE467bAA66f5b60368aFAaA3B9521aB94d");

public static final AccountKey DEFAULT_GENESIS_KEY = AccountKey.fromHex("c1d3b0104d55ddf7680181a46e93422e49e2ea9298e37794860f1ef1128427f7");
public static final AccountKey FIRST_PEER_KEY = AccountKey.fromHex("d6ef2d429b73ef1c78d9e46d87feb9d9535a991b8102099f54ed243f1e557d42");

private static final long RESERVED_USER_LIMIT = 64;
private static final long RESERVED_ACTOR_LIMIT = 128;

Expand Down
18 changes: 18 additions & 0 deletions convex-core/src/test/java/convex/core/init/GenesisTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package convex.core.init;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.List;

import org.junit.jupiter.api.Test;

import convex.core.cvm.State;

public class GenesisTest {

@Test
public static void testGenesis() {
State genesis=Init.createState(Init.DEFAULT_GOV_KEY, Init.DEFAULT_GENESIS_KEY, List.of(Init.FIRST_PEER_KEY));
assertEquals("b0e44f2a645abfa539f5b96b7a0eabb0f902866feaff0f7c12d1213e02333f13",genesis.getHash().toHexString());
}
}
21 changes: 21 additions & 0 deletions convex-core/src/test/java/lab/ArchonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import convex.core.cvm.Context;
import convex.core.data.ACell;
import convex.core.data.AHashMap;
import convex.core.data.ASet;
import convex.core.data.AString;
import convex.core.data.Strings;
import convex.core.lang.ACVMTest;
Expand Down Expand Up @@ -70,4 +71,24 @@ public class ArchonTest extends ACVMTest {
ctx=exec(ctx,"(asset/transfer "+VILLAIN+" [archon #{0x0123}])");
AssetTester.doAssetTests(ctx, ARCHON, HERO, VILLAIN);
}

@Test public void testPeaceSetup() {
Context ctx=context();

String patch="(let [vs [:I :believe :that :unarmed :truth :and :unconditional :love :will \r\n"
+ " :have :the :final :word :in :reality :This :is :why :right :temporarily \r\n"
+ " :defeated :is-1 :stronger :than :evil :triumphant :I-1 :believe-1 :that-1 :even \r\n"
+ " :amid :todays :mortar :bursts :and-1 :whining :bullets :there :is-2 :still :hope \r\n"
+ " :for :a :brighter :tomorrow :I-2 :believe-2 :that-2 :wounded :justice :lying\r\n"
+ " :prostrate :on :the-1 :blood-flowing :streets :of :our :nations :can :be :lifted \r\n"
+ " :from :this :dust :of :shame :to :reign :supreme :among :the-2 :children :of :men \r\n"
+ " :I-3 :have :the-3 :audacity :to :believe-3 :that-3 :peoples :everywhere :can :have\r\n"
+ " :three :meals :a :day :for-1 :their :bodies :education :and-2 :culture :for-2 \r\n"
+ " :their-1 :minds :dignity :bar1 :bar2 :bar3 :bar4 :bar5 :bar6 :bar7]\r\n"
+ " vset (into #{} vs)]\r\n"
+ " vset)";

ctx=exec(ctx,patch);
assertTrue(ctx.getResult() instanceof ASet);
}
}

0 comments on commit 0493b41

Please sign in to comment.