fix: wasm build and e2e fixes
This commit is contained in:
parent
9420f155b2
commit
791a3a58b5
17 changed files with 101 additions and 88 deletions
|
@ -1,35 +1,24 @@
|
||||||
const {
|
const { TlBinaryReader, TlBinaryWriter, TlSerializationCounter } = require('@mtcute/tl-runtime')
|
||||||
TlBinaryReader,
|
|
||||||
TlBinaryWriter,
|
|
||||||
TlSerializationCounter,
|
|
||||||
hexEncode,
|
|
||||||
hexDecode,
|
|
||||||
hexDecodeToBuffer,
|
|
||||||
} = require('@mtcute/tl-runtime')
|
|
||||||
const Long = require('long')
|
const Long = require('long')
|
||||||
const { describe, it } = require('mocha')
|
const { describe, it } = require('mocha')
|
||||||
const { expect } = require('chai')
|
const { expect } = require('chai')
|
||||||
|
const { NodePlatform } = require('@mtcute/node')
|
||||||
|
|
||||||
// here we primarily want to check that everything imports properly,
|
// here we primarily want to check that everything imports properly,
|
||||||
// and that the code is actually executable. The actual correctness
|
// and that the code is actually executable. The actual correctness
|
||||||
// of the implementation is covered tested by unit tests
|
// of the implementation is covered tested by unit tests
|
||||||
|
|
||||||
|
const p = new NodePlatform()
|
||||||
|
|
||||||
describe('@mtcute/tl-runtime', () => {
|
describe('@mtcute/tl-runtime', () => {
|
||||||
describe('encodings', () => {
|
describe('encodings', () => {
|
||||||
it('works with Buffers', () => {
|
it('works with Buffers', () => {
|
||||||
const buf = Buffer.alloc(5)
|
expect(p.hexEncode(Buffer.from('hello'))).to.equal('68656c6c6f')
|
||||||
hexDecode(buf, '0102030405')
|
expect(p.hexDecode('0102030405')).eql(Buffer.from([1, 2, 3, 4, 5]))
|
||||||
|
|
||||||
expect(hexEncode(Buffer.from('hello'))).to.equal('68656c6c6f')
|
|
||||||
expect(buf).eql(Buffer.from([1, 2, 3, 4, 5]))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works with Uint8Arrays', () => {
|
it('works with Uint8Arrays', () => {
|
||||||
const buf = new Uint8Array(5)
|
expect(p.hexEncode(new Uint8Array([1, 2, 3, 4, 5]))).to.equal('0102030405')
|
||||||
hexDecode(buf, '0102030405')
|
|
||||||
|
|
||||||
expect(hexEncode(new Uint8Array([1, 2, 3, 4, 5]))).to.equal('0102030405')
|
|
||||||
expect(buf).eql(new Uint8Array([1, 2, 3, 4, 5]))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -61,7 +50,7 @@ describe('@mtcute/tl-runtime', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should work with Uint8Arrays', () => {
|
it('should work with Uint8Arrays', () => {
|
||||||
const buf = hexDecodeToBuffer(data)
|
const buf = p.hexDecode(data)
|
||||||
|
|
||||||
const r = new TlBinaryReader(map, buf, 8)
|
const r = new TlBinaryReader(map, buf, 8)
|
||||||
|
|
||||||
|
@ -96,7 +85,7 @@ describe('@mtcute/tl-runtime', () => {
|
||||||
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
||||||
w.object(obj)
|
w.object(obj)
|
||||||
|
|
||||||
expect(hexEncode(w.result())).eq(
|
expect(p.hexEncode(w.result())).eq(
|
||||||
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -104,7 +93,7 @@ describe('@mtcute/tl-runtime', () => {
|
||||||
it('should work with Uint8Arrays', () => {
|
it('should work with Uint8Arrays', () => {
|
||||||
const obj = {
|
const obj = {
|
||||||
_: 'mt_resPQ',
|
_: 'mt_resPQ',
|
||||||
pq: hexDecodeToBuffer('17ED48941A08F981'),
|
pq: p.hexDecode('17ED48941A08F981'),
|
||||||
serverPublicKeyFingerprints: [Long.fromString('c3b42b026ce86b21', 16)],
|
serverPublicKeyFingerprints: [Long.fromString('c3b42b026ce86b21', 16)],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +104,7 @@ describe('@mtcute/tl-runtime', () => {
|
||||||
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
||||||
w.object(obj)
|
w.object(obj)
|
||||||
|
|
||||||
expect(hexEncode(w.result())).eq(
|
expect(p.hexEncode(w.result())).eq(
|
||||||
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
const Long = require('long')
|
const Long = require('long')
|
||||||
|
|
||||||
const {
|
const { TlBinaryReader, TlBinaryWriter } = require('@mtcute/tl-runtime')
|
||||||
TlBinaryReader,
|
|
||||||
TlBinaryWriter,
|
|
||||||
hexEncode,
|
|
||||||
} = require('@mtcute/tl-runtime')
|
|
||||||
const { tl } = require('@mtcute/tl')
|
const { tl } = require('@mtcute/tl')
|
||||||
const { __tlReaderMap } = require('@mtcute/tl/binary/reader')
|
const { __tlReaderMap } = require('@mtcute/tl/binary/reader')
|
||||||
const { __tlWriterMap } = require('@mtcute/tl/binary/writer')
|
const { __tlWriterMap } = require('@mtcute/tl/binary/writer')
|
||||||
const { describe, it } = require('mocha')
|
const { describe, it } = require('mocha')
|
||||||
const { expect } = require('chai')
|
const { expect } = require('chai')
|
||||||
|
const { NodePlatform } = require('@mtcute/node')
|
||||||
|
|
||||||
// here we primarily want to check that @mtcute/tl correctly works with @mtcute/tl-runtime
|
// here we primarily want to check that @mtcute/tl correctly works with @mtcute/tl-runtime
|
||||||
|
|
||||||
|
const p = new NodePlatform()
|
||||||
|
|
||||||
describe('@mtcute/tl', () => {
|
describe('@mtcute/tl', () => {
|
||||||
it('writers map works with TlBinaryWriter', () => {
|
it('writers map works with TlBinaryWriter', () => {
|
||||||
const obj = {
|
const obj = {
|
||||||
|
@ -21,7 +20,9 @@ describe('@mtcute/tl', () => {
|
||||||
accessHash: Long.fromNumber(456),
|
accessHash: Long.fromNumber(456),
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(hexEncode(TlBinaryWriter.serializeObject(__tlWriterMap, obj))).to.equal('4ca5e8dd7b00000000000000c801000000000000')
|
expect(p.hexEncode(TlBinaryWriter.serializeObject(__tlWriterMap, obj))).to.equal(
|
||||||
|
'4ca5e8dd7b00000000000000c801000000000000',
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('readers map works with TlBinaryReader', () => {
|
it('readers map works with TlBinaryReader', () => {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
const wasm = require('@mtcute/wasm')
|
const wasm = require('@mtcute/wasm')
|
||||||
const { describe, it, before } = require('mocha')
|
const { describe, it, before } = require('mocha')
|
||||||
const { expect } = require('chai')
|
const { expect } = require('chai')
|
||||||
|
const { NodeCryptoProvider } = require('@mtcute/node')
|
||||||
|
|
||||||
before(() => wasm.initAsync())
|
before(async () => {
|
||||||
|
await new NodeCryptoProvider().initialize()
|
||||||
|
})
|
||||||
|
|
||||||
describe('@mtcute/wasm', () => {
|
describe('@mtcute/wasm', () => {
|
||||||
const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex')
|
const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex')
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
const { MemoryStorage } = require('@mtcute/core')
|
const { MemoryStorage } = require('@mtcute/core')
|
||||||
|
const { setPlatform } = require('@mtcute/core/platform.js')
|
||||||
const { LogManager } = require('@mtcute/core/utils.js')
|
const { LogManager } = require('@mtcute/core/utils.js')
|
||||||
|
const { NodeCryptoProvider, NodePlatform, TcpTransport } = require('@mtcute/node')
|
||||||
|
|
||||||
exports.getApiParams = () => {
|
exports.getApiParams = () => {
|
||||||
if (!process.env.API_ID || !process.env.API_HASH) {
|
if (!process.env.API_ID || !process.env.API_HASH) {
|
||||||
throw new Error('API_ID and API_HASH env variables must be set')
|
throw new Error('API_ID and API_HASH env variables must be set')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPlatform(new NodePlatform())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
apiId: parseInt(process.env.API_ID),
|
apiId: parseInt(process.env.API_ID),
|
||||||
apiHash: process.env.API_HASH,
|
apiHash: process.env.API_HASH,
|
||||||
testMode: true,
|
testMode: true,
|
||||||
storage: new MemoryStorage(),
|
storage: new MemoryStorage(),
|
||||||
logLevel: LogManager.DEBUG,
|
logLevel: LogManager.DEBUG,
|
||||||
|
transport: () => new TcpTransport(),
|
||||||
|
crypto: new NodeCryptoProvider(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,34 +2,23 @@ import { expect } from 'chai'
|
||||||
import Long from 'long'
|
import Long from 'long'
|
||||||
import { describe, it } from 'mocha'
|
import { describe, it } from 'mocha'
|
||||||
|
|
||||||
import {
|
import { NodePlatform } from '@mtcute/node'
|
||||||
hexDecode,
|
import { TlBinaryReader, TlBinaryWriter, TlSerializationCounter } from '@mtcute/tl-runtime'
|
||||||
hexDecodeToBuffer,
|
|
||||||
hexEncode,
|
|
||||||
TlBinaryReader,
|
|
||||||
TlBinaryWriter,
|
|
||||||
TlSerializationCounter,
|
|
||||||
} from '@mtcute/tl-runtime'
|
|
||||||
|
|
||||||
// here we primarily want to check that everything imports properly,
|
// here we primarily want to check that everything imports properly,
|
||||||
// and that the code is actually executable. The actual correctness
|
// and that the code is actually executable. The actual correctness
|
||||||
// of the implementation is covered tested by unit tests
|
// of the implementation is covered tested by unit tests
|
||||||
|
|
||||||
|
const p = new NodePlatform()
|
||||||
|
|
||||||
describe('encodings', () => {
|
describe('encodings', () => {
|
||||||
it('works with Buffers', () => {
|
it('works with Buffers', () => {
|
||||||
const buf = Buffer.alloc(5)
|
expect(p.hexEncode(Buffer.from('hello'))).to.equal('68656c6c6f')
|
||||||
hexDecode(buf, '0102030405')
|
expect(p.hexDecode('0102030405')).eql(Buffer.from([1, 2, 3, 4, 5]))
|
||||||
|
|
||||||
expect(hexEncode(Buffer.from('hello'))).to.equal('68656c6c6f')
|
|
||||||
expect(buf).eql(Buffer.from([1, 2, 3, 4, 5]))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works with Uint8Arrays', () => {
|
it('works with Uint8Arrays', () => {
|
||||||
const buf = new Uint8Array(5)
|
expect(p.hexEncode(new Uint8Array([1, 2, 3, 4, 5]))).to.equal('0102030405')
|
||||||
hexDecode(buf, '0102030405')
|
|
||||||
|
|
||||||
expect(hexEncode(new Uint8Array([1, 2, 3, 4, 5]))).to.equal('0102030405')
|
|
||||||
expect(buf).eql(new Uint8Array([1, 2, 3, 4, 5]))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -61,7 +50,7 @@ describe('TlBinaryReader', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should work with Uint8Arrays', () => {
|
it('should work with Uint8Arrays', () => {
|
||||||
const buf = hexDecodeToBuffer(data)
|
const buf = p.hexDecode(data)
|
||||||
|
|
||||||
const r = new TlBinaryReader(map, buf, 8)
|
const r = new TlBinaryReader(map, buf, 8)
|
||||||
|
|
||||||
|
@ -96,7 +85,7 @@ describe('TlBinaryWriter', () => {
|
||||||
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
||||||
w.object(obj)
|
w.object(obj)
|
||||||
|
|
||||||
expect(hexEncode(w.result())).eq(
|
expect(p.hexEncode(w.result())).eq(
|
||||||
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -104,7 +93,7 @@ describe('TlBinaryWriter', () => {
|
||||||
it('should work with Uint8Arrays', () => {
|
it('should work with Uint8Arrays', () => {
|
||||||
const obj = {
|
const obj = {
|
||||||
_: 'mt_resPQ',
|
_: 'mt_resPQ',
|
||||||
pq: hexDecodeToBuffer('17ED48941A08F981'),
|
pq: p.hexDecode('17ED48941A08F981'),
|
||||||
serverPublicKeyFingerprints: [Long.fromString('c3b42b026ce86b21', 16)],
|
serverPublicKeyFingerprints: [Long.fromString('c3b42b026ce86b21', 16)],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +104,7 @@ describe('TlBinaryWriter', () => {
|
||||||
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
||||||
w.object(obj)
|
w.object(obj)
|
||||||
|
|
||||||
expect(hexEncode(w.result())).eq(
|
expect(p.hexEncode(w.result())).eq(
|
||||||
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,13 +2,16 @@ import { expect } from 'chai'
|
||||||
import Long from 'long'
|
import Long from 'long'
|
||||||
import { describe, it } from 'mocha'
|
import { describe, it } from 'mocha'
|
||||||
|
|
||||||
|
import { NodePlatform } from '@mtcute/node'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { __tlReaderMap } from '@mtcute/tl/binary/reader.js'
|
import { __tlReaderMap } from '@mtcute/tl/binary/reader.js'
|
||||||
import { __tlWriterMap } from '@mtcute/tl/binary/writer.js'
|
import { __tlWriterMap } from '@mtcute/tl/binary/writer.js'
|
||||||
import { hexDecodeToBuffer, hexEncode, TlBinaryReader, TlBinaryWriter } from '@mtcute/tl-runtime'
|
import { TlBinaryReader, TlBinaryWriter } from '@mtcute/tl-runtime'
|
||||||
|
|
||||||
// here we primarily want to check that @mtcute/tl correctly works with @mtcute/tl-runtime
|
// here we primarily want to check that @mtcute/tl correctly works with @mtcute/tl-runtime
|
||||||
|
|
||||||
|
const p = new NodePlatform()
|
||||||
|
|
||||||
describe('@mtcute/tl', () => {
|
describe('@mtcute/tl', () => {
|
||||||
it('writers map works with TlBinaryWriter', () => {
|
it('writers map works with TlBinaryWriter', () => {
|
||||||
const obj = {
|
const obj = {
|
||||||
|
@ -17,11 +20,13 @@ describe('@mtcute/tl', () => {
|
||||||
accessHash: Long.fromNumber(456),
|
accessHash: Long.fromNumber(456),
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(hexEncode(TlBinaryWriter.serializeObject(__tlWriterMap, obj))).to.equal('4ca5e8dd7b00000000000000c801000000000000')
|
expect(p.hexEncode(TlBinaryWriter.serializeObject(__tlWriterMap, obj))).to.equal(
|
||||||
|
'4ca5e8dd7b00000000000000c801000000000000',
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('readers map works with TlBinaryReader', () => {
|
it('readers map works with TlBinaryReader', () => {
|
||||||
const buf = hexDecodeToBuffer('4ca5e8dd7b00000000000000c801000000000000')
|
const buf = p.hexDecode('4ca5e8dd7b00000000000000c801000000000000')
|
||||||
const obj = TlBinaryReader.deserializeObject(__tlReaderMap, buf)
|
const obj = TlBinaryReader.deserializeObject(__tlReaderMap, buf)
|
||||||
|
|
||||||
expect(obj._).equal('inputPeerUser')
|
expect(obj._).equal('inputPeerUser')
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { before, describe, it } from 'mocha'
|
import { before, describe, it } from 'mocha'
|
||||||
|
|
||||||
import { ige256Decrypt, ige256Encrypt, initAsync } from '@mtcute/wasm'
|
import { NodeCryptoProvider } from '@mtcute/node'
|
||||||
|
import { ige256Decrypt, ige256Encrypt } from '@mtcute/wasm'
|
||||||
|
|
||||||
before(() => initAsync())
|
before(async () => {
|
||||||
|
await new NodeCryptoProvider().initialize()
|
||||||
|
})
|
||||||
|
|
||||||
describe('@mtcute/wasm', () => {
|
describe('@mtcute/wasm', () => {
|
||||||
const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex')
|
const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex')
|
||||||
|
|
|
@ -1,16 +1,22 @@
|
||||||
import { MemoryStorage } from '@mtcute/core'
|
import { MemoryStorage } from '@mtcute/core'
|
||||||
|
import { setPlatform } from '@mtcute/core/platform.js'
|
||||||
import { LogManager } from '@mtcute/core/utils.js'
|
import { LogManager } from '@mtcute/core/utils.js'
|
||||||
|
import { NodeCryptoProvider, NodePlatform, TcpTransport } from '@mtcute/node'
|
||||||
|
|
||||||
export const getApiParams = () => {
|
export const getApiParams = () => {
|
||||||
if (!process.env.API_ID || !process.env.API_HASH) {
|
if (!process.env.API_ID || !process.env.API_HASH) {
|
||||||
throw new Error('API_ID and API_HASH env variables must be set')
|
throw new Error('API_ID and API_HASH env variables must be set')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPlatform(new NodePlatform())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
apiId: parseInt(process.env.API_ID),
|
apiId: parseInt(process.env.API_ID),
|
||||||
apiHash: process.env.API_HASH,
|
apiHash: process.env.API_HASH,
|
||||||
testMode: true,
|
testMode: true,
|
||||||
storage: new MemoryStorage(),
|
storage: new MemoryStorage(),
|
||||||
logLevel: LogManager.DEBUG,
|
logLevel: LogManager.DEBUG,
|
||||||
|
transport: () => new TcpTransport(),
|
||||||
|
crypto: new NodeCryptoProvider(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { describe, it } from 'mocha'
|
import { describe, it } from 'mocha'
|
||||||
|
|
||||||
import { BaseTelegramClient, MtUnsupportedError, TelegramClient } from '@mtcute/core'
|
import { BaseTelegramClient, MtUnsupportedError } from '@mtcute/core'
|
||||||
|
import { TelegramClient } from '@mtcute/core/client.js'
|
||||||
|
|
||||||
import { getApiParams } from '../utils.js'
|
import { getApiParams } from '../utils.js'
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { describe, it } from 'mocha'
|
import { describe, it } from 'mocha'
|
||||||
|
|
||||||
import { TelegramClient } from '@mtcute/core'
|
import { TelegramClient } from '@mtcute/core/client.js'
|
||||||
|
|
||||||
import { getApiParams } from '../utils.js'
|
import { getApiParams } from '../utils.js'
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@ import { expect } from 'chai'
|
||||||
import { createHash } from 'crypto'
|
import { createHash } from 'crypto'
|
||||||
import { describe, it } from 'mocha'
|
import { describe, it } from 'mocha'
|
||||||
|
|
||||||
import { FileDownloadLocation, TelegramClient, Thumbnail } from '@mtcute/core'
|
import { FileDownloadLocation, Thumbnail } from '@mtcute/core'
|
||||||
|
import { TelegramClient } from '@mtcute/core/client.js'
|
||||||
import { sleep } from '@mtcute/core/utils.js'
|
import { sleep } from '@mtcute/core/utils.js'
|
||||||
|
|
||||||
import { getApiParams } from '../utils.js'
|
import { getApiParams } from '../utils.js'
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { describe, it } from 'mocha'
|
import { describe, it } from 'mocha'
|
||||||
|
|
||||||
import { Message, TelegramClient } from '@mtcute/core'
|
import { Message } from '@mtcute/core'
|
||||||
|
import { TelegramClient } from '@mtcute/core/client.js'
|
||||||
|
|
||||||
import { getApiParams, waitFor } from '../utils.js'
|
import { getApiParams, waitFor } from '../utils.js'
|
||||||
|
|
||||||
|
|
|
@ -3,34 +3,25 @@ import { expect } from 'chai'
|
||||||
import Long from 'long'
|
import Long from 'long'
|
||||||
import { describe, it } from 'mocha'
|
import { describe, it } from 'mocha'
|
||||||
|
|
||||||
import {
|
import { TlBinaryReader, TlBinaryWriter, TlSerializationCounter } from '@mtcute/tl-runtime'
|
||||||
hexDecode,
|
import { NodePlatform } from '@mtcute/node'
|
||||||
hexDecodeToBuffer,
|
import { setPlatform } from '@mtcute/core/platform.js'
|
||||||
hexEncode,
|
|
||||||
TlBinaryReader,
|
|
||||||
TlBinaryWriter,
|
|
||||||
TlSerializationCounter,
|
|
||||||
} from '@mtcute/tl-runtime'
|
|
||||||
|
|
||||||
// here we primarily want to check that everything imports properly,
|
// here we primarily want to check that everything imports properly,
|
||||||
// and that the code is actually executable. The actual correctness
|
// and that the code is actually executable. The actual correctness
|
||||||
// of the implementation is covered tested by unit tests
|
// of the implementation is covered tested by unit tests
|
||||||
|
|
||||||
|
const p = new NodePlatform()
|
||||||
|
setPlatform(p)
|
||||||
|
|
||||||
describe('encodings', () => {
|
describe('encodings', () => {
|
||||||
it('works with Buffers', () => {
|
it('works with Buffers', () => {
|
||||||
const buf = Buffer.alloc(5)
|
expect(p.hexEncode(Buffer.from('hello'))).to.equal('68656c6c6f')
|
||||||
hexDecode(buf, '0102030405')
|
expect(p.hexDecode('0102030405')).eql(Buffer.from([1, 2, 3, 4, 5]))
|
||||||
|
|
||||||
expect(hexEncode(Buffer.from('hello'))).to.equal('68656c6c6f')
|
|
||||||
expect(buf).eql(Buffer.from([1, 2, 3, 4, 5]))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('works with Uint8Arrays', () => {
|
it('works with Uint8Arrays', () => {
|
||||||
const buf = new Uint8Array(5)
|
expect(p.hexEncode(new Uint8Array([1, 2, 3, 4, 5]))).to.equal('0102030405')
|
||||||
hexDecode(buf, '0102030405')
|
|
||||||
|
|
||||||
expect(hexEncode(new Uint8Array([1, 2, 3, 4, 5]))).to.equal('0102030405')
|
|
||||||
expect(buf).eql(new Uint8Array([1, 2, 3, 4, 5]))
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -62,7 +53,7 @@ describe('TlBinaryReader', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should work with Uint8Arrays', () => {
|
it('should work with Uint8Arrays', () => {
|
||||||
const buf = hexDecodeToBuffer(data)
|
const buf = p.hexDecode(data)
|
||||||
|
|
||||||
const r = new TlBinaryReader(map, buf, 8)
|
const r = new TlBinaryReader(map, buf, 8)
|
||||||
|
|
||||||
|
@ -98,7 +89,7 @@ describe('TlBinaryWriter', () => {
|
||||||
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
||||||
w.object(obj)
|
w.object(obj)
|
||||||
|
|
||||||
expect(hexEncode(w.result())).eq(
|
expect(p.hexEncode(w.result())).eq(
|
||||||
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -106,7 +97,7 @@ describe('TlBinaryWriter', () => {
|
||||||
it('should work with Uint8Arrays', () => {
|
it('should work with Uint8Arrays', () => {
|
||||||
const obj = {
|
const obj = {
|
||||||
_: 'mt_resPQ',
|
_: 'mt_resPQ',
|
||||||
pq: hexDecodeToBuffer('17ED48941A08F981'),
|
pq: p.hexDecode('17ED48941A08F981'),
|
||||||
serverPublicKeyFingerprints: [Long.fromString('c3b42b026ce86b21', 16)],
|
serverPublicKeyFingerprints: [Long.fromString('c3b42b026ce86b21', 16)],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +108,7 @@ describe('TlBinaryWriter', () => {
|
||||||
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
w.long(Long.fromString('51E57AC91E83C801', true, 16)) // messageId
|
||||||
w.object(obj)
|
w.object(obj)
|
||||||
|
|
||||||
expect(hexEncode(w.result())).eq(
|
expect(p.hexEncode(w.result())).eq(
|
||||||
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
'000000000000000001c8831ec97ae551632416050817ed48941a08f98100000015c4b51c01000000216be86c022bb4c3',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -2,13 +2,18 @@ import { expect } from 'chai'
|
||||||
import Long from 'long'
|
import Long from 'long'
|
||||||
import { describe, it } from 'mocha'
|
import { describe, it } from 'mocha'
|
||||||
|
|
||||||
|
import { setPlatform } from '@mtcute/core/platform.js'
|
||||||
|
import { NodePlatform } from '@mtcute/node'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { __tlReaderMap } from '@mtcute/tl/binary/reader.js'
|
import { __tlReaderMap } from '@mtcute/tl/binary/reader.js'
|
||||||
import { __tlWriterMap } from '@mtcute/tl/binary/writer.js'
|
import { __tlWriterMap } from '@mtcute/tl/binary/writer.js'
|
||||||
import { hexDecodeToBuffer, hexEncode, TlBinaryReader, TlBinaryWriter } from '@mtcute/tl-runtime'
|
import { TlBinaryReader, TlBinaryWriter } from '@mtcute/tl-runtime'
|
||||||
|
|
||||||
// here we primarily want to check that @mtcute/tl correctly works with @mtcute/tl-runtime
|
// here we primarily want to check that @mtcute/tl correctly works with @mtcute/tl-runtime
|
||||||
|
|
||||||
|
const p = new NodePlatform()
|
||||||
|
setPlatform(p)
|
||||||
|
|
||||||
describe('@mtcute/tl', () => {
|
describe('@mtcute/tl', () => {
|
||||||
it('writers map works with TlBinaryWriter', () => {
|
it('writers map works with TlBinaryWriter', () => {
|
||||||
const obj = {
|
const obj = {
|
||||||
|
@ -17,13 +22,13 @@ describe('@mtcute/tl', () => {
|
||||||
accessHash: Long.fromNumber(456),
|
accessHash: Long.fromNumber(456),
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(hexEncode(TlBinaryWriter.serializeObject(__tlWriterMap, obj))).to.equal(
|
expect(p.hexEncode(TlBinaryWriter.serializeObject(__tlWriterMap, obj))).to.equal(
|
||||||
'4ca5e8dd7b00000000000000c801000000000000',
|
'4ca5e8dd7b00000000000000c801000000000000',
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('readers map works with TlBinaryReader', () => {
|
it('readers map works with TlBinaryReader', () => {
|
||||||
const buf = hexDecodeToBuffer('4ca5e8dd7b00000000000000c801000000000000')
|
const buf = p.hexDecode('4ca5e8dd7b00000000000000c801000000000000')
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const obj = TlBinaryReader.deserializeObject<any>(__tlReaderMap, buf)
|
const obj = TlBinaryReader.deserializeObject<any>(__tlReaderMap, buf)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { before, describe, it } from 'mocha'
|
import { before, describe, it } from 'mocha'
|
||||||
|
|
||||||
import { ige256Decrypt, ige256Encrypt, initAsync } from '@mtcute/wasm'
|
import { NodeCryptoProvider } from '@mtcute/node'
|
||||||
|
import { ige256Decrypt, ige256Encrypt } from '@mtcute/wasm'
|
||||||
|
|
||||||
before(() => initAsync())
|
before(async () => {
|
||||||
|
await new NodeCryptoProvider().initialize()
|
||||||
|
})
|
||||||
|
|
||||||
describe('@mtcute/wasm', () => {
|
describe('@mtcute/wasm', () => {
|
||||||
const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex')
|
const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex')
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
|
|
||||||
import { MaybePromise, MemoryStorage } from '@mtcute/core'
|
import { MaybePromise, MemoryStorage } from '@mtcute/core'
|
||||||
|
import { setPlatform } from '@mtcute/core/platform.js'
|
||||||
import { LogManager, sleep } from '@mtcute/core/utils.js'
|
import { LogManager, sleep } from '@mtcute/core/utils.js'
|
||||||
|
import { NodeCryptoProvider, NodePlatform, TcpTransport } from '@mtcute/node'
|
||||||
import { SqliteStorage } from '@mtcute/sqlite'
|
import { SqliteStorage } from '@mtcute/sqlite'
|
||||||
|
|
||||||
export const getApiParams = (storage?: string) => {
|
export const getApiParams = (storage?: string) => {
|
||||||
|
@ -10,12 +12,16 @@ export const getApiParams = (storage?: string) => {
|
||||||
throw new Error('API_ID and API_HASH env variables must be set')
|
throw new Error('API_ID and API_HASH env variables must be set')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setPlatform(new NodePlatform())
|
||||||
|
|
||||||
return {
|
return {
|
||||||
apiId: parseInt(process.env.API_ID),
|
apiId: parseInt(process.env.API_ID),
|
||||||
apiHash: process.env.API_HASH,
|
apiHash: process.env.API_HASH,
|
||||||
testMode: true,
|
testMode: true,
|
||||||
storage: storage ? new SqliteStorage(join(__dirname, storage)) : new MemoryStorage(),
|
storage: storage ? new SqliteStorage(join(__dirname, storage)) : new MemoryStorage(),
|
||||||
logLevel: LogManager.VERBOSE,
|
logLevel: LogManager.VERBOSE,
|
||||||
|
transport: () => new TcpTransport(),
|
||||||
|
crypto: new NodeCryptoProvider(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
module.exports = () => ({
|
module.exports = ({ path: { join }, fs, outDir, packageDir }) => ({
|
||||||
esmOnlyDirectives: true,
|
esmOnlyDirectives: true,
|
||||||
|
final() {
|
||||||
|
fs.cpSync(join(packageDir, 'lib/mtcute.wasm'), join(outDir, 'mtcute.wasm'))
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue