Add testing for assetId access from ExtrinsicPayload (#6033)
* Fix ExtrinsicPayload to return correct assetId as its type * add tests and cleanup * revert original deletion and fix test * remove console
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../create/index.js';
|
||||
import { fallbackExtensions } from './signedExtensions/index.js';
|
||||
import { GenericExtrinsicPayload as ExtrinsicPayload } from './index.js';
|
||||
|
||||
describe('ExtrinsicPayload', (): void => {
|
||||
@@ -21,6 +22,18 @@ describe('ExtrinsicPayload', (): void => {
|
||||
tip: '0x00000000000000000000000000005678'
|
||||
};
|
||||
|
||||
const TEST_WITH_ASSET = {
|
||||
address: '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE',
|
||||
assetId: '0x010002043205011f' as `0x${string}`,
|
||||
blockHash: '0xde8f69eeb5e065e18c6950ff708d7e551f68dc9bf59a07c52367c0280f805ec7',
|
||||
era: '0x0703',
|
||||
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
|
||||
method: '0x0600ffd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c',
|
||||
nonce: '0x00001234',
|
||||
specVersion: 123,
|
||||
tip: '0x00000000000000000000000000005678'
|
||||
};
|
||||
|
||||
it('creates and can re-create from itself (U8a)', (): void => {
|
||||
const a = new ExtrinsicPayload(registry, TEST, { version: 4 });
|
||||
const b = new ExtrinsicPayload(registry, a.toU8a(), { version: 4 });
|
||||
@@ -37,6 +50,27 @@ describe('ExtrinsicPayload', (): void => {
|
||||
expect(a.toJSON()).toEqual(b.toJSON());
|
||||
});
|
||||
|
||||
it('handles assetId correctly', () => {
|
||||
const reg = new TypeRegistry();
|
||||
|
||||
reg.setSignedExtensions(fallbackExtensions.concat(['ChargeAssetTxPayment']));
|
||||
const ext = new ExtrinsicPayload(reg, TEST_WITH_ASSET, { version: 4 });
|
||||
|
||||
expect(ext.assetId.toJSON()).toEqual({
|
||||
interior: {
|
||||
x2: [
|
||||
{
|
||||
palletInstance: 50
|
||||
},
|
||||
{
|
||||
generalIndex: 1984
|
||||
}
|
||||
]
|
||||
},
|
||||
parents: 0
|
||||
});
|
||||
});
|
||||
|
||||
it('handles toU8a(true) correctly', (): void => {
|
||||
expect(
|
||||
u8aToHex(
|
||||
|
||||
@@ -7,6 +7,7 @@ import rpcMetadata from '@polkadot/types-support/metadata/static-substrate';
|
||||
|
||||
import { TypeRegistry } from '../../create/index.js';
|
||||
import { decorateExtrinsics, Metadata } from '../../metadata/index.js';
|
||||
import { fallbackExtensions } from '../signedExtensions/index.js';
|
||||
import { GenericExtrinsicPayloadV4 as ExtrinsicPayload } from './index.js';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
@@ -36,4 +37,38 @@ describe('ExtrinsicPayload', (): void => {
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it('correctly decodes assetId', () => {
|
||||
const TEST_WITH_ASSET = {
|
||||
address: '5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE',
|
||||
assetId: '0x0002043205011f' as `0x${string}`,
|
||||
blockHash: '0xde8f69eeb5e065e18c6950ff708d7e551f68dc9bf59a07c52367c0280f805ec7',
|
||||
era: '0x0703',
|
||||
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
|
||||
method: '0x0600ffd7568e5f0a7eda67a82691ff379ac4bba4f9c9b859fe779b5d46363b61ad2db9e56c',
|
||||
nonce: '0x00001234',
|
||||
specVersion: 123,
|
||||
tip: '0x00000000000000000000000000005678',
|
||||
transactionVersion: '0x00'
|
||||
};
|
||||
|
||||
const reg = new TypeRegistry();
|
||||
|
||||
reg.setSignedExtensions(fallbackExtensions.concat(['ChargeAssetTxPayment']));
|
||||
const ext = new ExtrinsicPayload(reg, TEST_WITH_ASSET);
|
||||
|
||||
expect(ext.assetId.toJSON()).toEqual({
|
||||
interior: {
|
||||
x2: [
|
||||
{
|
||||
palletInstance: 50
|
||||
},
|
||||
{
|
||||
generalIndex: 1984
|
||||
}
|
||||
]
|
||||
},
|
||||
parents: 0
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user