Skip to content

Commit

Permalink
Add testing for assetId access from ExtrinsicPayload (#6033)
Browse files Browse the repository at this point in the history
* Fix ExtrinsicPayload to return correct assetId as its type

* add tests and cleanup

* revert original deletion and fix test

* remove console
  • Loading branch information
TarikGul authored Nov 20, 2024
1 parent 76ba1e5 commit 6316fae
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/types/src/extrinsic/ExtrinsicPayload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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 });
Expand All @@ -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(
Expand Down
35 changes: 35 additions & 0 deletions packages/types/src/extrinsic/v4/ExtrinsicPayload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
});
});
});

0 comments on commit 6316fae

Please sign in to comment.