2023-10-16 19:23:53 +03:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import Long from 'long'
|
|
|
|
import { describe, it } from 'mocha'
|
2024-03-01 18:16:07 +03:00
|
|
|
import { setPlatform } from '@mtcute/core/platform.js'
|
|
|
|
import { NodePlatform } from '@mtcute/node'
|
2023-10-16 19:23:53 +03:00
|
|
|
import { tl } from '@mtcute/tl'
|
|
|
|
import { __tlReaderMap } from '@mtcute/tl/binary/reader.js'
|
|
|
|
import { __tlWriterMap } from '@mtcute/tl/binary/writer.js'
|
2024-03-01 18:16:07 +03:00
|
|
|
import { TlBinaryReader, TlBinaryWriter } from '@mtcute/tl-runtime'
|
2023-10-16 19:23:53 +03:00
|
|
|
|
|
|
|
// here we primarily want to check that @mtcute/tl correctly works with @mtcute/tl-runtime
|
|
|
|
|
2024-03-01 18:16:07 +03:00
|
|
|
const p = new NodePlatform()
|
|
|
|
setPlatform(p)
|
|
|
|
|
2023-10-16 19:23:53 +03:00
|
|
|
describe('@mtcute/tl', () => {
|
|
|
|
it('writers map works with TlBinaryWriter', () => {
|
|
|
|
const obj = {
|
|
|
|
_: 'inputPeerUser',
|
|
|
|
userId: 123,
|
|
|
|
accessHash: Long.fromNumber(456),
|
|
|
|
}
|
|
|
|
|
2024-03-01 18:16:07 +03:00
|
|
|
expect(p.hexEncode(TlBinaryWriter.serializeObject(__tlWriterMap, obj))).to.equal(
|
2023-10-16 19:23:53 +03:00
|
|
|
'4ca5e8dd7b00000000000000c801000000000000',
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('readers map works with TlBinaryReader', () => {
|
2024-03-01 18:16:07 +03:00
|
|
|
const buf = p.hexDecode('4ca5e8dd7b00000000000000c801000000000000')
|
2023-10-16 19:23:53 +03:00
|
|
|
// eslint-disable-next-line
|
|
|
|
const obj = TlBinaryReader.deserializeObject<any>(__tlReaderMap, buf)
|
|
|
|
|
|
|
|
expect(obj._).equal('inputPeerUser')
|
|
|
|
expect(obj.userId).equal(123)
|
|
|
|
// eslint-disable-next-line
|
|
|
|
expect(obj.accessHash.toString()).equal('456')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('correctly checks for combinator types', () => {
|
2024-08-13 04:53:07 +03:00
|
|
|
expect(tl.isAnyInputUser({ _: 'inputUserEmpty' })).to.eq(true)
|
2023-10-16 19:23:53 +03:00
|
|
|
})
|
|
|
|
})
|