Skip to content

Commit

Permalink
fix nits
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Gundotra committed Jun 2, 2022
1 parent a2d90a4 commit 2be0bf7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
37 changes: 9 additions & 28 deletions contracts/tests/gumdrop-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,8 @@ import NodeWallet from '@project-serum/anchor/dist/cjs/nodewallet';
import { Gumdrop } from "../target/types/gumdrop";
import { MerkleTree } from './gumdropTree';
import { BinaryWriter } from 'borsh'

async function delay(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

async function succeedOrThrow(txId: string, connection: Connection) {
const err = (await connection.confirmTransaction(txId, "confirmed")).value.err
if (err) {
throw new Error(`${txId} failed: \n${JSON.stringify(err)}\n`);
}
}


function getMerkleRollAccountSize(maxDepth: number, maxBufferSize: number): number {
let headerSize = 8 + 32 + 32;
let changeLogSize = (maxDepth * 32 + 32 + 4 + 4) * maxBufferSize;
let rightMostPathSize = maxDepth * 32 + 32 + 4 + 4;
let merkleRollSize = 8 + 8 + 16 + changeLogSize + rightMostPathSize;
return merkleRollSize + headerSize;
}
import { getMerkleRollAccountSize } from './merkle-roll-serde';
import { succeedOrThrow } from './utils';

async function initMerkleTreeInstruction(
maxDepth: number,
Expand Down Expand Up @@ -76,15 +58,15 @@ async function getBubblegumTreeAuthority(tree: PublicKey, bubblegumProgramId: Pu
}

type GumdropLeaf = {
metadata: Metadata,
metadata: TokenMetadata,
publicKey: PublicKey,
};

type Creator = {
creator: PublicKey,
share: number,
};
type Metadata = {
type TokenMetadata = {
name: string,
symbol: string,
uri: string,
Expand All @@ -101,7 +83,7 @@ type Metadata = {
creators: Creator[],
};

const METADATA = [
const TOKEN_METADATA = [
{
name: "A",
symbol: "A",
Expand Down Expand Up @@ -184,7 +166,7 @@ const METADATA = [
},
];

function serializeMetadata(metadata: Metadata): Buffer {
function serializeMetadata(metadata: TokenMetadata): Buffer {
let writer = new BinaryWriter();
writer.writeString(metadata.name)
writer.writeString(metadata.symbol)
Expand Down Expand Up @@ -223,7 +205,7 @@ function hashLeaf(leaf: GumdropLeaf, index: number, bubblegumTree: PublicKey): B

function buildGumdropTree(bubblegumTree: PublicKey, claimer: PublicKey): MerkleTree {
let leaves: Buffer[] = [];
METADATA.forEach((metadata, index) => {
TOKEN_METADATA.forEach((metadata, index) => {
leaves.push(hashLeaf({
metadata,
publicKey: claimer
Expand Down Expand Up @@ -328,14 +310,13 @@ describe('Airdropping compressed NFTs with Gumdrop', () => {
const txId = await gumdrop.provider.send(tx, [merkleRollKeypair, payer], {
skipPreflight: true
});
console.log(`${txId} sent`);
await succeedOrThrow(txId, connection);
console.log("Compressed tree init succeeded 😎");

// Get nonce key for all compressed NFTs
let index = 0;
while (index < METADATA.length) {
const nftMetadata = METADATA[index];
while (index < TOKEN_METADATA.length) {
const nftMetadata = TOKEN_METADATA[index];
const proof = gumdropTree.getProof(index);
console.log("\nVerified proof:", gumdropTree.verifyProof(index, proof, gumdropTree.getRoot()));
const leafHash = gumdropTree.layers[0][index].buffer;
Expand Down
1 change: 1 addition & 0 deletions contracts/tests/gumdropTree.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Stolen from https://github.com/metaplex-foundation/gumdrop/blob/main/packages/gumdrop/src/utils/merkleTree.ts
import { keccak_256 } from 'js-sha3';

export class MerkleTree {
Expand Down
9 changes: 8 additions & 1 deletion contracts/tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Connection } from '@solana/web3.js';
import { Provider } from "@project-serum/anchor";
import { TransactionInstruction, Transaction, Signer } from "@solana/web3.js";

Expand All @@ -11,7 +12,6 @@ export async function logTx(provider: Provider, txId: string, verbose: boolean =
}
};


export async function execute(
provider: Provider,
instructions: TransactionInstruction[],
Expand All @@ -27,3 +27,10 @@ export async function execute(
await logTx(provider, txid, false);
return txid;
}

export async function succeedOrThrow(txId: string, connection: Connection) {
const err = (await connection.confirmTransaction(txId, "confirmed")).value.err
if (err) {
throw new Error(`${txId} failed: \n${JSON.stringify(err)}\n`);
}
}

0 comments on commit 2be0bf7

Please sign in to comment.