-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgateCheck.ts
104 lines (91 loc) · 2.97 KB
/
gateCheck.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import * as anchor from '@coral-xyz/anchor';
import { Program, BN } from '@coral-xyz/anchor';
import { Keypair, LAMPORTS_PER_SOL, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
MINT_SIZE,
TOKEN_PROGRAM_ID,
createAssociatedTokenAccountIdempotentInstruction,
createInitializeMint2Instruction,
createMintToInstruction,
getAssociatedTokenAddressSync,
getMinimumBalanceForRentExemptMint
} from '@solana/spl-token';
import { GateChecker } from './target/types/gate_checker';
describe('gateCheck', () => {
anchor.setProvider(anchor.AnchorProvider.env());
const provider = anchor.getProvider();
const connection = provider.connection;
const program = anchor.workspace.GateChecker as Program<GateChecker>;
const confirm = async (signature: string): Promise<string> => {
const block = await connection.getLatestBlockhash();
await connection.confirmTransaction({
signature,
...block
});
return signature;
};
const log = async (signature: string): Promise<string> => {
console.log(
`Your transaction signature: https://explorer.solana.com/transaction/${signature}?cluster=custom&customUrl=${connection.rpcEndpoint}`
);
return signature;
};
// Accounts
const main_wallet = Keypair.generate();
const nft = Keypair.generate();
const accountsPublicKeys = {
main_wallet: main_wallet.publicKey,
nft: nft.publicKey,
associatedTokenprogram: ASSOCIATED_TOKEN_PROGRAM_ID,
tokenProgram: TOKEN_PROGRAM_ID,
systemProgram: SystemProgram.programId
};
it('setup', async () => {
let lamports = await getMinimumBalanceForRentExemptMint(connection);
let tx = new Transaction();
tx.instructions = [
SystemProgram.transfer({
fromPubkey: provider.publicKey,
toPubkey: main_wallet.publicKey,
lamports: 10 * LAMPORTS_PER_SOL
}),
SystemProgram.createAccount({
fromPubkey: provider.publicKey,
newAccountPubkey: nft.publicKey,
lamports,
space: MINT_SIZE,
programId: TOKEN_PROGRAM_ID
})
];
await provider.sendAndConfirm(tx, [nft, main_wallet]).then(log);
});
it('Nfttest', async () => {
const accounts = {
associatedTokenAccount: accountsPublicKeys['nft'],
associatedTokenProgram: accountsPublicKeys['associated_token_program'],
mint: accountsPublicKeys['nft'],
rent: accountsPublicKeys['main_wallet'],
signer: accountsPublicKeys['main_wallet'],
systemProgram: accountsPublicKeys['system_program'],
tokenProgram: accountsPublicKeys['token_program']
};
await program.methods
.initNft()
.accounts({ ...accounts })
.signers([signer, mint])
.rpc()
.then(confirm)
.then(log);
});
it('first', async () => {
const accounts = {};
await program.methods
.initNft()
.accounts({ ...accounts })
.signers([signer, mint])
.rpc()
.then(confirm)
.then(log);
});
});