@@ -2,7 +2,7 @@ const I128 = StellarBase.Int128;
22const U128 = StellarBase . Uint128 ;
33const I256 = StellarBase . Int256 ;
44const U256 = StellarBase . Uint256 ;
5- const { xdr, XdrLargeInt } = StellarBase ; // shorthand
5+ const { xdr, Int } = StellarBase ; // shorthand
66
77describe ( 'creating large integers' , function ( ) {
88 describe ( 'picks the right types' , function ( ) {
@@ -14,7 +14,7 @@ describe('creating large integers', function () {
1414 } ) . forEach ( ( [ type , values ] ) => {
1515 values . forEach ( ( value ) => {
1616 it ( `picks ${ type } for ${ value } ` , function ( ) {
17- const bi = XdrLargeInt . fromValue ( value ) ;
17+ const bi = Int . fromValue ( value ) ;
1818 expect ( bi . type ) . to . equal ( type ) ;
1919 expect ( bi . toBigInt ( ) ) . to . equal ( BigInt ( value ) ) ;
2020 } ) ;
@@ -25,7 +25,7 @@ describe('creating large integers', function () {
2525 it ( 'has correct utility methods' , function ( ) {
2626 const v =
2727 123456789123456789123456789123456789123456789123456789123456789123456789n ;
28- const i = XdrLargeInt . fromValue ( v ) ;
28+ const i = Int . fromValue ( v ) ;
2929 expect ( i . valueOf ( ) ) . to . be . eql ( new U256 ( v ) ) ;
3030 expect ( i . toString ( ) ) . to . equal ( v . toString ( ) ) ;
3131 expect ( i . toJSON ( ) ) . to . be . eql ( { value : v . toString ( ) , type : 'u256' } ) ;
@@ -35,14 +35,14 @@ describe('creating large integers', function () {
3535 const sentinel = 800000085n ;
3636
3737 it ( 'handles u64' , function ( ) {
38- let b = XdrLargeInt . fromValue ( sentinel ) ;
38+ let b = Int . fromValue ( sentinel ) ;
3939 expect ( b . toBigInt ( ) ) . to . equal ( sentinel ) ;
4040 expect ( b . toNumber ( ) ) . to . equal ( Number ( sentinel ) ) ;
4141 let u64 = b . toU64 ( ) . u64 ( ) ;
4242 expect ( u64 . low ) . to . equal ( Number ( sentinel ) ) ;
4343 expect ( u64 . high ) . to . equal ( 0 ) ;
4444
45- b = XdrLargeInt . fromValue ( - sentinel ) ;
45+ b = Int . fromValue ( - sentinel ) ;
4646 expect ( b . toBigInt ( ) ) . to . equal ( - sentinel ) ;
4747 expect ( b . toNumber ( ) ) . to . equal ( Number ( - sentinel ) ) ;
4848 u64 = b . toU64 ( ) . u64 ( ) ;
@@ -51,7 +51,7 @@ describe('creating large integers', function () {
5151 } ) ;
5252
5353 it ( 'handles i64' , function ( ) {
54- let b = XdrLargeInt . fromValue ( sentinel ) ;
54+ let b = Int . fromValue ( sentinel ) ;
5555 expect ( b . toBigInt ( ) ) . to . equal ( sentinel ) ;
5656 expect ( b . toNumber ( ) ) . to . equal ( Number ( sentinel ) ) ;
5757 let i64 = b . toI64 ( ) . i64 ( ) ;
@@ -60,14 +60,14 @@ describe('creating large integers', function () {
6060 } ) ;
6161
6262 it ( `upscales u64 to 128` , function ( ) {
63- const b = XdrLargeInt . fromValue ( sentinel ) ;
63+ const b = Int . fromValue ( sentinel ) ;
6464 const i128 = b . toI128 ( ) . i128 ( ) ;
6565 expect ( i128 . lo ( ) . toBigInt ( ) ) . to . equal ( sentinel ) ;
6666 expect ( i128 . hi ( ) . toBigInt ( ) ) . to . equal ( 0n ) ;
6767 } ) ;
6868
6969 it ( `upscales i64 to 128` , function ( ) {
70- const b = XdrLargeInt . fromValue ( - sentinel ) ;
70+ const b = Int . fromValue ( - sentinel ) ;
7171 const i128 = b . toI128 ( ) . i128 ( ) ;
7272 const hi = i128 . hi ( ) . toBigInt ( ) ;
7373 const lo = i128 . lo ( ) . toBigInt ( ) ;
@@ -77,7 +77,7 @@ describe('creating large integers', function () {
7777 } ) ;
7878
7979 it ( `upscales i64 to 256` , function ( ) {
80- const b = XdrLargeInt . fromValue ( sentinel ) ;
80+ const b = Int . fromValue ( sentinel ) ;
8181 const i = b . toI256 ( ) . i256 ( ) ;
8282
8383 const [ hiHi , hiLo , loHi , loLo ] = [
@@ -100,7 +100,7 @@ describe('creating large integers', function () {
100100 } ) ;
101101
102102 it ( `upscales i64 to 256` , function ( ) {
103- const b = XdrLargeInt . fromValue ( - sentinel ) ;
103+ const b = Int . fromValue ( - sentinel ) ;
104104 const i = b . toI256 ( ) . i256 ( ) ;
105105
106106 const [ hiHi , hiLo , loHi , loLo ] = [
@@ -127,7 +127,7 @@ describe('creating large integers', function () {
127127 const sentinel = 800000000000000000000085n ; // 80 bits long
128128
129129 it ( 'handles inputs' , function ( ) {
130- let b = XdrLargeInt . fromValue ( sentinel ) ;
130+ let b = Int . fromValue ( sentinel ) ;
131131 expect ( b . toBigInt ( ) ) . to . equal ( sentinel ) ;
132132 expect ( ( ) => b . toNumber ( ) ) . to . throw ( / n o t i n r a n g e / i) ;
133133 expect ( ( ) => b . toU64 ( ) ) . to . throw ( / t o o l a r g e / i) ;
@@ -143,7 +143,7 @@ describe('creating large integers', function () {
143143 ] ) . toBigInt ( )
144144 ) . to . equal ( sentinel ) ;
145145
146- b = XdrLargeInt . fromValue ( - sentinel ) ;
146+ b = Int . fromValue ( - sentinel ) ;
147147 u128 = b . toU128 ( ) . u128 ( ) ;
148148 expect (
149149 new U128 ( [
@@ -154,7 +154,7 @@ describe('creating large integers', function () {
154154 ] ) . toBigInt ( )
155155 ) . to . equal ( BigInt . asUintN ( 128 , - sentinel ) ) ;
156156
157- b = XdrLargeInt . fromValue ( sentinel ) ;
157+ b = Int . fromValue ( sentinel ) ;
158158 let i128 = b . toI128 ( ) . i128 ( ) ;
159159 expect (
160160 new I128 ( [
@@ -165,7 +165,7 @@ describe('creating large integers', function () {
165165 ] ) . toBigInt ( )
166166 ) . to . equal ( sentinel ) ;
167167
168- b = XdrLargeInt . fromValue ( - sentinel ) ;
168+ b = Int . fromValue ( - sentinel ) ;
169169 i128 = b . toI128 ( ) . i128 ( ) ;
170170 expect (
171171 new I128 ( [
@@ -178,7 +178,7 @@ describe('creating large integers', function () {
178178 } ) ;
179179
180180 it ( 'upscales to 256 bits' , function ( ) {
181- let b = XdrLargeInt . fromValue ( - sentinel ) ;
181+ let b = Int . fromValue ( - sentinel ) ;
182182 let i256 = b . toI256 ( ) . i256 ( ) ;
183183 let u256 = b . toU256 ( ) . u256 ( ) ;
184184
@@ -212,7 +212,7 @@ describe('creating large integers', function () {
212212
213213 describe ( 'conversion to/from ScVals' , function ( ) {
214214 const v = 80000085n ;
215- const i = XdrLargeInt . fromValue ( v ) ;
215+ const i = Int . fromValue ( v ) ;
216216
217217 [
218218 [ i . toI64 ( ) , 'i64' ] ,
@@ -226,9 +226,9 @@ describe('creating large integers', function () {
226226 expect ( scv . switch ( ) . name ) . to . equal ( `scv${ type . toUpperCase ( ) } ` ) ;
227227 expect ( typeof scv . toXDR ( 'base64' ) ) . to . equal ( 'string' ) ;
228228
229- const bigi = StellarBase . XdrLargeInt . fromScVal ( scv ) . toBigInt ( ) ;
229+ const bigi = StellarBase . Int . fromScVal ( scv ) . toBigInt ( ) ;
230230 expect ( bigi ) . to . equal ( v ) ;
231- expect ( new StellarBase . XdrLargeInt ( type , bigi ) . toJSON ( ) ) . to . eql ( {
231+ expect ( new StellarBase . Int ( type , bigi ) . toJSON ( ) ) . to . eql ( {
232232 ...i . toJSON ( ) ,
233233 type
234234 } ) ;
@@ -239,44 +239,44 @@ describe('creating large integers', function () {
239239 const i32 = new xdr . ScVal . scvI32 ( Number ( v ) ) ;
240240 const u32 = new xdr . ScVal . scvU32 ( Number ( v ) ) ;
241241
242- expect ( XdrLargeInt . fromScVal ( i32 ) . toBigInt ( ) ) . to . equal ( v ) ;
243- expect ( XdrLargeInt . fromScVal ( u32 ) . toBigInt ( ) ) . to . equal ( v ) ;
242+ expect ( Int . fromScVal ( i32 ) . toBigInt ( ) ) . to . equal ( v ) ;
243+ expect ( Int . fromScVal ( u32 ) . toBigInt ( ) ) . to . equal ( v ) ;
244244 } ) ;
245245
246246 it ( 'throws for non-integers' , function ( ) {
247247 expect ( ( ) =>
248- XdrLargeInt . fromScVal ( new xdr . ScVal . scvString ( 'hello' ) )
248+ Int . fromScVal ( new xdr . ScVal . scvString ( 'hello' ) )
249249 ) . to . throw ( / i n t e g e r / i) ;
250250 } ) ;
251251 } ) ;
252252
253253 describe ( 'error handling' , function ( ) {
254254 [ 'u64' , 'u128' , 'u256' ] . forEach ( ( type ) => {
255255 it ( `throws when signed parts and {type: '${ type } '}` , function ( ) {
256- expect ( ( ) => new StellarBase . XdrLargeInt ( type , - 2 ) ) . to . throw (
256+ expect ( ( ) => new StellarBase . Int ( type , - 2 ) ) . to . throw (
257257 / p o s i t i v e / i
258258 ) ;
259259 } ) ;
260260 } ) ;
261261
262262 it ( 'throws when too big' , function ( ) {
263- expect ( ( ) => XdrLargeInt . fromValue ( 1n << 400n ) ) . to . throw ( / e x p e c t e d / i) ;
263+ expect ( ( ) => Int . fromValue ( 1n << 400n ) ) . to . throw ( / e x p e c t e d / i) ;
264264 } ) ;
265265
266266 it ( 'throws when big interpreted as small' , function ( ) {
267267 let big ;
268268
269- big = XdrLargeInt . fromValue ( 1n << 64n ) ;
269+ big = Int . fromValue ( 1n << 64n ) ;
270270 expect ( ( ) => big . toNumber ( ) ) . to . throw ( / n o t i n r a n g e / i) ;
271271
272- big = XdrLargeInt . fromValue ( Number . MAX_SAFE_INTEGER + 1 ) ;
272+ big = Int . fromValue ( Number . MAX_SAFE_INTEGER + 1 ) ;
273273 expect ( ( ) => big . toNumber ( ) ) . to . throw ( / n o t i n r a n g e / i) ;
274274
275- big = new XdrLargeInt ( 'i128' , 1 ) ;
275+ big = new Int ( 'i128' , 1 ) ;
276276 expect ( ( ) => big . toU64 ( ) ) . to . throw ( / t o o l a r g e / i) ;
277277 expect ( ( ) => big . toI64 ( ) ) . to . throw ( / t o o l a r g e / i) ;
278278
279- big = new XdrLargeInt ( 'i256' , 1 ) ;
279+ big = new Int ( 'i256' , 1 ) ;
280280 expect ( ( ) => big . toU64 ( ) ) . to . throw ( / t o o l a r g e / i) ;
281281 expect ( ( ) => big . toI64 ( ) ) . to . throw ( / t o o l a r g e / i) ;
282282 expect ( ( ) => big . toI128 ( ) ) . to . throw ( / t o o l a r g e / i) ;
@@ -294,7 +294,7 @@ describe('creating raw large XDR integers', function () {
294294 ] . forEach ( ( [ type , count ] , idx ) => {
295295 it ( `works for ${ type } ` , function ( ) {
296296 const input = new Array ( count ) . fill ( 1n ) ;
297- const xdrI = new StellarBase . XdrLargeInt ( type , input ) ;
297+ const xdrI = new StellarBase . Int ( type , input ) ;
298298
299299 let expected = input . reduce ( ( accum , v , i ) => {
300300 return ( accum << 32n ) | v ;
0 commit comments