Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Use current in request #57

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/perennial-oracle/contracts/pyth/PythOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ contract PythOracle is IPythOracle, Instance, Kept {
/// @notice Records a request for a new oracle version
/// @dev Original sender to optionally use for callbacks
function request(address) external onlyAuthorized {
if (versionList.length == 0 || versionList[versionList.length - 1] != block.timestamp) {
versionList.push(block.timestamp);
}
uint256 currentTimestamp = current();
if (versionList.length == 0 || versionList[versionList.length - 1] != currentTimestamp)
versionList.push(currentTimestamp);
}

/// @notice Returns the latest synced oracle version and the current oracle version
Expand Down
13 changes: 13 additions & 0 deletions packages/perennial-oracle/test/integration/pyth/PythOracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,19 @@ describe('PythOracle', () => {
await expect(pythOracle.callStatic.versionList(1)).to.be.reverted
})

it('can request a version w/ granularity', async () => {
await pythOracleFactory.updateGranularity(10)

// No requested versions
await expect(pythOracle.callStatic.versionList(0)).to.be.reverted
await pythOracle.connect(oracleSigner).request(user.address)
const currentTimestamp = await pythOracleFactory.current()

// Now there is exactly one requested version
expect(await pythOracle.callStatic.versionList(0)).to.equal(currentTimestamp)
await expect(pythOracle.callStatic.versionList(1)).to.be.reverted
})

it('does not allow unauthorized users to request', async () => {
await expect(pythOracle.connect(user).request(user.address)).to.be.reverted
})
Expand Down