From 9d1ff3f5a7af2008411dd3a33f81c66ba3324daf Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Tue, 17 Sep 2024 07:26:48 +0200 Subject: [PATCH] update tests --- README.md | 4 +- Tests/SingleFactorAuthTests/AquaTest.swift | 19 ++++--- Tests/SingleFactorAuthTests/CyanTest.swift | 19 ++++--- .../SapphireDevnetTests.swift | 49 +++++++++++++++++++ .../SapphireMainnetTests.swift | 49 +++++++++++++++++++ .../SingleFactorAuthTests.swift | 19 ++++--- 6 files changed, 127 insertions(+), 32 deletions(-) create mode 100644 Tests/SingleFactorAuthTests/SapphireDevnetTests.swift create mode 100644 Tests/SingleFactorAuthTests/SapphireMainnetTests.swift diff --git a/README.md b/README.md index ea347e4..c0fc0d9 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,10 @@ let singleFactoreAuth = SingleFactorAuth(params: SFAParams) Use the `getKey` function to login the user and get the privateKey and public address for the given user. ```swift -let idToken = try generateIdToken(email: TOURUS_TEST_EMAIL) +let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) let loginParams = LoginParams( verifier: TEST_VERIFIER, - verifierId: TOURUS_TEST_EMAIL, + verifierId: TORUS_TEST_EMAIL, idToken: idToken ) diff --git a/Tests/SingleFactorAuthTests/AquaTest.swift b/Tests/SingleFactorAuthTests/AquaTest.swift index a08100b..2bc5f4d 100644 --- a/Tests/SingleFactorAuthTests/AquaTest.swift +++ b/Tests/SingleFactorAuthTests/AquaTest.swift @@ -2,14 +2,13 @@ import BigInt import JWTKit import XCTest import FetchNodeDetails - -@testable import SingleFactorAuth +import SingleFactorAuth final class AquaTest: XCTestCase { var singleFactoreAuth: SingleFactorAuth! var singleFactorAuthArgs: SFAParams! - let TOURUS_TEST_EMAIL = "hello@tor.us" + let TORUS_TEST_EMAIL = "hello@tor.us" let TEST_VERIFIER = "torus-test-health" let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" @@ -19,8 +18,8 @@ final class AquaTest: XCTestCase { } func testConnect() async throws { - let idToken = try generateIdToken(email: TOURUS_TEST_EMAIL) - let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TOURUS_TEST_EMAIL, idToken: idToken) + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken) let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) let requiredPrivateKey = "d8204e9f8c270647294c54acd8d49ee208789f981a7503158e122527d38626d8" @@ -29,18 +28,18 @@ final class AquaTest: XCTestCase { } func testInitialise() async throws { - let idToken = try generateIdToken(email: TOURUS_TEST_EMAIL) - let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TOURUS_TEST_EMAIL, idToken: idToken) + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken) let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) let savedKey = try await singleFactoreAuth.initialize() let requiredPrivateKey = "d8204e9f8c270647294c54acd8d49ee208789f981a7503158e122527d38626d8" XCTAssertEqual(requiredPrivateKey, savedKey.getPrivateKey()) - XCTAssertEqual(torusKey.publicAddress, savedKey.getPublicAddress()) + XCTAssertEqual(torusKey.getPublicAddress(), savedKey.getPublicAddress()) } func testAggregrateGetTorusKey() async throws { - let idToken = try generateIdToken(email: TOURUS_TEST_EMAIL) - let loginParams = LoginParams(verifier: TEST_AGGREGRATE_VERIFIER, verifierId: TOURUS_TEST_EMAIL, idToken: idToken, subVerifierInfoArray: [TorusSubVerifierInfo(verifier: TEST_VERIFIER, idToken: idToken)]) + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_AGGREGRATE_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken, subVerifierInfoArray: [TorusSubVerifierInfo(verifier: TEST_VERIFIER, idToken: idToken)]) let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) let requiredPrivateKey = "6f8b884f19975fb0d138ed21b22a6a7e1b79e37f611d0a29f1442b34efc6bacd" diff --git a/Tests/SingleFactorAuthTests/CyanTest.swift b/Tests/SingleFactorAuthTests/CyanTest.swift index 56b1cf2..ecf1b81 100644 --- a/Tests/SingleFactorAuthTests/CyanTest.swift +++ b/Tests/SingleFactorAuthTests/CyanTest.swift @@ -1,14 +1,13 @@ import BigInt import JWTKit import XCTest - -@testable import SingleFactorAuth +import SingleFactorAuth final class CyanTest: XCTestCase { var singleFactoreAuth: SingleFactorAuth! var singleFactorAuthArgs: SFAParams! - let TOURUS_TEST_EMAIL = "hello@tor.us" + let TORUS_TEST_EMAIL = "hello@tor.us" let TEST_VERIFIER = "torus-test-health" let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" @@ -18,8 +17,8 @@ final class CyanTest: XCTestCase { } func testConnect() async throws { - let idToken = try generateIdToken(email: TOURUS_TEST_EMAIL) - let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TOURUS_TEST_EMAIL, idToken: idToken) + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken) let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) let requiredPrivateKey = "223d982054fa1ad27d1497560521e4cce5b8c6438c38533c7bad27ff21ce0546" @@ -28,18 +27,18 @@ final class CyanTest: XCTestCase { } func testInitialise() async throws { - let idToken = try generateIdToken(email: TOURUS_TEST_EMAIL) - let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TOURUS_TEST_EMAIL, idToken: idToken) + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken) let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) let requiredPrivateKey = "223d982054fa1ad27d1497560521e4cce5b8c6438c38533c7bad27ff21ce0546" let savedKey = try await singleFactoreAuth.initialize() XCTAssertEqual(requiredPrivateKey, savedKey.getPrivateKey()) - XCTAssertEqual(torusKey.publicAddress, savedKey.getPublicAddress()) + XCTAssertEqual(torusKey.getPublicAddress(), savedKey.getPublicAddress()) } func testAggregrateGetTorusKey() async throws { - let idToken = try generateIdToken(email: TOURUS_TEST_EMAIL) - let loginParams = LoginParams(verifier: TEST_AGGREGRATE_VERIFIER, verifierId: TOURUS_TEST_EMAIL, idToken: idToken, subVerifierInfoArray: [TorusSubVerifierInfo(verifier: TEST_VERIFIER, idToken: idToken)]) + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_AGGREGRATE_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken, subVerifierInfoArray: [TorusSubVerifierInfo(verifier: TEST_VERIFIER, idToken: idToken)]) let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) let requiredPrivateKey = "66af498ea82c95d52fdb8c8dedd44cf2f758424a0eecab7ac3dd8721527ea2d4" diff --git a/Tests/SingleFactorAuthTests/SapphireDevnetTests.swift b/Tests/SingleFactorAuthTests/SapphireDevnetTests.swift new file mode 100644 index 0000000..32f13a5 --- /dev/null +++ b/Tests/SingleFactorAuthTests/SapphireDevnetTests.swift @@ -0,0 +1,49 @@ +import BigInt +import JWTKit +import XCTest +import FetchNodeDetails +import SingleFactorAuth + +final class SapphireDevnetTests: XCTestCase { + var singleFactoreAuth: SingleFactorAuth! + var singleFactorAuthArgs: SFAParams! + + let TORUS_TEST_EMAIL = "devnettestuser@tor.us" + let TEST_VERIFIER = "torus-test-health" + let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" + + override func setUp() { + singleFactorAuthArgs = SFAParams(web3AuthClientId: "CLIENT ID", network: .sapphire(.SAPPHIRE_DEVNET)) + singleFactoreAuth = try! SingleFactorAuth(params: singleFactorAuthArgs) + } + + func testConnect() async throws { + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken) + let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) + + let requiredPrivateKey = "230dad9f42039569e891e6b066ff5258b14e9764ef5176d74aeb594d1a744203" + XCTAssertEqual(requiredPrivateKey, torusKey.getPrivateKey()) + XCTAssertEqual("0x462A8BF111A55C9354425F875F89B22678c0Bc44", torusKey.getPublicAddress()) + } + + func testInitialise() async throws { + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken) + let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) + let savedKey = try await singleFactoreAuth.initialize() + let requiredPrivateKey = "230dad9f42039569e891e6b066ff5258b14e9764ef5176d74aeb594d1a744203" + XCTAssertEqual(requiredPrivateKey, savedKey.getPrivateKey()) + XCTAssertEqual(torusKey.getPublicAddress(), savedKey.getPublicAddress()) + } + + func testAggregrateGetTorusKey() async throws { + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_AGGREGRATE_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken, subVerifierInfoArray: [TorusSubVerifierInfo(verifier: TEST_VERIFIER, idToken: idToken)]) + let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) + + let requiredPrivateKey = "edef171853fdf23ed3cfc702d32cf46f181b475a449d2f7b636924cabecd81d4" + XCTAssertEqual(requiredPrivateKey, torusKey.getPrivateKey()) + XCTAssertEqual("0xfC58EB0475F1E3fa05877eE2e1350f6A619E2d78", torusKey.getPublicAddress()) + } +} diff --git a/Tests/SingleFactorAuthTests/SapphireMainnetTests.swift b/Tests/SingleFactorAuthTests/SapphireMainnetTests.swift new file mode 100644 index 0000000..16d7131 --- /dev/null +++ b/Tests/SingleFactorAuthTests/SapphireMainnetTests.swift @@ -0,0 +1,49 @@ +import BigInt +import JWTKit +import XCTest +import FetchNodeDetails +import SingleFactorAuth + +final class SapphireMainnetTests: XCTestCase { + var singleFactoreAuth: SingleFactorAuth! + var singleFactorAuthArgs: SFAParams! + + let TORUS_TEST_EMAIL = "devnettestuser@tor.us" + let TEST_VERIFIER = "torus-test-health" + let TEST_AGGREGRATE_VERIFIER = "torus-aggregate-sapphire-mainnet" + + override func setUp() { + singleFactorAuthArgs = SFAParams(web3AuthClientId: "CLIENT ID", network: .sapphire(.SAPPHIRE_MAINNET)) + singleFactoreAuth = try! SingleFactorAuth(params: singleFactorAuthArgs) + } + + func testConnect() async throws { + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken) + let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) + + let requiredPrivateKey = "2c4b346a91ecd11fe8a02d111d00bd921bf9b543f0a1e811face91b5f28947d6" + XCTAssertEqual(requiredPrivateKey, torusKey.getPrivateKey()) + XCTAssertEqual("0x0934d844a0a6db37CF75aF0269436ae1b2Ae5D36", torusKey.getPublicAddress()) + } + + func testInitialise() async throws { + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken) + let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) + let savedKey = try await singleFactoreAuth.initialize() + let requiredPrivateKey = "2c4b346a91ecd11fe8a02d111d00bd921bf9b543f0a1e811face91b5f28947d6" + XCTAssertEqual(requiredPrivateKey, savedKey.getPrivateKey()) + XCTAssertEqual(torusKey.getPublicAddress(), savedKey.getPublicAddress()) + } + + func testAggregrateGetTorusKey() async throws { + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_AGGREGRATE_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken, subVerifierInfoArray: [TorusSubVerifierInfo(verifier: TEST_VERIFIER, idToken: idToken)]) + let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) + + let requiredPrivateKey = "0c724bb285560dc41e585b91aa2ded94fdd703c2e7133dcc64b1361b0d1fd105" + XCTAssertEqual(requiredPrivateKey, torusKey.getPrivateKey()) + XCTAssertEqual("0xA92E2C756B5b2abABc127907b02D4707dc085612", torusKey.getPublicAddress()) + } +} diff --git a/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift b/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift index 4e08843..f1d1c07 100644 --- a/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift +++ b/Tests/SingleFactorAuthTests/SingleFactorAuthTests.swift @@ -1,14 +1,13 @@ import BigInt import JWTKit import XCTest - -@testable import SingleFactorAuth +import SingleFactorAuth final class SingleFactorAuthTests: XCTestCase { var singleFactoreAuth: SingleFactorAuth! var singleFactorAuthArgs: SFAParams! - let TOURUS_TEST_EMAIL = "hello@tor.us" + let TORUS_TEST_EMAIL = "hello@tor.us" let TEST_VERIFIER = "torus-test-health" let TEST_AGGREGRATE_VERIFIER = "torus-test-health-aggregate" @@ -18,8 +17,8 @@ final class SingleFactorAuthTests: XCTestCase { } func testConnect() async throws { - let idToken = try generateIdToken(email: TOURUS_TEST_EMAIL) - let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TOURUS_TEST_EMAIL, idToken: idToken) + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken) let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) let requiredPrivateKey = "296045a5599afefda7afbdd1bf236358baff580a0fe2db62ae5c1bbe817fbae4" XCTAssertEqual(requiredPrivateKey, torusKey.getPrivateKey()) @@ -27,18 +26,18 @@ final class SingleFactorAuthTests: XCTestCase { } func testInitialise() async throws { - let idToken = try generateIdToken(email: TOURUS_TEST_EMAIL) - let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TOURUS_TEST_EMAIL, idToken: idToken) + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken) let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) let savedKey = try await singleFactoreAuth.initialize() let requiredPrivateKey = "296045a5599afefda7afbdd1bf236358baff580a0fe2db62ae5c1bbe817fbae4" XCTAssertEqual(requiredPrivateKey, savedKey.getPrivateKey()) - XCTAssertEqual(torusKey.publicAddress, savedKey.getPublicAddress()) + XCTAssertEqual(torusKey.getPublicAddress(), savedKey.getPublicAddress()) } func testAggregrateGetTorusKey() async throws { - let idToken = try generateIdToken(email: TOURUS_TEST_EMAIL) - let loginParams = LoginParams(verifier: TEST_AGGREGRATE_VERIFIER, verifierId: TOURUS_TEST_EMAIL, idToken: idToken, subVerifierInfoArray: [TorusSubVerifierInfo(verifier: TEST_VERIFIER, idToken: idToken)]) + let idToken = try generateIdToken(email: TORUS_TEST_EMAIL) + let loginParams = LoginParams(verifier: TEST_AGGREGRATE_VERIFIER, verifierId: TORUS_TEST_EMAIL, idToken: idToken, subVerifierInfoArray: [TorusSubVerifierInfo(verifier: TEST_VERIFIER, idToken: idToken)]) let torusKey = try await singleFactoreAuth.connect(loginParams: loginParams) let requiredPrivateKey = "ad47959db4cb2e63e641bac285df1b944f54d1a1cecdaeea40042b60d53c35d2"