Skip to content

Commit c05e8fb

Browse files
fix: do not error out in status when swap is disabled (#655)
* fix: do not error out in status when swap is disabled * test: add no-swap tests * test(fix): fix command * test(fix): fix wrong url used in test * test(fix): fix name * test: update test coverage --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b297f9d commit c05e8fb

File tree

8 files changed

+63
-15
lines changed

8 files changed

+63
-15
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ jobs:
4343
- name: Run bee-dev
4444
run: npx bee-dev --port 16337 &
4545

46+
- name: Run bee-dev with --no-swap
47+
run: npx bee-dev --port 16338 --no-swap &
48+
4649
- name: Start fdp-play environment
4750
run: fdp-play start --detach --fresh --bee-version ${{ matrix.bee-version }}
4851

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
},
6464
"dependencies": {
6565
"@ethereumjs/wallet": "^2.0.4",
66-
"@ethersphere/bee-js": "^9.8.1",
66+
"@ethersphere/bee-js": "^10.0.1",
6767
"cafe-utility": "^31.0.0",
6868
"chalk": "^2.4.2",
6969
"cli-progress": "^3.11.2",

src/command/addresses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class Addresses extends RootCommand implements LeafCommand {
4343
this.console.log('')
4444
this.console.log(chalk.bold('Chequebook Address'))
4545
this.console.divider()
46-
this.console.log(chequebookAddress.chequebookAddress)
46+
this.console.log(chequebookAddress.chequebookAddress.toHex())
4747
})
4848

4949
this.console.quiet('Ethereum ' + this.nodeAddresses.ethereum)

src/command/pss/subscribe.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export class Subscribe extends PssCommand implements LeafCommand {
3434
onError: (error: BeeError) => {
3535
this.console.error(error.message)
3636
},
37+
onClose: () => {
38+
this.console.log('Subscription closed')
39+
},
3740
})
3841
}
3942
}

src/command/status.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,27 @@ export class Status extends RootCommand implements LeafCommand {
5353
if (nodeInfo.beeMode !== BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== BeeModes.DEV) {
5454
this.console.all('')
5555
this.console.all(chalk.bold('Wallet'))
56-
const { bzzBalance, nativeTokenBalance } = await this.bee.getWalletBalance()
57-
this.console.all(createKeyValue('xBZZ', bzzBalance.toDecimalString()))
58-
this.console.all(createKeyValue('xDAI', nativeTokenBalance.toDecimalString()))
56+
try {
57+
const { bzzBalance, nativeTokenBalance } = await this.bee.getWalletBalance()
58+
this.console.all(createKeyValue('xBZZ', bzzBalance.toDecimalString()))
59+
this.console.all(createKeyValue('xDAI', nativeTokenBalance.toDecimalString()))
60+
} catch {
61+
this.console.all(chalk.yellow('Wallet balance not available'))
62+
this.console.all('This is normal if chequebook is disabled in the node configuration.')
63+
}
5964
}
6065

6166
if (nodeInfo.beeMode !== BeeModes.ULTRA_LIGHT && nodeInfo.beeMode !== BeeModes.DEV) {
6267
this.console.all('')
6368
this.console.all(chalk.bold('Chequebook'))
64-
const { totalBalance, availableBalance } = await this.bee.getChequebookBalance()
65-
this.console.all(createKeyValue('Available xBZZ', availableBalance.toDecimalString()))
66-
this.console.all(createKeyValue('Total xBZZ', totalBalance.toDecimalString()))
69+
try {
70+
const { totalBalance, availableBalance } = await this.bee.getChequebookBalance()
71+
this.console.all(createKeyValue('Available xBZZ', availableBalance.toDecimalString()))
72+
this.console.all(createKeyValue('Total xBZZ', totalBalance.toDecimalString()))
73+
} catch {
74+
this.console.all(chalk.yellow('Chequebook balance not available'))
75+
this.console.all('This is normal if chequebook is disabled in the node configuration.')
76+
}
6777
}
6878

6979
if (nodeInfo.beeMode === BeeModes.FULL) {

test/coverage/coverage-summary.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{"total": {"lines":{"total":2674,"covered":1953,"skipped":0,"pct":73.03},"statements":{"total":2694,"covered":1966,"skipped":0,"pct":72.97},"functions":{"total":318,"covered":242,"skipped":0,"pct":76.1},"branches":{"total":569,"covered":302,"skipped":0,"pct":53.07},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
1+
{"total": {"lines":{"total":2681,"covered":1959,"skipped":0,"pct":73.06},"statements":{"total":2701,"covered":1972,"skipped":0,"pct":73},"functions":{"total":319,"covered":242,"skipped":0,"pct":75.86},"branches":{"total":569,"covered":302,"skipped":0,"pct":53.07},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
22
,"/home/runner/work/swarm-cli/swarm-cli/src/application.ts": {"lines":{"total":2,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":2,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
33
,"/home/runner/work/swarm-cli/swarm-cli/src/config.ts": {"lines":{"total":31,"covered":30,"skipped":0,"pct":96.77},"functions":{"total":1,"covered":0,"skipped":0,"pct":0},"statements":{"total":31,"covered":30,"skipped":0,"pct":96.77},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
44
,"/home/runner/work/swarm-cli/swarm-cli/src/curl.ts": {"lines":{"total":24,"covered":24,"skipped":0,"pct":100},"functions":{"total":7,"covered":7,"skipped":0,"pct":100},"statements":{"total":25,"covered":25,"skipped":0,"pct":100},"branches":{"total":13,"covered":12,"skipped":0,"pct":92.3}}
@@ -7,7 +7,7 @@
77
,"/home/runner/work/swarm-cli/swarm-cli/src/command/addresses.ts": {"lines":{"total":37,"covered":32,"skipped":0,"pct":86.48},"functions":{"total":6,"covered":5,"skipped":0,"pct":83.33},"statements":{"total":37,"covered":32,"skipped":0,"pct":86.48},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
88
,"/home/runner/work/swarm-cli/swarm-cli/src/command/download.ts": {"lines":{"total":35,"covered":28,"skipped":0,"pct":80},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":35,"covered":28,"skipped":0,"pct":80},"branches":{"total":11,"covered":4,"skipped":0,"pct":36.36}}
99
,"/home/runner/work/swarm-cli/swarm-cli/src/command/hash.ts": {"lines":{"total":10,"covered":8,"skipped":0,"pct":80},"functions":{"total":2,"covered":1,"skipped":0,"pct":50},"statements":{"total":10,"covered":8,"skipped":0,"pct":80},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
10-
,"/home/runner/work/swarm-cli/swarm-cli/src/command/status.ts": {"lines":{"total":73,"covered":51,"skipped":0,"pct":69.86},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":73,"covered":51,"skipped":0,"pct":69.86},"branches":{"total":11,"covered":11,"skipped":0,"pct":100}}
10+
,"/home/runner/work/swarm-cli/swarm-cli/src/command/status.ts": {"lines":{"total":79,"covered":57,"skipped":0,"pct":72.15},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":79,"covered":57,"skipped":0,"pct":72.15},"branches":{"total":11,"covered":11,"skipped":0,"pct":100}}
1111
,"/home/runner/work/swarm-cli/swarm-cli/src/command/upload.ts": {"lines":{"total":212,"covered":147,"skipped":0,"pct":69.33},"functions":{"total":15,"covered":13,"skipped":0,"pct":86.66},"statements":{"total":213,"covered":148,"skipped":0,"pct":69.48},"branches":{"total":95,"covered":53,"skipped":0,"pct":55.78}}
1212
,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/cashout.ts": {"lines":{"total":32,"covered":30,"skipped":0,"pct":93.75},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":32,"covered":30,"skipped":0,"pct":93.75},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
1313
,"/home/runner/work/swarm-cli/swarm-cli/src/command/cheque/cheque-command.ts": {"lines":{"total":25,"covered":21,"skipped":0,"pct":84},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"statements":{"total":26,"covered":22,"skipped":0,"pct":84.61},"branches":{"total":2,"covered":0,"skipped":0,"pct":0}}
@@ -54,7 +54,7 @@
5454
,"/home/runner/work/swarm-cli/swarm-cli/src/command/pss/pss-command.ts": {"lines":{"total":8,"covered":8,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":8,"covered":8,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
5555
,"/home/runner/work/swarm-cli/swarm-cli/src/command/pss/receive.ts": {"lines":{"total":24,"covered":18,"skipped":0,"pct":75},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":24,"covered":18,"skipped":0,"pct":75},"branches":{"total":6,"covered":2,"skipped":0,"pct":33.33}}
5656
,"/home/runner/work/swarm-cli/swarm-cli/src/command/pss/send.ts": {"lines":{"total":34,"covered":29,"skipped":0,"pct":85.29},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":34,"covered":29,"skipped":0,"pct":85.29},"branches":{"total":5,"covered":2,"skipped":0,"pct":40}}
57-
,"/home/runner/work/swarm-cli/swarm-cli/src/command/pss/subscribe.ts": {"lines":{"total":17,"covered":8,"skipped":0,"pct":47.05},"functions":{"total":4,"covered":1,"skipped":0,"pct":25},"statements":{"total":17,"covered":8,"skipped":0,"pct":47.05},"branches":{"total":4,"covered":0,"skipped":0,"pct":0}}
57+
,"/home/runner/work/swarm-cli/swarm-cli/src/command/pss/subscribe.ts": {"lines":{"total":18,"covered":8,"skipped":0,"pct":44.44},"functions":{"total":5,"covered":1,"skipped":0,"pct":20},"statements":{"total":18,"covered":8,"skipped":0,"pct":44.44},"branches":{"total":4,"covered":0,"skipped":0,"pct":0}}
5858
,"/home/runner/work/swarm-cli/swarm-cli/src/command/root-command/command-config.ts": {"lines":{"total":36,"covered":30,"skipped":0,"pct":83.33},"functions":{"total":6,"covered":6,"skipped":0,"pct":100},"statements":{"total":39,"covered":32,"skipped":0,"pct":82.05},"branches":{"total":9,"covered":5,"skipped":0,"pct":55.55}}
5959
,"/home/runner/work/swarm-cli/swarm-cli/src/command/root-command/command-log.ts": {"lines":{"total":78,"covered":60,"skipped":0,"pct":76.92},"functions":{"total":9,"covered":6,"skipped":0,"pct":66.66},"statements":{"total":78,"covered":60,"skipped":0,"pct":76.92},"branches":{"total":11,"covered":7,"skipped":0,"pct":63.63}}
6060
,"/home/runner/work/swarm-cli/swarm-cli/src/command/root-command/index.ts": {"lines":{"total":44,"covered":40,"skipped":0,"pct":90.9},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":44,"covered":40,"skipped":0,"pct":90.9},"branches":{"total":9,"covered":5,"skipped":0,"pct":55.55}}

test/misc/status-swap.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { toMatchLinesInOrder } from '../custom-matcher'
2+
import { describeCommand, invokeTestCli } from '../utility'
3+
4+
expect.extend({
5+
toMatchLinesInOrder,
6+
})
7+
8+
describeCommand('Status command and swap', ({ consoleMessages }) => {
9+
it('should print wallet and chequebook balance', async () => {
10+
await invokeTestCli(['status', '--bee-api-url', 'http://localhost:16337'])
11+
expect(consoleMessages).toMatchLinesInOrder([
12+
['Wallet'],
13+
['xBZZ'],
14+
['xDAI'],
15+
['Chequebook'],
16+
['Available xBZZ'],
17+
['Total xBZZ'],
18+
])
19+
})
20+
21+
it('should handle missing wallet and chequebook balance', async () => {
22+
await invokeTestCli(['status', '--bee-api-url', 'http://localhost:16338'])
23+
expect(consoleMessages).toMatchLinesInOrder([
24+
['Wallet'],
25+
['Wallet balance not available'],
26+
['This is normal if chequebook is disabled in the node configuration.'],
27+
['Chequebook'],
28+
['Chequebook balance not available'],
29+
['This is normal if chequebook is disabled in the node configuration.'],
30+
])
31+
})
32+
})

0 commit comments

Comments
 (0)