-
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.
feat: add asCallsOnlyArg to reduce size of metadata (#149)
* feat: add asCallsOnlyArg to reduce size of metadata * add asCallsOnly to getRegistry * lint * add v9122 metadata and registry * adds test to check if asCallsOnly returns a smaller metadata hex * fix example build * take metadata from registry * cleanup * more tests for defineMethod and createMetadata * cleanup grumbles * lint * Update packages/txwrapper-core/src/test-helpers/constants.ts Co-authored-by: Zeke Mostov <[email protected]> * update examples * update chain builders guide Co-authored-by: Zeke Mostov <[email protected]>
- Loading branch information
Showing
20 changed files
with
195 additions
and
22 deletions.
There are no files selected for viewing
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
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
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
53 changes: 53 additions & 0 deletions
53
packages/txwrapper-core/src/core/metadata/createMetadata.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,53 @@ | ||
import { Metadata } from '@polkadot/types'; | ||
import { MetadataVersioned } from '@polkadot/types/metadata/MetadataVersioned'; | ||
|
||
import { polkadotV9122MetadataHex } from '../../test-helpers/metadata/polkadotV9122MetadataHex'; | ||
import { polkadotRegistryV9122 } from '../../test-helpers/registries'; | ||
import { createMetadata, createMetadataUnmemoized } from './createMetadata'; | ||
|
||
describe('createMetadata', () => { | ||
const unmemoizedMetadata: Metadata = createMetadataUnmemoized( | ||
polkadotRegistryV9122, | ||
polkadotV9122MetadataHex | ||
); | ||
const unmemoizedMetadataAsCalls: MetadataVersioned = createMetadataUnmemoized( | ||
polkadotRegistryV9122, | ||
polkadotV9122MetadataHex, | ||
true | ||
); | ||
const memoizedMetadata: Metadata = createMetadata( | ||
polkadotRegistryV9122, | ||
polkadotV9122MetadataHex | ||
); | ||
const memoizedMetadataAsCalls: MetadataVersioned = createMetadata( | ||
polkadotRegistryV9122, | ||
polkadotV9122MetadataHex, | ||
true | ||
); | ||
|
||
it('Metadata should decrease in byte size when `asCallsOnlyArg` is true with `createMetadataUnmemoized`', () => { | ||
const metadataBuffer = Buffer.from(unmemoizedMetadata.toHex(), 'utf-8'); | ||
const metadataAsCallsBuffer = Buffer.from( | ||
unmemoizedMetadataAsCalls.toHex(), | ||
'utf-8' | ||
); | ||
|
||
expect(metadataAsCallsBuffer.byteLength).toBeGreaterThan(0); | ||
expect(metadataBuffer.byteLength).toBeGreaterThan( | ||
metadataAsCallsBuffer.byteLength | ||
); | ||
}); | ||
|
||
it('Metadata should decrease in byte size when `asCallsOnlyArg` is true with `createMetadata`', () => { | ||
const metadataBuffer = Buffer.from(memoizedMetadata.toHex(), 'utf-8'); | ||
const metadataAsCallsBuffer = Buffer.from( | ||
memoizedMetadataAsCalls.toHex(), | ||
'utf-8' | ||
); | ||
|
||
expect(metadataAsCallsBuffer.byteLength).toBeGreaterThan(0); | ||
expect(metadataBuffer.byteLength).toBeGreaterThan( | ||
metadataAsCallsBuffer.byteLength | ||
); | ||
}); | ||
}); |
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
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
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
2 changes: 2 additions & 0 deletions
2
packages/txwrapper-core/src/test-helpers/metadata/polkadotV9122MetadataHex.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
export * from './polkadotRegistry'; |
10 changes: 10 additions & 0 deletions
10
packages/txwrapper-core/src/test-helpers/registries/polkadotRegistry.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 { getRegistryPolkadot } from '../getRegistryPolkadot'; | ||
import { polkadotV9122MetadataHex } from '../metadata/polkadotV9122MetadataHex'; | ||
|
||
/** | ||
* Polkadot v9122 TypeRegistry | ||
*/ | ||
export const polkadotRegistryV9122 = getRegistryPolkadot( | ||
9122, | ||
polkadotV9122MetadataHex | ||
); |
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
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
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 |
---|---|---|
|
@@ -67,5 +67,5 @@ export function signWith( | |
}) | ||
.sign(pair); | ||
|
||
return signature; | ||
return signature as unknown as `0x${string}`; | ||
} |
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