diff --git a/contracts/tests/bubblegum-test.ts b/contracts/tests/bubblegum-test.ts index 9c61de42cc1..a001e5ab496 100644 --- a/contracts/tests/bubblegum-test.ts +++ b/contracts/tests/bubblegum-test.ts @@ -1,9 +1,9 @@ import * as anchor from "@project-serum/anchor"; -import {keccak_256} from "js-sha3"; -import {BN, Provider, Program} from "@project-serum/anchor"; -import {Bubblegum} from "../target/types/bubblegum"; -import {Gummyroll} from "../target/types/gummyroll"; -import {PROGRAM_ID} from "@metaplex-foundation/mpl-token-metadata"; +import { keccak_256 } from "js-sha3"; +import { BN, Provider, Program } from "@project-serum/anchor"; +import { Bubblegum } from "../target/types/bubblegum"; +import { Gummyroll } from "../target/types/gummyroll"; +import { PROGRAM_ID } from "@metaplex-foundation/mpl-token-metadata"; import { PublicKey, Keypair, @@ -12,7 +12,7 @@ import { Connection as web3Connection, SYSVAR_RENT_PUBKEY, } from "@solana/web3.js"; -import {assert} from "chai"; +import { assert } from "chai"; import { createMintV1Instruction, createDecompressV1Instruction, @@ -20,16 +20,17 @@ import { createDelegateInstruction, createRedeemInstruction, createCancelRedeemInstruction, - createCreateTreeInstruction + createCreateTreeInstruction, } from "../sdk/bubblegum/src/generated"; -import {buildTree, Tree} from "./merkle-tree"; +import { buildTree, Tree } from "./merkle-tree"; import { decodeMerkleRoll, getMerkleRollAccountSize, getRootOfOnChainMerkleRoot, assertOnChainMerkleRollProperties, createTransferAuthorityIx, + createAllocTreeIx, } from "../sdk/gummyroll"; import NodeWallet from "@project-serum/anchor/dist/cjs/nodewallet"; import { @@ -39,6 +40,8 @@ import { } from "@solana/spl-token"; import { execute, logTx, bufferToArray } from "./utils"; import { TokenProgramVersion, Version } from "../sdk/bubblegum/src/generated"; +import { CANDY_WRAPPER_PROGRAM_ID } from "../sdk/utils"; +import { getBubblegumAuthorityPDA, getCreateTreeIxs, getNonceCount, getVoucherPDA } from "../sdk/bubblegum/src/convenience"; // @ts-ignore let Bubblegum; @@ -95,46 +98,20 @@ describe("bubblegum", () => { ), "confirmed" ); - const requiredSpace = getMerkleRollAccountSize(MAX_DEPTH, MAX_SIZE); const leaves = Array(2 ** MAX_DEPTH).fill(Buffer.alloc(32)); const tree = buildTree(leaves); - const allocAccountIx = SystemProgram.createAccount({ - fromPubkey: payer.publicKey, - newAccountPubkey: merkleRollKeypair.publicKey, - lamports: - await Bubblegum.provider.connection.getMinimumBalanceForRentExemption( - requiredSpace - ), - space: requiredSpace, - programId: GummyrollProgramId, + let tx = new Transaction(); + const ixs = await getCreateTreeIxs(connection, MAX_DEPTH, MAX_SIZE, 0, payer.publicKey, merkleRollKeypair.publicKey, payer.publicKey); + ixs.map((ix) => { + tx.add(ix); }); - let [authority] = await PublicKey.findProgramAddress( - [merkleRollKeypair.publicKey.toBuffer()], - Bubblegum.programId - ); - - const initGummyrollIx = createCreateTreeInstruction( - { - treeCreator: payer.publicKey, - payer: payer.publicKey, - authority: authority, - gummyrollProgram: GummyrollProgramId, - merkleSlab: merkleRollKeypair.publicKey - }, - { - maxDepth: MAX_DEPTH, - maxBufferSize: MAX_SIZE - } - ); - - let tx = new Transaction().add(allocAccountIx).add(initGummyrollIx); - await Bubblegum.provider.send(tx, [payer, merkleRollKeypair], { commitment: "confirmed", }); + const authority = await getBubblegumAuthorityPDA(merkleRollKeypair.publicKey); await assertOnChainMerkleRollProperties( Bubblegum.provider.connection, MAX_DEPTH, @@ -174,12 +151,13 @@ describe("bubblegum", () => { { mintAuthority: payer.publicKey, authority: treeAuthority, + candyWrapper: CANDY_WRAPPER_PROGRAM_ID, gummyrollProgram: GummyrollProgramId, owner: payer.publicKey, delegate: payer.publicKey, merkleSlab: merkleRollKeypair.publicKey, }, - {message: metadata} + { message: metadata } ); console.log(" - Minting to tree"); const mintTx = await Bubblegum.provider.send( @@ -195,20 +173,17 @@ describe("bubblegum", () => { ); const creatorHash = bufferToArray(Buffer.from(keccak_256.digest([]))); let onChainRoot = await getRootOfOnChainMerkleRoot(connection, merkleRollKeypair.publicKey); - - console.log(" - Transferring Ownership"); - const nonceInfo = await ( - Bubblegum.provider.connection as web3Connection - ).getAccountInfo(treeAuthority); - const leafNonce = new BN(nonceInfo.data.slice(8, 16), "le").sub( - new BN(1) - ); + + console.log(" - Transferring Ownership"); + const nonceCount = await getNonceCount(Bubblegum.provider.connection, merkleRollKeypair.publicKey); + const leafNonce = nonceCount.sub(new BN(1)); let transferIx = createTransferInstruction( { authority: treeAuthority, owner: payer.publicKey, delegate: payer.publicKey, newOwner: destination.publicKey, + candyWrapper: CANDY_WRAPPER_PROGRAM_ID, gummyrollProgram: GummyrollProgramId, merkleSlab: merkleRollKeypair.publicKey, }, @@ -231,6 +206,7 @@ describe("bubblegum", () => { owner: destination.publicKey, previousDelegate: destination.publicKey, newDelegate: delegateKey.publicKey, + candyWrapper: CANDY_WRAPPER_PROGRAM_ID, gummyrollProgram: GummyrollProgramId, merkleSlab: merkleRollKeypair.publicKey, }, @@ -253,6 +229,7 @@ describe("bubblegum", () => { owner: destination.publicKey, delegate: delegateKey.publicKey, newOwner: payer.publicKey, + candyWrapper: CANDY_WRAPPER_PROGRAM_ID, gummyrollProgram: GummyrollProgramId, merkleSlab: merkleRollKeypair.publicKey, }, @@ -276,13 +253,10 @@ describe("bubblegum", () => { onChainRoot = await getRootOfOnChainMerkleRoot(connection, merkleRollKeypair.publicKey); - let [voucher] = await PublicKey.findProgramAddress( - [ - Buffer.from("voucher", "utf8"), - merkleRollKeypair.publicKey.toBuffer(), - new BN(0).toBuffer("le", 8) - ], - Bubblegum.programId + let voucher = await getVoucherPDA( + Bubblegum.provider.connection, + merkleRollKeypair.publicKey, + 0, ); console.log(" - Redeeming Leaf", voucher.toBase58()); @@ -291,6 +265,7 @@ describe("bubblegum", () => { authority: treeAuthority, owner: payer.publicKey, delegate: payer.publicKey, + candyWrapper: CANDY_WRAPPER_PROGRAM_ID, gummyrollProgram: GummyrollProgramId, merkleSlab: merkleRollKeypair.publicKey, voucher: voucher, @@ -317,6 +292,7 @@ describe("bubblegum", () => { { authority: treeAuthority, owner: payer.publicKey, + candyWrapper: CANDY_WRAPPER_PROGRAM_ID, gummyrollProgram: GummyrollProgramId, merkleSlab: merkleRollKeypair.publicKey, voucher: voucher, @@ -340,6 +316,7 @@ describe("bubblegum", () => { authority: treeAuthority, owner: payer.publicKey, delegate: payer.publicKey, + candyWrapper: CANDY_WRAPPER_PROGRAM_ID, gummyrollProgram: GummyrollProgramId, merkleSlab: merkleRollKeypair.publicKey, voucher: voucher, @@ -363,7 +340,11 @@ describe("bubblegum", () => { let voucherData = await Bubblegum.account.voucher.fetch(voucher); let [asset] = await PublicKey.findProgramAddress( - [Buffer.from("asset"), merkleRollKeypair.publicKey.toBuffer(), leafNonce.toBuffer("le", 8)], + [ + Buffer.from("asset"), + merkleRollKeypair.publicKey.toBuffer(), + leafNonce.toBuffer("le", 8), + ], Bubblegum.programId );