Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
netbonus committed Jun 13, 2024
1 parent 19c8927 commit ad77963
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Constants } from '../../..';
import { initializeClient } from '../../utils/initializeClient';
import { Constants } from '../../../..';
import { initializeClient } from '../../../utils/initializeClient';
import { dexlabProgram, raydiumProgram } from './__mocks__/programs';

describe('Solana Programs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import {
SystemProgram as SolanaSystemProgram,
Transaction as SolanaTransaction,
} from '@solana/web3.js';
import { Constants } from '../../..';
import { HARDENED_OFFSET } from '../../../constants';
import { getPrng } from '../../utils/getters';
import { deriveED25519Key, prandomBuf } from '../../utils/helpers';
import { initializeClient, initializeSeed } from '../../utils/initializeClient';
import { runGeneric } from '../../utils/runners';
import { Constants } from '../../../..';
import { HARDENED_OFFSET } from '../../../../constants';
import { getPrng } from '../../../utils/getters';
import { deriveED25519Key, prandomBuf } from '../../../utils/helpers';
import {
initializeClient,
initializeSeed,
} from '../../../utils/initializeClient';
import { runGeneric } from '../../../utils/runners';

//---------------------------------------
// STATE DATA
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
VersionedTransaction,
} from '@solana/web3.js';
import { question } from 'readline-sync';
import { fetchSolanaAddresses, pair, signSolanaTx } from '../../..';
import { setupClient } from '../../utils/setup';
import { fetchSolanaAddresses, pair, signSolanaTx } from '../../../..';
import { setupClient } from '../../../utils/setup';

const SOLANA_RPC = new Connection('https://api.devnet.solana.com', 'confirmed');

const fetchSigningWallet = async () => {
const addresses = await fetchSolanaAddresses({ n: 1 });
Expand All @@ -22,8 +24,20 @@ const fetchSigningWallet = async () => {
return pubkey;
};

const requestAirdrop = async (wallet: PublicKey, lamports: number) => {
try {
await SOLANA_RPC.requestAirdrop(wallet, lamports * LAMPORTS_PER_SOL);
await new Promise((resolve) => setTimeout(resolve, 20000));
} catch (error) {
/**
* The faucet is flakey, so you might need to request funds manually from the faucet at https://faucet.solana.com/
* Also, for Solana to work, your address must have interacted with the network previously.
*/
console.log(error);
}
};

describe('solana.versioned', () => {
let SOLANA_RPC: Connection;
let SIGNER_WALLET: PublicKey;
let DESTINATION_WALLET_1: Keypair;
let DESTINATION_WALLET_2: Keypair;
Expand All @@ -35,7 +49,6 @@ describe('solana.versioned', () => {
const secret = question('Please enter the pairing secret: ');
await pair(secret.toUpperCase());
}
SOLANA_RPC = new Connection('https://api.testnet.solana.com', 'confirmed');
SIGNER_WALLET = await fetchSigningWallet();
DESTINATION_WALLET_1 = Keypair.generate();
DESTINATION_WALLET_2 = Keypair.generate();
Expand Down Expand Up @@ -101,9 +114,7 @@ describe('solana.versioned', () => {
});

test('simulate versioned solana transaction', async () => {
// Request airdrop to fund account
await SOLANA_RPC.requestAirdrop(SIGNER_WALLET, 2 * LAMPORTS_PER_SOL);
await new Promise((resolve) => setTimeout(resolve, 20000));
await requestAirdrop(SIGNER_WALLET, 1);

const txInstruction = SystemProgram.transfer({
fromPubkey: SIGNER_WALLET,
Expand Down Expand Up @@ -142,9 +153,7 @@ describe('solana.versioned', () => {

test('simulate versioned solana transaction with multiple instructions', async () => {
const payer = Keypair.generate();
// Request airdrop to fund account
await SOLANA_RPC.requestAirdrop(payer.publicKey, 2 * LAMPORTS_PER_SOL);
await new Promise((resolve) => setTimeout(resolve, 20000));
await requestAirdrop(payer.publicKey, 1);

const [transactionInstruction, pubkey] =
await AddressLookupTableProgram.createLookupTable({
Expand Down

0 comments on commit ad77963

Please sign in to comment.