You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
43 lines
1.3 KiB
/**
|
|
* @packageDocumentation
|
|
* @ignore
|
|
*/
|
|
|
|
import * as bytes from '../src/bytes';
|
|
|
|
describe('Bytes', () => {
|
|
it('hexlify on string of unsafe number', () => {
|
|
[9007199254740991, 9985956830000000000].forEach((value) => {
|
|
try {
|
|
bytes.hexlify(value);
|
|
} catch (error) {
|
|
expect(error.code).toEqual('NUMERIC_FAULT');
|
|
expect(error.fault).toEqual('out-of-safe-range');
|
|
}
|
|
});
|
|
});
|
|
it('splits a canonical signature', () => {
|
|
const r = '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
|
|
const s = '0xcafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7e';
|
|
for (let v = 27; v <= 28; v++) {
|
|
const signature = bytes.concat([r, s, [v]]);
|
|
const sig = bytes.splitSignature(signature);
|
|
expect(sig.r).toEqual(r);
|
|
expect(sig.s).toEqual(s);
|
|
expect(sig.v).toEqual(v);
|
|
}
|
|
});
|
|
|
|
it('splits a legacy signature', () => {
|
|
const r = '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
|
|
const s = '0xcafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7ecafe1a7e';
|
|
for (let v = 27; v <= 28; v++) {
|
|
const signature = bytes.concat([r, s, [v - 27]]);
|
|
const sig = bytes.splitSignature(signature);
|
|
|
|
expect(sig.r).toEqual(r);
|
|
expect(sig.s).toEqual(s);
|
|
expect(sig.v).toEqual(v);
|
|
}
|
|
});
|
|
});
|
|
|