1+ import { describe , it , expect } from 'bun:test'
2+ import { getTestnetMintParams } from '../src/slpx-testnet'
3+ import { parseUnits } from 'viem'
4+
5+ describe ( 'getTestnetMintParams' , ( ) => {
6+ describe ( 'successful cases' , ( ) => {
7+ it ( 'should return correct params for ETH on arbitrumSepolia with chain name' , ( ) => {
8+ const params = getTestnetMintParams ( 'eth' , 'arbitrumSepolia' , '1.0' )
9+
10+ expect ( params ) . toEqual ( {
11+ address : '0x62CA64454046BbC18e35066A6350Acb0378EB3c2' ,
12+ abi : expect . any ( Array ) ,
13+ functionName : 'createOrder' ,
14+ args : [
15+ '0x0000000000000000000000000000000000000000' , // ETH address
16+ parseUnits ( '1.0' , 18 ) ,
17+ 0 ,
18+ 'bifrost'
19+ ]
20+ } )
21+ } )
22+
23+ it ( 'should return correct params for DOT on baseSepolia with chain ID' , ( ) => {
24+ const params = getTestnetMintParams ( 'dot' , 84532 , '0.5' )
25+
26+ expect ( params ) . toEqual ( {
27+ address : '0x262e52beD191a441CBD28dB151A11D7c41384F72' ,
28+ abi : expect . any ( Array ) ,
29+ functionName : 'createOrder' ,
30+ args : [
31+ '0x4B16E254E7848e0826eBDd3049474fD9E70A244c' ,
32+ parseUnits ( '0.5' , 18 ) ,
33+ 0 ,
34+ 'bifrost'
35+ ]
36+ } )
37+ } )
38+
39+ it ( 'should accept custom partner code' , ( ) => {
40+ const params = getTestnetMintParams ( 'dot' , 'ethereumSepolia' , '2.0' , 'customPartner' )
41+
42+ expect ( params . args [ 3 ] ) . toBe ( 'customPartner' )
43+ } )
44+
45+ it ( 'should work with different decimal amounts' , ( ) => {
46+ const params = getTestnetMintParams ( 'dot' , 'bscTestnet' , '123.456789' )
47+
48+ expect ( params . args [ 1 ] ) . toBe ( parseUnits ( '123.456789' , 18 ) )
49+ } )
50+
51+ it ( 'should work with very small amounts' , ( ) => {
52+ const params = getTestnetMintParams ( 'eth' , 'unichainSepolia' , '0.000001' )
53+
54+ expect ( params . args [ 1 ] ) . toBe ( parseUnits ( '0.000001' , 18 ) )
55+ } )
56+ } )
57+
58+ describe ( 'error cases' , ( ) => {
59+ it ( 'should throw error for unsupported asset on chain' , ( ) => {
60+ expect ( ( ) => {
61+ getTestnetMintParams ( 'manta' , 'arbitrumSepolia' , '1.0' )
62+ } ) . toThrow ( 'Asset manta not found on chain arbitrumSepolia' )
63+ } )
64+
65+ it ( 'should throw error for invalid chain name' , ( ) => {
66+ expect ( ( ) => {
67+ // @ts -ignore - testing runtime error
68+ getTestnetMintParams ( 'eth' , 'invalidChain' , '1.0' )
69+ } ) . toThrow ( 'Unsupported chain: invalidChain' )
70+ } )
71+
72+ it ( 'should throw error for invalid chain ID' , ( ) => {
73+ expect ( ( ) => {
74+ // @ts -ignore - testing runtime error
75+ getTestnetMintParams ( 'eth' , 999999 , '1.0' )
76+ } ) . toThrow ( 'Unsupported chain ID: 999999' )
77+ } )
78+
79+ it ( 'should throw error for zero amount' , ( ) => {
80+ expect ( ( ) => {
81+ getTestnetMintParams ( 'eth' , 'arbitrumSepolia' , '0' )
82+ } ) . toThrow ( 'Amount must be a positive number' )
83+ } )
84+
85+ it ( 'should throw error for negative amount' , ( ) => {
86+ expect ( ( ) => {
87+ getTestnetMintParams ( 'eth' , 'arbitrumSepolia' , '-1.0' )
88+ } ) . toThrow ( 'Amount must be a positive number' )
89+ } )
90+
91+ it ( 'should throw error for invalid partner code type' , ( ) => {
92+ expect ( ( ) => {
93+ // @ts -ignore - testing runtime error
94+ getTestnetMintParams ( 'eth' , 'arbitrumSepolia' , '1.0' , 123 )
95+ } ) . toThrow ( 'Partner code must be a string' )
96+ } )
97+
98+ it ( 'should throw error for chain without SLPX contract' , ( ) => {
99+ expect ( ( ) => {
100+ getTestnetMintParams ( 'eth' , 'moonbaseTestnet' , '1.0' )
101+ } ) . toThrow ( 'Asset eth not found on chain moonbaseTestnet' )
102+ } )
103+ } )
104+
105+ describe ( 'parameter validation' , ( ) => {
106+ it ( 'should handle different supported assets on different chains' , ( ) => {
107+ // Test ETH on Ethereum Sepolia
108+ expect ( ( ) => getTestnetMintParams ( 'eth' , 'ethereumSepolia' , '1.0' ) ) . not . toThrow ( )
109+
110+ // Test DOT on BSC Testnet
111+ expect ( ( ) => getTestnetMintParams ( 'dot' , 'bscTestnet' , '1.0' ) ) . not . toThrow ( )
112+
113+ // Test DOT on Asset Hub
114+ expect ( ( ) => getTestnetMintParams ( 'dot' , 'passetHub' , '1.0' ) ) . not . toThrow ( )
115+ } )
116+
117+ it ( 'should correctly map chain names to chain IDs' , ( ) => {
118+ const paramsWithName = getTestnetMintParams ( 'eth' , 'arbitrumSepolia' , '1.0' )
119+ const paramsWithId = getTestnetMintParams ( 'eth' , 421614 , '1.0' )
120+
121+ expect ( paramsWithName . address ) . toBe ( paramsWithId . address )
122+ expect ( paramsWithName . args ) . toEqual ( paramsWithId . args )
123+ } )
124+
125+ it ( 'should use default partner code when not provided' , ( ) => {
126+ const params = getTestnetMintParams ( 'eth' , 'arbitrumSepolia' , '1.0' )
127+
128+ expect ( params . args [ 3 ] ) . toBe ( 'bifrost' )
129+ } )
130+
131+ it ( 'should preserve exact amount precision' , ( ) => {
132+ const amount = '1.123456789012345678'
133+ const params = getTestnetMintParams ( 'eth' , 'arbitrumSepolia' , amount )
134+
135+ expect ( params . args [ 1 ] ) . toBe ( parseUnits ( amount , 18 ) )
136+ } )
137+ } )
138+
139+ describe ( 'return value structure' , ( ) => {
140+ it ( 'should return object with correct structure' , ( ) => {
141+ const params = getTestnetMintParams ( 'eth' , 'arbitrumSepolia' , '1.0' )
142+
143+ expect ( params ) . toHaveProperty ( 'address' )
144+ expect ( params ) . toHaveProperty ( 'abi' )
145+ expect ( params ) . toHaveProperty ( 'functionName' )
146+ expect ( params ) . toHaveProperty ( 'args' )
147+
148+ expect ( typeof params . address ) . toBe ( 'string' )
149+ expect ( Array . isArray ( params . abi ) ) . toBe ( true )
150+ expect ( params . functionName ) . toBe ( 'createOrder' )
151+ expect ( Array . isArray ( params . args ) ) . toBe ( true )
152+ expect ( params . args ) . toHaveLength ( 4 )
153+ } )
154+
155+ it ( 'should have correct argument types' , ( ) => {
156+ const params = getTestnetMintParams ( 'dot' , 'bscTestnet' , '1.0' , 'test' )
157+
158+ expect ( typeof params . args [ 0 ] ) . toBe ( 'string' ) // asset address
159+ expect ( typeof params . args [ 1 ] ) . toBe ( 'bigint' ) // parsed amount
160+ expect ( typeof params . args [ 2 ] ) . toBe ( 'number' ) // always 0
161+ expect ( typeof params . args [ 3 ] ) . toBe ( 'string' ) // partner code
162+ } )
163+ } )
164+ } )
0 commit comments