Skip to content

Commit

Permalink
add tests for zero-length proof ixs
Browse files Browse the repository at this point in the history
  • Loading branch information
ngundotra committed Nov 15, 2023
1 parent 4a24df5 commit 7fa414b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions account-compression/sdk/tests/accountCompression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,40 @@ describe('Account Compression', () => {
await execute(provider, [replaceIx, replaceBackIx], [payerKeypair], true, true);
}
});
it('Zero length verifications and transfers work', async () => {
[cmtKeypair, offChainTree] = await createTreeOnChain(
provider,
payerKeypair,
2 ** DEPTH,
{ maxBufferSize: 8, maxDepth: DEPTH },
DEPTH // Store full tree on chain
);
cmt = cmtKeypair.publicKey;

for (let i = 0; i < 2 ** DEPTH; i += 1) {
const proof = offChainTree.getProof(i);
const verifyIx = createVerifyLeafIx(cmt, {
...proof,
proof: [],
});
await execute(provider, [verifyIx], [payerKeypair], true, false);

const newLeaf = crypto.randomBytes(32);
// Create an instruction to replace the leaf
const replaceIx = createReplaceIx(cmt, payer, newLeaf, {
...proof,
proof: [],
});
offChainTree.updateLeaf(i, newLeaf);

await execute(provider, [replaceIx], [payerKeypair], true, false);

const splCMT = await ConcurrentMerkleTreeAccount.fromAccountAddress(connection, cmt, {
commitment: 'confirmed',
});
assert(splCMT.getCurrentRoot().equals(Buffer.from(offChainTree.root)), 'Roots do not match');
}
});
});
describe(`Having created a tree with 8 leaves`, () => {
beforeEach(async () => {
Expand Down

0 comments on commit 7fa414b

Please sign in to comment.