Skip to content

Commit

Permalink
add some test vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
supermassive authored and dr497 committed Mar 5, 2024
1 parent 1be60b5 commit e930b83
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 6 deletions.
7 changes: 2 additions & 5 deletions js/src/nft/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
} from "@solana/spl-token";
import {
NAME_TOKENIZER_ID,
MINT_PREFIX,
NftRecord,
getRecordFromMint,
getDomainMint,
} from "./name-tokenizer";

/**
Expand All @@ -29,10 +29,7 @@ export const retrieveNftOwner = async (
nameAccount: PublicKey,
) => {
try {
const [mint] = await PublicKey.findProgramAddress(
[MINT_PREFIX, nameAccount.toBuffer()],
NAME_TOKENIZER_ID,
);
const mint = getDomainMint(nameAccount);

const mintInfo = await getMint(connection, mint);
if (mintInfo.supply.toString() === "0") {
Expand Down
20 changes: 19 additions & 1 deletion js/tests/nft.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require("dotenv").config();
import { test, jest } from "@jest/globals";
import { PublicKey, Connection } from "@solana/web3.js";
import { getTokenizedDomains } from "../src/utils";
import { getDomainKeySync, getTokenizedDomains } from "../src/utils";
import { getDomainMint } from "../src/nft/name-tokenizer";

jest.setTimeout(10_000);
const connection = new Connection(process.env.RPC_URL!);
Expand Down Expand Up @@ -42,3 +43,20 @@ test("Get tokenized domains", async () => {
expect(domains).toEqual(item.domains);
}
});

describe("getDomainMint", () => {
test.each([
{
domain: "domain1.sol",
address: "3YTxXhhVue9BVjgjPwJbbJ4uGPsnwN453DDf72rYE5WN",
},
{
domain: "sub.domain2.sol",
address: "66CnogoXDBqYeYRGYzQf19VyrMnB4uGxpZQDuDYfbKCX",
},
])("$domain", (e) => {
expect(getDomainMint(getDomainKeySync(e.domain).pubkey).toBase58()).toBe(
e.address,
);
});
});
38 changes: 38 additions & 0 deletions js/tests/records-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
deserializeRecordV2Content,
getMultipleRecordsV2,
getRecordV2,
getRecordV2Key,
serializeRecordV2Content,
} from "../src/record_v2";
import { Record } from "../src/types/record";
Expand Down Expand Up @@ -340,3 +341,40 @@ test("getMultipleRecordsV2", async () => {
expect(items[i].record).toBe(res[i]?.record);
}
});

describe("getRecordV2Key", () => {
test.each([
{
domain: "domain1.sol",
record: Record.SOL,
expected: "GBrd6Q53eu1T2PiaQAtm92r3DwxmoGvZ2D6xjtVtN1Qt",
},
{
domain: "sub.domain2.sol",
record: Record.SOL,
expected: "A3EFmyCmK5rp73TdgLH8aW49PJ8SJw915arhydRZ6Sws",
},
{
domain: "domain3.sol",
record: Record.Url,
expected: "DMZmnjcAnUwSje4o2LGJhipCfNZ5b37GEbbkwbQBWEW1",
},
{
domain: "sub.domain4.sol",
record: Record.Url,
expected: "6o8JQ7vss6r9sw9GWNVugZktwfEJ67iUz6H63hhmg4sj",
},
{
domain: "domain5.sol",
record: Record.IPFS,
expected: "DQHeVmAj9Nz4uAn2dneEsgBZWcfhUqLdtbDcfWhGL47D",
},
{
domain: "sub.domain6.sol",
record: Record.IPFS,
expected: "Dj7tnTTaktrrmdtatRuLG3YdtGZk8XEBMb4w5WtCBHvr",
},
])("$domain", (e) => {
expect(getRecordV2Key(e.domain, e.record).toBase58()).toBe(e.expected);
});
});
38 changes: 38 additions & 0 deletions js/tests/records.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Record } from "../src/types/record";
import { createRecordInstruction } from "../src/bindings";
import { resolveSolRecordV1 } from "../src/resolve";
import { NameRegistryState } from "../src/state";
import { getRecordKeySync } from "../src/record";

jest.setTimeout(20_000);

Expand Down Expand Up @@ -162,3 +163,40 @@ test("Des/ser", () => {
expect(des).toBe(e.content);
});
});

describe("getRecordKeySync", () => {
test.each([
{
domain: "domain1.sol",
record: Record.SOL,
expected: "ATH9akc5pi1PWDB39YY7VCoYzCxmz8XVj23oegSoNSPL",
},
{
domain: "sub.domain2.sol",
record: Record.SOL,
expected: "AEgJVf6zaQfkyYPnYu8Y9Vxa1Sy69EtRSP8iGubx5MnC",
},
{
domain: "domain3.sol",
record: Record.Url,
expected: "EuxtWLCKsdpwM8ftKjnD2Q8vBdzZunh7DY1mHwXhLTqx",
},
{
domain: "sub.domain4.sol",
record: Record.Url,
expected: "64nv6HSbifdUgdWst48V4YUB3Y3uQXVQRD4iDZPd9qGx",
},
{
domain: "domain5.sol",
record: Record.IPFS,
expected: "2uRMeYzKXaYgFVQ1Yh7fKyZWcxsFUMgpEwMi19sVjwjk",
},
{
domain: "sub.domain6.sol",
record: Record.IPFS,
expected: "61JdnEhbd2bEfxnu2uQ38gM2SUry2yY8kBMEseYh8dDy",
},
])("$domain", (e) => {
expect(getRecordKeySync(e.domain, e.record).toBase58()).toBe(e.expected);
});
});

0 comments on commit e930b83

Please sign in to comment.