Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions test/command/cheque.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Server } from 'http'
import { createChequeMockHttpServer } from '../http-mock/cheque-mock'
import { describeCommand, invokeTestCli } from '../utility'

async function runCommandAndExpectError(
Expand All @@ -15,39 +13,27 @@ async function runCommandAndExpectError(
describeCommand(
'Test Cheque command',
({ consoleMessages, getNthLastMessage, getLastMessage }) => {
let server: Server

beforeAll(() => {
if (!server) {
server = createChequeMockHttpServer(1377)
}
})

afterAll(() => {
server.close()
})

it('should print cheques', async () => {
process.env.BEE_API_URL = 'http://localhost:1377'
process.env.BEE_API_URL = 'http://localhost:16337'
await invokeTestCli(['cheque', 'list'])
expect(getLastMessage()).toContain('Cheque Value:')
expect(getLastMessage()).toContain('0.0008944000000000 xBZZ')
})

it('should not print cheques when --minimum is higher', async () => {
process.env.BEE_API_URL = 'http://localhost:1377'
process.env.BEE_API_URL = 'http://localhost:16337'
await invokeTestCli(['cheque', 'list', '--minimum', '10000000000000000000'])
expect(getLastMessage()).toContain('No uncashed cheques found')
})

it('should print cheques when --minimum is lower', async () => {
process.env.BEE_API_URL = 'http://localhost:1377'
process.env.BEE_API_URL = 'http://localhost:16337'
await invokeTestCli(['cheque', 'list', '--minimum', '1000'])
expect(getLastMessage()).toContain('Cheque Value')
})

it('should cashout all cheques', async () => {
process.env.BEE_API_URL = 'http://localhost:1377'
process.env.BEE_API_URL = 'http://localhost:16337'
await invokeTestCli(['cheque', 'cashout', '--all'])
expect(getNthLastMessage(3)).toContain('Peer Address:')
expect(getNthLastMessage(3)).toContain('1105536d0f270ecaa9e6e4347e687d1a1afbde7b534354dfd7050d66b3c0faad')
Expand All @@ -58,20 +44,20 @@ describeCommand(
})

it('should allow specifying gas price and limit for cashout', async () => {
process.env.BEE_API_URL = 'http://localhost:1377'
process.env.BEE_API_URL = 'http://localhost:16337'
await invokeTestCli(['cheque', 'cashout', '--all', '--gas-price', '100', '--gas-limit', '100'])
expect(getLastMessage()).toContain('Tx:')
expect(getLastMessage()).toContain('11df9811dc8caaa1ff4389503f2493a8c46b30c0a0b5f8aa54adbb965374c0ae')
})

it('should not cashout any cheques when --minimum is higher', async () => {
process.env.BEE_API_URL = 'http://localhost:1377'
process.env.BEE_API_URL = 'http://localhost:16337'
await invokeTestCli(['cheque', 'cashout', '--all', '--minimum', '10000000000000000000'])
expect(getLastMessage()).toContain('Found 0 cheques')
})

it('should cashout one specific cheque', async () => {
process.env.BEE_API_URL = 'http://localhost:1377'
process.env.BEE_API_URL = 'http://localhost:16337'
await invokeTestCli([
'cheque',
'cashout',
Expand Down
8 changes: 4 additions & 4 deletions test/command/manifest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ describeCommand('Test Manifest command', ({ consoleMessages, hasMessageContainin
['address.ts', 'UNCHANGED'],
])
consoleMessages.length = 0
hash = await runAndGetManifest(['manifest', 'sync', hash, 'test/http-mock'])
expect(consoleMessages).toMatchLinesInOrder([['cheque-mock.ts', 'NEW']])
hash = await runAndGetManifest(['manifest', 'sync', hash, 'test/testpage/images'])
expect(consoleMessages).toMatchLinesInOrder([['swarm.png', 'NEW']])
consoleMessages.length = 0
await runAndGetManifest(['manifest', 'sync', hash, 'test/http-mock', '--remove'])
await runAndGetManifest(['manifest', 'sync', hash, 'test/testpage/images', '--remove'])
expect(consoleMessages).toMatchLinesInAnyOrder([
['cheque-mock.ts', 'UNCHANGED'],
['swarm.png', 'UNCHANGED'],
['address.ts', 'REMOVED'],
['index.ts', 'REMOVED'],
['stamp.ts', 'REMOVED'],
Expand Down
11 changes: 0 additions & 11 deletions test/command/status.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { toMatchLinesInOrder } from '../custom-matcher'
import { createChequeMockHttpServer } from '../http-mock/cheque-mock'
import { describeCommand, invokeTestCli } from '../utility'

expect.extend({
toMatchLinesInOrder,
})

describeCommand('Test Status command', ({ consoleMessages }) => {
let server: ReturnType<typeof createChequeMockHttpServer>

beforeAll(() => {
server = createChequeMockHttpServer(1333)
})

afterAll(() => {
server.close()
})

it('should print when api is unavailable', async () => {
await invokeTestCli(['status', '--bee-api-url', 'http://localhost:14999'])
await invokeTestCli(['status'])
Expand Down
208 changes: 0 additions & 208 deletions test/http-mock/cheque-mock.ts

This file was deleted.

25 changes: 7 additions & 18 deletions test/misc/monetary-units.spec.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { toMatchLinesInOrder } from '../custom-matcher'
import { createChequeMockHttpServer } from '../http-mock/cheque-mock'
import { describeCommand, invokeTestCli } from '../utility'

expect.extend({
toMatchLinesInOrder,
})

describeCommand('Test Monetary units', ({ consoleMessages }) => {
let server: ReturnType<typeof createChequeMockHttpServer>

beforeAll(() => {
server = createChequeMockHttpServer(1378)
})

afterAll(() => {
server.close()
})

const containsAllSubstrings = (string: string, substrings: string[]): boolean => {
return substrings.every(substring => string.includes(substring))
}
Expand Down Expand Up @@ -58,24 +47,24 @@ describeCommand('Test Monetary units', ({ consoleMessages }) => {
})

it('should show units after running: cheque list', async () => {
await invokeTestCli(['cheque', 'list', '--bee-api-url', 'http://localhost:1378'])
await invokeTestCli(['cheque', 'list', '--bee-api-url', 'http://localhost:16337'])
expectSubstringsPrinted('Cheque Value', 'xBZZ')
})

it('should show units after running: cheque cashout', async () => {
await invokeTestCli(['cheque', 'cashout', '--all', '--bee-api-url', 'http://localhost:1378'])
await invokeTestCli(['cheque', 'cashout', '--all', '--bee-api-url', 'http://localhost:16337'])
expectSubstringsPrinted('Cheque Value', 'xBZZ')
})

it('should show units after running: balance', async () => {
await invokeTestCli(['status', '--bee-api-url', 'http://localhost:1378'])
await invokeTestCli(['status', '--bee-api-url', 'http://localhost:16337'])
const pattern = [
['Wallet'],
['xBZZ', '0.3904'],
['xDAI', '0.0961'],
['xBZZ', '10.0000000000000000'],
['xDAI', '5.000000000000000000'],
['Chequebook'],
['Available xBZZ', '10.001856'],
['Total xBZZ', '10.002685'],
['Available xBZZ', '0.0000000001000000'],
['Total xBZZ', '0.0000000001000000'],
]
expect(consoleMessages).toMatchLinesInOrder(pattern)
})
Expand Down
Loading