Skip to content

Commit

Permalink
fix finally() handling, more whitespaces fun
Browse files Browse the repository at this point in the history
  • Loading branch information
shazarre committed Oct 16, 2024
1 parent d751205 commit 9468c3c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
4 changes: 3 additions & 1 deletion packages/cli/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ export abstract class BaseCommand extends CeloCommand {
}
}

protected onError(): void {
async finally(arg?: Error): Promise<any> {
try {
if (this._kit !== null) {
this._kit.connection.stop()
}
} catch (error) {
this.log(`Failed to close the connection: ${error}`)
}

super.finally(arg)
}

protected async checkIfL2(): Promise<boolean> {
Expand Down
4 changes: 0 additions & 4 deletions packages/cli/src/celo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ export abstract class CeloCommand extends Command {

protected abstract checkIfL2(): Promise<boolean>

protected onError(_: any) {}

protected async getNodeUrl(): Promise<string> {
const res = await this.parse()

Expand Down Expand Up @@ -167,8 +165,6 @@ https://github.com/celo-org/developer-tooling/issues/new?assignees=&labels=bug+r
arg
)
}

this.onError(arg)
}

return super.finally(arg)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/network/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class Info extends ViemCommand {
printValueMapRecursive({
blockNumber,
epochs: epochs.length === 1 ? epochs[0] : epochs,
...(isL2 && { epochDuration: epochSize }),
...(isL2 && { epochDuration: Number(epochSize) }),
...(!isL2 && { epochSize }),
})
}
Expand Down
20 changes: 10 additions & 10 deletions packages/cli/src/commands/network/parameters-l2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ testWithAnvilL2('network:parameters', (web3) => {
currentThreshold: 60000000000000000000 (~6.000e+19)
electabilityThreshold: 0.001
electableValidators:
max: 100
min: 1
maxNumGroupsVotedFor: 10
max: 100
min: 1
maxNumGroupsVotedFor: 10
totalVotes: 60000000000000000000000 (~6.000e+22)
EpochManager:
currentEpochNumber: 4
currentEpochNumber: 4
epochDuration: 86400
isTimeForNextEpoch: false
FeeCurrencyDirectory:
Expand All @@ -34,7 +34,7 @@ testWithAnvilL2('network:parameters', (web3) => {
0x9cA64d4663B4A623C3E9a7F9155451647592bEc7: 21000 (~2.100e+4)
0xC458f5ab25a47741205722d465cDea9aB1E1154A: 21000 (~2.100e+4)
Governance:
concurrentProposals: 3
concurrentProposals: 3
dequeueFrequency: 4 hours
minDeposit: 100000000000000000000 (~1.000e+20)
participationParameters:
Expand All @@ -50,8 +50,8 @@ testWithAnvilL2('network:parameters', (web3) => {
totalLockedGold: 120000000000000000000000 (~1.200e+23)
unlockingPeriod: 6 hours
Reserve:
frozenReserveGoldDays: 0
frozenReserveGoldStartBalance: 0
frozenReserveGoldDays: 0
frozenReserveGoldStartBalance: 0
frozenReserveGoldStartDay: 19991 (~1.999e+4)
otherReserveAddresses:
Expand All @@ -60,12 +60,12 @@ testWithAnvilL2('network:parameters', (web3) => {
reportExpiry: 5 minutes
Validators:
commissionUpdateDelay: 3 days
downtimeGracePeriod: 0
downtimeGracePeriod: 0
groupLockedGoldRequirements:
duration: 6 months
value: 10000000000000000000000 (~1.000e+22)
maxGroupSize: 2
membershipHistoryLength: 60
maxGroupSize: 2
membershipHistoryLength: 60
slashingMultiplierResetPeriod: 1 month
validatorLockedGoldRequirements:
duration: 2 months
Expand Down
18 changes: 9 additions & 9 deletions packages/cli/src/commands/network/parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ testWithAnvilL1('network:parameters', (web3: Web3) => {
currentThreshold: 60000000000000000000 (~6.000e+19)
electabilityThreshold: 0.001
electableValidators:
max: 100
min: 1
maxNumGroupsVotedFor: 10
max: 100
min: 1
maxNumGroupsVotedFor: 10
totalVotes: 60000000000000000000000 (~6.000e+22)
EpochRewards:
carbonOffsetting:
Expand All @@ -49,7 +49,7 @@ testWithAnvilL1('network:parameters', (web3: Web3) => {
gasPriceMinimum: 100000000 (~1.000e+8)
targetDensity: 0.5
Governance:
concurrentProposals: 3
concurrentProposals: 3
dequeueFrequency: 4 hours
minDeposit: 100000000000000000000 (~1.000e+20)
participationParameters:
Expand All @@ -65,8 +65,8 @@ testWithAnvilL1('network:parameters', (web3: Web3) => {
totalLockedGold: 120000000000000000000000 (~1.200e+23)
unlockingPeriod: 6 hours
Reserve:
frozenReserveGoldDays: 0
frozenReserveGoldStartBalance: 0
frozenReserveGoldDays: 0
frozenReserveGoldStartBalance: 0
frozenReserveGoldStartDay: 19991 (~1.999e+4)
otherReserveAddresses:
Expand All @@ -75,12 +75,12 @@ testWithAnvilL1('network:parameters', (web3: Web3) => {
reportExpiry: 5 minutes
Validators:
commissionUpdateDelay: 3 days
downtimeGracePeriod: 0
downtimeGracePeriod: 0
groupLockedGoldRequirements:
duration: 6 months
value: 10000000000000000000000 (~1.000e+22)
maxGroupSize: 2
membershipHistoryLength: 60
maxGroupSize: 2
membershipHistoryLength: 60
slashingMultiplierResetPeriod: 1 month
validatorLockedGoldRequirements:
duration: 2 months
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/utils/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ function toStringValueMapRecursive(valueMap: Record<string, any>, prefix: string
const printValue = (v: any): string => {
if (typeof v === 'object' && v != null) {
if (BigNumber.isBigNumber(v)) {
const extra = v.isGreaterThan(new BigNumber(10).pow(3)) ? `(~${v.toExponential(3)})` : ''
return `${v.toFixed()} ${extra}`
const extra = v.isGreaterThan(new BigNumber(10).pow(3)) ? ` (~${v.toExponential(3)})` : ''
return `${v.toFixed()}${extra}`
} else if (v instanceof Error) {
return '\n' + chalk.red(v.message)
}
return '\n' + toStringValueMapRecursive(v, prefix + ' ')
} else if (typeof v === 'bigint') {
const extra = v > 1000n ? `(~${Number(v).toExponential(3)})` : ''
const extra = v > 1000n ? ` (~${Number(v).toExponential(3)})` : ''

return `${v} ${extra}`
return `${v}${extra}`
} else if (typeof v === 'number') {
return `${v}`
}
Expand Down

0 comments on commit 9468c3c

Please sign in to comment.