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 assert from 'assert';
import { BN } from 'bn.js';
import _ from 'lodash';
/**
* 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(
this.program,
{
@ -974,11 +976,9 @@ export class AggregatorAccount extends Account<types.AggregatorAccountData> {
minJobResults: params.minJobResults ?? null,
forceReportPeriod: params.forceReportPeriod ?? null,
varianceThreshold:
params.varianceThreshold && params.varianceThreshold >= 0
varianceThreshold >= 0
? new types.BorshDecimal(
types.SwitchboardDecimal.fromBig(
new Big(params.varianceThreshold)
)
types.SwitchboardDecimal.fromBig(new Big(varianceThreshold))
)
: null,
basePriorityFee: params.basePriorityFee ?? null,

View File

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