This repository has been archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 0.9.6.2 finalization points (#306)
- Loading branch information
1 parent
8524c3e
commit 8da61f7
Showing
14 changed files
with
216 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,44 @@ | ||
/* | ||
* | ||
* Copyright 2018-present NEM | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import { Options } from 'clime'; | ||
import { UInt64 } from 'symbol-sdk'; | ||
|
||
import { OptionsResolver } from '../options-resolver'; | ||
import { FinalizationPointValidator } from '../validators/finalizationPoint.validator'; | ||
import { Resolver } from './resolver'; | ||
|
||
export class FinalizationPointResolver implements Resolver { | ||
/** | ||
* Resolves a finalization point provided by user. | ||
* @param {Options} options - Command options. | ||
* @param {string} altText - Alternative text. | ||
* @param {string} altKey - Alternative key. | ||
* @returns {Promise<UInt64>} | ||
*/ | ||
async resolve(options: Options, altText?: string, altKey?: string): Promise<UInt64> { | ||
const resolution = await OptionsResolver( | ||
options, | ||
altKey ? altKey : 'point', | ||
() => undefined, | ||
altText ? altText : 'Enter a finalization point:', | ||
'text', | ||
new FinalizationPointValidator(), | ||
); | ||
return UInt64.fromNumericString(resolution); | ||
} | ||
} |
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,38 @@ | ||
/* | ||
* | ||
* Copyright 2018-present NEM | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
import { Validator } from 'clime'; | ||
import { UInt64 } from 'symbol-sdk'; | ||
|
||
/** | ||
* Finalization point validator | ||
*/ | ||
export class FinalizationPointValidator implements Validator<string> { | ||
/** | ||
* validates if a point is valid. | ||
* @param {string} value. | ||
* @returns {true | string} | ||
*/ | ||
validate(value: string): boolean | string { | ||
try { | ||
UInt64.fromNumericString(value); | ||
} catch (err) { | ||
return 'Finalization point must be an integer'; | ||
} | ||
return 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
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,35 @@ | ||
/* | ||
* | ||
* Copyright 2018-present NEM | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
|
||
import { FinalizationPointResolver } from '../../src/resolvers/finalizationPoint.resolver'; | ||
|
||
describe('Finalization point resolver', () => { | ||
it('should return point', async () => { | ||
const point = '15'; | ||
const options = { point } as any; | ||
expect((await new FinalizationPointResolver().resolve(options)).toString()).to.be.equal(point); | ||
}); | ||
|
||
it('should change key', async () => { | ||
const key = '16'; | ||
const options = { key } as any; | ||
expect((await new FinalizationPointResolver().resolve(options, 'altText', 'key')).toString()).to.be.equal(key); | ||
}); | ||
}); |
Oops, something went wrong.