create-pool.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import * as anchor from "@coral-xyz/anchor";
  2. import { Program } from "@coral-xyz/anchor";
  3. import { PublicKey } from "@solana/web3.js";
  4. import { SwapExample } from "../target/types/swap_example";
  5. import { 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
  15. .createAmm(values.id, values.fee)
  16. .accounts({ amm: values.ammKey, admin: values.admin.publicKey })
  17. .rpc();
  18. await mintingTokens({
  19. connection,
  20. creator: values.admin,
  21. mintAKeypair: values.mintAKeypair,
  22. mintBKeypair: values.mintBKeypair,
  23. });
  24. });
  25. it("Creation", async () => {
  26. await program.methods
  27. .createPool()
  28. .accounts({
  29. amm: values.ammKey,
  30. pool: values.poolKey,
  31. poolAuthority: values.poolAuthority,
  32. mintLiquidity: values.mintLiquidity,
  33. mintA: values.mintAKeypair.publicKey,
  34. mintB: values.mintBKeypair.publicKey,
  35. poolAccountA: values.poolAccountA,
  36. poolAccountB: values.poolAccountB,
  37. })
  38. .rpc({ skipPreflight: true });
  39. });
  40. it("Invalid mints", async () => {
  41. values = createValues({
  42. mintBKeypair: values.mintAKeypair,
  43. poolKey: PublicKey.findProgramAddressSync(
  44. [
  45. values.id.toBuffer(),
  46. values.mintAKeypair.publicKey.toBuffer(),
  47. values.mintBKeypair.publicKey.toBuffer(),
  48. ],
  49. program.programId
  50. )[0],
  51. poolAuthority: PublicKey.findProgramAddressSync(
  52. [
  53. values.id.toBuffer(),
  54. values.mintAKeypair.publicKey.toBuffer(),
  55. values.mintBKeypair.publicKey.toBuffer(),
  56. Buffer.from("authority"),
  57. ],
  58. program.programId
  59. )[0],
  60. });
  61. await expectRevert(
  62. program.methods
  63. .createPool()
  64. .accounts({
  65. amm: values.ammKey,
  66. pool: values.poolKey,
  67. poolAuthority: values.poolAuthority,
  68. mintLiquidity: values.mintLiquidity,
  69. mintA: values.mintAKeypair.publicKey,
  70. mintB: values.mintBKeypair.publicKey,
  71. poolAccountA: values.poolAccountA,
  72. poolAccountB: values.poolAccountB,
  73. })
  74. .rpc()
  75. );
  76. });
  77. });