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

feat: cache latest fuels version #3186

Closed
wants to merge 15 commits into from
Closed

Conversation

Dhaiwat10
Copy link
Member

@Dhaiwat10 Dhaiwat10 commented Sep 19, 2024

Closes TS-654

Summary

This PR adds a basic local cache for the latest fuels version fetched by the fuels CLI.

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@Dhaiwat10 Dhaiwat10 self-assigned this Sep 19, 2024
Copy link

vercel bot commented Sep 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
create-fuels-template ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 10:47am
fuels-template ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 10:47am
ts-api-docs ❌ Failed (Inspect) Oct 4, 2024 10:47am
ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 4, 2024 10:47am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
create-fuels-counter-example ⬜️ Ignored (Inspect) Oct 4, 2024 10:47am

Copy link

codspeed-hq bot commented Sep 19, 2024

CodSpeed Performance Report

Merging #3186 will degrade performances by 60.41%

Comparing dp/fuels-version-cache (a8f0431) with next (a35d644)

Summary

❌ 2 regressions
✅ 16 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark next dp/fuels-version-cache Change
should successfully get transaction cost estimate for multi contract calls (x10 times) 24.3 ms 30.8 ms -20.88%
should successfully conduct a custom transfer between wallets (x10 times) 48.1 ms 121.5 ms -60.41%

nedsalk
nedsalk previously approved these changes Sep 19, 2024
arboleya
arboleya previously approved these changes Sep 19, 2024
Copy link
Contributor

github-actions bot commented Oct 3, 2024

Coverage Report:

Lines Branches Functions Statements
76.69%(+0.02%) 70.65%(-0.83%) 75.54%(-0.11%) 76.81%(+0.05%)
Changed Files:
Ok File (✨=New File) Lines Branches Functions Statements
🔴 ✨ internal/benchmarks/src/config.ts 0%
(+0%)
0%
(+0%)
0%
(+0%)
0%
(+0%)
🔴 internal/benchmarks/src/contract-interaction.bench.ts 0%
(+0%)
0%
(-100%)
0%
(+0%)
0%
(+0%)
🔴 internal/benchmarks/src/cost-estimation.bench.ts 0%
(+0%)
0%
(-100%)
0%
(+0%)
0%
(+0%)
🔴 internal/benchmarks/src/transaction-results.bench.ts 0%
(+0%)
0%
(-100%)
0%
(+0%)
0%
(+0%)
🔴 internal/benchmarks/src/wallet.bench.ts 0%
(+0%)
0%
(-100%)
0%
(+0%)
0%
(+0%)
🔴 packages/fuels/src/cli/commands/deploy/deployContract.ts 100%
(+0%)
70%
(-13.33%)
100%
(+0%)
100%
(+0%)
🔴 packages/fuels/src/cli/commands/deploy/proxy/types/Src14OwnedProxyFactory.ts 33.33%
(-33.33%)
0%
(+0%)
0%
(-66.66%)
33.33%
(-33.33%)
🔴 packages/fuels/src/cli/utils/checkForAndDisplayUpdates.ts 86.66%
(-13.34%)
66.66%
(-16.67%)
100%
(+0%)
86.66%
(-13.34%)
🔴 ✨ packages/fuels/src/cli/utils/fuelsVersionCache.ts 54.54%
(+54.54%)
16.66%
(+16.66%)
50%
(+50%)
54.54%
(+54.54%)
✨ packages/fuels/src/cli/utils/getLatestFuelsVersion.ts 100%
(+100%)
100%
(+100%)
100%
(+100%)
100%
(+100%)

packages/fuels/src/cli/utils/fuelsVersionCache.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,25 @@
import { checkAndLoadCache, saveToCache } from './fuelsVersionCache';

export const getLatestFuelsVersion = async (): Promise<string | undefined> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we potentially document the throwable conditions here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if I follow you, can you share some pseudo code? What do you mean by documenting the throwable conditions?

@@ -0,0 +1,7 @@
import * as checkForUpdatesMod from '../../src/cli/utils/checkForAndDisplayUpdates';

export const mockCheckForUpdates = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we always mock a successful resolution?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because as of now this helper for the mock is only used in places where we always expect this functionality to succeed or not run.

packages/fuels/src/cli.test.ts Outdated Show resolved Hide resolved
const doesVersionCacheExist = fs.existsSync(FUELS_VERSION_CACHE_FILE);

if (doesVersionCacheExist) {
const cachedVersion = fs.readFileSync(FUELS_VERSION_CACHE_FILE, 'utf-8');
Copy link
Member

Choose a reason for hiding this comment

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

Should we trim this?

Suggested change
const cachedVersion = fs.readFileSync(FUELS_VERSION_CACHE_FILE, 'utf-8');
const cachedVersion = fs.readFileSync(FUELS_VERSION_CACHE_FILE, 'utf-8').trim();

const version = await getLatestFuelsVersion();
expect(fetchSpy).toHaveBeenCalled();
expect(version).toEqual('1.0.0');
expect(saveCacheSpy).toHaveBeenCalledWith('1.0.0');
Copy link
Member

Choose a reason for hiding this comment

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

Because [I'm presuming] you're mocking everything related to the cache, the tests may not cover some critical parts of the functionality. Can we get all files in 100%?

coverage

Copy link
Contributor

Choose a reason for hiding this comment

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

Think this relates - we should cover both success and failure conditions in my opinion.

@arboleya arboleya deleted the branch next October 9, 2024 10:26
@arboleya arboleya closed this Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Issue is a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement caching to check latest fuels version
5 participants