tests.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import * as anchor from '@coral-xyz/anchor';
  2. import { PROGRAM_ID as BUBBLEGUM_PROGRAM_ID } from '@metaplex-foundation/mpl-bubblegum/dist/src/generated';
  3. import { SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, SPL_NOOP_PROGRAM_ID } from '@solana/spl-account-compression';
  4. import type { Cutils } from '../target/types/cutils';
  5. import { loadOrGenerateKeypair, loadPublicKeysFromFile } from './utils/helpers';
  6. import { getAsset, getAssetProof } from './utils/readAPI';
  7. import { decode, getAccounts, mapProof } from './utils/utils';
  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
  21. .mint({ uri })
  22. .accounts({
  23. payer: payer.publicKey,
  24. leafOwner: testWallet.publicKey,
  25. leafDelegate: testWallet.publicKey, //verify
  26. treeDelegate: payer.publicKey,
  27. collectionAuthority: payer.publicKey,
  28. collectionAuthorityRecordPda: BUBBLEGUM_PROGRAM_ID,
  29. ...getAccounts(collectionMint, treeAddress),
  30. })
  31. .transaction();
  32. const sx = await program.provider.sendAndConfirm(tx, [payer], {
  33. skipPreflight: true,
  34. });
  35. console.log(` Tx Signature: ${sx}`);
  36. });
  37. // it("Verify", async () => {
  38. // // TODO: replace assetId
  39. // const assetId = "HUBMRAcYpow1ZUojdSMuvhcbNuCuRSAPWnXWjjYrpAVQ";
  40. //
  41. // const asset = await getAsset(assetId);
  42. // const proof = await getAssetProof(assetId);
  43. // const proofPathAsAccounts = mapProof(proof);
  44. // const root = decode(proof.root);
  45. // const dataHash = decode(asset.compression.data_hash);
  46. // const creatorHash = decode(asset.compression.creator_hash);
  47. // const nonce = new anchor.BN(asset.compression.leaf_id);
  48. // const index = asset.compression.leaf_id;
  49. //
  50. // const tx = await program.methods
  51. // .verify({
  52. // root, dataHash, creatorHash, nonce, index
  53. // })
  54. // .accounts({
  55. // leafOwner: testWallet.publicKey,
  56. // leafDelegate: testWallet.publicKey,
  57. // merkleTree: treeAddress,
  58. // compressionProgram: SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
  59. // })
  60. // .remainingAccounts(proofPathAsAccounts)
  61. // .transaction();
  62. //
  63. // const sx = await program.provider.sendAndConfirm(tx, [testWallet], {skipPreflight: true});
  64. //
  65. // // This fails due to incorrect owner
  66. // // const sx = await program.provider.sendAndConfirm(tx, [payer], {skipPreflight: true});
  67. //
  68. // console.log(` Tx Signature: ${sx}`);
  69. // });
  70. });