tests.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import * as anchor from "@coral-xyz/anchor";
  2. import {decode, getAccounts, mapProof} from "./utils/utils";
  3. import {SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, SPL_NOOP_PROGRAM_ID} from "@solana/spl-account-compression";
  4. import {getAsset, getAssetProof} from "./utils/readAPI";
  5. import {Cutils} from "../target/types/cutils";
  6. import {loadOrGenerateKeypair, loadPublicKeysFromFile} from "./utils/helpers";
  7. import { PROGRAM_ID as BUBBLEGUM_PROGRAM_ID } from "@metaplex-foundation/mpl-bubblegum/dist/src/generated";
  8. describe("cutils", () => {
  9. const provider = anchor.AnchorProvider.env();
  10. anchor.setProvider(provider);
  11. const program = anchor.workspace.Cutils as anchor.Program<Cutils>;
  12. // NFT metadata pointer
  13. // TODO change
  14. const uri = "https://arweave.net/nVRvZDaOk5YAdr4ZBEeMjOVhynuv8P3vywvuN5sYSPo"
  15. const payer = loadOrGenerateKeypair("payer");
  16. // cNFT receiver
  17. const testWallet = loadOrGenerateKeypair("testWallet")
  18. const {collectionMint, treeAddress} = loadPublicKeysFromFile()
  19. it("Mint!", async () => {
  20. const tx = await program.methods.mint({uri})
  21. .accounts({
  22. payer: payer.publicKey,
  23. leafOwner: testWallet.publicKey,
  24. leafDelegate: testWallet.publicKey, //verify
  25. treeDelegate: payer.publicKey,
  26. collectionAuthority: payer.publicKey,
  27. collectionAuthorityRecordPda: BUBBLEGUM_PROGRAM_ID,
  28. ...getAccounts(collectionMint, treeAddress)
  29. })
  30. .transaction()
  31. const sx = await program.provider.sendAndConfirm(tx, [payer], {skipPreflight: true});
  32. console.log(` Tx Signature: ${sx}`);
  33. });
  34. // it("Verify", async () => {
  35. // // TODO: replace assetId
  36. // const assetId = "HUBMRAcYpow1ZUojdSMuvhcbNuCuRSAPWnXWjjYrpAVQ";
  37. //
  38. // const asset = await getAsset(assetId);
  39. // const proof = await getAssetProof(assetId);
  40. // const proofPathAsAccounts = mapProof(proof);
  41. // const root = decode(proof.root);
  42. // const dataHash = decode(asset.compression.data_hash);
  43. // const creatorHash = decode(asset.compression.creator_hash);
  44. // const nonce = new anchor.BN(asset.compression.leaf_id);
  45. // const index = asset.compression.leaf_id;
  46. //
  47. // const tx = await program.methods
  48. // .verify({
  49. // root, dataHash, creatorHash, nonce, index
  50. // })
  51. // .accounts({
  52. // leafOwner: testWallet.publicKey,
  53. // leafDelegate: testWallet.publicKey,
  54. // merkleTree: treeAddress,
  55. // compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
  56. // })
  57. // .remainingAccounts(proofPathAsAccounts)
  58. // .transaction();
  59. //
  60. // const sx = await program.provider.sendAndConfirm(tx, [testWallet], {skipPreflight: true});
  61. //
  62. // // This fails due to incorrect owner
  63. // // const sx = await program.provider.sendAndConfirm(tx, [payer], {skipPreflight: true});
  64. //
  65. // console.log(` Tx Signature: ${sx}`);
  66. // });
  67. });