Use MultiAddress as the default type (#3123)

* Use MultiAddress as the default type

* Update tests

* Update tests
This commit is contained in:
Jaco Greeff
2021-01-31 11:02:54 +01:00
committed by GitHub
parent 859679ce09
commit 23b5601eeb
13 changed files with 76 additions and 67 deletions
+1 -1
View File
@@ -389,7 +389,7 @@ describe('Enum', (): void => {
expect(test.toHex()).toEqual(
'0x' +
'00' + // index
'ff' + // Address indicating an embedded AccountId
'00' + // MultiAddress indicating an embedded AccountId
'0001020304050607080910111213141516171819202122232425262728293031' // AccountId
);
});
@@ -20,7 +20,7 @@ describe('Extrinsic', (): void => {
'0x' +
'5d02' + // length
'84' + // V4, signing bit set
'ff' + // lookup, AccountId of sender follows
'00' + // MultiAddress, AccountId of sender follows
'fcc4910cb536b4333db4bccb40e2cf6427b4766518e754b91e70c97e4a87dbb3' + // sender
'00' + // multisig, type ed25519
'd99ffe3e610ad234e1414bda5831395a6df9098bf80b01561ce89a5065ae89d5' + // sig first 32
@@ -29,7 +29,7 @@ describe('Extrinsic', (): void => {
'1101' + // nonce, compact 68
'0700ac23fc06' + // tip, 0.03 KSM
'0600' + // balances.transfer (on Kusama this was 0400, changed here to match metadata)
'ff' + // lookup, AccountId of recipient follows
'00' + // MultiAddress, AccountId of recipient follows
'495e1e506f266418af07fa0c5c108dd436f2faa59fe7d9e54403779f5bbd7718' + // recipient
'0bc01eb1fc185f' // value, 104.560 KSM
);
@@ -38,7 +38,7 @@ describe('Extrinsic', (): void => {
expect(extrinsic.nonce.toNumber()).toEqual(68);
expect(extrinsic.tip.toHuman()).toEqual('30.0000 mUnit');
expect(extrinsic.callIndex).toEqual(new Uint8Array([6, 0]));
expect(extrinsic.args[0].toHex()).toEqual('0xff495e1e506f266418af07fa0c5c108dd436f2faa59fe7d9e54403779f5bbd7718');
expect(extrinsic.args[0].toHex()).toEqual('0x00495e1e506f266418af07fa0c5c108dd436f2faa59fe7d9e54403779f5bbd7718');
expect(extrinsic.args[1].toHuman()).toEqual('104.5609 Unit');
});
});
@@ -19,7 +19,7 @@ describe('SignerPayload', (): void => {
blockNumber: '0x00231d30',
era: '0x0703',
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
method: '0x0600ffd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c',
method: '0x060000d7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c',
nonce: '0x00001234',
signedExtensions: ['CheckNonce', 'CheckWeight'],
specVersion: '0x00000006',
@@ -36,7 +36,7 @@ describe('SignerPayload', (): void => {
blockNumber: '0x231d30',
era: registry.createType('ExtrinsicEra', { current: 2301232, period: 200 }),
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
method: registry.createType('Call', '0x0600ffd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c'),
method: registry.createType('Call', '0x060000d7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c'),
nonce: 0x1234,
signedExtensions: ['CheckNonce'],
tip: 0x5678,
@@ -48,7 +48,7 @@ describe('SignerPayload', (): void => {
blockNumber: '0x00231d30',
era: '0x0703',
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
method: '0x0600ffd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c',
method: '0x060000d7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c',
nonce: '0x00001234',
signedExtensions: ['CheckNonce'],
specVersion: '0x00000000',
@@ -32,7 +32,7 @@ describe('ExtrinsicSignatureV4', (): void => {
const u8a = new Uint8Array([
// signer as an AccountIndex
0x09,
0x01, 0x08, // 4 << 2
// signature type
0x01,
// signature
@@ -65,7 +65,7 @@ describe('ExtrinsicSignatureV4', (): void => {
).toHex()
).toEqual(
'0x' +
'ff' +
'00' + // MultiAddress
'd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d' +
'01' +
'4242424242424242424242424242424242424242424242424242424242424242' +
@@ -93,7 +93,7 @@ describe('ExtrinsicSignatureV4', (): void => {
).toEqual(
'0x' +
// Address = AccountId
// 'ff' +
// '00' +
'd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d' +
// This is a prefix-less signature, anySignture as opposed to Multi above
// '01' +
+6 -2
View File
@@ -19,12 +19,16 @@ describe('Call', (): void => {
args: [],
callIndex: [6, 1] // balances.setBalance
}).toU8a()
).toEqual(new Uint8Array([6, 1, 0, 0, 0]));
).toEqual(
new Uint8Array([6, 1, 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, 0, 0, 0])
);
});
it('handles creation from a hex value properly', (): void => {
expect(
new Call(registry, '0x0601').toU8a()
).toEqual(new Uint8Array([6, 1, 0, 0, 0])); // balances.setBalance
).toEqual(
new Uint8Array([6, 1, 1, 110, 7, 17, 0, 0, 0])
); // balances.setBalance
});
});
@@ -9,7 +9,7 @@ describe('LookupSource', (): void => {
const testDecode = (type: string, input: LookupSource | AccountId | AccountIndex | number[] | Uint8Array, expected: string): void =>
it(`can decode from ${type}`, (): void => {
const a = registry.createType('Address', input);
const a = registry.createType('IndicesLookupSource', input);
expect(a.toString()).toBe(expected);
});
@@ -18,19 +18,19 @@ describe('LookupSource', (): void => {
it('equals on AccountId', (): void => {
const addr = '5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo';
expect(registry.createType('LookupSource', addr).eq(addr)).toBe(true);
expect(registry.createType('IndicesLookupSource', addr).eq(addr)).toBe(true);
});
it('equals on AccountIndex', (): void => {
// see the test below - these are equivalent (with different prefix encoding)
expect(registry.createType('LookupSource', '2jpAFn').eq('25GUyv')).toBe(true);
expect(registry.createType('IndicesLookupSource', '2jpAFn').eq('25GUyv')).toBe(true);
});
});
describe('decoding', (): void => {
testDecode(
'Address',
registry.createType('LookupSource', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'),
registry.createType('IndicesLookupSource', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'),
'5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'
);
testDecode(
@@ -40,7 +40,7 @@ describe('LookupSource', (): void => {
);
testDecode(
'AccountIndex (mixed prefixes)',
registry.createType('LookupSource', '2jpAFn'),
registry.createType('IndicesLookupSource', '2jpAFn'),
// NOTE Expected adress here is encoded with prefix 42, input above with 68
'25GUyv'
);
@@ -95,7 +95,7 @@ describe('LookupSource', (): void => {
describe('encoding', (): void => {
const testEncode = (to: 'toHex' | 'toString' | 'toU8a', expected: string | Uint8Array): void =>
it(`can encode ${to}`, (): void => {
const a = registry.createType('Address', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
const a = registry.createType('IndicesLookupSource', '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF');
expect(a[to]()).toEqual(expected);
});
@@ -29,7 +29,7 @@ export default {
AccountId: 'GenericAccountId',
AccountIdOf: 'AccountId',
AccountIndex: 'GenericAccountIndex',
Address: 'LookupSource',
Address: 'MultiAddress',
AssetId: 'u32',
Balance: 'UInt<128, Balance>',
BalanceOf: 'Balance',
@@ -82,7 +82,7 @@ export default {
KeyValue: '(StorageKey, StorageData)',
KeyTypeId: 'u32',
LockIdentifier: '[u8; 8]',
LookupSource: 'IndicesLookupSource',
LookupSource: 'MultiAddress',
LookupTarget: 'AccountId',
ModuleId: 'LockIdentifier',
MultiAddress: 'GenericMultiAddress',
@@ -17,7 +17,7 @@ export interface AccountIdOf extends AccountId {}
export interface AccountIndex extends GenericAccountIndex {}
/** @name Address */
export interface Address extends LookupSource {}
export interface Address extends MultiAddress {}
/** @name AssetId */
export interface AssetId extends u32 {}
@@ -157,7 +157,7 @@ export interface KeyValue extends ITuple<[StorageKey, StorageData]> {}
export interface LockIdentifier extends U8aFixed {}
/** @name LookupSource */
export interface LookupSource extends IndicesLookupSource {}
export interface LookupSource extends MultiAddress {}
/** @name LookupTarget */
export interface LookupTarget extends AccountId {}