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
14 changes: 13 additions & 1 deletion src/command/stamp/create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BatchId, Duration, Size } from '@ethersphere/bee-js'
import { Dates, Numbers } from 'cafe-utility'
import chalk from 'chalk'
import { LeafCommand, Option } from 'furious-commander'
import { LeafCommand, Option, Utils } from 'furious-commander'
import { exit } from 'process'
import { isChainStateReady } from '../../utils/chainsync'
import { createSpinner } from '../../utils/spinner'
Expand Down Expand Up @@ -43,6 +43,10 @@ export class Create extends StampCommand implements LeafCommand {

public postageBatchId!: BatchId

private shouldAskForImmutable(): boolean {
return !this.quiet && !this.yes && Utils.getSourcemap()['immutable'] === 'default'
}

public async run(): Promise<void> {
super.init()

Expand Down Expand Up @@ -80,6 +84,14 @@ export class Create extends StampCommand implements LeafCommand {
return
}

if (this.shouldAskForImmutable()) {
this.console.log('Please select the type of the postage stamp')
this.console.log(`${chalk.bold('Immutable')}: at full capacity, new uploads are rejected`)
this.console.log(`${chalk.bold('Mutable')}: at full capacity, new uploads overwrite old content`)
this.immutable = (await this.console.promptList(['Immutable', 'Mutable'], 'Type')) === 'Immutable'
this.console.log('')
}

this.console.log('You have provided the following parameters:')
this.console.log(createKeyValue('Capacity', size.toFormattedString()))
this.console.log(createKeyValue('TTL', Dates.secondsToHumanTime(duration.toSeconds())))
Expand Down
25 changes: 25 additions & 0 deletions test/prompt/stamp-prompt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ describeCommand('Postage stamp prompt', ({ consoleMessages, getNthLastMessage })
})
})

describe('Stamp type', () => {
it('stamp create should prompt for immutable or mutable', async () => {
jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: 'Mutable' }).mockResolvedValueOnce({ value: false })
await invokeTestCli(['stamp', 'create', '--capacity', '1GB', '--ttl', '1d'])
expect(inquirer.prompt).toHaveBeenCalledWith({
message: 'Type',
name: 'value',
prefix: chalk.bold.cyan('?'),
type: 'list',
choices: ['Immutable', 'Mutable'],
loop: false,
})
expect(consoleMessages).toContain(createKeyValue('Type', 'Mutable'))
})

it('stamp create should not prompt for type when it is given', async () => {
const prompt = jest.spyOn(inquirer, 'prompt')
prompt.mockClear()
prompt.mockResolvedValueOnce({ value: false })
await invokeTestCli(['stamp', 'create', '--capacity', '1GB', '--ttl', '1d', '--immutable', 'false'])
expect(prompt).not.toHaveBeenCalledWith(expect.objectContaining({ type: 'list' }))
expect(consoleMessages).toContain(createKeyValue('Type', 'Mutable'))
})
})

describe('Rename postage stamp', () => {
it('should prompt for new name', async () => {
jest.spyOn(inquirer, 'prompt').mockResolvedValueOnce({ value: 'new-stamp-name' })
Expand Down
Loading