Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: enable waiting for postage batch to be usable by default #746

Merged
merged 3 commits into from
Jul 28, 2022
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
2 changes: 1 addition & 1 deletion src/bee-debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export class BeeDebug {

const stamp = await stamps.createPostageBatch(this.getKy(options), amount, depth, options)

if (options?.waitForUsable) {
if (options?.waitForUsable !== false) {
await this.waitForUsablePostageStamp(stamp, options?.waitForUsableTimeout)
}

Expand Down
6 changes: 3 additions & 3 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,12 @@ export interface PostageBatchOptions extends RequestOptions {
/**
* The returned Promise will await until the purchased Postage Batch is usable.
* In other word, it has to have enough block confirmations that Bee pronounce it usable.
* If turned on, this significantly prolong the creation of postage batch!
* When turned on, this significantly prolongs the creation of postage batch!
*
* If you plan to use the stamp right away for some action with Bee (like uploading using this stamp) it is
* highly recommended to use this option, otherwise you might get errors "stamp not usable" from Bee.
*
* In next breaking release this option will be turned on by default.
* @default false
* @default true
*/
waitForUsable?: boolean

Expand Down
18 changes: 9 additions & 9 deletions test/integration/bee-debug-class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ describe('Bee Debug class', () => {

describe('PostageBatch', () => {
it(
'should create a new postage batch with zero amount',
'should create a new postage batch with zero amount and be usable',
async () => {
const batchId = await beeDebug.createPostageBatch('10', 17)
const stamp = await beeDebug.getPostageBatch(batchId)
expect(stamp.usable).toEqual(false)
expect(stamp.usable).toEqual(true)

const allBatches = await beeDebug.getAllPostageBatch()
expect(allBatches.find(batch => batch.batchID === batchId)).toBeTruthy()
},
BLOCKCHAIN_TRANSACTION_TIMEOUT,
WAITING_USABLE_STAMP_TIMEOUT + BLOCKCHAIN_TRANSACTION_TIMEOUT,
)

it(
'should wait for the stamp to be usable',
'should not wait for the stamp to be usable if specified',
async () => {
const batchId = await beeDebug.createPostageBatch('1000', 17, { waitForUsable: true })
const batchId = await beeDebug.createPostageBatch('1000', 17, { waitForUsable: false })
const stamp = await beeDebug.getPostageBatch(batchId)
expect(stamp.usable).toEqual(true)
expect(stamp.usable).toEqual(false)
},
WAITING_USABLE_STAMP_TIMEOUT + BLOCKCHAIN_TRANSACTION_TIMEOUT,
BLOCKCHAIN_TRANSACTION_TIMEOUT,
)

// TODO: Finish topup and dilute testing https://github.com/ethersphere/bee-js/issues/427
Expand Down Expand Up @@ -70,8 +70,8 @@ describe('Bee Debug class', () => {
it(
'should have both immutable true and false',
async () => {
await beeDebug.createPostageBatch('1', 17, { immutableFlag: true })
await beeDebug.createPostageBatch('1', 17, { immutableFlag: false })
await beeDebug.createPostageBatch('1', 17, { immutableFlag: true, waitForUsable: false })
await beeDebug.createPostageBatch('1', 17, { immutableFlag: false, waitForUsable: false })
const allBatches = await beeDebug.getAllPostageBatch()

expect(allBatches.find(batch => batch.immutableFlag === true)).toBeTruthy()
Expand Down
6 changes: 4 additions & 2 deletions test/unit/bee-debug-class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,17 @@ describe('BeeDebug class', () => {
createPostageBatchMock('10', '17').reply(201, BATCH_RESPONSE)

const bee = new BeeDebug(MOCK_SERVER_URL)
await expect(bee.createPostageBatch('10', 17)).resolves.toEqual(BATCH_ID)
await expect(bee.createPostageBatch('10', 17, { waitForUsable: false })).resolves.toEqual(BATCH_ID)
assertAllIsDone()
})

it('should pass headers if gas price is specified', async () => {
createPostageBatchMock('10', '17', '100').reply(201, BATCH_RESPONSE)

const bee = new BeeDebug(MOCK_SERVER_URL)
await expect(bee.createPostageBatch('10', 17, { gasPrice: '100' })).resolves.toEqual(BATCH_ID)
await expect(bee.createPostageBatch('10', 17, { waitForUsable: false, gasPrice: '100' })).resolves.toEqual(
BATCH_ID,
)
assertAllIsDone()
})

Expand Down