iota-converter
Version:
Converts between trytes, trits and bytes
32 lines (22 loc) • 870 B
text/typescript
import { expect } from 'chai'
import { bytesToTrytes } from '../src/bytes-to-trytes'
import { trytesToBytes } from '../src/trytes-to-bytes'
import { TRYTES } from '../src/constants'
import { generateBytes } from './utils'
describe("bytesToTryts(bytes)", () => {
it("should convert bytes to trytes", () => {
const bytes = generateBytes(10)
const trytes = bytesToTrytes(bytes)
expect(trytes).to.be.a("string")
expect(trytes.length).to.equal(Math.ceil(bytes.length * 5/3))
for (let i = 0; i < trytes.length; i++) {
expect(trytes[i]).to.be.oneOf(TRYTES.split(''))
}
})
it("should be possible to convert trytes back to bytes", () => {
const bytes = generateBytes(10)
const trytes = bytesToTrytes(bytes)
const bytes2 = trytesToBytes(trytes)
expect(bytes2.slice(0, bytes.length).equals(bytes)).to.be.true
})
})