-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1628 from spacemeshos/fix-cli-tools
Fix CLI tools
- Loading branch information
Showing
15 changed files
with
125 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import util from 'util'; | ||
import fs from 'fs'; | ||
import { F_OK } from 'constants'; | ||
|
||
export const readFileAsync = util.promisify(fs.readFile); | ||
|
||
export const writeFileAsync = util.promisify(fs.writeFile); | ||
export const deleteFileAsync = util.promisify(fs.unlink); | ||
|
||
export const isFileExists = (filePath: string) => | ||
fs.promises | ||
.access(filePath, F_OK) | ||
.then(() => true) | ||
.catch(() => false); | ||
|
||
export const isEmptyDir = async (path: string) => { | ||
try { | ||
const fsp = fs.promises; | ||
const directory = await fsp.opendir(path); | ||
const entry = await directory.read(); | ||
await directory.close(); | ||
return entry === null; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as sm from '@spacemesh/sm-codec'; | ||
import prompts from 'prompts'; | ||
import { SingleSigMethods } from '../shared/templateConsts'; | ||
|
||
(async () => { | ||
// Inputs | ||
const inputs = await prompts([ | ||
{ | ||
type: 'select', | ||
name: 'templateAddress', | ||
message: 'Choose the template', | ||
choices: [ | ||
{ title: 'SingleSig', value: sm.SingleSigTemplate.key }, | ||
], | ||
}, | ||
{ | ||
type: prev => prev === sm.SingleSigTemplate.key ? 'select' : null, | ||
name: 'method', | ||
message: 'Choose the method', | ||
choices: [ | ||
{ title: 'SelfSpawn', value: SingleSigMethods.Spawn }, | ||
{ title: 'Spend', value: SingleSigMethods.Spend }, | ||
], | ||
}, | ||
{ | ||
type: 'text', | ||
name: 'rawTx', | ||
message: 'Put here raw transaction (in format `0, 0, 0, 0, 0, 0, 227, ..., 23`)', | ||
}, | ||
], { | ||
onCancel: () => { | ||
console.log('Composing transaction cancelled'); | ||
process.exit(0); | ||
} | ||
}); | ||
|
||
// SCRIPT | ||
const tpl = sm.TemplateRegistry.get(inputs.templateAddress, inputs.method); | ||
const bytes = Uint8Array.from( | ||
JSON.parse( | ||
`[${inputs.rawTx.replace('[', '').replace(']', '')}]` | ||
) | ||
); | ||
|
||
console.dir(tpl.decode(bytes), { depth: null, colors: true }); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import { generateGenesisID } from '../../desktop/main/Networks'; | ||
import { generateGenesisID } from '../../shared/utils'; | ||
|
||
describe('test Network util functions', () => { | ||
describe('generateGenesisID', () => { | ||
const genesisTime = '2022-11-20T20:00:00.498Z'; | ||
const extraData = 'unique-testnet-identifier'; | ||
|
||
const expectedGenesisId = 'b92736fb23dfe78efe03c2c45fb638b9fe3afa70'; | ||
|
||
it('test for generateGenesisID', () => { | ||
it('is pure & determenistic', () => { | ||
expect(generateGenesisID(genesisTime, extraData)).toEqual( | ||
generateGenesisID(genesisTime, extraData) | ||
); | ||
|
||
}); | ||
it('works as expected', () => { | ||
expect(generateGenesisID(genesisTime, extraData)).toEqual( | ||
expectedGenesisId | ||
'b92736fb23dfe78efe03c2c45fb638b9fe3afa70' | ||
); | ||
}); | ||
}); |