Quantillon Protocol

MockAggregatorV3

Git Source

Inherits: AggregatorV3Interface

Title: MockAggregatorV3

Mock Chainlink price feed for testing

Implements AggregatorV3Interface with configurable behavior to simulate:

  • Price updates with variable decimals
  • Revert scenarios and invalid price outputs
  • Stale timestamps and round progression

Note: security-contact: team@quantillon.money

State Variables

price

int256 public price

decimals_

uint8 public decimals_

updatedAt

uint256 public updatedAt

shouldRevert

bool public shouldRevert

shouldReturnInvalidPrice

bool public shouldReturnInvalidPrice

roundId

uint80 public roundId = 1

Functions

constructor

Constructor for MockPriceFeed

Mock function for testing purposes

Notes:

  • security: No security validations - test mock

  • validation: No input validation - test mock

  • state-changes: Initializes decimals and updatedAt timestamp

  • events: No events emitted

  • errors: No errors thrown

  • reentrancy: Not protected - test mock

  • access: Public - test mock

  • oracle: No oracle dependencies

constructor(uint8 _decimals) ;

Parameters

NameTypeDescription
_decimalsuint8The number of decimals for the price feed

setPrice

Sets the price for the mock price feed

Mock function for testing purposes

Notes:

  • security: No security validations - test mock

  • validation: No input validation - test mock

  • state-changes: Updates price and increments roundId

  • events: No events emitted

  • errors: No errors thrown

  • reentrancy: Not protected - test mock

  • access: Public - test mock

  • oracle: No oracle dependencies

function setPrice(int256 _price) external;

Parameters

NameTypeDescription
_priceint256The price to set

setShouldRevert

Sets whether the mock price feed should revert

Mock function for testing purposes

Notes:

  • security: No security validations - test mock

  • validation: No input validation - test mock

  • state-changes: Updates shouldRevert flag

  • events: No events emitted

  • errors: No errors thrown

  • reentrancy: Not protected - test mock

  • access: Public - test mock

  • oracle: No oracle dependencies

function setShouldRevert(bool _shouldRevert) external;

Parameters

NameTypeDescription
_shouldRevertboolWhether the price feed should revert

setShouldReturnInvalidPrice

Sets whether the mock price feed should return invalid price

Mock function for testing purposes

Notes:

  • security: No security validations - test mock

  • validation: No input validation - test mock

  • state-changes: Updates shouldReturnInvalidPrice flag

  • events: No events emitted

  • errors: No errors thrown

  • reentrancy: Not protected - test mock

  • access: Public - test mock

  • oracle: No oracle dependencies

function setShouldReturnInvalidPrice(bool _shouldReturnInvalidPrice) external;

Parameters

NameTypeDescription
_shouldReturnInvalidPriceboolWhether the price feed should return invalid price

setUpdatedAt

Sets the updated timestamp for the mock price feed

Test helper function to control price feed timestamps

Notes:

  • security: No security implications - test helper function

  • validation: No input validation required - test helper

  • state-changes: Updates the updatedAt timestamp for testing

  • events: No events emitted

  • errors: No errors thrown

  • reentrancy: Not applicable - simple state update

  • access: Public - no access restrictions

  • oracle: No oracle dependency - mock function

function setUpdatedAt(uint256 _updatedAt) external;

Parameters

NameTypeDescription
_updatedAtuint256The timestamp to set as the last update time

latestRoundData

Returns the latest round data for the mock price feed

Mock implementation of Chainlink's latestRoundData function for testing

Notes:

  • security: No security implications - test function

  • validation: No input validation required - test function

  • state-changes: No state changes - test function

  • events: No events emitted - test function

  • errors: No errors thrown - test function

  • reentrancy: Not applicable - test function

  • access: Public - no access restrictions

  • oracle: No oracle dependency for test function

function latestRoundData()
    external
    view
    returns (uint80 _roundId, int256 _answer, uint256 _startedAt, uint256 _updatedAt, uint80 _answeredInRound);

Returns

NameTypeDescription
_roundIduint80The round ID
_answerint256The price answer
_startedAtuint256The timestamp when the round started
_updatedAtuint256The timestamp when the round was last updated
_answeredInRounduint80The round ID in which the answer was computed

getRoundData

Gets round data for the mock price feed

Mock function for testing purposes

Notes:

  • security: No security validations - test mock

  • validation: No input validation - test mock

  • state-changes: No state changes - view function

  • events: No events emitted

  • errors: Throws "MockAggregator: Simulated failure" if shouldRevert is true

  • reentrancy: Not protected - test mock

  • access: Public - test mock

  • oracle: No oracle dependencies

function getRoundData(
    uint80 /* _id */
)
    external
    view
    returns (uint80 _roundId, int256 _answer, uint256 _startedAt, uint256 _updatedAt, uint80 _answeredInRound);

Returns

NameTypeDescription
_roundIduint80The round ID
_answerint256The price answer
_startedAtuint256The timestamp when the round started
_updatedAtuint256The timestamp when the round was updated
_answeredInRounduint80The round ID when the answer was provided

decimals

Gets the number of decimals for the mock price feed

Mock function for testing purposes

Notes:

  • security: No security validations - test mock

  • validation: No input validation - test mock

  • state-changes: No state changes - view function

  • events: No events emitted

  • errors: No errors thrown

  • reentrancy: Not protected - test mock

  • access: Public - test mock

  • oracle: No oracle dependencies

function decimals() external view returns (uint8);

Returns

NameTypeDescription
<none>uint8The number of decimals

description

Gets the description of the mock price feed

Mock function for testing purposes

Notes:

  • security: No security validations - test mock

  • validation: No input validation - test mock

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: No errors thrown

  • reentrancy: Not protected - test mock

  • access: Public - test mock

  • oracle: No oracle dependencies

function description() external pure returns (string memory);

Returns

NameTypeDescription
<none>stringThe description string

version

Gets the version of the mock price feed

Mock function for testing purposes

Notes:

  • security: No security validations - test mock

  • validation: No input validation - test mock

  • state-changes: No state changes - pure function

  • events: No events emitted

  • errors: No errors thrown

  • reentrancy: Not protected - test mock

  • access: Public - test mock

  • oracle: No oracle dependencies

function version() external pure returns (uint256);

Returns

NameTypeDescription
<none>uint256The version number