import * as anchor from "@project-serum/anchor"; import { getAssociatedTokenAddress } from "@solana/spl-token"; import { expect } from "chai"; import { readFileSync } from "fs"; import { resolve } from "path"; import { createPutOption, getAllOptions, getOption } from "../src"; import { STRIKR_AUTHORITY_SEED, STRIKR_TREASURY, TOKEN_METADATA_PROGRAM_ID, } from "../src/constants"; import { getStrikr } from "../src/utils"; import { mintNft } from "./utils"; describe("Strikr core", () => { const provider = anchor.getProvider() as anchor.AnchorProvider; const program = getStrikr(provider); const strikrAdminKeypair = anchor.web3.Keypair.fromSecretKey( Uint8Array.from( JSON.parse( readFileSync(resolve(__dirname, "./keypairs/strikr-admin.json"), { encoding: "utf-8", }) ) ) ); const strikrCollectionMintKeypair = anchor.web3.Keypair.fromSecretKey( Uint8Array.from( JSON.parse( readFileSync(resolve(__dirname, "./keypairs/strikr-collection.json"), { encoding: "utf-8", }) ) ) ); before(async () => { await provider.connection.confirmTransaction( await provider.connection.requestAirdrop( strikrAdminKeypair.publicKey, 10 * anchor.web3.LAMPORTS_PER_SOL ) ); const [strikrAuthorityAddress] = await anchor.web3.PublicKey.findProgramAddress( [STRIKR_AUTHORITY_SEED], program.programId ); await provider.connection.confirmTransaction( await provider.connection.requestAirdrop( strikrAuthorityAddress, 10 * anchor.web3.LAMPORTS_PER_SOL ) ); const strikrCollectionMint = strikrCollectionMintKeypair.publicKey; const strikrCollectionNftAta = await getAssociatedTokenAddress( strikrCollectionMint, strikrAuthorityAddress, true ); await provider.connection.confirmTransaction( await program.methods .initializeStrikrCollection() .accounts({ signer: strikrAdminKeypair.publicKey, strikrCollectionMint, strikrCollectionTokenAccount: strikrCollectionNftAta, tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID, strikrTreasury: STRIKR_TREASURY, }) .signers([strikrAdminKeypair, strikrCollectionMintKeypair]) .rpc() ); }); it("can create put option", async () => { const assetNftMint = await mintNft(provider, provider.wallet.publicKey); await createPutOption( provider, assetNftMint, new anchor.BN(10), new anchor.BN(10), new anchor.BN(1) ); // Assert OptionState has expected content const optionState = await getOption(provider.connection, assetNftMint); expect(optionState.assetNftMint.toBase58()).to.equal( assetNftMint.toBase58() ); }); it("can fetch all options", async () => { await getAllOptions(provider.connection); }); });