@@ -49,6 +49,14 @@ const conf: NttRoute.Config = {
49
49
} ;
50
50
const network : Network = "Testnet" ;
51
51
52
+ const dummyGetProtocol = async function ( name : string , params : any ) {
53
+ if ( name !== "Ntt" ) throw new Error ( "Unexpected protocol" ) ;
54
+ return {
55
+ getRateLimitDuration : async ( ) => 0n ,
56
+ getCurrentInboundCapacity : async ( ) => 0n ,
57
+ } ;
58
+ } ;
59
+
52
60
describe ( "Manual Route Tests" , function ( ) {
53
61
const wh = new Wormhole ( "Testnet" , [ SolanaPlatform , EvmPlatform ] ) ;
54
62
const fromChain = wh . getChain ( "Solana" ) ;
@@ -88,14 +96,15 @@ describe("Manual Route Tests", function () {
88
96
} ) ;
89
97
90
98
let found : routes . ManualRoute < Network > ;
99
+ let request : routes . RouteTransferRequest < Network > ;
91
100
it ( "Should resolve a given route request" , async function ( ) {
92
- const request = await routes . RouteTransferRequest . create ( wh , {
101
+ request = await routes . RouteTransferRequest . create ( wh , {
93
102
source : Wormhole . tokenId ( "Solana" , SOL_TOKEN ) ,
94
103
destination : Wormhole . tokenId ( "Sepolia" , SEPOLIA_TOKEN ) ,
95
104
} ) ;
96
105
const foundRoutes = await resolver . findRoutes ( request ) ;
97
106
expect ( foundRoutes ) . toHaveLength ( 1 ) ;
98
- expect ( foundRoutes [ 0 ] ! . request . fromChain . chain ) . toEqual ( "Solana" ) ;
107
+ expect ( request . fromChain . chain ) . toEqual ( "Solana" ) ;
99
108
100
109
const rt = foundRoutes [ 0 ] ! ;
101
110
if ( ! routes . isManual ( rt ) ) throw new Error ( "Expected manual route" ) ;
@@ -111,15 +120,20 @@ describe("Manual Route Tests", function () {
111
120
112
121
let vp : routes . ValidationResult < typeof op > ;
113
122
it ( "Should validate a transfer request" , async function ( ) {
114
- vp = await found . validate ( { amount : "1.0" , options : op } ) ;
123
+ vp = await found . validate ( request , { amount : "1.0" , options : op } ) ;
115
124
expect ( vp . valid ) . toBeTruthy ( ) ;
116
125
expect ( vp . params . amount ) . toEqual ( "1.0" ) ;
117
126
} ) ;
118
127
119
128
let qr : Awaited < ReturnType < typeof found . quote > > ;
120
129
it ( "Should fetch a quote given the validated parameters" , async function ( ) {
121
130
if ( ! vp . valid ) throw new Error ( "Invalid transfer params used" ) ;
122
- qr = await found . quote ( vp . params ) ;
131
+ const getProtocol = request . toChain . getProtocol ;
132
+ // @ts -ignore
133
+ // TODO: mock instead of monkey patch
134
+ request . toChain . getProtocol = dummyGetProtocol ;
135
+ qr = await found . quote ( request , vp . params ) ;
136
+ request . toChain . getProtocol = getProtocol ;
123
137
if ( ! qr . success ) throw new Error ( "Failed to fetch quote" ) ;
124
138
125
139
expect ( qr . params . amount ) . toEqual ( "1.0" ) ;
@@ -179,14 +193,15 @@ describe("Automatic Route Tests", function () {
179
193
} ) ;
180
194
181
195
let found : routes . AutomaticRoute < Network > ;
196
+ let request : routes . RouteTransferRequest < Network > ;
182
197
it ( "Should resolve a given route request" , async function ( ) {
183
- const request = await routes . RouteTransferRequest . create ( wh , {
198
+ request = await routes . RouteTransferRequest . create ( wh , {
184
199
source : Wormhole . tokenId ( "Solana" , SOL_TOKEN ) ,
185
200
destination : Wormhole . tokenId ( "Sepolia" , SEPOLIA_TOKEN ) ,
186
201
} ) ;
187
202
const foundRoutes = await resolver . findRoutes ( request ) ;
188
203
expect ( foundRoutes ) . toHaveLength ( 1 ) ;
189
- expect ( foundRoutes [ 0 ] ! . request . fromChain . chain ) . toEqual ( "Solana" ) ;
204
+ expect ( request . fromChain . chain ) . toEqual ( "Solana" ) ;
190
205
191
206
const rt = foundRoutes [ 0 ] ! ;
192
207
if ( ! routes . isAutomatic ( rt ) ) throw new Error ( "Expected automatic route" ) ;
@@ -202,15 +217,20 @@ describe("Automatic Route Tests", function () {
202
217
203
218
let vp : routes . ValidationResult < typeof op > ;
204
219
it ( "Should validate a transfer request" , async function ( ) {
205
- vp = await found . validate ( { amount : "1.0" , options : op } ) ;
220
+ vp = await found . validate ( request , { amount : "1.0" , options : op } ) ;
206
221
expect ( vp . valid ) . toBeTruthy ( ) ;
207
222
expect ( vp . params . amount ) . toEqual ( "1.0" ) ;
208
223
} ) ;
209
224
210
225
let qr : Awaited < ReturnType < typeof found . quote > > ;
211
226
it ( "Should fetch a quote given the validated parameters" , async function ( ) {
212
227
if ( ! vp . valid ) throw new Error ( "Invalid transfer params used" ) ;
213
- qr = await found . quote ( vp . params ) ;
228
+ const getProtocol = request . toChain . getProtocol ;
229
+ // @ts -ignore
230
+ // TODO: mock instead of monkey patch
231
+ request . toChain . getProtocol = dummyGetProtocol ;
232
+ qr = await found . quote ( request , vp . params ) ;
233
+ request . toChain . getProtocol = getProtocol ;
214
234
if ( ! qr . success ) throw new Error ( "Failed to fetch quote" ) ;
215
235
216
236
expect ( qr . params . amount ) . toEqual ( "1.0" ) ;
0 commit comments