Skip to content

Commit

Permalink
refactor(sdk): Add types for method property ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldev5 authored and dudo50 committed Sep 4, 2024
1 parent 1e92486 commit 58abfb6
Show file tree
Hide file tree
Showing 72 changed files with 1,030 additions and 296 deletions.
119 changes: 0 additions & 119 deletions packages/sdk/src/nodes/XTokensTransferImpl.ts

This file was deleted.

106 changes: 0 additions & 106 deletions packages/sdk/src/nodes/XTransferTransferImpl.ts

This file was deleted.

150 changes: 150 additions & 0 deletions packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { describe, it, expect, vi } from 'vitest'
import PolkadotXCMTransferImpl from './PolkadotXCMTransferImpl'
import { ApiPromise } from '@polkadot/api'
import {
PolkadotXcmSection,
PolkadotXCMTransferInput,
TCurrencySelectionHeaderArr,
TMultiLocationHeader,
Version
} from '../../types'

const mockApi = {
tx: {
polkadotXcm: {
limitedReserveTransferAssets: vi.fn()
}
}
} as unknown as ApiPromise

const mockHeader: TMultiLocationHeader = {
[Version.V4]: {
parents: 0,
interior: {
Here: null
}
}
}

const mockAddressSelection: TMultiLocationHeader = {
[Version.V4]: {
parents: 0,
interior: {
Here: null
}
}
}
const mockCurrencySelection: TCurrencySelectionHeaderArr = {
[Version.V4]: [
{
id: {
parents: 0,
interior: {
Here: null
}
},
fun: {
Fungible: '123'
}
}
]
}
const mockFeeAsset = 1
const mockSection: PolkadotXcmSection = 'limitedReserveTransferAssets'

describe('PolkadotXCMTransferImpl.transferPolkadotXCM', () => {
it('should return serialized call structure when serializedApiCallEnabled is true', () => {
const result = PolkadotXCMTransferImpl.transferPolkadotXCM(
{
api: mockApi,
header: mockHeader,
addressSelection: mockAddressSelection,
currencySelection: mockCurrencySelection,
feeAsset: mockFeeAsset,
serializedApiCallEnabled: true
} as PolkadotXCMTransferInput,
mockSection,
{ Limited: '1000' }
)

expect(result).toEqual({
module: 'polkadotXcm',
section: mockSection,
parameters: [
mockHeader,
mockAddressSelection,
mockCurrencySelection,
mockFeeAsset,
{ Limited: '1000' }
]
})
})

it('should call api.tx[module][section] with correct parameters when serializedApiCallEnabled is false and fees is undefined', () => {
PolkadotXCMTransferImpl.transferPolkadotXCM(
{
api: mockApi,
header: mockHeader,
addressSelection: mockAddressSelection,
currencySelection: mockCurrencySelection,
feeAsset: mockFeeAsset,
serializedApiCallEnabled: false
} as PolkadotXCMTransferInput,
mockSection,
undefined
)

expect(mockApi.tx.polkadotXcm[mockSection]).toHaveBeenCalledWith(
mockHeader,
mockAddressSelection,
mockCurrencySelection,
mockFeeAsset
)
})

it('should call api.tx[module][section] with correct parameters when serializedApiCallEnabled is false and fees is "Unlimited"', () => {
PolkadotXCMTransferImpl.transferPolkadotXCM(
{
api: mockApi,
header: mockHeader,
addressSelection: mockAddressSelection,
currencySelection: mockCurrencySelection,
feeAsset: mockFeeAsset,
serializedApiCallEnabled: false
} as PolkadotXCMTransferInput,
mockSection,
'Unlimited'
)

expect(mockApi.tx.polkadotXcm[mockSection]).toHaveBeenCalledWith(
mockHeader,
mockAddressSelection,
mockCurrencySelection,
mockFeeAsset,
'Unlimited'
)
})

it('should call api.tx[module][section] with correct parameters when serializedApiCallEnabled is false and fees is Limited', () => {
PolkadotXCMTransferImpl.transferPolkadotXCM(
{
api: mockApi,
header: mockHeader,
addressSelection: mockAddressSelection,
currencySelection: mockCurrencySelection,
feeAsset: mockFeeAsset,
serializedApiCallEnabled: false
} as PolkadotXCMTransferInput,
mockSection,
{ Limited: '1000' }
)

expect(mockApi.tx.polkadotXcm[mockSection]).toHaveBeenCalledWith(
mockHeader,
mockAddressSelection,
mockCurrencySelection,
mockFeeAsset,
{ Limited: '1000' }
)
})
})
Loading

0 comments on commit 58abfb6

Please sign in to comment.