create-pool.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import * as anchor from '@coral-xyz/anchor';
  2. import type { Program } from '@coral-xyz/anchor';
  3. import { PublicKey } from '@solana/web3.js';
  4. import { BankrunProvider } from 'anchor-bankrun';
  5. import { startAnchor } from 'solana-bankrun';
  6. import type { TokenSwap } from '../target/types/token_swap';
  7. import { type TestValues, createValues, expectRevert, mintingTokens } from './utils';
  8. const IDL = require('../target/idl/token_swap.json');
  9. const PROGRAM_ID = new PublicKey(IDL.address);
  10. describe('Create pool', async () => {
  11. const context = await startAnchor('', [{ name: 'token_swap', programId: PROGRAM_ID }], []);
  12. const provider = new BankrunProvider(context);
  13. const connection = provider.connection;
  14. const payer = provider.wallet as anchor.Wallet;
  15. const program = new anchor.Program<TokenSwap>(IDL, provider);
  16. let values: TestValues;
  17. beforeEach(async () => {
  18. values = createValues();
  19. const id = new anchor.BN(values.id);
  20. const fee = values.fee;
  21. await program.methods
  22. .createAmm(id, fee)
  23. .accounts({
  24. // admin: values.admin.publicKey
  25. })
  26. .rpc();
  27. await mintingTokens({
  28. connection,
  29. creator: values.admin,
  30. mintAKeypair: values.mintAKeypair,
  31. mintBKeypair: values.mintBKeypair,
  32. });
  33. });
  34. it('Creation', async () => {
  35. const id = new anchor.BN(values.id);
  36. await program.methods
  37. .createPool(id)
  38. .accounts({
  39. // amm: values.ammKey,
  40. // pool: values.poolKey,
  41. // poolAuthority: values.poolAuthority,
  42. // mintLiquidity: values.mintLiquidity,
  43. mintA: values.mintAKeypair.publicKey,
  44. mintB: values.mintBKeypair.publicKey,
  45. // poolAccountA: values.poolAccountA,
  46. // poolAccountB: values.poolAccountB,
  47. })
  48. .rpc({ skipPreflight: true });
  49. });
  50. it('Invalid mints', async () => {
  51. values = createValues({
  52. mintBKeypair: values.mintAKeypair,
  53. poolKey: PublicKey.findProgramAddressSync(
  54. [Buffer.alloc(values.id), values.mintAKeypair.publicKey.toBuffer(), values.mintBKeypair.publicKey.toBuffer()],
  55. program.programId,
  56. )[0],
  57. poolAuthority: PublicKey.findProgramAddressSync(
  58. [Buffer.alloc(values.id), values.mintAKeypair.publicKey.toBuffer(), values.mintBKeypair.publicKey.toBuffer(), Buffer.from('authority')],
  59. program.programId,
  60. )[0],
  61. });
  62. const id = new anchor.BN(values.id);
  63. await expectRevert(
  64. program.methods
  65. .createPool(id)
  66. .accounts({
  67. // amm: values.ammKey,
  68. // pool: values.poolKey,
  69. // poolAuthority: values.poolAuthority,
  70. // mintLiquidity: values.mintLiquidity,
  71. mintA: values.mintAKeypair.publicKey,
  72. mintB: values.mintBKeypair.publicKey,
  73. // poolAccountA: values.poolAccountA,
  74. // poolAccountB: values.poolAccountB,
  75. })
  76. .rpc(),
  77. );
  78. });
  79. });