create-pool.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 type { SwapExample } from '../target/types/swap_example';
  5. import { type TestValues, createValues, expectRevert, mintingTokens } from './utils';
  6. describe('Create pool', () => {
  7. const provider = anchor.AnchorProvider.env();
  8. const connection = provider.connection;
  9. anchor.setProvider(provider);
  10. const program = anchor.workspace.SwapExample as Program<SwapExample>;
  11. let values: TestValues;
  12. beforeEach(async () => {
  13. values = createValues();
  14. await program.methods.createAmm(values.id, values.fee).accounts({ amm: values.ammKey, admin: values.admin.publicKey }).rpc();
  15. await mintingTokens({
  16. connection,
  17. creator: values.admin,
  18. mintAKeypair: values.mintAKeypair,
  19. mintBKeypair: values.mintBKeypair,
  20. });
  21. });
  22. it('Creation', async () => {
  23. await program.methods
  24. .createPool()
  25. .accounts({
  26. amm: values.ammKey,
  27. pool: values.poolKey,
  28. poolAuthority: values.poolAuthority,
  29. mintLiquidity: values.mintLiquidity,
  30. mintA: values.mintAKeypair.publicKey,
  31. mintB: values.mintBKeypair.publicKey,
  32. poolAccountA: values.poolAccountA,
  33. poolAccountB: values.poolAccountB,
  34. })
  35. .rpc({ skipPreflight: true });
  36. });
  37. it('Invalid mints', async () => {
  38. values = createValues({
  39. mintBKeypair: values.mintAKeypair,
  40. poolKey: PublicKey.findProgramAddressSync(
  41. [values.id.toBuffer(), values.mintAKeypair.publicKey.toBuffer(), values.mintBKeypair.publicKey.toBuffer()],
  42. program.programId,
  43. )[0],
  44. poolAuthority: PublicKey.findProgramAddressSync(
  45. [values.id.toBuffer(), values.mintAKeypair.publicKey.toBuffer(), values.mintBKeypair.publicKey.toBuffer(), Buffer.from('authority')],
  46. program.programId,
  47. )[0],
  48. });
  49. await expectRevert(
  50. program.methods
  51. .createPool()
  52. .accounts({
  53. amm: values.ammKey,
  54. pool: values.poolKey,
  55. poolAuthority: values.poolAuthority,
  56. mintLiquidity: values.mintLiquidity,
  57. mintA: values.mintAKeypair.publicKey,
  58. mintB: values.mintBKeypair.publicKey,
  59. poolAccountA: values.poolAccountA,
  60. poolAccountB: values.poolAccountB,
  61. })
  62. .rpc(),
  63. );
  64. });
  65. });