Update keyring, new ss58 checksums (#812)

This commit is contained in:
Jaco Greeff
2019-03-29 15:16:11 +01:00
committed by GitHub
parent bd4493c771
commit e2b15adaf2
43 changed files with 120 additions and 114 deletions
+3 -3
View File
@@ -129,12 +129,12 @@ describe('Vector', () => {
});
it('finds the index of an value', () => {
const myId = '5GfWeNe33QeyzVMV2uENuvSXLVfVXCiuLvfEP6WCDHADZhen';
const myId = '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY';
const vec = new Vector(AccountId, [
'5H4787dXL43BaA6PvTwUTyA38JBbfC9r8QyK3ay8Nozc2Ta3', '5GeJHN5EcUGPoa5pUwYkXjymoDVN1DJHsBR4UGX4XRAwKBVk', '5Dn8F1SUX6SoLt1BTfKEPL5VY9wMvG1A6tEJTSCHpLsinThm', '5DPW1n4q2THUjKGj3QKkcqdh6oxY1bmLsSQ7t8FuiuNtRoUc', '5E8k3u7iRysqPPYsBK1UgetCquZznwRZxryTzynkDTzg3vNy', '5DteAmjoppNJ8rrBugKctCXM82UVWZSCHeU8pqFwQBbyAWyB', '5GfWeNe33QeyzVMV2uENuvSXLVfVXCiuLvfEP6WCDHADZhen'
'5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw', '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty', '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
]);
expect(vec.indexOf(myId)).toEqual(6);
expect(vec.indexOf(myId)).toEqual(2);
});
});
});
@@ -2,6 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { hexToU8a } from '@polkadot/util';
import storage from '@polkadot/storage/static';
import StorageKey from './StorageKey';
@@ -12,10 +13,10 @@ describe('StorageKey', () => {
new StorageKey(
storage
.balances
.freeBalance('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ')
.freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
)
.toHex()
).toBe('0xce3f3d8f09e3411403f5ca59d042a40e'); // FIXME OK this should be length-prefixed in reality
).toBe('0xc99f5446efa57788f39ab529311f4550'); // FIXME OK this should be length-prefixed in reality
});
it(`should correctly get Alice's freeBalance storage key (u8a)`, () => {
@@ -23,11 +24,12 @@ describe('StorageKey', () => {
new StorageKey(
storage
.balances
.freeBalance('5GoKvZWG5ZPYL1WUovuHW3zJBWBP5eT8CbqjdRY4Q6iMaDtZ')
.freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY')
)
.toU8a()
).toEqual(
Uint8Array.from([64, 206, 63, 61, 143, 9, 227, 65, 20, 3, 245, 202, 89, 208, 66, 164, 14]) // Length-prefixed
// length prefix attached
hexToU8a('0x40c99f5446efa57788f39ab529311f4550')
);
});
});
+19 -19
View File
@@ -22,7 +22,7 @@ describe('AccountId', () => {
});
it('equals the empty address', () => {
expect(id.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUppTZ')).toBe(true);
expect(id.eq('5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM')).toBe(true);
});
});
@@ -36,17 +36,17 @@ describe('AccountId', () => {
testDecode(
'AccountId',
new AccountId('0x0102030405060708010203040506070801020304050607080102030405060708'),
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
);
testDecode('hex', '0x0102030405060708010203040506070801020304050607080102030405060708', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s');
testDecode('string', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s');
testDecode('hex', '0x0102030405060708010203040506070801020304050607080102030405060708', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
testDecode('string', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
testDecode(
'U8a',
new U8a([
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8,
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
]),
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
);
testDecode(
'Uint8Array',
@@ -54,12 +54,12 @@ describe('AccountId', () => {
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8,
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
]),
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
);
});
describe('encoding', () => {
const testEncode = (to: 'toHex' | 'toJSON' | 'toString' | 'toU8a', expected: Uint8Array | string, input: string = '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s') =>
const testEncode = (to: 'toHex' | 'toJSON' | 'toString' | 'toU8a', expected: Uint8Array | string, input: string = '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF') =>
it(`can encode ${to}`, () => {
const a = new AccountId(input);
@@ -67,16 +67,16 @@ describe('AccountId', () => {
});
testEncode('toHex', '0x0102030405060708010203040506070801020304050607080102030405060708');
testEncode('toJSON', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s');
testEncode('toString', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s');
testEncode('toString', '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUppTZ', '0x00');
testEncode('toJSON', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
testEncode('toString', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
testEncode('toString', '5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM', '0x00');
testEncode('toU8a', Uint8Array.from([
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8,
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
]));
it('decodes to a non-empty value', () => {
expect(new AccountId('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s').isEmpty).toBe(false);
expect(new AccountId('7qT1BvpawNbqb3BZaBTMFMMAKrpJKLPf1LmEHR1JyarWJdMX').isEmpty).toBe(false);
});
});
@@ -88,14 +88,14 @@ describe('AccountId', () => {
const list = new Vector(AccountId, data).map((accountId) => accountId.toString());
expect(list).toEqual([
'7qVJujLF3EDbZt5WfQXWvueFedMS4Vfk2Hb4GyR8jwksTZQ5',
'7pHyqeYaJjJPgxQgCXoS2EZMhBhtpm6BLCqQ4jJZTQB2kEDM',
'7pYLWV6PTUmLTMQfHmmuBwBNLkhcKhRAnkM36CSJtjat9Cxe',
'7qT1BvpawNbqb3BZaBTMFMMAKrpJKLPf1LmEHR1JyarWJpvA',
'7rADc9JW5EUGFPWLjPMipH4c3bJ2GyAUedmqQHiaGucWVifb',
'7oK5KRH6jt4p8auipnru9ptqeuRwbLMHA2tgCViZzhmW4Mo2',
'7ndAVsHvonnzTg4AvRhpraNCKj9g4CGQXKoLrgkTZ91NaLgJ',
'7oL7VfXgLA8L3pJJwi11v3sBYc1b5R3tLrweHwzMNxgEpWuv'
'7qVJujLF3EDbZt5WfQXWvueFedMS4Vfk2Hb4GyR8jwksTLup',
'7pHyqeYaJjJPgxQgCXoS2EZMhBhtpm6BLCqQ4jJZTQB2kMhw',
'7pYLWV6PTUmLTMQfHmmuBwBNLkhcKhRAnkM36CSJtjat9ACb',
'7qT1BvpawNbqb3BZaBTMFMMAKrpJKLPf1LmEHR1JyarWJdMX',
'7rADc9JW5EUGFPWLjPMipH4c3bJ2GyAUedmqQHiaGucWVrsT',
'7oK5KRH6jt4p8auipnru9ptqeuRwbLMHA2tgCViZzhmW4Lox',
'7ndAVsHvonnzTg4AvRhpraNCKj9g4CGQXKoLrgkTZ91Na6PE',
'7oL7VfXgLA8L3pJJwi11v3sBYc1b5R3tLrweHwzMNxgEpjxP'
]);
});
});
+5 -5
View File
@@ -14,28 +14,28 @@ describe('AccountIndex', () => {
it('creates a BN representation (from ss-58)', () => {
expect(
new AccountIndex('Mwz15xN8').toNumber()
new AccountIndex('Mwz15xP2').toNumber()
).toEqual(336794129);
});
it('constructs 2-byte from number', () => {
expect(
new AccountIndex(256 * 1).toString()
).toEqual('25GUyk');
).toEqual('25GUyv');
});
it('constructs from number', () => {
expect(
new AccountIndex(new BN(336794129)).toString()
).toEqual('Mwz15xN8');
).toEqual('Mwz15xP2');
});
it('compares ss-58 values', () => {
expect(new AccountIndex(256 * 1).eq('25GUyk')).toBe(true);
expect(new AccountIndex(256 * 1).eq('25GUyv')).toBe(true);
});
it('compares numbers', () => {
expect(new AccountIndex('25GUyk').eq(256 * 1)).toBe(true);
expect(new AccountIndex('2jpAFn').eq(256 * 1)).toBe(true);
});
describe('calcLength', () => {
+16 -16
View File
@@ -15,38 +15,38 @@ describe('Address', () => {
describe('utility', () => {
it('equals on AccountId', () => {
const addr = '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s';
const addr = '5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo';
expect(new Address(addr).eq(addr)).toBe(true);
});
it('equals on AccountIndex', () => {
// see the test below - these are equivalent (with different prefix encoding)
expect(new Address('PrF3').eq('F7ih')).toBe(true);
expect(new Address('2jpAFn').eq('25GUyv')).toBe(true);
});
});
describe('decoding', () => {
testDecode(
'Address',
new Address('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'),
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'
new Address('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'),
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
);
testDecode(
'AccountId',
new AccountId('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'),
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'
new AccountId('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'),
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
);
testDecode(
'AccountIndex (mixed prefixes)',
new Address('PrF3'),
new Address('2jpAFn'),
// NOTE Expected adress here is encoded with prefix 42, input above with 68
'F7ih'
'25GUyv'
);
testDecode(
'AccountIndex (hex)',
new AccountIndex('0x0100'),
'25GUyk'
'25GUyv'
);
testDecode(
'Array',
@@ -55,7 +55,7 @@ describe('Address', () => {
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8,
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
],
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
);
testDecode(
'Uint8Array (with prefix 255)',
@@ -64,22 +64,22 @@ describe('Address', () => {
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8,
1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8
]),
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
);
testDecode(
'Uint8Array (with prefix 1 byte)',
Uint8Array.from([1]),
'F7L6'
'F7NZ'
);
testDecode(
'Uint8Array (with prefix 2 bytes)',
Uint8Array.from([0xfc, 0, 1]),
'25GUyk'
'25GUyv'
);
testDecode(
'Uint8Array (with prefix 4 bytes)',
Uint8Array.from([0xfd, 17, 18, 19, 20]),
'Mwz15xN8'
'Mwz15xP2'
);
// FIXME The specification allows for 8 byte addresses, however since AccountIndex is u32 internally
// (and defined that way in thd efault Substrate),this does not actually work since it is 8 bytes,
@@ -94,7 +94,7 @@ describe('Address', () => {
describe('encoding', () => {
const testEncode = (to: 'toHex' | 'toString' | 'toU8a', expected: string | Uint8Array) =>
it(`can encode ${to}`, () => {
const a = new Address('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s');
const a = new Address('5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
expect(a[to]()).toEqual(expected);
});
@@ -104,7 +104,7 @@ describe('Address', () => {
);
testEncode(
'toString',
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCt72s'
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
);
testEncode(
'toU8a',
+2 -2
View File
@@ -29,7 +29,7 @@ describe('Extrinsic', () => {
expect(extrinsic.signature.nonce.toNumber()).toEqual(3);
expect(extrinsic.signature.era.toU8a()).toEqual(new Uint8Array([0]));
expect(extrinsic.callIndex).toEqual(new Uint8Array([3, 0]));
expect(extrinsic.args[0].toString()).toEqual('5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5nni');
expect(extrinsic.args[0].toString()).toEqual('5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo');
});
it('decodes an actual transaction (old format)', () => {
@@ -43,6 +43,6 @@ describe('Extrinsic', () => {
expect(extrinsic.signature.nonce.toNumber()).toEqual(3);
expect(extrinsic.signature.era.toU8a()).toEqual(new Uint8Array([0]));
expect(extrinsic.callIndex).toEqual(new Uint8Array([3, 0]));
expect(extrinsic.args[0].toString()).toEqual('5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5nni');
expect(extrinsic.args[0].toString()).toEqual('5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo');
});
});