mirror of
https://github.com/simplex-chat/simplexmq.git
synced 2026-04-25 18:32:21 +00:00
20 lines
714 B
TypeScript
20 lines
714 B
TypeScript
import {test, expect} from 'vitest'
|
|
import {encryptFileForUpload, uploadFile, downloadFile, newXFTPAgent, closeXFTPAgent} from '../src/agent.js'
|
|
import {parseXFTPServer} from '../src/protocol/address.js'
|
|
|
|
const server = parseXFTPServer(import.meta.env.XFTP_SERVER)
|
|
|
|
test('browser upload + download round-trip', async () => {
|
|
const agent = newXFTPAgent()
|
|
try {
|
|
const data = new Uint8Array(50000)
|
|
crypto.getRandomValues(data)
|
|
const encrypted = encryptFileForUpload(data, 'test.bin')
|
|
const {rcvDescription} = await uploadFile(agent, server, encrypted)
|
|
const {content} = await downloadFile(agent, rcvDescription)
|
|
expect(content).toEqual(data)
|
|
} finally {
|
|
closeXFTPAgent(agent)
|
|
}
|
|
})
|