|
| 1 | +// |
| 2 | +// TransactionReceiptTests.swift |
| 3 | +// |
| 4 | +// Created by JeneaVranceanu on 10.01.2023. |
| 5 | +// |
| 6 | + |
| 7 | +import Foundation |
| 8 | +import XCTest |
| 9 | +import BigInt |
| 10 | + |
| 11 | +@testable import Web3Core |
| 12 | + |
| 13 | +class TransactionReceiptTests: XCTestCase { |
| 14 | + |
| 15 | + func testDecodeTransactionReceiptJson() throws { |
| 16 | + let transactionHash: Data = Data.fromHex("0xbe981126f05b4110d5bf4a22d474b6a7ef861ae79fc6939260bb2c3003367eed")! |
| 17 | + let blockHash: Data = Data.fromHex("0x0103a5759c39720ecd23d48281e32526ae50eaa3e651a5e8c86e47838e060cb8")! |
| 18 | + let blockNumber: BigUInt = 12 |
| 19 | + let transactionIndex: BigUInt = 10 |
| 20 | + let contractAddress = EthereumAddress("0xdf85ee41abbf15cdf1dbf89fb7af9a9557c5dd7e")! |
| 21 | + let cumulativeGasUsed: BigUInt = 789456132 |
| 22 | + let gasUsed: BigUInt = 8857745 |
| 23 | + let effectiveGasPrice: BigUInt = 123456 |
| 24 | + /// This is not an EventLog decoding test so the array is empty |
| 25 | + let logs: [EventLog] = [] |
| 26 | + let status = TransactionReceipt.TXStatus.ok |
| 27 | + let logsBloom = EthereumBloomFilter(12348880)! |
| 28 | + |
| 29 | + let transactionJson = "{\"transactionHash\":\"\(transactionHash.toHexString().addHexPrefix())\",\"transactionIndex\":\"\(transactionIndex.hexString)\",\"blockNumber\":\"\(blockNumber.hexString)\",\"blockHash\":\"\(blockHash.toHexString().addHexPrefix())\",\"from\":\"0xdf85ee41abbf15cdf1dbf89fb7af9a9557c5dd7e\",\"to\":\"0xe22b8979739d724343bd002f9f432f5990879901\",\"cumulativeGasUsed\":\"\(cumulativeGasUsed.hexString)\",\"gasUsed\":\"\(gasUsed.hexString)\",\"contractAddress\":\"\(contractAddress.address)\",\"logs\":[],\"logsBloom\":\"\(logsBloom.bytes.toHexString().addHexPrefix())\",\"status\":\"0x1\",\"effectiveGasPrice\":\"\(effectiveGasPrice.hexString)\",\"type\":\"0x2\"}" |
| 30 | + let transactionReceipt = try JSONDecoder().decode(TransactionReceipt.self, from: transactionJson.data(using: .utf8)!) |
| 31 | + |
| 32 | + XCTAssertEqual(blockHash, transactionReceipt.blockHash) |
| 33 | + XCTAssertEqual(blockNumber, transactionReceipt.blockNumber) |
| 34 | + XCTAssertEqual(transactionIndex, transactionReceipt.transactionIndex) |
| 35 | + XCTAssertEqual(contractAddress, transactionReceipt.contractAddress) |
| 36 | + XCTAssertEqual(cumulativeGasUsed, transactionReceipt.cumulativeGasUsed) |
| 37 | + XCTAssertEqual(gasUsed, transactionReceipt.gasUsed) |
| 38 | + XCTAssertEqual(effectiveGasPrice, transactionReceipt.effectiveGasPrice) |
| 39 | + XCTAssertEqual(logs.count, transactionReceipt.logs.count) |
| 40 | + XCTAssertEqual(status, transactionReceipt.status) |
| 41 | + XCTAssertEqual(logsBloom.bytes, transactionReceipt.logsBloom?.bytes) |
| 42 | + } |
| 43 | + |
| 44 | +} |
0 commit comments