From dfc35699d87d2f6b397428b2a36489a77acc7b73 Mon Sep 17 00:00:00 2001 From: Jackson Jessup Date: Wed, 7 Dec 2022 17:48:07 -0500 Subject: [PATCH] Add setConfigs test --- .../src/accounts/aggregatorAccount.ts | 14 +++-- javascript/solana.js/test/aggregator.spec.ts | 60 +++++++++++++++++++ 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/javascript/solana.js/src/accounts/aggregatorAccount.ts b/javascript/solana.js/src/accounts/aggregatorAccount.ts index 04e62b1..3db92a6 100644 --- a/javascript/solana.js/src/accounts/aggregatorAccount.ts +++ b/javascript/solana.js/src/accounts/aggregatorAccount.ts @@ -675,12 +675,13 @@ export class AggregatorAccount extends Account { minUpdateDelaySeconds: number; forceReportPeriod: number; varianceThreshold: number; - authority?: Keypair; - basePriorityFee?: number; - priorityFeeBump?: number; - priorityFeeBumpPeriod?: number; - maxPriorityFeeMultiplier?: number; - }> & { force?: boolean } + authority: Keypair; + basePriorityFee: number; + priorityFeeBump: number; + priorityFeeBumpPeriod: number; + maxPriorityFeeMultiplier: number; + force: boolean; + }> ): Promise { if (!(params.force ?? false)) { const aggregator = await this.loadData(); @@ -758,6 +759,7 @@ export class AggregatorAccount extends Account { priorityFeeBump?: number; priorityFeeBumpPeriod?: number; maxPriorityFeeMultiplier?: number; + force: boolean; }> ): Promise { const setConfigTxn = await this.setConfigInstruction( diff --git a/javascript/solana.js/test/aggregator.spec.ts b/javascript/solana.js/test/aggregator.spec.ts index 2ae7a16..32a0322 100644 --- a/javascript/solana.js/test/aggregator.spec.ts +++ b/javascript/solana.js/test/aggregator.spec.ts @@ -338,4 +338,64 @@ describe('Aggregator Tests', () => { }, received ${newPermission.permissions}` ); }); + + it("Adds job, updates it's config, then removes it from aggregator", async () => { + const aggregatorKeypair = Keypair.generate(); + const aggregatorAuthority = Keypair.generate(); + + const [aggregatorAccount] = await AggregatorAccount.create(ctx.program, { + queueAccount, + queueAuthority: queueAuthority.publicKey, + authority: aggregatorAuthority.publicKey, + batchSize: 1, + minRequiredOracleResults: 1, + minRequiredJobResults: 1, + minUpdateDelaySeconds: 60, + keypair: aggregatorKeypair, + }); + await aggregatorAccount.loadData(); + + const oracleJob = OracleJob.fromObject({ + tasks: [{ valueTask: { value: 1 } }], + }); + + const [jobAccount] = await JobAccount.create(ctx.program, { + data: OracleJob.encodeDelimited(oracleJob).finish(), + name: 'Job1', + }); + + await aggregatorAccount.addJob({ + job: jobAccount, + weight: 1, + authority: aggregatorAuthority, + }); + + const postAddJobAggregatorState = await aggregatorAccount.loadData(); + const jobIdx = postAddJobAggregatorState.jobPubkeysData.findIndex(pubkey => + pubkey.equals(jobAccount.publicKey) + ); + if (jobIdx === -1) { + throw new Error(`Failed to add job to aggregator`); + } + + const badSetConfigSignature = await aggregatorAccount + .setConfigInstruction(aggregatorAuthority.publicKey, { minJobResults: 2 }) + .catch(() => undefined); + // If badSetConfigSignature isn't undefined, a (bad) transaction was built and sent. + if (badSetConfigSignature) { + throw new Error( + 'Aggregator should not let minJobResults increase above numJobs' + ); + } + + await aggregatorAccount.setConfig({ + authority: aggregatorAuthority, + minUpdateDelaySeconds: 300, + force: true, // Bypass validation rules. + }); + const postUpdateAggregatorState = await aggregatorAccount.loadData(); + if (postUpdateAggregatorState.minUpdateDelaySeconds !== 300) { + throw new Error(`Failed to setConfig on aggregator`); + } + }); });