From 92e1eb876fe1193cd25d5d388f1a37b87d718a7b Mon Sep 17 00:00:00 2001 From: aalu1418 Date: Wed, 9 Mar 2022 14:52:18 -0500 Subject: [PATCH] test case for incorrect feed size --- contracts/tests/ocr2.spec.ts | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/contracts/tests/ocr2.spec.ts b/contracts/tests/ocr2.spec.ts index 3f842e2c2..b7b0862ff 100644 --- a/contracts/tests/ocr2.spec.ts +++ b/contracts/tests/ocr2.spec.ts @@ -969,4 +969,44 @@ describe("ocr2", async () => { ); assert.ok(closedAccount === null); }); + + it("Fails to create new feeds for invalid account sizes", async () => { + const granularity = 30; + const liveLength = 3; + + const header = 8 + 192 // account discriminator + header + const transmissionSize = 48 + const invalidLengths = [ + header - 1, // insufficient for header size + header + 6 * transmissionSize - 1, // incorrect size for ring buffer + header + 2 * transmissionSize, // live length exceeds total capacity + ] + for (let i = 0; i < invalidLengths.length; i++) { + try { + const invalidFeed = Keypair.generate(); + await workspace.Store.rpc.createFeed( + description, + decimals, + granularity, + liveLength, + { + accounts: { + feed: invalidFeed.publicKey, + authority: owner.publicKey, + }, + signers: [invalidFeed], + preInstructions: [ + await workspace.Store.account.transmissions.createInstruction( + invalidFeed, + invalidLengths[i] + ), + ], + } + ); + } catch { + continue; // expect error + } + assert.fail(`create feed shouldn't have succeeded with account size ${invalidLengths[i]}`); + } + }); });