mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-26 07:05:49 +00:00
198 lines
8.5 KiB
TypeScript
198 lines
8.5 KiB
TypeScript
import { UInt8, UInt64 } from '../src/types'
|
|
import { encode, decode } from '../src'
|
|
|
|
const binary =
|
|
'11007222000300003700000000000000003800000000000000006280000000000000000000000000000000000000005553440000000000000000000000000000000000000000000000000166D5438D7EA4C680000000000000000000000000005553440000000000AE123A8556F3CF91154711376AFB0F894F832B3D67D5438D7EA4C680000000000000000000000000005553440000000000F51DFC2A09D62CBBA1DFBDD4691DAC96AD98B90F'
|
|
const json = {
|
|
Balance: {
|
|
currency: 'USD',
|
|
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
|
|
value: '0',
|
|
},
|
|
Flags: 196608,
|
|
HighLimit: {
|
|
currency: 'USD',
|
|
issuer: 'rPMh7Pi9ct699iZUTWaytJUoHcJ7cgyziK',
|
|
value: '1000',
|
|
},
|
|
HighNode: '0',
|
|
LedgerEntryType: 'RippleState',
|
|
LowLimit: {
|
|
currency: 'USD',
|
|
issuer: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn',
|
|
value: '1000',
|
|
},
|
|
LowNode: '0',
|
|
}
|
|
|
|
const binaryEntry0 =
|
|
'11007222001100002501EC24873700000000000000003800000000000000A35506FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA62D44BF89AC2A40B800000000000000000000000004A50590000000000000000000000000000000000000000000000000166D6C38D7EA4C680000000000000000000000000004A5059000000000047C1258B4B79774B28176324068F759EDE226F686780000000000000000000000000000000000000004A505900000000005BBC0F22F61D9224A110650CFE21CC0C4BE13098'
|
|
const jsonEntry0 = {
|
|
Balance: {
|
|
currency: 'JPY',
|
|
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
|
|
value: '0.3369568318',
|
|
},
|
|
Flags: 1114112,
|
|
HighLimit: {
|
|
currency: 'JPY',
|
|
issuer: 'r94s8px6kSw1uZ1MV98dhSRTvc6VMPoPcN',
|
|
value: '0',
|
|
},
|
|
HighNode: 'a3',
|
|
LedgerEntryType: 'RippleState',
|
|
LowLimit: {
|
|
currency: 'JPY',
|
|
issuer: 'rfYQMgj3g3Qp8VLoZNvvU35mEuuJC8nCmY',
|
|
value: '1000000000',
|
|
},
|
|
LowNode: '0',
|
|
PreviousTxnID:
|
|
'06FC7DE374089D50F81AAE13E7BBF3D0E694769331E14F55351B38D0148018EA',
|
|
PreviousTxnLgrSeq: 32253063,
|
|
index: '000319BAE0A618A7D3BB492F17E98E5D92EA0C6458AFEBED44206B5B4798A840',
|
|
}
|
|
|
|
const binaryEntry1 =
|
|
'1100642200000000320000000000000002580CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E7528214BA53D10260FFCC968ACD16BA30F7CEABAD6E5D92011340A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6AE1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F'
|
|
const jsonEntry1 = {
|
|
Flags: 0,
|
|
IndexPrevious: '2',
|
|
Indexes: [
|
|
'A3454ACED87177146EABD5E4A256021D836D1E3617618B1EB362D10B0D1BAC6A',
|
|
'E1ED9E8D280BBE0B6656748FD647231851C6C650794D5E6852DFA1E35E68630F',
|
|
],
|
|
LedgerEntryType: 'DirectoryNode',
|
|
Owner: 'rHzDaMNybxQppiE3uWyt2N265KvAKdiRdP',
|
|
RootIndex: '0CB3C1AD2C371136AEA434246D971C5FCCD32CBF520667E131AB7B10D706E752',
|
|
index: '0B4A2E68C111F7E42FAEEE405F7344560C8240840B151D9D04131EB79D080167',
|
|
}
|
|
|
|
const binaryEntry2 =
|
|
'1100722200210000250178D1CA37000000000000000038000000000000028355C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D66946280000000000000000000000000000000000000004743420000000000000000000000000000000000000000000000000166D6071AFD498D000000000000000000000000000047434200000000002599D1D255BCA61189CA64C84528F2FCBE4BFC3867800000000000000000000000000000000000000047434200000000006EEBB1D1852CE667876A0B3630861FB6C6AB358E'
|
|
const jsonEntry2 = {
|
|
Balance: {
|
|
currency: 'GCB',
|
|
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
|
|
value: '0',
|
|
},
|
|
Flags: 2162688,
|
|
HighLimit: {
|
|
currency: 'GCB',
|
|
issuer: 'rBfVgTnsdh8ckC19RM8aVGNuMZnpwrMP6n',
|
|
value: '0',
|
|
},
|
|
HighNode: '283',
|
|
LedgerEntryType: 'RippleState',
|
|
LowLimit: {
|
|
currency: 'GCB',
|
|
issuer: 'rhRFGCy2RJTA8oxkjjtYTvofPVGqcgvXWj',
|
|
value: '2000000',
|
|
},
|
|
LowNode: '0',
|
|
PreviousTxnID:
|
|
'C0C37CE200B509E0A529880634F7841A9EF4CB65F03C12E6004CFAD9718D6694',
|
|
PreviousTxnLgrSeq: 24695242,
|
|
index: '0000041EFD027808D3F78C8352F97E324CB816318E00B977C74ECDDC7CD975B2',
|
|
}
|
|
|
|
const mptIssuanceEntryBinary =
|
|
'11007E220000006224000002DF25000002E434000000000000000030187FFFFFFFFFFFFFFF30190000000000000064552E78C1FFBDDAEE077253CEB12CFEA83689AA0899F94762190A357208DADC76FE701EC1EC7B226E616D65223A2255532054726561737572792042696C6C20546F6B656E222C2273796D626F6C223A225553544254222C22646563696D616C73223A322C22746F74616C537570706C79223A313030303030302C22697373756572223A225553205472656173757279222C22697373756544617465223A22323032342D30332D3235222C226D6174757269747944617465223A22323032352D30332D3235222C226661636556616C7565223A2231303030222C22696E74657265737452617465223A22322E35222C22696E7465726573744672657175656E6379223A22517561727465726C79222C22636F6C6C61746572616C223A22555320476F7665726E6D656E74222C226A7572697364696374696F6E223A22556E6974656420537461746573222C22726567756C61746F7279436F6D706C69616E6365223A2253454320526567756C6174696F6E73222C22736563757269747954797065223A2254726561737572792042696C6C222C2265787465726E616C5F75726C223A2268747470733A2F2F6578616D706C652E636F6D2F742D62696C6C2D746F6B656E2D6D657461646174612E6A736F6E227D8414A4D893CFBC4DC6AE877EB585F90A3B47528B958D051003'
|
|
|
|
const mptIssuanceEntryJson = {
|
|
AssetScale: 3,
|
|
Flags: 98,
|
|
Issuer: 'rGpdGXDV2RFPeLEfWS9RFo5Nh9cpVDToZa',
|
|
LedgerEntryType: 'MPTokenIssuance',
|
|
MPTokenMetadata:
|
|
'7B226E616D65223A2255532054726561737572792042696C6C20546F6B656E222C2273796D626F6C223A225553544254222C22646563696D616C73223A322C22746F74616C537570706C79223A313030303030302C22697373756572223A225553205472656173757279222C22697373756544617465223A22323032342D30332D3235222C226D6174757269747944617465223A22323032352D30332D3235222C226661636556616C7565223A2231303030222C22696E74657265737452617465223A22322E35222C22696E7465726573744672657175656E6379223A22517561727465726C79222C22636F6C6C61746572616C223A22555320476F7665726E6D656E74222C226A7572697364696374696F6E223A22556E6974656420537461746573222C22726567756C61746F7279436F6D706C69616E6365223A2253454320526567756C6174696F6E73222C22736563757269747954797065223A2254726561737572792042696C6C222C2265787465726E616C5F75726C223A2268747470733A2F2F6578616D706C652E636F6D2F742D62696C6C2D746F6B656E2D6D657461646174612E6A736F6E227D',
|
|
MaximumAmount: '9223372036854775807',
|
|
OutstandingAmount: '100',
|
|
OwnerNode: '0000000000000000',
|
|
PreviousTxnID:
|
|
'2E78C1FFBDDAEE077253CEB12CFEA83689AA0899F94762190A357208DADC76FE',
|
|
PreviousTxnLgrSeq: 740,
|
|
Sequence: 735,
|
|
}
|
|
|
|
const mptokenEntryJson = {
|
|
Account: 'raDQsd1s8rqGjL476g59a9vVNi1rSwrC44',
|
|
Flags: 0,
|
|
LedgerEntryType: 'MPToken',
|
|
MPTAmount: '100',
|
|
MPTokenIssuanceID: '000002DF71CAE59C9B7E56587FFF74D4EA5830D9BE3CE0CC',
|
|
OwnerNode: '0000000000000000',
|
|
PreviousTxnID:
|
|
'222EF3C7E82D8A44984A66E2B8E357CB536EC2547359CCF70E56E14BC4C284C8',
|
|
PreviousTxnLgrSeq: 741,
|
|
}
|
|
|
|
const mptokenEntryBinary =
|
|
'11007F220000000025000002E5340000000000000000301A000000000000006455222EF3C7E82D8A44984A66E2B8E357CB536EC2547359CCF70E56E14BC4C284C881143930DB9A74C26D96CB58ADFFD7E8BB78BCFE62340115000002DF71CAE59C9B7E56587FFF74D4EA5830D9BE3CE0CC'
|
|
|
|
it('compareToTests[0]', () => {
|
|
expect(UInt8.from(124).compareTo(UInt64.from(124))).toBe(0)
|
|
})
|
|
|
|
it('compareToTest[1]', () => {
|
|
expect(UInt64.from(124).compareTo(UInt8.from(124))).toBe(0)
|
|
})
|
|
|
|
it('compareToTest[2]', () => {
|
|
expect(UInt64.from(124).compareTo(UInt8.from(123))).toBe(1)
|
|
})
|
|
|
|
it('compareToTest[3]', () => {
|
|
expect(UInt8.from(124).compareTo(UInt8.from(13))).toBe(1)
|
|
})
|
|
|
|
it('compareToTest[4]', () => {
|
|
expect(UInt8.from(124).compareTo(124)).toBe(0)
|
|
})
|
|
|
|
it('compareToTest[5]', () => {
|
|
expect(UInt64.from(124).compareTo(124)).toBe(0)
|
|
})
|
|
|
|
it('compareToTest[6]', () => {
|
|
expect(UInt64.from(124).compareTo(123)).toBe(1)
|
|
})
|
|
|
|
it('compareToTest[7]', () => {
|
|
expect(UInt8.from(124).compareTo(13)).toBe(1)
|
|
})
|
|
|
|
it('UInt64 from string zero', () => {
|
|
expect(UInt64.from('0')).toEqual(UInt64.from(0))
|
|
expect(encode(json)).toEqual(binary)
|
|
})
|
|
|
|
it('UInt64 from non 16 length hex', () => {
|
|
expect(encode(jsonEntry0)).toEqual(binaryEntry0)
|
|
expect(encode(jsonEntry1)).toEqual(binaryEntry1)
|
|
expect(encode(jsonEntry2)).toEqual(binaryEntry2)
|
|
})
|
|
|
|
it('valueOf tests', () => {
|
|
let val = UInt8.from(1)
|
|
|
|
expect(val.valueOf() | 0x2).toBe(3)
|
|
})
|
|
|
|
it('UInt64 is parsed as base 10 for MPT amounts', () => {
|
|
expect(encode(mptIssuanceEntryJson)).toEqual(mptIssuanceEntryBinary)
|
|
expect(decode(mptIssuanceEntryBinary)).toEqual(mptIssuanceEntryJson)
|
|
|
|
expect(encode(mptokenEntryJson)).toEqual(mptokenEntryBinary)
|
|
expect(decode(mptokenEntryBinary)).toEqual(mptokenEntryJson)
|
|
|
|
const decodedIssuance = decode(mptIssuanceEntryBinary)
|
|
expect(typeof decodedIssuance.MaximumAmount).toBe('string')
|
|
expect(decodedIssuance.MaximumAmount).toBe('9223372036854775807')
|
|
expect(decodedIssuance.OutstandingAmount).toBe('100')
|
|
|
|
const decodedToken = decode(mptokenEntryBinary)
|
|
expect(typeof decodedToken.MPTAmount).toBe('string')
|
|
expect(decodedToken.MPTAmount).toBe('100')
|
|
})
|