Skip to content

Commit

Permalink
Merge pull request solana-labs#100 from jarry-xiao/gummyshop
Browse files Browse the repository at this point in the history
Sugar Shack Contract, Test + SDK
  • Loading branch information
samwise2 authored Jun 27, 2022
2 parents 51640c5 + cfaa84a commit 5d917c6
Showing 1 changed file with 9 additions and 38 deletions.
47 changes: 9 additions & 38 deletions contracts/tests/bubblegum-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {buildTree, Tree} from "./merkle-tree";
import {
decodeMerkleRoll,
getMerkleRollAccountSize,
getRootOfOnChainMerkleRoot,
assertOnChainMerkleRollProperties,
createTransferAuthorityIx,
} from "../sdk/gummyroll";
Expand All @@ -36,23 +37,14 @@ import {
TOKEN_PROGRAM_ID,
Token,
} from "@solana/spl-token";
import {execute, logTx} from "./utils";
import {TokenProgramVersion, Version} from "../sdk/bubblegum/src/generated";
import { execute, logTx, bufferToArray } from "./utils";
import { TokenProgramVersion, Version } from "../sdk/bubblegum/src/generated";

// @ts-ignore
let Bubblegum;
// @ts-ignore
let GummyrollProgramId;

/// Converts to Uint8Array
function bufferToArray(buffer: Buffer): number[] {
const nums = [];
for (let i = 0; i < buffer.length; i++) {
nums.push(buffer.at(i));
}
return nums;
}

describe("bubblegum", () => {
// Configure the client to use the local cluster.
let offChainTree: Tree;
Expand Down Expand Up @@ -202,15 +194,9 @@ describe("bubblegum", () => {
Buffer.from(keccak_256.digest(mintIx.data.slice(8)))
);
const creatorHash = bufferToArray(Buffer.from(keccak_256.digest([])));
let merkleRollAccount =
await Bubblegum.provider.connection.getAccountInfo(
merkleRollKeypair.publicKey
);
let merkleRoll = decodeMerkleRoll(merkleRollAccount.data);
let onChainRoot =
merkleRoll.roll.changeLogs[merkleRoll.roll.activeIndex].root.toBuffer();

console.log(" - Transferring Ownership");
let onChainRoot = await getRootOfOnChainMerkleRoot(connection, merkleRollKeypair.publicKey);

console.log(" - Transferring Ownership");
const nonceInfo = await (
Bubblegum.provider.connection as web3Connection
).getAccountInfo(treeAuthority);
Expand All @@ -236,12 +222,7 @@ describe("bubblegum", () => {
);
await execute(Bubblegum.provider, [transferIx], [payer]);

merkleRollAccount = await Bubblegum.provider.connection.getAccountInfo(
merkleRollKeypair.publicKey
);
merkleRoll = decodeMerkleRoll(merkleRollAccount.data);
onChainRoot =
merkleRoll.roll.changeLogs[merkleRoll.roll.activeIndex].root.toBuffer();
onChainRoot = await getRootOfOnChainMerkleRoot(connection, merkleRollKeypair.publicKey);

console.log(" - Delegating Ownership");
let delegateIx = await createDelegateInstruction(
Expand All @@ -263,12 +244,7 @@ describe("bubblegum", () => {
);
await execute(Bubblegum.provider, [delegateIx], [destination]);

merkleRollAccount = await Bubblegum.provider.connection.getAccountInfo(
merkleRollKeypair.publicKey
);
merkleRoll = decodeMerkleRoll(merkleRollAccount.data);
onChainRoot =
merkleRoll.roll.changeLogs[merkleRoll.roll.activeIndex].root.toBuffer();
onChainRoot = await getRootOfOnChainMerkleRoot(connection, merkleRollKeypair.publicKey);

console.log(" - Transferring Ownership (through delegate)");
let delTransferIx = createTransferInstruction(
Expand Down Expand Up @@ -298,12 +274,7 @@ describe("bubblegum", () => {
}
);

merkleRollAccount = await Bubblegum.provider.connection.getAccountInfo(
merkleRollKeypair.publicKey
);
merkleRoll = decodeMerkleRoll(merkleRollAccount.data);
onChainRoot =
merkleRoll.roll.changeLogs[merkleRoll.roll.activeIndex].root.toBuffer();
onChainRoot = await getRootOfOnChainMerkleRoot(connection, merkleRollKeypair.publicKey);

let [voucher] = await PublicKey.findProgramAddress(
[
Expand Down

0 comments on commit 5d917c6

Please sign in to comment.