mhunt_ticket_store/tests/ticket_store.ts.bkp
2024-10-26 15:19:21 +05:30

63 lines
2.8 KiB
Plaintext

import * as anchor from "@coral-xyz/anchor";
import { Program} from "@coral-xyz/anchor";
import {Connection, Keypair, PublicKey} from "@solana/web3.js";
import { TicketStore } from "../target/types/ticket_store";
import {createMint, getAccount} from "@solana/spl-token";
import { expect } from "chai";
const IDL = require('../target/idl/ticket_store.json');
const programID = new PublicKey("Cy1DGkDcqwL5viNnbiZZgQR4PSzv6rtCDmEXj9bv8cVc");
const ticketMint = Keypair.fromSecretKey(Uint8Array.from([229,133,46,6,15,114,88,149,178,253,116,33,217,111,94,244,105,170,38,6,63,11,240,208,100,188,213,19,214,172,25,104,13,66,62,178,5,210,60,27,205,73,155,208,220,115,21,71,229,90,136,12,171,103,219,77,230,84,214,49,107,123,186,61]));
const connection = new Connection("https://api.devnet.solana.com");
const walletKeyPair = Keypair.fromSecretKey(Uint8Array.from([202,150,67,41,155,133,176,172,9,100,150,190,239,37,69,73,18,16,76,65,164,197,99,134,240,151,112,65,61,122,95,41,9,44,6,237,108,123,86,90,144,27,1,160,101,95,239,35,53,91,195,220,22,214,2,84,132,37,20,236,133,242,104,197]));
describe("ticket_store", () => {
let wallet:anchor.Wallet = new anchor.Wallet(walletKeyPair);;
let provider:anchor.AnchorProvider = new anchor.AnchorProvider(connection,wallet);
anchor.setProvider(provider);
let program:Program<TicketStore>;
let tokenAccount;
before(async()=>{
// console.log("Starting test env");
// // context = await startAnchor("", [{name:"ticket_store",programId: programID}],[]);
// // provider = new BankrunProvider(context);
// wallet = new anchor.Wallet(walletKeyPair);
// provider = new anchor.AnchorProvider(connection,wallet);
// program = new Program<TicketStore>(IDL,provider);
// console.log("Program is init");
program = anchor.workspace.TicketStore as Program<TicketStore>;
console.log("Program is init");
console.log(program.programId);
try{
await createMint(
provider.connection,
wallet.payer,
wallet.publicKey,
wallet.publicKey,
0,
ticketMint
)
console.log("minted tickets");
}catch{
console.log(`tickets are already minted mint:${ticketMint.publicKey}`)
}
})
it("Is initialized!", async () => {
// Add your test here.
console.log(`Initializing ${program.programId.toBase58()}`);
const tx = await program.methods.initialize().accounts({mint:ticketMint.publicKey}).rpc()
console.log("Your transaction signature", tx);
const [sellerAccountAddress] = PublicKey.findProgramAddressSync([Buffer.from("sales"), wallet.publicKey.toBuffer()], programID);
const sellerAccount = await program.account.sales.fetch(sellerAccountAddress);
console.log(sellerAccount);
expect(sellerAccount.owner).equal(wallet.publicKey);
});
});