Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Update tests to Swift5 #223

Merged
merged 1 commit into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions BitcoinKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.bitcoinkit.BitcoinKitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG BitcoinKitXcode";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -1568,7 +1568,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.bitcoinkit.BitcoinKitTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = BitcoinKitXcode;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
9 changes: 7 additions & 2 deletions Sources/BitcoinKit/Scripts/Script.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,13 @@ extension Script {
// Standard Transaction to Bitcoin address (pay-to-pubkey-hash)
// scriptPubKey: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
public static func buildPublicKeyHashOut(pubKeyHash: Data) -> Data {
let tmp: Data = Data() + OpCode.OP_DUP + OpCode.OP_HASH160 + UInt8(pubKeyHash.count) + pubKeyHash + OpCode.OP_EQUALVERIFY
return tmp + OpCode.OP_CHECKSIG
let script = try! Script()
.append(.OP_DUP)
.append(.OP_HASH160)
.appendData(pubKeyHash)
.append(.OP_EQUALVERIFY)
.append(.OP_CHECKSIG)
return script.data
}

public static func buildPublicKeyUnlockingScript(signature: Data, pubkey: PublicKey, hashType: SighashType) -> Data {
Expand Down
8 changes: 4 additions & 4 deletions Tests/BitcoinKitTests/PointMultiplicationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ import XCTest

class PointMultiplicationTests: XCTestCase {
func testPointMultiplication() {
let gX = Data(bytes: [
let gX = Data([
0x79, 0xBE, 0x66, 0x7E, 0xF9, 0xDC, 0xBB, 0xAC,
0x55, 0xA0, 0x62, 0x95, 0xCE, 0x87, 0x0B, 0x07,
0x02, 0x9B, 0xFC, 0xDB, 0x2D, 0xCE, 0x28, 0xD9,
0x59, 0xF2, 0x81, 0x5B, 0x16, 0xF8, 0x17, 0x98
])

let gY = Data(bytes: [
let gY = Data([
0x48, 0x3A, 0xDA, 0x77, 0x26, 0xA3, 0xC4, 0x65,
0x5D, 0xA4, 0xFB, 0xFC, 0x0E, 0x11, 0x08, 0xA8,
0xFD, 0x17, 0xB4, 0x48, 0xA6, 0x85, 0x54, 0x19,
0x9C, 0x47, 0xD0, 0x8F, 0xFB, 0x10, 0xD4, 0xB8
])

let curveOrderPlusOne = Data(bytes: [
let curveOrderPlusOne = Data([
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B,
0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x42
])

let one = Data(bytes: [
let one = Data([
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down
6 changes: 3 additions & 3 deletions Tests/BitcoinKitTests/SerializationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ class SerializationTests: XCTestCase {
}

func testUInt32toHex() {
let d = Data(bytes: [1, 2, 3, 4])
let d = Data([1, 2, 3, 4])
let i: UInt32 = d.to(type: UInt32.self)
XCTAssertEqual(i.hex, "04030201")
XCTAssertEqual(i, 0x04030201)
}

func testUInt64toHex() {
let d = Data(bytes: [1, 2, 3, 4, 5, 6, 7, 8])
let d = Data([1, 2, 3, 4, 5, 6, 7, 8])
let i: UInt64 = d.to(type: UInt64.self)
XCTAssertEqual(i.hex, "0807060504030201")
XCTAssertEqual(i, 0x0807060504030201)
}

func testDataToUInt256() {
let d = Data(bytes: [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
let d = Data([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2])
let i: UInt256 = d.to(type: UInt256.self)
XCTAssertEqual(i.hex, "0200000000000000000000000000000000000000000000000000000000000001")
}
Expand Down
4 changes: 2 additions & 2 deletions WalletExample/WalletExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = tech.yenom.WalletExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -318,7 +318,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = tech.yenom.WalletExample;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down