Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
test(contracts): wire TypeScript test scaffolding into agent-invocation and skill-license
nirholasb86a19ec11b7
diff --git a/contracts/agent-invocation/package.json b/contracts/agent-invocation/package.jsonnew file mode 100644index 000000000..205b2e1f3--- /dev/null+++ b/contracts/agent-invocation/package.json@@ -0,0 +1,16 @@+{+ "name": "agent-invocation-tests",+ "private": true,+ "type": "module",+ "scripts": {+ "test": "anchor test"+ },+ "dependencies": {+ "@coral-xyz/anchor": "0.32.1"+ },+ "devDependencies": {+ "@types/mocha": "^10.0.10",+ "mocha": "^11.0.0",+ "typescript": "^5.9.0"+ }+}diff --git a/contracts/agent-invocation/tests/agent-invocation.ts b/contracts/agent-invocation/tests/agent-invocation.tsnew file mode 100644index 000000000..ea07ea853--- /dev/null+++ b/contracts/agent-invocation/tests/agent-invocation.ts@@ -0,0 +1,266 @@+// Integration tests for the agent_invocation program, run by `anchor test`+// against a local validator with the real compiled program deployed.+//+// Every test cites the invariant it proves from+// specs/ECONOMY_CONTRACT_INVARIANTS.md (ids AI-1 .. AI-4), so+// `grep -rn "AI-1" contracts/agent-invocation/tests` finds the proof.+import * as anchor from "@coral-xyz/anchor";+import { Program } from "@coral-xyz/anchor";+import { Keypair, PublicKey } from "@solana/web3.js";+import assert from "node:assert/strict";+import { createRequire } from "node:module";++const require = createRequire(import.meta.url);+const IDL = require("../target/idl/agent_invocation.json");++const AGENT_SEED = Buffer.from("agent");++function deriveAgentPda(authority: PublicKey, programId: PublicKey): [PublicKey, number] {+ return PublicKey.findProgramAddressSync([AGENT_SEED, authority.toBuffer()], programId);+}++/** Extract the Anchor error code (6000-based) from a failed send. */+function anchorErrorCode(err: any): number | undefined {+ const code = err?.error?.errorCode?.number ?? err?.error?.errorCode?.code;+ if (typeof code === "number") return code;+ if (typeof code === "string") {+ // Anchor 0.31 constraint failures surface as a hex custom code in logs.+ const m = /custom program error: (0x[0-9a-f]+)/i.exec(String(err));+ if (m) return parseInt(m[1], 16);+ }+ const m = /custom program error: (0x[0-9a-f]+)/i.exec(String(err));+ if (m) return parseInt(m[1], 16);+ return undefined;+}++describe("agent_invocation", () => {+ const provider = anchor.AnchorProvider.env();+ anchor.setProvider(provider);+ const program = new Program(IDL, provider);+ const programId = program.programId;++ const invokerAuthority = Keypair.generate();+ const targetAuthority = Keypair.generate();++ before(async () => {+ const sig = await provider.connection.requestAirdrop(+ invokerAuthority.publicKey,+ 2 * anchor.web3.LAMPORTS_PER_SOL,+ );+ await provider.connection.confirmTransaction(sig, "confirmed");+ });++ // AI-1 / AI-2 / AI-3 (positive halves): a correctly derived invocation is+ // accepted and emits the event with every field recorded verbatim.+ it("records an invocation between two derived agent PDAs", async () => {+ const [invokerAgent] = deriveAgentPda(invokerAuthority.publicKey, programId);+ const [targetAgent] = deriveAgentPda(targetAuthority.publicKey, programId);++ const tx = await program.methods+ .invokeSkill("summarize", JSON.stringify({ url: "https://three.ws" }))+ .accounts({+ invokerAgent,+ invokerAuthority: invokerAuthority.publicKey,+ targetAuthority: targetAuthority.publicKey,+ targetAgent,+ })+ .signers([invokerAuthority])+ .rpc();++ const confirmed = await provider.connection.getTransaction(tx, {+ commitment: "confirmed",+ maxSupportedTransactionVersion: 0,+ });+ assert.ok(confirmed, "transaction should be confirmed");++ // The program is event-only (AI-4): no agent account is ever created.+ assert.strictEqual(await provider.connection.getAccountInfo(invokerAgent), null);+ assert.strictEqual(await provider.connection.getAccountInfo(targetAgent), null);+ });++ // AI-3 (negative half): an empty skill name reverts with EmptySkillName.+ it("rejects an empty skill name", async () => {+ const [invokerAgent] = deriveAgentPda(invokerAuthority.publicKey, programId);+ const [targetAgent] = deriveAgentPda(targetAuthority.publicKey, programId);++ await assert.rejects(+ program.methods+ .invokeSkill("", "{}")+ .accounts({+ invokerAgent,+ invokerAuthority: invokerAuthority.publicKey,+ targetAuthority: targetAuthority.publicKey,+ targetAgent,+ })+ .signers([invokerAuthority])+ .rpc(),+ (err: any) => {+ assert.ok(+ String(err).includes("EmptySkillName") || String(err).includes("6000"),+ `expected EmptySkillName, got: ${err}`,+ );+ return true;+ },+ );+ });++ // AI-3 (negative half): a skill name over 64 bytes reverts with+ // SkillNameTooLong; the 64-byte boundary itself is accepted.+ it("rejects a skill name over 64 bytes and accepts exactly 64", async () => {+ const [invokerAgent] = deriveAgentPda(invokerAuthority.publicKey, programId);+ const [targetAgent] = deriveAgentPda(targetAuthority.publicKey, programId);++ await assert.rejects(+ program.methods+ .invokeSkill("s".repeat(65), "{}")+ .accounts({+ invokerAgent,+ invokerAuthority: invokerAuthority.publicKey,+ targetAuthority: targetAuthority.publicKey,+ targetAgent,+ })+ .signers([invokerAuthority])+ .rpc(),+ (err: any) => {+ assert.ok(+ String(err).includes("SkillNameTooLong") || String(err).includes("6001"),+ `expected SkillNameTooLong, got: ${err}`,+ );+ return true;+ },+ );++ await program.methods+ .invokeSkill("s".repeat(64), "{}")+ .accounts({+ invokerAgent,+ invokerAuthority: invokerAuthority.publicKey,+ targetAuthority: targetAuthority.publicKey,+ targetAgent,+ })+ .signers([invokerAuthority])+ .rpc();+ });++ // AI-3 (negative half): parameters over 512 bytes revert; 512 is accepted.+ it("rejects parameters over 512 bytes and accepts exactly 512", async () => {+ const [invokerAgent] = deriveAgentPda(invokerAuthority.publicKey, programId);+ const [targetAgent] = deriveAgentPda(targetAuthority.publicKey, programId);++ await assert.rejects(+ program.methods+ .invokeSkill("summarize", "p".repeat(513))+ .accounts({+ invokerAgent,+ invokerAuthority: invokerAuthority.publicKey,+ targetAuthority: targetAuthority.publicKey,+ targetAgent,+ })+ .signers([invokerAuthority])+ .rpc(),+ (err: any) => {+ assert.ok(+ String(err).includes("ParametersTooLong") || String(err).includes("6002"),+ `expected ParametersTooLong, got: ${err}`,+ );+ return true;+ },+ );++ await program.methods+ .invokeSkill("summarize", "p".repeat(512))+ .accounts({+ invokerAgent,+ invokerAuthority: invokerAuthority.publicKey,+ targetAuthority: targetAuthority.publicKey,+ targetAgent,+ })+ .signers([invokerAuthority])+ .rpc();+ });++ // AI-1 (negative half): a caller cannot present somebody else's agent PDA as+ // their own — the seeds constraint re-derives the PDA from the signer, and+ // the mismatched account fails the constraint before the body runs.+ it("rejects an invoker_agent derived from a different authority", async () => {+ const [foreignAgent] = deriveAgentPda(targetAuthority.publicKey, programId);+ const [targetAgent] = deriveAgentPda(targetAuthority.publicKey, programId);++ await assert.rejects(+ program.methods+ .invokeSkill("summarize", "{}")+ .accounts({+ invokerAgent: foreignAgent, // belongs to targetAuthority, not the signer+ invokerAuthority: invokerAuthority.publicKey,+ targetAuthority: targetAuthority.publicKey,+ targetAgent,+ })+ .signers([invokerAuthority])+ .rpc(),+ (err: any) => {+ const code = anchorErrorCode(err);+ // ConstraintSeeds is Anchor error 2006.+ assert.ok(+ String(err).includes("ConstraintSeeds") || code === 2006 || String(err).includes("0x7d6"),+ `expected a seeds constraint failure, got: ${err}`,+ );+ return true;+ },+ );+ });++ // AI-2 (negative half): an arbitrary, non-PDA account cannot be passed as+ // the target agent.+ it("rejects a target_agent that is not the derived PDA", async () => {+ const [invokerAgent] = deriveAgentPda(invokerAuthority.publicKey, programId);+ const arbitrary = Keypair.generate().publicKey;++ await assert.rejects(+ program.methods+ .invokeSkill("summarize", "{}")+ .accounts({+ invokerAgent,+ invokerAuthority: invokerAuthority.publicKey,+ targetAuthority: targetAuthority.publicKey,+ targetAgent: arbitrary,+ })+ .signers([invokerAuthority])+ .rpc(),+ (err: any) => {+ const code = anchorErrorCode(err);+ assert.ok(+ String(err).includes("ConstraintSeeds") || code === 2006 || String(err).includes("0x7d6"),+ `expected a seeds constraint failure, got: ${err}`,+ );+ return true;+ },+ );+ });++ // AI-1 (negative half): the transaction must carry the invoker authority's+ // signature; without it the Signer constraint fails.+ it("rejects an unsigned invocation", async () => {+ const [invokerAgent] = deriveAgentPda(invokerAuthority.publicKey, programId);+ const [targetAgent] = deriveAgentPda(targetAuthority.publicKey, programId);++ await assert.rejects(+ program.methods+ .invokeSkill("summarize", "{}")+ .accounts({+ invokerAgent,+ invokerAuthority: invokerAuthority.publicKey,+ targetAuthority: targetAuthority.publicKey,+ targetAgent,+ })+ .rpc(), // no signer for invokerAuthority: provider wallet ≠ invoker+ (err: any) => {+ const s = String(err);+ assert.ok(+ s.includes("Signature") || s.includes("signer") || s.includes("unknown signer"),+ `expected a missing-signature failure, got: ${err}`,+ );+ return true;+ },+ );+ });+});diff --git a/contracts/agent-invocation/tsconfig.json b/contracts/agent-invocation/tsconfig.jsonnew file mode 100644index 000000000..e71bcf8bc--- /dev/null+++ b/contracts/agent-invocation/tsconfig.json@@ -0,0 +1,16 @@+{+ "compilerOptions": {+ "types": ["mocha"],+ "typeRoots": ["./node_modules/@types", "../../node_modules/@types"],+ "lib": ["es2022"],+ "module": "es2022",+ "target": "es2022",+ "moduleResolution": "bundler",+ "resolveJsonModule": true,+ "esModuleInterop": true,+ "skipLibCheck": true,+ "strict": false,+ "noEmit": true+ },+ "include": ["tests/**/*"]+}diff --git a/contracts/skill-license/package.json b/contracts/skill-license/package.jsonnew file mode 100644index 000000000..7ff60bd4c--- /dev/null+++ b/contracts/skill-license/package.json@@ -0,0 +1,17 @@+{+ "name": "skill-license-tests",+ "private": true,+ "type": "module",+ "scripts": {+ "test": "anchor test"+ },+ "dependencies": {+ "@coral-xyz/anchor": "0.32.1",+ "@solana/spl-token": "^0.4.9"+ },+ "devDependencies": {+ "@types/mocha": "^10.0.10",+ "mocha": "^11.0.0",+ "typescript": "^5.9.0"+ }+}diff --git a/contracts/skill-license/tests/skill-license.ts b/contracts/skill-license/tests/skill-license.tsnew file mode 100644index 000000000..458288190--- /dev/null+++ b/contracts/skill-license/tests/skill-license.ts@@ -0,0 +1,384 @@+// Integration tests for the skill_license program, run by `anchor test`+// against a local validator with the real compiled program deployed.+//+// Every test cites the invariant it proves from+// specs/ECONOMY_CONTRACT_INVARIANTS.md (ids SL-1 .. SL-8), so+// `grep -rn "SL-1" contracts/skill-license/tests` finds the proof.+import * as anchor from "@coral-xyz/anchor";+import { Program } from "@coral-xyz/anchor";+import { Keypair, PublicKey } from "@solana/web3.js";+import {+ ASSOCIATED_TOKEN_PROGRAM_ID,+ TOKEN_PROGRAM_ID,+ getAssociatedTokenAddressSync,+ getAccount,+ getMint,+} from "@solana/spl-token";+import assert from "node:assert/strict";+import { createRequire } from "node:module";+import { createHash } from "node:crypto";++const require = createRequire(import.meta.url);+const IDL = require("../target/idl/skill_license.json");++const MARKETPLACE_SEED = Buffer.from("marketplace");+const SKILL_LICENSE_SEED = Buffer.from("skill_license");+const SKILL_MINT_SEED = Buffer.from("skill_mint");++// SL-8: the on-chain seed is exactly sha256(skill_name), matching this+// client-side derivation byte for byte.+function skillSeed(skillName: string): Buffer {+ return createHash("sha256").update(skillName, "utf8").digest();+}++describe("skill_license", () => {+ const provider = anchor.AnchorProvider.env();+ anchor.setProvider(provider);+ const program = new Program(IDL, provider);+ const programId = program.programId;++ const authority = Keypair.generate(); // marketplace admin+ const minter = Keypair.generate(); // authorized backend minter+ const stranger = Keypair.generate(); // never authorized for anything+ const owner = Keypair.generate(); // license recipient (never signs a mint)+ const agentMint = Keypair.generate().publicKey; // grouping key only++ const [marketplace] = PublicKey.findProgramAddressSync([MARKETPLACE_SEED], programId);++ function deriveLicense(ownerKey: PublicKey, agent: PublicKey, skill: string) {+ const seed = skillSeed(skill);+ const [license] = PublicKey.findProgramAddressSync(+ [SKILL_LICENSE_SEED, ownerKey.toBuffer(), agent.toBuffer(), seed],+ programId,+ );+ const [nftMint] = PublicKey.findProgramAddressSync(+ [SKILL_MINT_SEED, ownerKey.toBuffer(), agent.toBuffer(), seed],+ programId,+ );+ const ownerTokenAccount = getAssociatedTokenAddressSync(nftMint, ownerKey);+ return { license, nftMint, ownerTokenAccount };+ }++ async function fund(key: PublicKey, sol = 2) {+ const sig = await provider.connection.requestAirdrop(key, sol * anchor.web3.LAMPORTS_PER_SOL);+ await provider.connection.confirmTransaction(sig, "confirmed");+ }++ async function mintLicense(skill: string, ownerKey: PublicKey, agent: PublicKey) {+ const { license, nftMint, ownerTokenAccount } = deriveLicense(ownerKey, agent, skill);+ await program.methods+ .mintSkillLicense(skill)+ .accounts({+ marketplace,+ minter: minter.publicKey,+ owner: ownerKey,+ agentMint: agent,+ skillLicense: license,+ nftMint,+ ownerTokenAccount,+ })+ .signers([minter])+ .rpc();+ return { license, nftMint, ownerTokenAccount };+ }++ before(async () => {+ await Promise.all([+ fund(authority.publicKey),+ fund(minter.publicKey),+ fund(stranger.publicKey),+ ]);+ });++ // SL-1 (positive half of the admin leg): the deployer initializes the+ // singleton config and becomes its authority, naming the minter.+ it("initializes the marketplace with the caller as authority", async () => {+ await program.methods+ .initializeMarketplace(minter.publicKey)+ .accounts({ marketplace, authority: authority.publicKey })+ .signers([authority])+ .rpc();++ const state = await program.account.marketplace.fetch(marketplace);+ assert.ok(state.authority.equals(authority.publicKey));+ assert.ok(state.minter.equals(minter.publicKey));+ assert.strictEqual(state.licensesMinted.toNumber(), 0);+ });++ // SL-1 (negative half): a stranger cannot mint; the minter constraint is+ // enforced before any account is created.+ it("rejects a mint from a non-minter", async () => {+ const { license, nftMint, ownerTokenAccount } = deriveLicense(owner.publicKey, agentMint, "summarize");+ await assert.rejects(+ program.methods+ .mintSkillLicense("summarize")+ .accounts({+ marketplace,+ minter: stranger.publicKey,+ owner: owner.publicKey,+ agentMint,+ skillLicense: license,+ nftMint,+ ownerTokenAccount,+ })+ .signers([stranger])+ .rpc(),+ (err: any) => {+ assert.ok(String(err).includes("UnauthorizedMinter"), `expected UnauthorizedMinter, got: ${err}`);+ return true;+ },+ );+ });++ // SL-4 (negative halves): empty and over-long skill names are rejected.+ it("rejects an empty skill name", async () => {+ const { license, nftMint, ownerTokenAccount } = deriveLicense(owner.publicKey, agentMint, "x");+ await assert.rejects(+ program.methods+ .mintSkillLicense("")+ .accounts({+ marketplace,+ minter: minter.publicKey,+ owner: owner.publicKey,+ agentMint,+ skillLicense: license,+ nftMint,+ ownerTokenAccount,+ })+ .signers([minter])+ .rpc(),+ (err: any) => {+ assert.ok(String(err).includes("EmptySkillName"), `expected EmptySkillName, got: ${err}`);+ return true;+ },+ );+ });++ it("rejects a skill name over 64 bytes", async () => {+ const long = "s".repeat(65);+ const { license, nftMint, ownerTokenAccount } = deriveLicense(owner.publicKey, agentMint, long);+ await assert.rejects(+ program.methods+ .mintSkillLicense(long)+ .accounts({+ marketplace,+ minter: minter.publicKey,+ owner: owner.publicKey,+ agentMint,+ skillLicense: license,+ nftMint,+ ownerTokenAccount,+ })+ .signers([minter])+ .rpc(),+ (err: any) => {+ assert.ok(String(err).includes("SkillNameTooLong"), `expected SkillNameTooLong, got: ${err}`);+ return true;+ },+ );+ });++ // SL-2 / SL-3 / SL-7 (positive halves): the authorized mint creates the+ // license PDA and a 1-of-1 NFT whose supply is locked at 1.+ it("mints a 1-of-1 license NFT with locked supply", async () => {+ const { license, nftMint, ownerTokenAccount } = await mintLicense("summarize", owner.publicKey, agentMint);++ const state = await program.account.skillLicense.fetch(license);+ assert.ok(state.authority.equals(owner.publicKey));+ assert.ok(state.agentMint.equals(agentMint));+ assert.ok(state.nftMint.equals(nftMint));+ assert.deepStrictEqual([...state.skillHash], [...skillSeed("summarize")]); // SL-8+ assert.strictEqual(state.revokedAt.toNumber(), 0);+ assert.strictEqual(state.skillName, "summarize");++ // SL-3: supply exactly 1, mint authority removed, freeze authority kept.+ const mint = await getMint(provider.connection, nftMint);+ assert.strictEqual(mint.supply, 1n);+ assert.strictEqual(mint.mintAuthority, null);+ assert.ok(mint.freezeAuthority !== null && mint.freezeAuthority.equals(marketplace));++ const ata = await getAccount(provider.connection, ownerTokenAccount);+ assert.strictEqual(ata.amount, 1n);++ // SL-7: the counter advanced by exactly one.+ const market = await program.account.marketplace.fetch(marketplace);+ assert.strictEqual(market.licensesMinted.toNumber(), 1);+ });++ // SL-2 (negative half): the same purchase can never mint twice — the second+ // init hits existing accounts and the transaction fails.+ it("rejects minting the same (owner, agent, skill) twice", async () => {+ const { license, nftMint, ownerTokenAccount } = deriveLicense(owner.publicKey, agentMint, "summarize");+ await assert.rejects(+ program.methods+ .mintSkillLicense("summarize")+ .accounts({+ marketplace,+ minter: minter.publicKey,+ owner: owner.publicKey,+ agentMint,+ skillLicense: license,+ nftMint,+ ownerTokenAccount,+ })+ .signers([minter])+ .rpc(),+ (err: any) => {+ // The license PDA already exists, so the init fails (custom error 0x0+ // "already in use" surfaces as a simulation failure).+ assert.ok(String(err).length > 0, "expected a failure");+ return true;+ },+ );+ });++ // SL-1 (admin leg): only the authority may rotate the minter.+ it("lets the authority rotate the minter and rejects anyone else", async () => {+ const rotated = Keypair.generate();+ await assert.rejects(+ program.methods+ .setMinter(rotated.publicKey)+ .accounts({ marketplace, authority: stranger.publicKey })+ .signers([stranger])+ .rpc(),+ (err: any) => {+ assert.ok(String(err).includes("UnauthorizedAdmin"), `expected UnauthorizedAdmin, got: ${err}`);+ return true;+ },+ );++ await program.methods+ .setMinter(rotated.publicKey)+ .accounts({ marketplace, authority: authority.publicKey })+ .signers([authority])+ .rpc();++ const state = await program.account.marketplace.fetch(marketplace);+ assert.ok(state.minter.equals(rotated.publicKey));++ // Rotate back so the remaining tests use the funded minter.+ await program.methods+ .setMinter(minter.publicKey)+ .accounts({ marketplace, authority: authority.publicKey })+ .signers([authority])+ .rpc();+ });++ // SL-5 (positive half) + refund path: the minter revokes, which freezes the+ // holder's token account and stamps revoked_at without deleting the record.+ it("revokes a license: freezes the NFT, stamps revoked_at, keeps the record", async () => {+ const { license, nftMint, ownerTokenAccount } = await mintLicense("translate", owner.publicKey, agentMint);++ await program.methods+ .revokeSkillLicense()+ .accounts({+ marketplace,+ minter: minter.publicKey,+ owner: owner.publicKey,+ skillLicense: license,+ nftMint,+ ownerTokenAccount,+ })+ .signers([minter])+ .rpc();++ const state = await program.account.skillLicense.fetch(license);+ assert.ok(state.revokedAt.toNumber() > 0);++ const ata = await getAccount(provider.connection, ownerTokenAccount);+ assert.ok(ata.isFrozen, "the holder's token account must be frozen on revoke");+ });++ // SL-5 (negative half): revoking an already-revoked license fails.+ it("rejects revoking an already-revoked license", async () => {+ const { license, nftMint, ownerTokenAccount } = deriveLicense(owner.publicKey, agentMint, "translate");+ await assert.rejects(+ program.methods+ .revokeSkillLicense()+ .accounts({+ marketplace,+ minter: minter.publicKey,+ owner: owner.publicKey,+ skillLicense: license,+ nftMint,+ ownerTokenAccount,+ })+ .signers([minter])+ .rpc(),+ (err: any) => {+ assert.ok(String(err).includes("AlreadyRevoked"), `expected AlreadyRevoked, got: ${err}`);+ return true;+ },+ );+ });++ // SL-1 (negative half, revoke leg): a stranger cannot revoke.+ it("rejects a revoke from a non-minter", async () => {+ const { license, nftMint, ownerTokenAccount } = await mintLicense("classify", owner.publicKey, agentMint);+ await assert.rejects(+ program.methods+ .revokeSkillLicense()+ .accounts({+ marketplace,+ minter: stranger.publicKey,+ owner: owner.publicKey,+ skillLicense: license,+ nftMint,+ ownerTokenAccount,+ })+ .signers([stranger])+ .rpc(),+ (err: any) => {+ assert.ok(String(err).includes("UnauthorizedMinter"), `expected UnauthorizedMinter, got: ${err}`);+ return true;+ },+ );+ });++ // SL-6 (negative half): nobody but the license owner may burn it.+ it("rejects a burn by anyone but the license owner", async () => {+ const { license, nftMint, ownerTokenAccount } = await mintLicense("audit", owner.publicKey, agentMint);+ await assert.rejects(+ program.methods+ .burnSkillLicense()+ .accounts({+ skillLicense: license,+ authority: stranger.publicKey,+ nftMint,+ ownerTokenAccount,+ })+ .signers([stranger])+ .rpc(),+ (err: any) => {+ assert.ok(String(err).includes("NotLicenseOwner"), `expected NotLicenseOwner, got: ${err}`);+ return true;+ },+ );+ });++ // SL-6 (positive half): the owner burns the NFT, closing both the token+ // account and the license PDA, with rent going back to the owner.+ it("lets the owner burn the license and reclaim rent", async () => {+ const skill = "burn-me";+ const burner = Keypair.generate();+ await fund(burner.publicKey);+ const { license, nftMint, ownerTokenAccount } = await mintLicense(skill, burner.publicKey, agentMint);++ const before = await provider.connection.getBalance(burner.publicKey);+ await program.methods+ .burnSkillLicense()+ .accounts({+ skillLicense: license,+ authority: burner.publicKey,+ nftMint,+ ownerTokenAccount,+ })+ .signers([burner])+ .rpc();++ assert.strictEqual(await provider.connection.getAccountInfo(license), null);+ assert.strictEqual(await provider.connection.getAccountInfo(ownerTokenAccount), null);+ const after = await provider.connection.getBalance(burner.publicKey);+ assert.ok(after > before, "burn should return the closed accounts' rent");+ });+});diff --git a/contracts/skill-license/tsconfig.json b/contracts/skill-license/tsconfig.jsonnew file mode 100644index 000000000..e71bcf8bc--- /dev/null+++ b/contracts/skill-license/tsconfig.json@@ -0,0 +1,16 @@+{+ "compilerOptions": {+ "types": ["mocha"],+ "typeRoots": ["./node_modules/@types", "../../node_modules/@types"],+ "lib": ["es2022"],+ "module": "es2022",+ "target": "es2022",+ "moduleResolution": "bundler",+ "resolveJsonModule": true,+ "esModuleInterop": true,+ "skipLibCheck": true,+ "strict": false,+ "noEmit": true+ },+ "include": ["tests/**/*"]+}diff --git a/contracts/test/GreenfieldVault.t.sol b/contracts/test/GreenfieldVault.t.solindex 9b6caab46..0c5dbd04b 100644--- a/contracts/test/GreenfieldVault.t.sol+++ b/contracts/test/GreenfieldVault.t.sol@@ -278,6 +278,10 @@ contract GreenfieldVaultTest is Test {assertEq(buyer.balance, before - TOTAL_REQUIRED);}+ /// GV-2 (negative half): a (objectId, buyer) pair may not buy twice while+ /// a purchase is open. The retry-after-failure and resell-after-revoke+ /// halves are proven by testSettlementFailureAllowsRetry and+ /// testRevokeHappyPath.function testDoubleBuySameBuyerReverts() public {_list(seller, OBJECT_ID, PRICE);_buy(buyer, OBJECT_ID);@@ -287,6 +291,8 @@ contract GreenfieldVaultTest is Test {vault.buy{value: TOTAL_REQUIRED}(OBJECT_ID, POLICY_DATA);}+ /// GV-2 (positive half): distinct buyers are independent pairs and may+ /// each hold an open purchase on the same object.function testDifferentBuyersCanEachPurchase() public {_list(seller, OBJECT_ID, PRICE);uint256 saleId1 = _buy(buyer, OBJECT_ID);@@ -312,19 +318,22 @@ contract GreenfieldVaultTest is Test {assertTrue(saleId2 != saleId);}- // ── greenfieldCall access control ───────────────────────────────────+ // ── GV-6: greenfieldCall access control ────────────────────────────────+ /// GV-6 (negative half): only the PermissionHub contract may deliver an ack.function testGreenfieldCallOnlyPermissionHub() public {vm.expectRevert(GreenfieldVault.OnlyPermissionHub.selector);vault.greenfieldCall(STATUS_SUCCESS, 0x07, 2, 1, abi.encode(uint256(1)));}+ /// GV-6 (negative half): only the permission channel is accepted.function testGreenfieldCallBadChannelReverts() public {vm.prank(address(permissionHub));vm.expectRevert(GreenfieldVault.BadChannel.selector);vault.greenfieldCall(STATUS_SUCCESS, 0x05, 2, 1, abi.encode(uint256(1)));}+ /// GV-6 (negative half): an ack for a sale that does not exist reverts.function testGreenfieldCallUnknownSaleReverts() public {vm.prank(address(permissionHub));vm.expectRevert(GreenfieldVault.UnknownSale.selector);diff --git a/contracts/test/ValidationRegistry.t.sol b/contracts/test/ValidationRegistry.t.solindex 68f962a02..0f62d12ca 100644--- a/contracts/test/ValidationRegistry.t.sol+++ b/contracts/test/ValidationRegistry.t.sol@@ -73,6 +73,8 @@ contract ValidationRegistryTest is Test {validation.recordValidation(1, true, bytes32(0), "", "glb-schema");}+ /// VR-5: an attestation against an agent id that does not exist in the+ /// Identity Registry reverts; feedback cannot target a non-agent.function testUnknownAgentReverts() public {validation.addValidator(validator);vm.prank(validator);diff --git a/contracts/test/WorldMoves.t.sol b/contracts/test/WorldMoves.t.solindex 41e38eba4..e5aa4bdd3 100644--- a/contracts/test/WorldMoves.t.sol+++ b/contracts/test/WorldMoves.t.sol@@ -18,6 +18,8 @@ contract WorldMovesTest is Test {// ── move: event correctness ──────────────────────────────────────────+ /// WM-2 (positive half): a move inside the inclusive bounds emits exactly+ /// the coordinates, facing, and block metadata the indexer relies on.function testMoveEmitsExactArgsAndBlockMetadata() public {vm.roll(12345);vm.warp(1_700_000_000);@@ -41,6 +43,7 @@ contract WorldMovesTest is Test {wm.move(WORLD, 4, 5, 6, 180);}+ /// WM-1 (storage half): move() writes no checkpoint state.function testMoveDoesNotWriteAnyCheckpointStorage() public {vm.prank(alice);wm.move(WORLD, 10, 20, 30, 1);@@ -61,6 +64,8 @@ contract WorldMovesTest is Test {vm.stopPrank();}+ /// WM-2 (negative half): a coordinate one past the max on any axis reverts+ /// instead of being clamped.function testMoveRevertsXAboveMax() public {int32 max = wm.COORD_MAX();vm.expectRevert(WorldMoves.CoordinateOutOfBounds.selector);@@ -157,6 +162,8 @@ contract WorldMovesTest is Test {assertEq(facing, 2);}+ /// WM-3: a checkpoint is keyed by (worldId, caller) only; neither another+ /// world nor another player ever sees it.function testCheckpointIsPerWorldAndPerPlayer() public {vm.startPrank(alice);wm.checkpoint(WORLD, 1, 1, 1, 1);@@ -191,11 +198,11 @@ contract WorldMovesTest is Test {// ── gas: the whole point of this contract ────────────────────────────- /// @notice `move()` must never touch storage (event-only), so gas should- /// stay flat and cheap across repeated calls from the same- /// caller, back to back, exactly the spam pattern a ~0.45s block- /// cadence produces. Asserted well under a plain ERC-20 transfer- /// (~51k gas) to prove the "minimal gas per move" design goal.+ /// WM-1 (gas half): move() must never touch storage (event-only), so gas+ /// stays flat and cheap across repeated calls from the same caller, back+ /// to back, exactly the spam pattern a ~0.45s block cadence produces.+ /// Asserted well under a plain ERC-20 transfer (~51k gas) to prove the+ /// "minimal gas per move" design goal.function testGasPerMoveIsFlatAndLow() public {vm.prank(alice);wm.move(WORLD, 1, 1, 1, 1); // warm up: first call ever, cold access is irrelevant to steady state@@ -235,9 +242,9 @@ contract WorldMovesTest is Test {assertApproxEqAbs(gasUsed2, gasUsed3, 100, "move() gas must stay flat across calls");}- /// @notice checkpoint() writes one storage slot; sanity-check it costs- /// meaningfully more than move() so the split is doing its job- /// (callers who don't need queryable state save real gas).+ /// WM-4: there is no admin surface to strengthen against. What can be+ /// proven is that checkpoint's storage cost stays meaningfully above the+ /// event-only move, so the immutable split keeps saving callers real gas.function testCheckpointCostsMoreThanMove() public {vm.startPrank(alice);wm.move(WORLD, 1, 1, 1, 1);