Skip to content

Commit

Permalink
feat(config): update naming to overwriteWitnetNodeConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Jun 2, 2022
1 parent a8a75fd commit 477dcd5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/background/autoUpdaterManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { autoUpdater } from 'electron-updater'
import { BrowserWindow, dialog } from 'electron'
import { WalletManager } from './walletManager'
import { AppManager } from './appManager'
import overwriteWalletConfigFile from './utils/overwriteWalletConfigFile'
import overwriteWitnetNodeConfiguration from './utils/overwriteWitnetNodeConfiguration'
import {
SHEIKAH_PATH,
WITNET_CONFIG_FILE_NAME,
Expand Down Expand Up @@ -40,7 +40,7 @@ export class AutoUpdaterManager {
cancelId: 1, // bound to buttons array
}
this.wallet.setIsUpdating(true)
overwriteWalletConfigFile({
overwriteWitnetNodeConfiguration({
sheikahPath: SHEIKAH_PATH,
witnetConfigFileName: WITNET_CONFIG_FILE_NAME,
publicNodeUrls: URLS_PUBLIC_WITNET_NODES,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path'
import fs from 'fs-extra'

// Overwrite wallet config file only when new version is downloaded
export function overwriteWalletConfigFile({
// Replace witnet nodes urls in witnet configuration file
export function overwriteWitnetNodeConfiguration({
sheikahPath,
witnetConfigFileName,
publicNodeUrls,
Expand All @@ -22,11 +22,11 @@ export function overwriteWalletConfigFile({
'node_url = "127.0.0.1:21338"',
`node_url = ${JSON.stringify(publicNodeUrls)}\n`.replace("'", ''),
)
.replace('52.166.178.145:21338', `20.126.70.77:21338`.replace("'", '')),
.replace('52.166.178.145:21338', `20.126.70.77:21338`),
)
} catch (error) {
console.log('Error overwriting configuration file')
}
}

export default overwriteWalletConfigFile
export default overwriteWitnetNodeConfiguration
8 changes: 4 additions & 4 deletions src/background/walletManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from './constants'
import { AppManager } from './appManager'
import getVersionFromName from './utils/getVersionFromName'
import overwriteWalletConfigFile from './utils/overwriteWalletConfigFile'
import overwriteWitnetNodeConfiguration from './utils/overwriteWitnetNodeConfiguration'
import sleep from './utils/sleep'

interface GithubReleaseAsset {
Expand Down Expand Up @@ -251,7 +251,7 @@ async function decompressDarwinWallet(file: string) {
process.chdir(currentCwd)

await sleep(3000)
overwriteWalletConfigFile({
overwriteWitnetNodeConfiguration({
sheikahPath: SHEIKAH_PATH,
witnetConfigFileName: WITNET_CONFIG_FILE_NAME,
publicNodeUrls: URLS_PUBLIC_WITNET_NODES,
Expand All @@ -276,7 +276,7 @@ async function decompressWin32Wallet(file: string) {
)
await sleep(3000)

overwriteWalletConfigFile({
overwriteWitnetNodeConfiguration({
sheikahPath: SHEIKAH_PATH,
witnetConfigFileName: WITNET_CONFIG_FILE_NAME,
publicNodeUrls: URLS_PUBLIC_WITNET_NODES,
Expand All @@ -298,7 +298,7 @@ async function decompressLinuxWallet(file: string) {
)

await sleep(3000)
overwriteWalletConfigFile({
overwriteWitnetNodeConfiguration({
sheikahPath: SHEIKAH_PATH,
witnetConfigFileName: WITNET_CONFIG_FILE_NAME,
publicNodeUrls: URLS_PUBLIC_WITNET_NODES,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs-extra'

import { overwriteWalletConfigFile } from '../../../../../src/background/utils/overwriteWalletConfigFile'
import { overwriteWitnetNodeConfiguration } from '../../../../../src/background/utils/overwriteWitnetNodeConfiguration'

afterEach(() => {
jest.restoreAllMocks()
Expand All @@ -13,7 +13,7 @@ describe('overwriteConfigFile', () => {
.spyOn(fs, 'readFileSync')
.mockImplementation(() => 'node_url = "127.0.0.1:21338"')

overwriteWalletConfigFile({
overwriteWitnetNodeConfiguration({
sheikahPath: 'sheikah_path',
publicNodeUrls: ['public_node_url1', 'public_node_url2'],
witnetConfigFileName: 'witnet_config_file_name',
Expand All @@ -28,11 +28,34 @@ describe('overwriteConfigFile', () => {
)
})

it('Should overwrite the outdated node urls', () => {
jest.spyOn(fs, 'writeFileSync').mockImplementation()
jest
.spyOn(fs, 'readFileSync')
.mockImplementation(
() => 'node_url = ["52.166.178.145:21338","public_node_url2"]',
)

overwriteWitnetNodeConfiguration({
sheikahPath: 'sheikah_path',
publicNodeUrls: ['public_node_url1', 'public_node_url2'],
witnetConfigFileName: 'witnet_config_file_name',
})

expect(fs.readFileSync).toBeCalledWith(
'sheikah_path/witnet_config_file_name',
)
expect(fs.writeFileSync).toBeCalledWith(
'sheikah_path/witnet_config_file_name',
'node_url = ["20.126.70.77:21338","public_node_url2"]',
)
})

it("Should handle error if read file doesn't exists", () => {
jest.spyOn(fs, 'writeFileSync').mockImplementation()
jest.spyOn(fs, 'readFileSync').mockImplementation()

overwriteWalletConfigFile({
overwriteWitnetNodeConfiguration({
sheikahPath: 'sheikah_path',
publicNodeUrls: ['public_node_url1', 'public_node_url2'],
witnetConfigFileName: 'witnet_config_file_name',
Expand Down

0 comments on commit 477dcd5

Please sign in to comment.