11import { Bee , Size , Utils } from '../../src'
22import { Duration } from '../../src/utils/duration'
3- import { mocked } from '../mocks'
3+
4+ const bee = new Bee ( 'http://localhost:16337' )
45
56test ( 'Utils.getDepthForSize' , ( ) => {
67 expect ( Utils . getDepthForSize ( Size . fromGigabytes ( 0 ) ) ) . toBe ( 17 )
@@ -21,86 +22,79 @@ test('Utils.getAmountForDuration', () => {
2122} )
2223
2324test ( 'bee.getStorageCost' , async ( ) => {
24- await mocked ( async bee => {
25- const bzz = await bee . getStorageCost ( Size . fromGigabytes ( 4 ) , Duration . fromDays ( 1 ) )
26- expect ( bzz . toSignificantDigits ( 3 ) ) . toBe ( '0.192' )
27- } )
25+ const bzz = await bee . getStorageCost ( Size . fromGigabytes ( 1 ) , Duration . fromDays ( 2 ) )
26+ expect ( bzz . toSignificantDigits ( 4 ) ) . toBe ( '0.1739' )
27+ } )
28+
29+ test ( 'bee.getDurationExtensionCost for 1GB/2days' , async ( ) => {
30+ const batchId = await bee . buyStorage ( Size . fromGigabytes ( 1 ) , Duration . fromDays ( 2 ) )
31+ const bzz = await bee . getDurationExtensionCost ( batchId , Duration . fromDays ( 2 ) )
32+ expect ( bzz . toSignificantDigits ( 4 ) ) . toBe ( '0.1739' )
33+ } )
34+
35+ test ( 'bee.getSizeExtensionCost for 1GB/2days' , async ( ) => {
36+ const batchId = await bee . buyStorage ( Size . fromGigabytes ( 1 ) , Duration . fromDays ( 2 ) )
37+ const bzz = await bee . getSizeExtensionCost ( batchId , Size . fromGigabytes ( 3 ) )
38+ expect ( bzz . toSignificantDigits ( 4 ) ) . toBe ( '0.1739' )
39+ } )
40+
41+ test ( 'bee.getExtensionCost (size) for 1GB/2days' , async ( ) => {
42+ const batchId = await bee . buyStorage ( Size . fromGigabytes ( 1 ) , Duration . fromDays ( 2 ) )
43+ const bzz = await bee . getExtensionCost ( batchId , Size . fromGigabytes ( 3 ) , Duration . ZERO )
44+ expect ( bzz . toSignificantDigits ( 4 ) ) . toBe ( '0.1739' )
45+ } )
46+
47+ test ( 'bee.getExtensionCost (duration) for 1GB/2days' , async ( ) => {
48+ const batchId = await bee . buyStorage ( Size . fromGigabytes ( 1 ) , Duration . fromDays ( 2 ) )
49+ const bzz = await bee . getExtensionCost ( batchId , Size . fromGigabytes ( 1 ) , Duration . fromDays ( 2 ) )
50+ expect ( bzz . toSignificantDigits ( 4 ) ) . toBe ( '0.1739' )
2851} )
2952
3053test ( 'bee.getDurationExtensionCost' , async ( ) => {
31- await mocked ( async bee => {
32- const cost = await bee . getDurationExtensionCost (
33- 'f8b2ad296d64824a8fe51a33ff15fe8668df13a20ad3d4eea4bb97ca600029aa' ,
34- Duration . fromDays ( 31 ) ,
35- )
36- expect ( cost . toSignificantDigits ( 3 ) ) . toBe ( '11.934' )
37- } )
54+ const batchId = await bee . buyStorage ( Size . fromGigabytes ( 8 ) , Duration . fromDays ( 1 ) )
55+ const cost = await bee . getDurationExtensionCost ( batchId , Duration . fromDays ( 31 ) )
56+ expect ( cost . toSignificantDigits ( 3 ) ) . toBe ( '10.784' )
3857} )
3958
4059test ( 'bee.getSizeExtensionCost' , async ( ) => {
41- await mocked ( async bee => {
42- const cost = await bee . getSizeExtensionCost (
43- 'f8b2ad296d64824a8fe51a33ff15fe8668df13a20ad3d4eea4bb97ca600029aa' ,
44- Size . fromGigabytes ( 19 ) ,
45- )
46- expect ( cost . toSignificantDigits ( 3 ) ) . toBe ( '72.011' )
47-
48- await expect ( async ( ) =>
49- bee . getSizeExtensionCost (
50- 'f8b2ad296d64824a8fe51a33ff15fe8668df13a20ad3d4eea4bb97ca600029aa' ,
51- Size . fromGigabytes ( 1 ) ,
52- ) ,
53- ) . rejects . toThrow ( 'New depth has to be greater than the original depth' )
54- } )
60+ const batchId = await bee . buyStorage ( Size . fromGigabytes ( 8 ) , Duration . fromDays ( 31 ) )
61+ const cost = await bee . getSizeExtensionCost ( batchId , Size . fromGigabytes ( 100 ) )
62+ expect ( cost . toSignificantDigits ( 3 ) ) . toBe ( '75.492' )
63+
64+ await expect ( async ( ) => bee . getSizeExtensionCost ( batchId , Size . fromGigabytes ( 1 ) ) ) . rejects . toThrow (
65+ 'New depth has to be greater than the original depth' ,
66+ )
5567} )
5668
5769test ( 'bee.getExtensionCost' , async ( ) => {
58- await mocked ( async ( bee : Bee ) => {
59- const cost = await bee . getExtensionCost (
60- 'f8b2ad296d64824a8fe51a33ff15fe8668df13a20ad3d4eea4bb97ca600029aa' ,
61- Size . fromGigabytes ( 18 ) ,
62- Duration . fromYears ( 1 ) ,
63- )
64- expect ( cost . toDecimalString ( ) ) . toBe ( '68.5035408119037952' )
65- } )
70+ const batchId = await bee . buyStorage ( Size . fromGigabytes ( 8 ) , Duration . fromDays ( 31 ) )
71+ const cost = await bee . getExtensionCost ( batchId , Size . fromGigabytes ( 18 ) , Duration . fromYears ( 1 ) )
72+ expect ( cost . toDecimalString ( ) ) . toBe ( '126.9807081070788608' )
6673} )
6774
68- test ( 'bee.buyStorage with extensions' , async ( ) => {
69- const calls = await mocked ( async ( bee : Bee ) => {
70- const batchId = await bee . buyStorage ( Size . fromGigabytes ( 1 ) , Duration . fromDays ( 1 ) )
71- await bee . buyStorage ( Size . fromGigabytes ( 1 ) , Duration . fromDays ( 1 ) , { waitForUsable : false } )
72- await bee . extendStorageDuration ( batchId , Duration . fromDays ( 1 ) )
73- await bee . extendStorageSize ( batchId , Size . fromGigabytes ( 8 ) )
74- await bee . extendStorageSize ( batchId , Size . fromGigabytes ( 24 ) )
75- await expect ( async ( ) => bee . extendStorageSize ( batchId , Size . fromGigabytes ( 1 ) ) ) . rejects . toThrow (
76- 'New depth has to be greater than the original depth' ,
77- )
78- } )
79- expect ( calls . map ( x => `${ x . method } ${ x . url } ` ) ) . toEqual ( [
80- // create stamp
81- 'GET /chainstate' ,
82- 'GET /chainstate' ,
83- 'POST /stamps/458922241/21' ,
84- 'GET /stamps/b330000000000000000000000000000000000000000000000000000000000000' ,
85- // create stamp, do not wait for usable
86- 'GET /chainstate' ,
87- 'GET /chainstate' ,
88- 'POST /stamps/458922241/21' ,
89- // extend duration
90- 'GET /stamps/b330000000000000000000000000000000000000000000000000000000000000' ,
91- 'GET /chainstate' ,
92- 'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/458922241' ,
93- // extend size +1 depth
94- 'GET /stamps/b330000000000000000000000000000000000000000000000000000000000000' ,
95- 'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/458922241' ,
96- 'PATCH /stamps/dilute/b330000000000000000000000000000000000000000000000000000000000000/23' ,
97- // extend size +2 depth
98- 'GET /stamps/b330000000000000000000000000000000000000000000000000000000000000' ,
99- 'PATCH /stamps/topup/b330000000000000000000000000000000000000000000000000000000000000/917844481' ,
100- 'PATCH /stamps/dilute/b330000000000000000000000000000000000000000000000000000000000000/24' ,
101- // error case
102- 'GET /stamps/b330000000000000000000000000000000000000000000000000000000000000' ,
103- ] )
75+ test ( 'bee.buyStorage with extensions (extendStorageDuration, extendStorageSize)' , async ( ) => {
76+ const batchId = await bee . buyStorage ( Size . fromGigabytes ( 1 ) , Duration . fromDays ( 1 ) )
77+ await bee . extendStorageDuration ( batchId , Duration . fromDays ( 1 ) )
78+ await bee . extendStorageSize ( batchId , Size . fromGigabytes ( 8 ) )
79+ await bee . extendStorageSize ( batchId , Size . fromGigabytes ( 24 ) )
80+ await expect ( async ( ) => bee . extendStorageSize ( batchId , Size . fromGigabytes ( 1 ) ) ) . rejects . toThrow (
81+ 'New depth has to be greater than the original depth' ,
82+ )
83+ const batch = await bee . getPostageBatch ( batchId )
84+ expect ( batch . depth ) . toBe ( 24 )
85+ expect ( batch . duration . toDays ( ) ) . toBe ( 2 )
86+ expect ( BigInt ( batch . amount ) ) . toBe ( Utils . getAmountForDuration ( Duration . fromDays ( 2 ) , 24000 , 5 ) + 1n )
87+ } )
88+
89+ test ( 'bee.buyStorage with extensions (extendStorage)' , async ( ) => {
90+ const batchId = await bee . buyStorage ( Size . fromGigabytes ( 1 ) , Duration . fromDays ( 1 ) )
91+ await bee . extendStorage ( batchId , Size . fromGigabytes ( 1 ) , Duration . fromDays ( 1 ) )
92+ await bee . extendStorage ( batchId , Size . fromGigabytes ( 8 ) , Duration . ZERO )
93+ await bee . extendStorage ( batchId , Size . fromGigabytes ( 24 ) , Duration . ZERO )
94+ const batch = await bee . getPostageBatch ( batchId )
95+ expect ( batch . depth ) . toBe ( 24 )
96+ expect ( batch . duration . toDays ( ) ) . toBe ( 2 )
97+ expect ( BigInt ( batch . amount ) ) . toBe ( Utils . getAmountForDuration ( Duration . fromDays ( 2 ) , 24000 , 5 ) + 1n )
10498} )
10599
106100test ( 'getStampEffectiveBytesBreakpoints' , ( ) => {
0 commit comments