-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bug): toTxMethod sanitizing (#183)
* fix number check for toTxMethod * toTxMethod test * add kusama registry for kusama v9160 * fix naming * fix inline comment grumbles * fix expected response in tests * fix and refactor santization * add inline comments * fix imports, and small grumble * Update packages/txwrapper-core/src/core/method/toTxMethod.ts Co-authored-by: David <dvdplm@gmail.com> Co-authored-by: David <dvdplm@gmail.com>
- Loading branch information
Showing
6 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/txwrapper-core/src/core/method/toTxMethod.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { hexToU8a } from '@polkadot/util'; | ||
|
||
import { KUSAMA_9160_TEST_OPTIONS } from '../../test-helpers'; | ||
import { toTxMethod } from './toTxMethod'; | ||
|
||
const { registry } = KUSAMA_9160_TEST_OPTIONS; | ||
|
||
describe('toTxMethod', () => { | ||
// transferKeepAlive signedTx constructed using kusama v9160 metadata | ||
const signedTx = | ||
'0x4d028400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d014c39c61d2526afa7adf0a5683a97cefe6cd1cbdc4dd220eaa34ee20c88051057ad726f28371bbe9dcede5213ed29ef5817da15090db7d1886698836847098887550100000403008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4813f6ffffffffff3f01'; | ||
const extrinsic = registry.createType('Extrinsic', hexToU8a(signedTx), { | ||
isSigned: true, | ||
}); | ||
const txMethodCall = registry.createType('Call', extrinsic.method); | ||
|
||
it('decode an extrinsics method', () => { | ||
const expectedResponse = { | ||
args: { | ||
dest: { | ||
id: 'FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP', | ||
}, | ||
value: '90071992547409910', | ||
}, | ||
name: 'transferKeepAlive', | ||
pallet: 'balances', | ||
}; | ||
|
||
const txMethod = toTxMethod( | ||
KUSAMA_9160_TEST_OPTIONS.registry, | ||
txMethodCall | ||
); | ||
|
||
expect(txMethod).toStrictEqual(expectedResponse); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/txwrapper-core/src/test-helpers/getRegistryKusama.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { TypeRegistry } from '@polkadot/types'; | ||
import { getSpecTypes } from '@polkadot/types-known'; | ||
|
||
import { getRegistryBase } from '../core'; | ||
|
||
/** | ||
* Get the Kusama type registry for a given spec version for testing purposes | ||
* | ||
* @param specVersion | ||
* @param metadataRpc | ||
*/ | ||
export function getRegistryKusama( | ||
specVersion: number, | ||
metadataRpc: `0x${string}` | ||
): TypeRegistry { | ||
return getRegistryBase({ | ||
chainProperties: { | ||
ss58Format: 2, | ||
tokenDecimals: 12, | ||
tokenSymbol: 'KSM', | ||
}, | ||
specTypes: getSpecTypes( | ||
new TypeRegistry(), | ||
'Kusama', | ||
'kusama', | ||
specVersion | ||
), | ||
metadataRpc, | ||
}); | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/txwrapper-core/src/test-helpers/metadata/kusamaV9160MetadataHex.ts
Large diffs are not rendered by default.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
packages/txwrapper-core/src/test-helpers/registries/kusamaRegistry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { getRegistryKusama } from '../getRegistryKusama'; | ||
import { kusamaV9160MetadataHex } from '../metadata/kusamaV9160MetadataHex'; | ||
|
||
/** | ||
* Polkadot v9122 TypeRegistry | ||
*/ | ||
export const kusamaRegistryV9160 = getRegistryKusama( | ||
9160, | ||
kusamaV9160MetadataHex | ||
); |