2018-09-30 18:42:45 -07:00
|
|
|
// @flow
|
|
|
|
import {PublicKey} from '../src/publickey';
|
|
|
|
|
|
|
|
test('invalid', () => {
|
|
|
|
expect(() => {
|
|
|
|
new PublicKey([
|
2018-11-04 11:41:21 -08:00
|
|
|
3,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2018-09-30 18:42:45 -07:00
|
|
|
]);
|
|
|
|
}).toThrow();
|
|
|
|
|
|
|
|
expect(() => {
|
2018-11-04 11:41:21 -08:00
|
|
|
new PublicKey(
|
|
|
|
'0x300000000000000000000000000000000000000000000000000000000000000000000',
|
|
|
|
);
|
2018-09-30 18:42:45 -07:00
|
|
|
}).toThrow();
|
|
|
|
|
|
|
|
expect(() => {
|
2018-11-04 11:41:21 -08:00
|
|
|
new PublicKey(
|
|
|
|
'135693854574979916511997248057056142015550763280047535983739356259273198796800000',
|
|
|
|
);
|
2018-09-30 18:42:45 -07:00
|
|
|
}).toThrow();
|
2019-08-28 10:45:17 -04:00
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
new PublicKey('12345');
|
|
|
|
}).toThrow();
|
2018-09-30 18:42:45 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('equals', () => {
|
|
|
|
const arrayKey = new PublicKey([
|
2018-11-04 11:41:21 -08:00
|
|
|
3,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2018-09-30 18:42:45 -07:00
|
|
|
]);
|
2018-11-04 11:41:21 -08:00
|
|
|
const hexKey = new PublicKey(
|
|
|
|
'0x300000000000000000000000000000000000000000000000000000000000000',
|
|
|
|
);
|
|
|
|
const base56Key = new PublicKey(
|
|
|
|
'CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3',
|
|
|
|
);
|
2018-09-30 18:42:45 -07:00
|
|
|
|
2018-10-23 12:25:02 -07:00
|
|
|
expect(arrayKey.equals(hexKey)).toBe(true);
|
|
|
|
expect(arrayKey.equals(base56Key)).toBe(true);
|
2018-09-30 18:42:45 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('isPublicKey', () => {
|
2018-11-04 11:41:21 -08:00
|
|
|
const key = new PublicKey(
|
|
|
|
'0x100000000000000000000000000000000000000000000000000000000000000',
|
|
|
|
);
|
2018-10-23 12:25:02 -07:00
|
|
|
expect(PublicKey.isPublicKey(key)).toBe(true);
|
|
|
|
expect(PublicKey.isPublicKey({})).toBe(false);
|
2018-09-30 18:42:45 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('toBase58', () => {
|
2018-11-04 11:41:21 -08:00
|
|
|
const key = new PublicKey(
|
|
|
|
'0x300000000000000000000000000000000000000000000000000000000000000',
|
|
|
|
);
|
2018-09-30 18:42:45 -07:00
|
|
|
expect(key.toBase58()).toBe('CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3');
|
2018-10-07 20:12:03 -07:00
|
|
|
expect(key.toString()).toBe('CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3');
|
2018-09-30 20:07:28 -07:00
|
|
|
|
2018-10-24 07:58:25 -07:00
|
|
|
const key2 = new PublicKey('1111111111111111111111111111BukQL');
|
2018-10-23 12:25:02 -07:00
|
|
|
expect(key2.toBase58()).toBe('1111111111111111111111111111BukQL');
|
|
|
|
expect(key2.toString()).toBe('1111111111111111111111111111BukQL');
|
2018-10-24 07:58:25 -07:00
|
|
|
|
|
|
|
const key3 = new PublicKey('11111111111111111111111111111111');
|
|
|
|
expect(key3.toBase58()).toBe('11111111111111111111111111111111');
|
|
|
|
|
|
|
|
const key4 = new PublicKey([
|
2018-11-04 11:41:21 -08:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2018-10-24 07:58:25 -07:00
|
|
|
]);
|
|
|
|
expect(key4.toBase58()).toBe('11111111111111111111111111111111');
|
2018-09-30 18:42:45 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
test('toBuffer', () => {
|
2018-11-04 11:41:21 -08:00
|
|
|
const key = new PublicKey(
|
|
|
|
'0x300000000000000000000000000000000000000000000000000000000000000',
|
|
|
|
);
|
2018-09-30 18:42:45 -07:00
|
|
|
expect(key.toBuffer()).toHaveLength(32);
|
|
|
|
expect(key.toBase58()).toBe('CiDwVBFgWV9E5MvXWoLgnEgn2hK7rJikbvfWavzAQz3');
|
|
|
|
|
2018-11-04 11:41:21 -08:00
|
|
|
const key2 = new PublicKey(
|
|
|
|
'0x000000000000000000000000000000000000000000000000000000000000000',
|
|
|
|
);
|
2018-09-30 18:42:45 -07:00
|
|
|
expect(key2.toBuffer()).toHaveLength(32);
|
|
|
|
expect(key2.toBase58()).toBe('11111111111111111111111111111111');
|
2019-08-28 10:45:17 -04:00
|
|
|
|
|
|
|
const key3 = new PublicKey(0);
|
|
|
|
expect(key3.toBuffer()).toHaveLength(32);
|
|
|
|
expect(key3.toBase58()).toBe('11111111111111111111111111111111');
|
|
|
|
|
|
|
|
const key4 = new PublicKey('0x0');
|
|
|
|
expect(key4.toBuffer()).toHaveLength(32);
|
|
|
|
expect(key4.toBase58()).toBe('11111111111111111111111111111111');
|
2018-09-30 18:42:45 -07:00
|
|
|
});
|
|
|
|
|
2018-10-23 12:25:02 -07:00
|
|
|
test('equals (II)', () => {
|
|
|
|
const key1 = new PublicKey([
|
2018-11-04 11:41:21 -08:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1,
|
2018-10-23 12:25:02 -07:00
|
|
|
]);
|
|
|
|
const key2 = new PublicKey(key1.toBuffer());
|
|
|
|
|
|
|
|
expect(key1.equals(key2)).toBe(true);
|
|
|
|
});
|
2019-12-20 16:14:37 -07:00
|
|
|
|
|
|
|
test('createWithSeed', () => {
|
|
|
|
const defaultPublicKey = new PublicKey([
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
]);
|
|
|
|
const derivedKey = PublicKey.createWithSeed(defaultPublicKey, 'limber chicken: 4/45', defaultPublicKey);
|
|
|
|
|
|
|
|
expect(derivedKey.equals(new PublicKey('9h1HyLCW5dZnBVap8C5egQ9Z6pHyjsh5MNy83iPqqRuq'))).toBe(true);
|
|
|
|
});
|