-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(sdk): Add types for method property ✨
- Loading branch information
1 parent
1e92486
commit 58abfb6
Showing
72 changed files
with
1,030 additions
and
296 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
150 changes: 150 additions & 0 deletions
150
packages/sdk/src/nodes/polkadotXcm/PolkadotXCMTransferImpl.test.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,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' } | ||
) | ||
}) | ||
}) |
Oops, something went wrong.