2021-03-22 16:02:10 +11:00
|
|
|
import { expect } from 'chai';
|
|
|
|
|
|
2021-03-12 17:08:42 +11:00
|
|
|
import { argsToArray, bufToHex, defaultArgs, strToHex } from './nim_waku';
|
2021-03-11 10:54:35 +11:00
|
|
|
|
2021-03-22 16:02:10 +11:00
|
|
|
it('Correctly serialized arguments', function () {
|
2021-03-12 17:08:42 +11:00
|
|
|
const args = defaultArgs();
|
|
|
|
|
Object.assign(args, { portsShift: 42 });
|
2021-03-11 10:54:35 +11:00
|
|
|
|
|
|
|
|
const actual = argsToArray(args);
|
|
|
|
|
|
|
|
|
|
const expected = [
|
|
|
|
|
'--nat=none',
|
|
|
|
|
'--listen-address=127.0.0.1',
|
|
|
|
|
'--relay=true',
|
|
|
|
|
'--rpc=true',
|
|
|
|
|
'--rpc-admin=true',
|
2022-01-20 13:00:58 +11:00
|
|
|
'--websocket-support=true',
|
2021-03-12 17:08:42 +11:00
|
|
|
'--ports-shift=42',
|
2021-03-11 10:54:35 +11:00
|
|
|
];
|
|
|
|
|
|
2021-03-22 16:02:10 +11:00
|
|
|
expect(actual).to.deep.equal(expected);
|
2021-03-11 10:54:35 +11:00
|
|
|
});
|
2021-03-12 10:44:47 +11:00
|
|
|
|
2021-03-22 16:02:10 +11:00
|
|
|
it('Convert utf-8 string to hex', function () {
|
2021-03-12 10:44:47 +11:00
|
|
|
const str = 'This is an utf-8 string.';
|
2021-03-29 14:25:03 +11:00
|
|
|
const expected = '5468697320697320616e207574662d3820737472696e672e';
|
2021-03-12 10:44:47 +11:00
|
|
|
|
|
|
|
|
const actual = strToHex(str);
|
2021-03-22 16:02:10 +11:00
|
|
|
expect(actual).deep.equal(expected);
|
2021-03-12 10:44:47 +11:00
|
|
|
});
|
|
|
|
|
|
2021-03-22 16:02:10 +11:00
|
|
|
it('Convert buffer to hex', function () {
|
2021-03-12 10:44:47 +11:00
|
|
|
const buf = Uint8Array.from([
|
2021-06-21 16:37:31 +10:00
|
|
|
0x54, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x6e, 0x20, 0x75,
|
|
|
|
|
0x74, 0x66, 0x2d, 0x38, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e,
|
2021-03-12 10:44:47 +11:00
|
|
|
]);
|
2021-03-29 14:25:03 +11:00
|
|
|
const expected = '5468697320697320616e207574662d3820737472696e672e';
|
2021-03-12 10:44:47 +11:00
|
|
|
|
|
|
|
|
const actual = bufToHex(buf);
|
2021-03-22 16:02:10 +11:00
|
|
|
expect(actual).to.deep.equal(expected);
|
2021-03-12 10:44:47 +11:00
|
|
|
});
|