Skip to content

Commit

Permalink
Change mock clock check (#269)
Browse files Browse the repository at this point in the history
* Fix

* Comment
  • Loading branch information
guibescos authored Nov 14, 2023
1 parent dcacb3c commit 121b94e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions staking/app/StakeConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,8 @@ export class StakeConnection {

// Gets the current unix time, as would be perceived by the on-chain program
public async getTime(): Promise<BN> {
// The Idl contains mockClockTime even when we build it with mock-clock feature disabled.
// Therefore if the field doesn't exist it gets parsed as 0.
// Thus, if mockClockTime is 0 we need to use real time.
if ("mockClockTime" in this.config && this.config.mockClockTime.gtn(0)) {
// This is a hack, we are using this deprecated flag to flag whether we are using the mock clock or not
if (this.config.freeze) {
// On chain program using mock clock, so get that time
const updatedConfig = await this.program.account.globalConfig.fetch(
this.configAddress
Expand Down
2 changes: 1 addition & 1 deletion staking/tests/clock_api_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("clock_api", async () => {

it("gets real time", async () => {
// Delete the property, which will make the API think it's not using mock clock anymore
delete stakeConnection.config.mockClockTime;
stakeConnection.config.freeze = false;
let sysTime = Date.now() / 1000;
let solanaTime = (await stakeConnection.getTime()).toNumber();
assert.ok(Math.abs(sysTime - solanaTime) < CLOCK_TOLERANCE_SECONDS);
Expand Down
2 changes: 1 addition & 1 deletion staking/tests/utils/before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export function makeDefaultConfig(
pythTokenMint: pythMint,
unlockingDuration: 1,
epochDuration: new BN(3600),
freeze: false,
freeze: true,
mockClockTime: new BN(10),
bump: 0,
pythTokenListTime: null,
Expand Down

1 comment on commit 121b94e

@vercel
Copy link

@vercel vercel bot commented on 121b94e Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.