From 121b94ea3ecbf654887b243f296b0bbf8ff3bb0e Mon Sep 17 00:00:00 2001 From: guibescos <59208140+guibescos@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:46:10 -0600 Subject: [PATCH] Change mock clock check (#269) * Fix * Comment --- staking/app/StakeConnection.ts | 6 ++---- staking/tests/clock_api_test.ts | 2 +- staking/tests/utils/before.ts | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/staking/app/StakeConnection.ts b/staking/app/StakeConnection.ts index c378ed21..6341314c 100644 --- a/staking/app/StakeConnection.ts +++ b/staking/app/StakeConnection.ts @@ -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 { - // 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 diff --git a/staking/tests/clock_api_test.ts b/staking/tests/clock_api_test.ts index 042beb8b..41208f65 100644 --- a/staking/tests/clock_api_test.ts +++ b/staking/tests/clock_api_test.ts @@ -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); diff --git a/staking/tests/utils/before.ts b/staking/tests/utils/before.ts index bfc82a2f..a80025be 100644 --- a/staking/tests/utils/before.ts +++ b/staking/tests/utils/before.ts @@ -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,