-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
877 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* | ||
* Hedera Swift SDK | ||
* | ||
* Copyright (C) 2023 - 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import HederaProtobufs | ||
import SnapshotTesting | ||
import XCTest | ||
|
||
@testable import Hedera | ||
|
||
internal final class CryptoPemTests: XCTestCase { | ||
internal func testLabelType() throws { | ||
let pemString = | ||
""" | ||
-----BEGIN PRIVATE KEY----- | ||
MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjeB6TNNQX+1gICCAAw | ||
-----END PRIVATE KEY----- | ||
""" | ||
|
||
let doc = try Crypto.Pem.decode(pemString) | ||
|
||
XCTAssertEqual(doc.typeLabel, "PRIVATE KEY") | ||
} | ||
|
||
internal func testExceedsLineLimitFail() throws { | ||
let pemString = | ||
""" | ||
-----BEGIN PRIVATE KEY----- | ||
MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjeB6TNNQX+1gICCAAwMIGb | ||
-----END PRIVATE KEY----- | ||
""" | ||
|
||
XCTAssertThrowsError(try Crypto.Pem.decode(pemString)) | ||
} | ||
|
||
internal func testShortLineFail() throws { | ||
let pemString = | ||
""" | ||
-----BEGIN PRIVATE KEY----- | ||
MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFD | ||
-----END PRIVATE KEY----- | ||
""" | ||
|
||
XCTAssertThrowsError(try Crypto.Pem.decode(pemString)) | ||
} | ||
|
||
internal func testNonBase64CharacterFail() throws { | ||
let pemString = | ||
""" | ||
-----BEGIN PRIVATE KEY----- | ||
≈MIGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjeB6TNNQX+1gICCAAw | ||
-----END PRIVATE KEY----- | ||
""" | ||
|
||
XCTAssertThrowsError(try Crypto.Pem.decode(pemString)) | ||
} | ||
|
||
internal func testBadHeaderFail() throws { | ||
let pemString = | ||
""" | ||
-----BEGIN PRIVATE KEYS----- | ||
MIGbMFcGCSqGSIb3DQEFDSTBKMCkGCSqGSIb3DQEFDDAcBAjeB6TNNQX+1gICCAAw | ||
-----END PRIVATE KEY----- | ||
""" | ||
|
||
XCTAssertThrowsError(try Crypto.Pem.decode(pemString)) | ||
} | ||
|
||
internal func testBadFooterFail() throws { | ||
let pemString = | ||
""" | ||
-----BEGIN PRIVATE KEY----- | ||
MIGbMFcGCSqGSIb3DQEFDSTBKMCkGCSqGSIb3DQEFDDAcBAjeB6TNNQX+1gICCAAw | ||
-----END PRIVATE KEYS----- | ||
""" | ||
|
||
XCTAssertThrowsError(try Crypto.Pem.decode(pemString)) | ||
} | ||
|
||
internal func testBase64CharacterFail() throws { | ||
let pemString = | ||
""" | ||
-----BEGIN PRIVATE KEY----- | ||
@IGbMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAjeB6TNNQX+1gICCAAw | ||
-----END PRIVATE KEY----- | ||
""" | ||
|
||
XCTAssertThrowsError(try Crypto.Pem.decode(pemString)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* | ||
* Hedera Swift SDK | ||
* | ||
* Copyright (C) 2023 - 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import HederaProtobufs | ||
import SnapshotTesting | ||
import XCTest | ||
|
||
@testable import Hedera | ||
|
||
internal final class CustomFeeTests: XCTestCase { | ||
private static let customFixedFee = Proto_CustomFee.with { proto in | ||
proto.feeCollectorAccountID = AccountId(4322).toProtobuf() | ||
proto.fee = .fixedFee( | ||
Proto_FixedFee.with { proto in | ||
proto.amount = 10 | ||
proto.denominatingTokenID = TokenId(483902).toProtobuf() | ||
}) | ||
} | ||
|
||
private static let customFractionalFee = Proto_CustomFee.with { proto in | ||
proto.feeCollectorAccountID = AccountId(389042).toProtobuf() | ||
proto.fee = .fractionalFee( | ||
Proto_FractionalFee.with { proto in | ||
proto.fractionalAmount = .with { proto in | ||
proto.numerator = 3 | ||
proto.denominator = 7 | ||
} | ||
proto.minimumAmount = 3 | ||
proto.maximumAmount = 100 | ||
}) | ||
} | ||
|
||
private static let customRoyaltyFee = Proto_CustomFee.with { proto in | ||
proto.feeCollectorAccountID = AccountId(23423).toProtobuf() | ||
proto.fee = .royaltyFee( | ||
Proto_RoyaltyFee.with { proto in | ||
proto.fallbackFee = .with { proto in | ||
proto.amount = 10 | ||
proto.denominatingTokenID = TokenId(483902).toProtobuf() | ||
} | ||
proto.exchangeValueFraction = .with { proto in | ||
proto.numerator = 5 | ||
proto.denominator = 8 | ||
} | ||
}) | ||
} | ||
|
||
internal func testSerializeFixed() throws { | ||
assertSnapshot(matching: Self.customFixedFee, as: .description) | ||
} | ||
|
||
internal func testSerializeFractional() throws { | ||
assertSnapshot(matching: Self.customFractionalFee, as: .description) | ||
} | ||
|
||
internal func testSerializeRoyalty() throws { | ||
assertSnapshot(matching: Self.customRoyaltyFee, as: .description) | ||
} | ||
|
||
internal func testFixedFromToBytes() throws { | ||
let fixed = try AnyCustomFee.fromProtobuf(Self.customFixedFee) | ||
let bytes = fixed.toBytes() | ||
XCTAssertEqual(try AnyCustomFee.fromBytes(bytes), fixed) | ||
} | ||
|
||
internal func testFractionalFromToBytes() throws { | ||
let fractional = try AnyCustomFee.fromProtobuf(Self.customFractionalFee) | ||
let bytes = fractional.toBytes() | ||
XCTAssertEqual(try AnyCustomFee.fromBytes(bytes), fractional) | ||
} | ||
|
||
internal func testRoyaltyFromToBytes() throws { | ||
let royalty = try AnyCustomFee.fromProtobuf(Self.customRoyaltyFee) | ||
let bytes = royalty.toBytes() | ||
XCTAssertEqual(try AnyCustomFee.fromBytes(bytes), royalty) | ||
} | ||
|
||
internal func testFixedFromProtobuf() throws { | ||
assertSnapshot(matching: try AnyCustomFee.fromProtobuf(Self.customFixedFee), as: .description) | ||
} | ||
|
||
internal func testFractionalFromProtobuf() throws { | ||
assertSnapshot(matching: try AnyCustomFee.fromProtobuf(Self.customFractionalFee), as: .description) | ||
} | ||
|
||
internal func testRoyaltyFromProtobuf() throws { | ||
assertSnapshot(matching: try AnyCustomFee.fromProtobuf(Self.customRoyaltyFee), as: .description) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* | ||
* Hedera Swift SDK | ||
* | ||
* Copyright (C) 2023 - 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import SnapshotTesting | ||
import XCTest | ||
|
||
@testable import Hedera | ||
|
||
internal final class FeeScheduleTests: XCTestCase { | ||
private static func makeFeeComponent(_ min: UInt64, _ max: UInt64) -> FeeComponents { | ||
FeeComponents( | ||
min: min, max: max, constant: 0, bandwidthByte: 0, verification: 0, storageByteHour: 0, ramByteHour: 0, | ||
contractTransactionGas: 0, transferVolumeHbar: 0, responseMemoryByte: 0, responseDiskByte: 0) | ||
} | ||
|
||
private let feeSchedule: FeeSchedule = | ||
FeeSchedule.init( | ||
transactionFeeSchedules: [ | ||
TransactionFeeSchedule( | ||
requestType: nil, | ||
fees: [ | ||
FeeData.init( | ||
node: makeFeeComponent(0, 0), network: makeFeeComponent(2, 5), | ||
service: makeFeeComponent(0, 0), kind: FeeDataType.default) | ||
]) | ||
], expirationTime: Timestamp(seconds: 1_554_158_542, subSecondNanos: 0)) | ||
|
||
internal func testSerialize() throws { | ||
assertSnapshot(matching: feeSchedule, as: .description) | ||
} | ||
|
||
internal func testToFromBytes() throws { | ||
assertSnapshot(matching: try FeeSchedule.fromBytes(feeSchedule.toBytes()), as: .description) | ||
} | ||
|
||
internal func testFromProtobuf() throws { | ||
let feeSchedule = try FeeSchedule.fromProtobuf(feeSchedule.toProtobuf()) | ||
|
||
assertSnapshot(matching: feeSchedule, as: .description) | ||
} | ||
|
||
internal func testToProtobuf() throws { | ||
let protoFeeSchedule = feeSchedule.toProtobuf() | ||
|
||
assertSnapshot(matching: protoFeeSchedule, as: .description) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* | ||
* Hedera Swift SDK | ||
* | ||
* Copyright (C) 2022 - 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import SnapshotTesting | ||
import XCTest | ||
|
||
import struct HederaProtobufs.Proto_Key | ||
|
||
@testable import Hedera | ||
|
||
internal final class LedgerIdTests: XCTestCase { | ||
internal func testToString() throws { | ||
XCTAssertEqual(LedgerId.mainnet.toString(), "mainnet") | ||
XCTAssertEqual(LedgerId.testnet.toString(), "testnet") | ||
XCTAssertEqual(LedgerId.previewnet.toString(), "previewnet") | ||
XCTAssertEqual(LedgerId.fromBytes(Data([0x00, 0xFF, 0x00, 0xFF])), "00FF00FF") | ||
} | ||
|
||
internal func testFromString() throws { | ||
XCTAssertEqual(LedgerId.fromString("mainnet"), LedgerId.mainnet) | ||
XCTAssertEqual(LedgerId.fromString("testnet"), LedgerId.testnet) | ||
XCTAssertEqual(LedgerId.fromString("previewnet"), LedgerId.previewnet) | ||
XCTAssertEqual(LedgerId.fromString("00ff00ff"), LedgerId.fromBytes(Data([0x00, 0xFF, 0x00, 0xFF]))) | ||
XCTAssertEqual(LedgerId.fromString("00FF00FF"), LedgerId.fromBytes(Data([0x00, 0xFF, 0x00, 0xFF]))) | ||
} | ||
|
||
internal func testToBytes() throws { | ||
let bytes = Data([0x00, 0xFF, 0x00, 0xFF]) | ||
XCTAssertEqual(LedgerId.fromBytes(Data([0x00, 0xFF, 0x00, 0xFF])).bytes, bytes) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* | ||
* Hedera Swift SDK | ||
* | ||
* Copyright (C) 2022 - 2023 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import HederaProtobufs | ||
import SnapshotTesting | ||
import XCTest | ||
|
||
@testable import Hedera | ||
|
||
internal class TokenNftTransferTests: XCTestCase { | ||
internal static let testReceiver = AccountId("0.0.5008") | ||
internal static let testSerialNumber = 4 | ||
|
||
private func makeTransfer() throws -> TokenNftTransfer { | ||
TokenNftTransfer.init( | ||
tokenId: Resources.tokenId, sender: Resources.accountId, receiver: Self.testReceiver, serial: 4, | ||
isApproved: true) | ||
} | ||
|
||
internal func testSerialize() throws { | ||
let transfer = try makeTransfer() | ||
|
||
assertSnapshot(of: transfer, as: .description) | ||
} | ||
} |
Oops, something went wrong.