test(e2e): added wasm tests

This commit is contained in:
alina 🌸 2023-11-04 21:23:45 +03:00
parent 0a7979a986
commit 3415f2ae3f
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
4 changed files with 84 additions and 1 deletions

View file

@ -240,7 +240,7 @@ module.exports = {
}, },
}, },
{ {
files: ['e2e/cjs/**'], files: ['e2e/**'],
rules: { rules: {
'no-restricted-globals': 'off', 'no-restricted-globals': 'off',
}, },

27
e2e/cjs/tests/wasm.js Normal file
View file

@ -0,0 +1,27 @@
const wasm = require('@mtcute/wasm')
const { describe, it, before } = require('mocha')
const { expect } = require('chai')
before(() => wasm.initAsync())
describe('@mtcute/wasm', () => {
const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex')
const iv = Buffer.from('6D656E746174696F6E206F6620494745206D6F646520666F72204F70656E5353', 'hex')
const data = Buffer.from('99706487a1cde613bc6de0b6f24b1c7aa448c8b9c3403e3467a8cad89340f53b', 'hex')
const dataEnc = Buffer.from('792ea8ae577b1a66cb3bd92679b8030ca54ee631976bd3a04547fdcb4639fa69', 'hex')
it('should work with Buffers', () => {
expect(wasm.ige256Encrypt(data, key, iv)).to.deep.equal(new Uint8Array(dataEnc))
expect(wasm.ige256Decrypt(dataEnc, key, iv)).to.deep.equal(new Uint8Array(data))
})
it('should work with Uint8Arrays', () => {
expect(wasm.ige256Encrypt(new Uint8Array(data), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal(
new Uint8Array(dataEnc),
)
expect(wasm.ige256Decrypt(new Uint8Array(dataEnc), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal(
new Uint8Array(data),
)
})
})

28
e2e/esm/tests/wasm.js Normal file
View file

@ -0,0 +1,28 @@
import { expect } from 'chai'
import { before, describe, it } from 'mocha'
import { ige256Decrypt, ige256Encrypt, initAsync } from '@mtcute/wasm'
before(() => initAsync())
describe('@mtcute/wasm', () => {
const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex')
const iv = Buffer.from('6D656E746174696F6E206F6620494745206D6F646520666F72204F70656E5353', 'hex')
const data = Buffer.from('99706487a1cde613bc6de0b6f24b1c7aa448c8b9c3403e3467a8cad89340f53b', 'hex')
const dataEnc = Buffer.from('792ea8ae577b1a66cb3bd92679b8030ca54ee631976bd3a04547fdcb4639fa69', 'hex')
it('should work with Buffers', () => {
expect(ige256Encrypt(data, key, iv)).to.deep.equal(new Uint8Array(dataEnc))
expect(ige256Decrypt(dataEnc, key, iv)).to.deep.equal(new Uint8Array(data))
})
it('should work with Uint8Arrays', () => {
expect(ige256Encrypt(new Uint8Array(data), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal(
new Uint8Array(dataEnc),
)
expect(ige256Decrypt(new Uint8Array(dataEnc), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal(
new Uint8Array(data),
)
})
})

28
e2e/ts/tests/wasm.ts Normal file
View file

@ -0,0 +1,28 @@
import { expect } from 'chai'
import { before, describe, it } from 'mocha'
import { ige256Decrypt, ige256Encrypt, initAsync } from '@mtcute/wasm'
before(() => initAsync())
describe('@mtcute/wasm', () => {
const key = Buffer.from('5468697320697320616E20696D706C655468697320697320616E20696D706C65', 'hex')
const iv = Buffer.from('6D656E746174696F6E206F6620494745206D6F646520666F72204F70656E5353', 'hex')
const data = Buffer.from('99706487a1cde613bc6de0b6f24b1c7aa448c8b9c3403e3467a8cad89340f53b', 'hex')
const dataEnc = Buffer.from('792ea8ae577b1a66cb3bd92679b8030ca54ee631976bd3a04547fdcb4639fa69', 'hex')
it('should work with Buffers', () => {
expect(ige256Encrypt(data, key, iv)).to.deep.equal(new Uint8Array(dataEnc))
expect(ige256Decrypt(dataEnc, key, iv)).to.deep.equal(new Uint8Array(data))
})
it('should work with Uint8Arrays', () => {
expect(ige256Encrypt(new Uint8Array(data), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal(
new Uint8Array(dataEnc),
)
expect(ige256Decrypt(new Uint8Array(dataEnc), new Uint8Array(key), new Uint8Array(iv))).to.deep.equal(
new Uint8Array(data),
)
})
})