Skip to content

Commit

Permalink
ts: Extract some constants
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Sep 16, 2022
1 parent c84bc54 commit e3c4c3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions contracts/examples/hello-world/tests/hello-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ describe("hello-world", () => {

const program = anchor.workspace.HelloWorld as Program<HelloWorld>;

const header = 8 + 192; // account discriminator + header
const transmissionSize = 48;

it("Is initialized!", async () => {
const owner = provider.wallet;
const store = anchor.web3.Keypair.generate();
const feed = anchor.web3.Keypair.generate();
const accessController = anchor.web3.Keypair.generate();

let storeIdl = JSON.parse(fs.readFileSync("../../target/idl/store.json"));
const storeProgram = new Program(storeIdl, CHAINLINK_PROGRAM_ID, provider);
Expand All @@ -27,6 +29,7 @@ describe("hello-world", () => {
const decimals = 18;
const granularity = 30;
const liveLength = 3;
const historicalLength = 3;
await storeProgram.rpc.createFeed(
description,
decimals,
Expand All @@ -41,7 +44,7 @@ describe("hello-world", () => {
preInstructions: [
await storeProgram.account.transmissions.createInstruction(
feed,
8 + 192 + 6 * 24
header + (liveLength + historicalLength) * transmissionSize
),
],
}
Expand Down
10 changes: 5 additions & 5 deletions contracts/tests/ocr2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class Assignable {
}
class Round extends Assignable {}

const header = 8 + 192; // account discriminator + header
const transmissionSize = 48;

describe("ocr2", async () => {
// Configure the client to use the local cluster.
const provider = anchor.AnchorProvider.env();
Expand Down Expand Up @@ -356,6 +359,7 @@ describe("ocr2", async () => {

const granularity = 30;
const liveLength = 3;
const historicalLength = 3;
await workspace.Store.methods
.createFeed(description, decimals, granularity, liveLength)
.accounts({
Expand All @@ -366,7 +370,7 @@ describe("ocr2", async () => {
.preInstructions([
await workspace.Store.account.transmissions.createInstruction(
feed,
8 + 192 + 6 * 48
header + (liveLength + historicalLength) * transmissionSize
),
])
.rpc();
Expand Down Expand Up @@ -1096,8 +1100,6 @@ describe("ocr2", 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
Expand Down Expand Up @@ -1138,8 +1140,6 @@ describe("ocr2", async () => {
const granularity = 1;
const liveLength = 3;

const header = 8 + 192; // account discriminator + header
const transmissionSize = 48;
const feed = Keypair.generate();
const length = header + transmissionSize * liveLength;

Expand Down

0 comments on commit e3c4c3a

Please sign in to comment.