Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js: allow separate fee payer in createSub #62

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions js/src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,14 @@ export const createReverseName = async (
* @param subdomain The subdomain to create with or without .sol e.g something.bonfida.sol or something.bonfida
* @param owner The owner of the parent domain creating the subdomain
* @param space The space to allocate to the subdomain (defaults to 2kb)
* @param feePayer Optional: Specifies a fee payer different from the parent owner
*/
export const createSubdomain = async (
connection: Connection,
subdomain: string,
owner: PublicKey,
space = 2_000,
feePayer?: PublicKey,
) => {
const ixs: TransactionInstruction[] = [];
const sub = subdomain.split(".")[0];
Expand All @@ -431,7 +433,7 @@ export const createSubdomain = async (
connection,
"\0".concat(sub),
space, // Hardcode space to 2kB
owner,
feePayer || owner,
owner,
lamports,
undefined,
Expand All @@ -446,7 +448,7 @@ export const createSubdomain = async (
const [, ix_reverse] = await createReverseName(
pubkey,
"\0".concat(sub),
owner,
feePayer || owner,
parent,
owner,
);
Expand Down
2 changes: 1 addition & 1 deletion js/tests/reverse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test("Create sub", async () => {
connection,
sub + "." + parent,
parentOwner,
1_000
1_000,
);
const tx = new Transaction();
tx.add(...ix);
Expand Down
24 changes: 24 additions & 0 deletions js/tests/sub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createSubdomain, transferSubdomain } from "../src/bindings";
import { randomBytes } from "crypto";
import { VAULT_OWNER } from "../src/constants";
import { findSubdomains, getDomainKeySync } from "../src/utils";
import { resolve } from "../src/resolve";

jest.setTimeout(20_000);

Expand Down Expand Up @@ -68,3 +69,26 @@ test("Find sub domain", async () => {
const expectedSub = ["dex", "naming", "test"];
subs.sort().forEach((e, idx) => expect(e).toBe(expectedSub[idx]));
});

test("Create sub - Fee payer ", async () => {
const sub = "gvbhnjklmjnhb";
const parent = "bonfida.sol";
const feePayer = VAULT_OWNER;

const parentOwner = await resolve(connection, parent);
const [, ix] = await createSubdomain(
connection,
sub + "." + parent,
parentOwner,
1_000,
feePayer,
);
const tx = new Transaction();
tx.add(...ix);
const { blockhash } = await connection.getLatestBlockhash();

tx.recentBlockhash = blockhash;
tx.feePayer = VAULT_OWNER;
const res = await connection.simulateTransaction(tx);
expect(res.value.err).toBe(null);
});
Loading