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
2 people authored and ngundotra committed Sep 8, 2022
1 parent 75daa55 commit f178b3c
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions contracts/tests/gummyroll-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ import {
getMerkleRollAccountSize,
createVerifyLeafIx,
assertOnChainMerkleRollProperties,
createAllocTreeIx,
} from "../sdk/gummyroll";
import { execute, logTx } from "./utils";
import NodeWallet from "@project-serum/anchor/dist/cjs/nodewallet";
import { CANDY_WRAPPER_PROGRAM_ID } from "../sdk/utils";

// @ts-ignore
let Gummyroll;
Expand Down Expand Up @@ -60,27 +63,20 @@ describe("gummyroll", () => {
}
const merkleRollKeypair = Keypair.generate();

const requiredSpace = getMerkleRollAccountSize(
maxDepth,
maxSize,
canopyDepth
);
const leaves = Array(2 ** maxDepth).fill(Buffer.alloc(32));
for (let i = 0; i < numLeaves; i++) {
leaves[i] = crypto.randomBytes(32);
}
const tree = buildTree(leaves);

const allocAccountIx = SystemProgram.createAccount({
fromPubkey: payer.publicKey,
newAccountPubkey: merkleRollKeypair.publicKey,
lamports:
await Gummyroll.provider.connection.getMinimumBalanceForRentExemption(
requiredSpace
),
space: requiredSpace,
programId: Gummyroll.programId,
});
const allocAccountIx = await createAllocTreeIx(
Gummyroll.provider.connection,
maxSize,
maxDepth,
canopyDepth,
payer.publicKey,
merkleRollKeypair.publicKey,
);

let tx = new Transaction().add(allocAccountIx);
if (numLeaves > 0) {
Expand Down Expand Up @@ -108,6 +104,7 @@ describe("gummyroll", () => {
merkleRoll: merkleRollKeypair.publicKey,
authority: payer.publicKey,
appendAuthority: payer.publicKey,
candyWrapper: CANDY_WRAPPER_PROGRAM_ID,
},
signers: [payer],
remainingAccounts: proof,
Expand All @@ -121,6 +118,7 @@ describe("gummyroll", () => {
merkleRoll: merkleRollKeypair.publicKey,
authority: payer.publicKey,
appendAuthority: payer.publicKey,
candyWrapper: CANDY_WRAPPER_PROGRAM_ID,
},
signers: [payer],
})
Expand Down Expand Up @@ -260,7 +258,7 @@ describe("gummyroll", () => {
try {
await execute(Gummyroll.provider, [verifyLeafIx], [payer]);
assert(false, "Proof should have failed to verify");
} catch {}
} catch { }

// Replace instruction with same proof fails
const replaceLeafIx = createReplaceIx(
Expand All @@ -276,7 +274,7 @@ describe("gummyroll", () => {
try {
await execute(Gummyroll.provider, [replaceLeafIx], [payer]);
assert(false, "Replace should have failed to verify");
} catch {}
} catch { }
const merkleRollAccount =
await Gummyroll.provider.connection.getAccountInfo(
merkleRollKeypair.publicKey
Expand Down Expand Up @@ -308,7 +306,7 @@ describe("gummyroll", () => {
})
);
assert(
replaceLeafIx.keys.length == 2 + MAX_DEPTH,
replaceLeafIx.keys.length == 3 + MAX_DEPTH,
`Failed to create proof for ${MAX_DEPTH}`
);

Expand Down Expand Up @@ -348,7 +346,7 @@ describe("gummyroll", () => {
})
);
assert(
replaceLeafIx.keys.length == 2 + 1,
replaceLeafIx.keys.length == 3 + 1,
"Failed to minimize proof to expected size of 1"
);
await execute(Gummyroll.provider, [replaceLeafIx], [payer]);
Expand Down Expand Up @@ -403,7 +401,7 @@ describe("gummyroll", () => {
false,
"Transaction should have failed, since `randomSigner` is not append authority"
);
} catch {}
} catch { }
});
it("But authority can transfer appendAuthority", async () => {
const transferAppendAuthorityIx = createTransferAuthorityIx(
Expand Down Expand Up @@ -486,7 +484,7 @@ describe("gummyroll", () => {
false,
"Transaction should have failed since the append authority cannot act as the authority for replaces"
);
} catch {}
} catch { }
});
});
describe("Examples transferring authority", () => {
Expand Down Expand Up @@ -530,7 +528,7 @@ describe("gummyroll", () => {
false,
"Transaction should have failed since incorrect authority cannot execute replaces"
);
} catch {}
} catch { }
});
it("Can transfer authority", async () => {
const transferAppendAuthorityIx = createTransferAuthorityIx(
Expand Down Expand Up @@ -587,7 +585,7 @@ describe("gummyroll", () => {
false,
"Transaction should have failed since incorrect authority cannot execute replaces"
);
} catch {}
} catch { }
});
});
});
Expand Down Expand Up @@ -731,7 +729,7 @@ describe("gummyroll", () => {
false,
"Attacker was able to succesfully write fake existence of a leaf"
);
} catch (e) {}
} catch (e) { }

const merkleRoll = decodeMerkleRoll(
(
Expand Down Expand Up @@ -772,7 +770,7 @@ describe("gummyroll", () => {
false,
"Attacker was able to succesfully write fake existence of a leaf"
);
} catch (e) {}
} catch (e) { }

const merkleRoll = decodeMerkleRoll(
(
Expand Down Expand Up @@ -801,7 +799,7 @@ describe("gummyroll", () => {

let leaves = [];
let i = 0;
let stepSize = 8;
let stepSize = 4;
while (i < 2 ** DEPTH) {
let ixs = [];
for (let j = 0; j < stepSize; ++j) {
Expand Down

0 comments on commit f178b3c

Please sign in to comment.