Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit de9d4cf

Browse files
committed
adding more tests
1 parent 374f0e6 commit de9d4cf

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

account-compression/sdk/tests/accountCompression.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
createReplaceIx,
1818
createTransferAuthorityIx,
1919
createVerifyLeafIx,
20+
prepareTreeIx,
2021
ValidDepthSizePair,
2122
} from '../src';
2223
import { hash, MerkleTree } from '../src/merkle-tree';
@@ -708,6 +709,30 @@ describe('Account Compression', () => {
708709
'Updated on chain root matches root of updated off chain tree',
709710
);
710711
});
712+
713+
it('Should fail to prepare a batch ready tree for an existing tree', async () => {
714+
const prepareIx = prepareTreeIx(cmt, payer, DEPTH_SIZE_PAIR);
715+
try {
716+
await execute(provider, [prepareIx], [payerKeypair]);
717+
assert(false, 'Prepare a batch tree should have failed for the existing tree');
718+
} catch {}
719+
});
720+
721+
it('Should fail to finalize an existing tree', async () => {
722+
const index = offChainTree.leaves.length - 1;
723+
const finalizeIx = createFinalizeMerkleTreeWithRootIx(
724+
cmt,
725+
payer,
726+
offChainTree.root,
727+
offChainTree.leaves[index].node,
728+
index,
729+
offChainTree.getProof(index).proof,
730+
);
731+
try {
732+
await execute(provider, [finalizeIx], [payerKeypair]);
733+
assert(false, 'Finalize an existing tree should have failed');
734+
} catch {}
735+
});
711736
});
712737

713738
describe('Examples transferring authority', () => {
@@ -1022,6 +1047,22 @@ describe('Account Compression', () => {
10221047
await execute(provider, [replaceIx, replaceBackIx], [payerKeypair], true, true);
10231048
}
10241049
});
1050+
1051+
it('Should fail to append a canopy node for an existing tree', async () => {
1052+
[cmtKeypair, offChainTree] = await createTreeOnChain(
1053+
provider,
1054+
payerKeypair,
1055+
0,
1056+
{ maxBufferSize: 8, maxDepth: DEPTH },
1057+
DEPTH // Store full tree on chain
1058+
);
1059+
cmt = cmtKeypair.publicKey;
1060+
const appendIx = createAppendCanopyNodesIx(cmt, payer, [crypto.randomBytes(32)], 0);
1061+
try {
1062+
await execute(provider, [appendIx], [payerKeypair]);
1063+
assert(false, 'Appending a canopy node for an existing tree should have failed');
1064+
} catch {}
1065+
});
10251066
});
10261067
describe(`Having created a tree with 8 leaves`, () => {
10271068
beforeEach(async () => {

0 commit comments

Comments
 (0)