Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Use swift-custom-dump's XCTAssertNoDifference for test vectors (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
amika-sq authored Jan 4, 2024
1 parent ced0e52 commit d70c16d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/GigaBitcoin/secp256k1.swift.git", from: "0.14.0"),
.package(url: "https://github.com/swift-extras/swift-extras-base64.git", from: "0.7.0"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "1.1.2"),
],
targets: [
.target(
Expand All @@ -27,7 +28,10 @@ let package = Package(
),
.testTarget(
name: "tbDEXTests",
dependencies: ["tbDEX"],
dependencies: [
"tbDEX",
.product(name: "CustomDump", package: "swift-custom-dump"),
],
resources: [
.copy("TestVectors/ed25519"),
.copy("TestVectors/secp256k1"),
Expand Down
13 changes: 7 additions & 6 deletions Tests/tbDEXTests/crypto/Ed25519Tests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CustomDump
import XCTest

@testable import tbDEX
Expand Down Expand Up @@ -27,7 +28,7 @@ final class Ed25519Tests: XCTestCase {
for vector in testVector.vectors {
let privateKeyBytes = Data.fromHexString(vector.input["privateKeyBytes"]!)!
let privateKey = try Ed25519.shared.bytesToPrivateKey(privateKeyBytes)
XCTAssertEqual(privateKey, vector.output)
XCTAssertNoDifference(privateKey, vector.output)
}
}

Expand All @@ -40,7 +41,7 @@ final class Ed25519Tests: XCTestCase {
for vector in testVector.vectors {
let publicKeyBytes = Data.fromHexString(vector.input["publicKeyBytes"]!)!
let publicKey = try Ed25519.shared.bytesToPublicKey(publicKeyBytes)
XCTAssertEqual(publicKey, vector.output)
XCTAssertNoDifference(publicKey, vector.output)
}
}

Expand All @@ -52,7 +53,7 @@ final class Ed25519Tests: XCTestCase {

for vector in testVector.vectors {
let publicKey = try Ed25519.shared.computePublicKey(privateKey: vector.input["privateKey"]!)
XCTAssertEqual(publicKey, vector.output)
XCTAssertNoDifference(publicKey, vector.output)
}
}

Expand All @@ -64,7 +65,7 @@ final class Ed25519Tests: XCTestCase {

for vector in testVector.vectors {
let privateKeyBytes = try Ed25519.shared.privateKeyToBytes(vector.input["privateKey"]!)
XCTAssertEqual(privateKeyBytes, Data.fromHexString(vector.output)!)
XCTAssertNoDifference(privateKeyBytes, Data.fromHexString(vector.output)!)
}
}

Expand All @@ -76,7 +77,7 @@ final class Ed25519Tests: XCTestCase {

for vector in testVector.vectors {
let publicKeyBytes = try Ed25519.shared.publicKeyToBytes(vector.input["publicKey"]!)
XCTAssertEqual(publicKeyBytes, Data.fromHexString(vector.output)!)
XCTAssertNoDifference(publicKeyBytes, Data.fromHexString(vector.output)!)
}
}

Expand Down Expand Up @@ -141,7 +142,7 @@ final class Ed25519Tests: XCTestCase {
signature: Data.fromHexString(vector.input.signature)!,
signedPayload: Data.fromHexString(vector.input.data)!
)
XCTAssertEqual(isValid, vector.output)
XCTAssertNoDifference(isValid, vector.output)
}
}

Expand Down
9 changes: 5 additions & 4 deletions Tests/tbDEXTests/crypto/Secp256k1Tests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CustomDump
import XCTest
import secp256k1

Expand Down Expand Up @@ -55,7 +56,7 @@ final class Secp256k1Tests: XCTestCase {
for vector in testVector.vectors {
let privateKeyBytes = Data.fromHexString(vector.input["privateKeyBytes"]!)!
let privateKey = try Secp256k1.shared.bytesToPrivateKey(privateKeyBytes)
XCTAssertEqual(privateKey, vector.output)
XCTAssertNoDifference(privateKey, vector.output)
}
}

Expand All @@ -82,7 +83,7 @@ final class Secp256k1Tests: XCTestCase {
for vector in testVector.vectors {
let privateKeyBytes = Data.fromHexString(vector.input["publicKeyBytes"]!)!
let publicKey = try Secp256k1.shared.bytesToPublicKey(privateKeyBytes)
XCTAssertEqual(publicKey, vector.output)
XCTAssertNoDifference(publicKey, vector.output)
}
}

Expand Down Expand Up @@ -191,7 +192,7 @@ final class Secp256k1Tests: XCTestCase {

for vector in testVector.vectors {
let privateKeyBytes = Data.fromHexString(vector.input["key"]!)!
XCTAssertEqual(Secp256k1.shared.validatePrivateKey(privateKeyBytes: privateKeyBytes), vector.output)
XCTAssertNoDifference(Secp256k1.shared.validatePrivateKey(privateKeyBytes: privateKeyBytes), vector.output)
}
}

Expand All @@ -203,7 +204,7 @@ final class Secp256k1Tests: XCTestCase {

for vector in testVector.vectors {
let publicKeyBytes = Data.fromHexString(vector.input["key"]!)!
XCTAssertEqual(Secp256k1.shared.validatePublicKey(publicKeyBytes: publicKeyBytes), vector.output)
XCTAssertNoDifference(Secp256k1.shared.validatePublicKey(publicKeyBytes: publicKeyBytes), vector.output)
}
}

Expand Down

0 comments on commit d70c16d

Please sign in to comment.