Skip to content

Commit

Permalink
Jxiao/fix log truncation (solana-labs#121)
Browse files Browse the repository at this point in the history
* Initial implementation of log truncation fix

* Add new files

* refactor bubblegum pda

* amend me

* update basic ts sdk

* better bgum convenience

* addProof modifies instructions to add proof fluently

* better bg init

* fix rebase issues

* fix sugar shack tests

* use convenience initializer

* revert maxSeq change, update smokeTest

Co-authored-by: Noah Gundotra <noahgundotra@noahs-mbp.mynetworksettings.com>
  • Loading branch information
jarry-xiao and Noah Gundotra authored Jun 30, 2022
1 parent bec1760 commit 3dcb54f
Showing 1 changed file with 37 additions and 56 deletions.
93 changes: 37 additions & 56 deletions contracts/tests/bubblegum-test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -12,24 +12,25 @@ import {
Connection as web3Connection,
SYSVAR_RENT_PUBKEY,
} from "@solana/web3.js";
import {assert} from "chai";
import { assert } from "chai";
import {
createMintV1Instruction,
createDecompressV1Instruction,
createTransferInstruction,
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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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());
Expand All @@ -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,
Expand All @@ -317,6 +292,7 @@ describe("bubblegum", () => {
{
authority: treeAuthority,
owner: payer.publicKey,
candyWrapper: CANDY_WRAPPER_PROGRAM_ID,
gummyrollProgram: GummyrollProgramId,
merkleSlab: merkleRollKeypair.publicKey,
voucher: voucher,
Expand All @@ -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,
Expand All @@ -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
);

Expand Down

0 comments on commit 3dcb54f

Please sign in to comment.