Skip to content

Commit

Permalink
Fixed imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ASCorreia committed Aug 27, 2024
1 parent 6068375 commit 902c472
Showing 1 changed file with 54 additions and 93 deletions.
147 changes: 54 additions & 93 deletions tokens/nft-staking/anchor/tests/nft-staking.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
import * as anchor from "@coral-xyz/anchor";
import * as anchor from '@coral-xyz/anchor';
import { Program } from '@coral-xyz/anchor';
import { SYSTEM_PROGRAM_ID } from '@coral-xyz/anchor/dist/cjs/native/system';
import NodeWallet from '@coral-xyz/anchor/dist/cjs/nodewallet';
import {
createNft,
findMasterEditionPda,
findMetadataPda,
mplTokenMetadata,
verifySizedCollectionItem,
} from "@metaplex-foundation/mpl-token-metadata";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import {
KeypairSigner,
PublicKey,
createSignerFromKeypair,
generateSigner,
keypairIdentity,
percentAmount,
} from "@metaplex-foundation/umi";
import { Program } from "@coral-xyz/anchor";
import { NftStaking } from "../target/types/nft_staking";
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
getAssociatedTokenAddressSync,
} from "@solana/spl-token";
import NodeWallet from "@coral-xyz/anchor/dist/cjs/nodewallet";
import { SYSTEM_PROGRAM_ID } from "@coral-xyz/anchor/dist/cjs/native/system";

describe("nft-staking", () => {
} from '@metaplex-foundation/mpl-token-metadata';
import { KeypairSigner, PublicKey, createSignerFromKeypair, generateSigner, keypairIdentity, percentAmount } from '@metaplex-foundation/umi';
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
import { NftStaking } from '../target/types/nft_staking';

describe('nft-staking', () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.env();
anchor.setProvider(provider);
Expand All @@ -36,76 +25,57 @@ describe("nft-staking", () => {

const payer = provider.wallet as NodeWallet;

let nftMint: KeypairSigner = generateSigner(umi);
let collectionMint: KeypairSigner = generateSigner(umi);
const nftMint: KeypairSigner = generateSigner(umi);
const collectionMint: KeypairSigner = generateSigner(umi);

const creatorWallet = umi.eddsa.createKeypairFromSecretKey(
new Uint8Array(payer.payer.secretKey)
);
const creatorWallet = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(payer.payer.secretKey));
const creator = createSignerFromKeypair(umi, creatorWallet);
umi.use(keypairIdentity(creator));
umi.use(mplTokenMetadata());

const collection: anchor.web3.PublicKey = new anchor.web3.PublicKey(
collectionMint.publicKey.toString()
);
const collection: anchor.web3.PublicKey = new anchor.web3.PublicKey(collectionMint.publicKey.toString());

const config = anchor.web3.PublicKey.findProgramAddressSync(
[Buffer.from("config")],
program.programId
)[0];
const config = anchor.web3.PublicKey.findProgramAddressSync([Buffer.from('config')], program.programId)[0];

const rewardsMint = anchor.web3.PublicKey.findProgramAddressSync(
[Buffer.from("rewards"), config.toBuffer()],
program.programId
)[0];
const rewardsMint = anchor.web3.PublicKey.findProgramAddressSync([Buffer.from('rewards'), config.toBuffer()], program.programId)[0];

const userAccount = anchor.web3.PublicKey.findProgramAddressSync(
[Buffer.from("user"), provider.publicKey.toBuffer()],
program.programId
)[0];
const userAccount = anchor.web3.PublicKey.findProgramAddressSync([Buffer.from('user'), provider.publicKey.toBuffer()], program.programId)[0];

const stakeAccount = anchor.web3.PublicKey.findProgramAddressSync(
[
Buffer.from("stake"),
new anchor.web3.PublicKey(nftMint.publicKey as PublicKey).toBuffer(),
config.toBuffer(),
],
program.programId
[Buffer.from('stake'), new anchor.web3.PublicKey(nftMint.publicKey as PublicKey).toBuffer(), config.toBuffer()],
program.programId,
)[0];

it("Mint Collection NFT", async () => {
it('Mint Collection NFT', async () => {
await createNft(umi, {
mint: collectionMint,
name: "GM",
symbol: "GM",
uri: "https://arweave.net/123",
name: 'GM',
symbol: 'GM',
uri: 'https://arweave.net/123',
sellerFeeBasisPoints: percentAmount(5.5),
creators: null,
collectionDetails: {
__kind: "V1",
__kind: 'V1',
size: 10,
},
}).sendAndConfirm(umi);
console.log(
`Created Collection NFT: ${collectionMint.publicKey.toString()}`
);
console.log(`Created Collection NFT: ${collectionMint.publicKey.toString()}`);
});

it("Mint NFT", async () => {
it('Mint NFT', async () => {
await createNft(umi, {
mint: nftMint,
name: "GM",
symbol: "GM",
uri: "https://arweave.net/123",
name: 'GM',
symbol: 'GM',
uri: 'https://arweave.net/123',
sellerFeeBasisPoints: percentAmount(5.5),
collection: { verified: false, key: collectionMint.publicKey },
creators: null,
}).sendAndConfirm(umi);
console.log(`\nCreated NFT: ${nftMint.publicKey.toString()}`);
});

it("Verify Collection NFT", async () => {
it('Verify Collection NFT', async () => {
const collectionMetadata = findMetadataPda(umi, {
mint: collectionMint.publicKey,
});
Expand All @@ -121,10 +91,10 @@ describe("nft-staking", () => {
collection: collectionMetadata,
collectionMasterEditionAccount: collectionMasterEdition,
}).sendAndConfirm(umi);
console.log("\nCollection NFT Verified!");
console.log('\nCollection NFT Verified!');
});

it("Initialize Config Account", async () => {
it('Initialize Config Account', async () => {
const tx = await program.methods
.initializeConfig(10, 10, 0)
.accountsPartial({
Expand All @@ -135,11 +105,11 @@ describe("nft-staking", () => {
tokenProgram: TOKEN_PROGRAM_ID,
})
.rpc();
console.log("\nConfig Account Initialized!");
console.log("Your transaction signature", tx);
console.log('\nConfig Account Initialized!');
console.log('Your transaction signature', tx);
});

it("Initialize User Account", async () => {
it('Initialize User Account', async () => {
const tx = await program.methods
.initializeUser()
.accountsPartial({
Expand All @@ -148,15 +118,12 @@ describe("nft-staking", () => {
systemProgram: anchor.web3.SystemProgram.programId,
})
.rpc();
console.log("\nUser Account Initialized!");
console.log("Your transaction signature", tx);
console.log('\nUser Account Initialized!');
console.log('Your transaction signature', tx);
});

it("Stake NFT", async () => {
const mintAta = getAssociatedTokenAddressSync(
new anchor.web3.PublicKey(nftMint.publicKey as PublicKey),
provider.wallet.publicKey
);
it('Stake NFT', async () => {
const mintAta = getAssociatedTokenAddressSync(new anchor.web3.PublicKey(nftMint.publicKey as PublicKey), provider.wallet.publicKey);

const nftMetadata = findMetadataPda(umi, { mint: nftMint.publicKey });
const nftEdition = findMasterEditionPda(umi, { mint: nftMint.publicKey });
Expand All @@ -176,15 +143,12 @@ describe("nft-staking", () => {
})
.rpc();

console.log("\nNFT Staked!");
console.log("Your transaction signature", tx);
console.log('\nNFT Staked!');
console.log('Your transaction signature', tx);
});

it("Unstake NFT", async () => {
const mintAta = getAssociatedTokenAddressSync(
new anchor.web3.PublicKey(nftMint.publicKey as PublicKey),
provider.wallet.publicKey
);
it('Unstake NFT', async () => {
const mintAta = getAssociatedTokenAddressSync(new anchor.web3.PublicKey(nftMint.publicKey as PublicKey), provider.wallet.publicKey);

const nftEdition = findMasterEditionPda(umi, { mint: nftMint.publicKey });

Expand All @@ -201,18 +165,15 @@ describe("nft-staking", () => {
})
.rpc();

console.log("\nNFT unstaked!");
console.log("Your transaction signature", tx);
console.log('\nNFT unstaked!');
console.log('Your transaction signature', tx);

let account = await program.account.userAccount.fetch(userAccount);
console.log("user points: ", account.points);
const account = await program.account.userAccount.fetch(userAccount);
console.log('user points: ', account.points);
});

it("Claim Rewards", async () => {
const rewardsAta = getAssociatedTokenAddressSync(
rewardsMint,
provider.wallet.publicKey
);
it('Claim Rewards', async () => {
const rewardsAta = getAssociatedTokenAddressSync(rewardsMint, provider.wallet.publicKey);

const tx = await program.methods
.claim()
Expand All @@ -228,10 +189,10 @@ describe("nft-staking", () => {
})
.rpc();

console.log("\nRewards claimed");
console.log("Your transaction signature", tx);
console.log('\nRewards claimed');
console.log('Your transaction signature', tx);

let account = await program.account.userAccount.fetch(userAccount);
console.log("User points: ", account.points);
const account = await program.account.userAccount.fetch(userAccount);
console.log('User points: ', account.points);
});
});

0 comments on commit 902c472

Please sign in to comment.