Skip to content

Commit

Permalink
JettonTransferData
Browse files Browse the repository at this point in the history
- use loadMaybeRef for forwardPayload
- update tests
  • Loading branch information
grishamsc committed May 7, 2024
1 parent 5c14ab1 commit 9b5061a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
4 changes: 1 addition & 3 deletions Source/TonSwift/Jettons/JettonTransferData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public struct JettonTransferData: CellCodable {
let responseAddress: Address = try slice.loadType()
try slice.skip(1)
let forwardAmount = try slice.loadCoins().amount

let hasComment = try slice.loadBoolean()
let forwardPayload = try slice.loadRef()
let forwardPayload = try slice.loadMaybeRef()


return JettonTransferData(queryId: queryId,
Expand Down
36 changes: 21 additions & 15 deletions Tests/TonSwiftTests/Jettons/JettonTransferDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,38 @@ import BigInt
final class JettonTransferDataTests: XCTestCase {

private var transferJettonData: JettonTransferData {
let queryId: UInt64 = 543
let amount = BigUInt(stringLiteral: "63546")
let toAddress = Address.mock(workchain: 0, seed: "toAddressSeed")
let responseAddress = Address.mock(workchain: 0, seed: "responseAddressSeed")
let forwardAmount = BigUInt(stringLiteral: "789")
let comment = "Hello, this is a comment"

return JettonTransferData(queryId: queryId,
amount: amount,
toAddress: toAddress,
responseAddress: responseAddress,
forwardAmount: forwardAmount,
comment: comment)
get throws {
let queryId: UInt64 = 543
let amount = BigUInt(stringLiteral: "63546")
let toAddress = Address.mock(workchain: 0, seed: "toAddressSeed")
let responseAddress = Address.mock(workchain: 0, seed: "responseAddressSeed")
let forwardAmount = BigUInt(stringLiteral: "789")
let comment = "Hello, this is a comment"
let forwardPayload = try Builder().store(int: 0, bits: 32).writeSnakeData(Data(comment.utf8)).endCell()


return JettonTransferData(queryId: queryId,
amount: amount,
toAddress: toAddress,
responseAddress: responseAddress,
forwardAmount: forwardAmount,
forwardPayload: forwardPayload)
}
}

func testJettonTransferDataEncodeAndDecode() throws {
let builder = Builder()
let transferJettonDataCell = try builder.store(transferJettonData).endCell()
let decodedJettonTransferData: JettonTransferData = try Slice(cell: transferJettonDataCell).loadType()

let transferJettonData = try transferJettonData

XCTAssertEqual(transferJettonData.queryId, decodedJettonTransferData.queryId)
XCTAssertEqual(transferJettonData.amount, decodedJettonTransferData.amount)
XCTAssertEqual(transferJettonData.toAddress, decodedJettonTransferData.toAddress)
XCTAssertEqual(transferJettonData.responseAddress, decodedJettonTransferData.responseAddress)
XCTAssertEqual(transferJettonData.forwardAmount, decodedJettonTransferData.forwardAmount)
XCTAssertEqual(transferJettonData.comment, decodedJettonTransferData.comment )
XCTAssertEqual(transferJettonData.forwardPayload, decodedJettonTransferData.forwardPayload)
}

func testJettonTransferDataEncode() throws {
Expand All @@ -46,7 +52,7 @@ final class JettonTransferDataTests: XCTestCase {

XCTAssertEqual(try transferJettonDataCell.toString(),
"""
x{0F8A7EA5000000000000021F2F83A8011740C74E876FBD00C1F39161C9DF68563FC469A730CBF932D464EB819239084F001AAD4BD6DAA342C7D03C496083C01AEC31F1A457B8C993C62823E3713E11FD8184062BC_}
x{0F8A7EA5000000000000021F2F83A8011740C74E876FBD00C1F39161C9DF68563FC469A730CBF932D464EB819239084F001AAD4BD6DAA342C7D03C496083C01AEC31F1A457B8C993C62823E3713E11FD8184062B}
x{0000000048656C6C6F2C2074686973206973206120636F6D6D656E74}
""")
}
Expand Down

0 comments on commit 9b5061a

Please sign in to comment.