Skip to content

Commit

Permalink
js: allow separate fee payer in createSub
Browse files Browse the repository at this point in the history
  • Loading branch information
dr497 committed Apr 22, 2024
1 parent 7e466ea commit bae14b1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
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);
});

0 comments on commit bae14b1

Please sign in to comment.