Skip to content

Commit

Permalink
Jxiao/tree nonces (solana-labs#103)
Browse files Browse the repository at this point in the history
- Tree nonces V0 (better schema to come)
  • Loading branch information
jarry-xiao authored Jun 15, 2022
1 parent 4f8be68 commit 451bd35
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions contracts/tests/bubblegum-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,23 @@ describe("bubblegum", () => {
[merkleRollKeypair.publicKey.toBuffer()],
Bubblegum.programId
);
let [nonce] = await PublicKey.findProgramAddress(
[Buffer.from("bubblegum"), merkleRollKeypair.publicKey.toBuffer()],
Bubblegum.programId
);

const initGummyrollIx = Bubblegum.instruction.createTree(
MAX_DEPTH,
MAX_SIZE,
{
accounts: {
treeCreator: payer.publicKey,
payer: payer.publicKey,
nonce: nonce,
authority: authority,
gummyrollProgram: GummyrollProgramId,
merkleSlab: merkleRollKeypair.publicKey,
systemProgram: SystemProgram.programId,
},
signers: [payer],
}
Expand All @@ -143,29 +150,6 @@ describe("bubblegum", () => {
.add(allocAccountIx)
.add(initGummyrollIx);

let [nonce] = await PublicKey.findProgramAddress(
[Buffer.from("bubblegum")],
Bubblegum.programId
);
try {
const nonceAccount = await Bubblegum.provider.connection.getAccountInfo(
nonce
);
if (nonceAccount.data.length === 0 || nonceAccount.lamports === 0) {
throw new Error("Nonce account not yet initialized");
}
} catch {
// Only initialize the nonce if it does not exist
const initNonceIx = Bubblegum.instruction.initializeNonce({
accounts: {
nonce: nonce,
payer: payer.publicKey,
systemProgram: SystemProgram.programId,
},
signers: [payer],
});
tx = tx.add(initNonceIx);
}

await Bubblegum.provider.send(tx, [payer, merkleRollKeypair], {
commitment: "confirmed",
Expand Down

0 comments on commit 451bd35

Please sign in to comment.