Skip to content

Commit 313c272

Browse files
jakubuidclaude
andcommitted
test(tvf): un-wrap dispatcher-level payloads for fixed collectors
The dispatcher-level TVFCollectorTests still fed the removed {"result": ...} envelope for the seven collectors fixed to decode the raw result value (XRPL, Sui, Hedera, Stacks, Bitcoin, Algorand), so those eight tests failed once the collectors read the real shape. Tron and Near keep the wrapped payloads on purpose — their collectors were intentionally left unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 79d3ada commit 313c272

1 file changed

Lines changed: 22 additions & 33 deletions

File tree

Tests/RelayerTests/TVFCollectorTests.swift

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,11 @@ final class TVFCollectorTests: XCTestCase {
277277
let expectedHash = "73734B611DDA23D3F5F62E20A173B78AB8406AC5015094DA53F53D39B9EDB06C"
278278
let resultModel = XRPLMockFactory.createTransactionResult(hash: expectedHash)
279279

280-
// Create proper nested RPCResult
280+
// Raw result value — RPCResult.response already holds the unwrapped result
281281
let jsonData = try! JSONEncoder().encode(resultModel)
282282
let jsonDict = try! JSONSerialization.jsonObject(with: jsonData) as! [String: Any]
283-
let nestedData = ["result": jsonDict]
284-
let rpcResult = RPCResult.response(AnyCodable(any: nestedData))
285-
283+
let rpcResult = RPCResult.response(AnyCodable(any: jsonDict))
284+
286285
// Act
287286
let data = tvf.collect(
288287
rpcMethod: "xrpl_signTransaction",
@@ -302,12 +301,11 @@ final class TVFCollectorTests: XCTestCase {
302301
let expectedHash = "BA2AF0C652F46C97B85C1D17080EEC7422C092B0BD906DCA344B42EF30FA8285"
303302
let resultModel = XRPLMockFactory.createTransactionResult(hash: expectedHash)
304303

305-
// Create proper nested RPCResult
304+
// Raw result value — RPCResult.response already holds the unwrapped result
306305
let jsonData = try! JSONEncoder().encode(resultModel)
307306
let jsonDict = try! JSONSerialization.jsonObject(with: jsonData) as! [String: Any]
308-
let nestedData = ["result": jsonDict]
309-
let rpcResult = RPCResult.response(AnyCodable(any: nestedData))
310-
307+
let rpcResult = RPCResult.response(AnyCodable(any: jsonDict))
308+
311309
// Act
312310
let data = tvf.collect(
313311
rpcMethod: "xrpl_signTransactionFor",
@@ -327,12 +325,11 @@ final class TVFCollectorTests: XCTestCase {
327325
let expectedTransactionId = "0.0.12345678@1689281510.675369303"
328326
let resultModel = HederaMockFactory.createTransactionResult(transactionId: expectedTransactionId)
329327

330-
// Create proper nested RPCResult
328+
// Raw result value — RPCResult.response already holds the unwrapped result
331329
let jsonData = try! JSONEncoder().encode(resultModel)
332330
let jsonDict = try! JSONSerialization.jsonObject(with: jsonData) as! [String: Any]
333-
let nestedData = ["result": jsonDict]
334-
let rpcResult = RPCResult.response(AnyCodable(any: nestedData))
335-
331+
let rpcResult = RPCResult.response(AnyCodable(any: jsonDict))
332+
336333
// Act
337334
let data = tvf.collect(
338335
rpcMethod: "hedera_signAndExecuteTransaction",
@@ -352,12 +349,11 @@ final class TVFCollectorTests: XCTestCase {
352349
let expectedTransactionId = "0.0.98765432@1689281510.675369303"
353350
let resultModel = HederaMockFactory.createTransactionResult(transactionId: expectedTransactionId)
354351

355-
// Create proper nested RPCResult
352+
// Raw result value — RPCResult.response already holds the unwrapped result
356353
let jsonData = try! JSONEncoder().encode(resultModel)
357354
let jsonDict = try! JSONSerialization.jsonObject(with: jsonData) as! [String: Any]
358-
let nestedData = ["result": jsonDict]
359-
let rpcResult = RPCResult.response(AnyCodable(any: nestedData))
360-
355+
let rpcResult = RPCResult.response(AnyCodable(any: jsonDict))
356+
361357
// Act
362358
let data = tvf.collect(
363359
rpcMethod: "hedera_executeTransaction",
@@ -377,8 +373,8 @@ final class TVFCollectorTests: XCTestCase {
377373
"gqNzaWfEQNGPgbxS9pTu0sTikT3cJVO48WFltc8MM8meFR+aAnGwOo3FO+0nFkAludT0jNqHRM6E65gW6k/m92sHVCxVnQWjdHhuiaNhbXTOAAehIKNmZWXNA+iiZnbOAv0CO6NnZW6sbWFpbm5ldC12MS4womdoxCDAYcTY/B293tLXYEvkVo4/bQQZh6w3veS2ILWrOSSK36Jsds4C/QYjo3JjdsQgeqRNTBEXudHx2kO9Btq289aRzj5DlNUw0jwX9KEnaZqjc25kxCDH1s5tvgARbjtHceUG07Sj5IDfqzn7Zwx0P+XuvCYMz6R0eXBlo3BheQ=="
378374
]
379375

380-
// Create proper JSON-RPC format response
381-
let rpcResult = RPCResult.response(AnyCodable(any: ["result": signedTxns]))
376+
// Raw result value — RPCResult.response already holds the unwrapped result
377+
let rpcResult = RPCResult.response(AnyCodable(any: signedTxns))
382378

383379
// Act
384380
let data = tvf.collect(
@@ -402,15 +398,10 @@ final class TVFCollectorTests: XCTestCase {
402398
let expectedDigest = "8cZk5Zj1sMZes9jBxrKF3Nv8uZJor3V5XTFmxp3GTxhp"
403399
let resultModel = SuiMockFactory.createSignAndExecuteTransactionResult(digest: expectedDigest)
404400

405-
// Create proper JSON-RPC format response (Tron-style)
406-
// 1. Encode the resultModel to JSON Data
401+
// Raw result value — RPCResult.response already holds the unwrapped result
407402
let resultModelData = try! JSONEncoder().encode(resultModel)
408-
// 2. Convert JSON Data to a [String: Any] dictionary
409403
let resultModelJsonDict = try! JSONSerialization.jsonObject(with: resultModelData) as! [String: Any]
410-
// 3. Create the payload dictionary for AnyCodable(any:)
411-
let rpcPayloadForAnyCodable: [String: Any] = ["result": resultModelJsonDict]
412-
// 4. Wrap this payload using AnyCodable(any:)
413-
let rpcResult = RPCResult.response(AnyCodable(any: rpcPayloadForAnyCodable))
404+
let rpcResult = RPCResult.response(AnyCodable(any: resultModelJsonDict))
414405

415406
// Act
416407
let data = tvf.collect(
@@ -497,12 +488,11 @@ final class TVFCollectorTests: XCTestCase {
497488
let expectedTxid = "f007551f169722ce74104d6673bd46ce193c624b8550889526d1b93820d725f7"
498489
let resultModel = BitcoinMockFactory.createTransferResult(txid: expectedTxid)
499490

500-
// Create proper JSON-RPC format response
491+
// Raw result value — RPCResult.response already holds the unwrapped result
501492
let resultModelData = try! JSONEncoder().encode(resultModel)
502493
let resultModelJsonDict = try! JSONSerialization.jsonObject(with: resultModelData) as! [String: Any]
503-
let rpcPayloadForAnyCodable: [String: Any] = ["result": resultModelJsonDict]
504-
let rpcResult = RPCResult.response(AnyCodable(any: rpcPayloadForAnyCodable))
505-
494+
let rpcResult = RPCResult.response(AnyCodable(any: resultModelJsonDict))
495+
506496
// Act
507497
let data = tvf.collect(
508498
rpcMethod: "sendTransfer",
@@ -523,12 +513,11 @@ final class TVFCollectorTests: XCTestCase {
523513
let expectedTxId = "stack_tx_id"
524514
let resultModel = StacksMockFactory.createTransferResult(txid: expectedTxId)
525515

526-
// Create proper JSON-RPC format response
516+
// Raw result value — RPCResult.response already holds the unwrapped result
527517
let resultModelData = try! JSONEncoder().encode(resultModel)
528518
let resultModelJsonDict = try! JSONSerialization.jsonObject(with: resultModelData) as! [String: Any]
529-
let rpcPayloadForAnyCodable: [String: Any] = ["result": resultModelJsonDict]
530-
let rpcResult = RPCResult.response(AnyCodable(any: rpcPayloadForAnyCodable))
531-
519+
let rpcResult = RPCResult.response(AnyCodable(any: resultModelJsonDict))
520+
532521
// Act
533522
let data = tvf.collect(
534523
rpcMethod: "stx_transferStx",

0 commit comments

Comments
 (0)