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

Simplify naming. This is just doing a before/after test. #50

Merged
merged 1 commit into from
Sep 5, 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
20 changes: 8 additions & 12 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,11 @@ describe("initializeKeypair", () => {
envVariableName: keypairVariableName,
};

const signerFirstLoad = await initializeKeypair(connection, options);
const userBefore = await initializeKeypair(connection, options);

// Check balance
const firstBalanceLoad = await connection.getBalance(
signerFirstLoad.publicKey,
);
assert.ok(firstBalanceLoad > 0);
const balanceBefore = await connection.getBalance(userBefore.publicKey);
assert.ok(balanceBefore > 0);

// Check that the environment variable was created
dotenv.config({ path: envFileName });
Expand All @@ -221,19 +219,17 @@ describe("initializeKeypair", () => {
}

// Now reload the environment and check it matches our test keypair
const signerSecondLoad = await initializeKeypair(connection, options);
const userAfter = await initializeKeypair(connection, options);

// Check the keypair is the same
assert.ok(signerFirstLoad.publicKey.equals(signerSecondLoad.publicKey));
assert.ok(userBefore.publicKey.equals(userAfter.publicKey));

// Check balance has not changed
const secondBalanceLoad = await connection.getBalance(
signerSecondLoad.publicKey,
);
assert.equal(firstBalanceLoad, secondBalanceLoad);
const balanceAfter = await connection.getBalance(userAfter.publicKey);
assert.equal(balanceBefore, balanceAfter);

// Check there is a secret key
assert.ok(signerSecondLoad.secretKey);
assert.ok(userAfter.secretKey);

await deleteFile(envFileName);
});
Expand Down
3 changes: 3 additions & 0 deletions src/lib/airdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const DEFAULT_AIRDROP_AMOUNT = 1 * LAMPORTS_PER_SOL;
const DEFAULT_MINIMUM_BALANCE = 0.5 * LAMPORTS_PER_SOL;
const DEFAULT_ENV_KEYPAIR_VARIABLE_NAME = "PRIVATE_KEY";

// TODO: honestly initializeKeypair is a bit vague
// we can probably give this a better name,
// just not sure what yet
export const initializeKeypair = async (
connection: Connection,
options?: InitializeKeypairOptions,
Expand Down
Loading