Fix variance threshold in Aggregator.setConfig

This commit is contained in:
Jackson Jessup 2023-01-04 14:09:03 -05:00
parent 909b488454
commit 2e13de18a7
2 changed files with 11 additions and 5 deletions

View File

@ -32,6 +32,7 @@ import { AggregatorHistoryBuffer } from './aggregatorHistoryBuffer';
import { CrankAccount } from './crankAccount'; import { CrankAccount } from './crankAccount';
import assert from 'assert'; import assert from 'assert';
import { BN } from 'bn.js'; import { BN } from 'bn.js';
import _ from 'lodash';
/** /**
* Account type holding a data feed's update configuration, job accounts, and its current result. * Account type holding a data feed's update configuration, job accounts, and its current result.
@ -954,6 +955,7 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
}); });
} }
const varianceThreshold = params.varianceThreshold ?? 0;
const setConfigIxn = types.aggregatorSetConfig( const setConfigIxn = types.aggregatorSetConfig(
this.program, this.program,
{ {
@ -974,11 +976,9 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
minJobResults: params.minJobResults ?? null, minJobResults: params.minJobResults ?? null,
forceReportPeriod: params.forceReportPeriod ?? null, forceReportPeriod: params.forceReportPeriod ?? null,
varianceThreshold: varianceThreshold:
params.varianceThreshold && params.varianceThreshold >= 0 varianceThreshold >= 0
? new types.BorshDecimal( ? new types.BorshDecimal(
types.SwitchboardDecimal.fromBig( types.SwitchboardDecimal.fromBig(new Big(varianceThreshold))
new Big(params.varianceThreshold)
)
) )
: null, : null,
basePriorityFee: params.basePriorityFee ?? null, basePriorityFee: params.basePriorityFee ?? null,

View File

@ -333,6 +333,7 @@ describe('Aggregator Tests', () => {
minRequiredJobResults: 1, minRequiredJobResults: 1,
minUpdateDelaySeconds: 60, minUpdateDelaySeconds: 60,
keypair: aggregatorKeypair, keypair: aggregatorKeypair,
varianceThreshold: 1,
}); });
await aggregatorAccount.loadData(); await aggregatorAccount.loadData();
@ -372,11 +373,16 @@ describe('Aggregator Tests', () => {
authority: aggregatorAuthority, authority: aggregatorAuthority,
minUpdateDelaySeconds: 300, minUpdateDelaySeconds: 300,
force: true, // Bypass validation rules. force: true, // Bypass validation rules.
varianceThreshold: 0,
}); });
const postUpdateAggregatorState = await aggregatorAccount.loadData(); const postUpdateAggregatorState = await aggregatorAccount.loadData();
assert( assert(
postUpdateAggregatorState.minUpdateDelaySeconds === 300, postUpdateAggregatorState.minUpdateDelaySeconds === 300,
`Failed to setConfig on aggregator` `Failed to setConfig on aggregator (minUpdateDelaySeconds)`
);
assert(
postUpdateAggregatorState.varianceThreshold.toBig().toNumber() === 0,
`Failed to setConfig on aggregator (varianceThreshold)`
); );
}); });