diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/TestCoinType.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/TestCoinType.kt index 21349ebfa3c..5b92dd34849 100644 --- a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/TestCoinType.kt +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/TestCoinType.kt @@ -1,13 +1,15 @@ package com.trustwallet.core.app.blockchains +import com.trustwallet.core.app.utils.toHexByteArray import wallet.core.jni.CoinType import wallet.core.jni.Curve +import wallet.core.jni.PublicKey import wallet.core.jni.Purpose import wallet.core.jni.Derivation import org.junit.Assert.assertEquals import org.junit.Test - +import wallet.core.jni.PublicKeyType class TestCoinType { @@ -55,4 +57,12 @@ class TestCoinType { res = CoinType.createFromValue(CoinType.SOLANA.value()).derivationPathWithDerivation(Derivation.SOLANASOLANA).toString() assertEquals(res, "m/44'/501'/0'/0'") } + + @Test + fun testDeriveAddressFromPublicKeyAndDerivation() { + val publicKey = PublicKey("0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798".toHexByteArray(), PublicKeyType.SECP256K1) + + val address = CoinType.BITCOIN.deriveAddressFromPublicKeyAndDerivation(publicKey, Derivation.BITCOINSEGWIT) + assertEquals(address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4") + } } diff --git a/swift/Tests/CoinTypeTests.swift b/swift/Tests/CoinTypeTests.swift index 8884a0fe0eb..7ef5b5e2260 100644 --- a/swift/Tests/CoinTypeTests.swift +++ b/swift/Tests/CoinTypeTests.swift @@ -36,4 +36,12 @@ class CoinTypeTests: XCTestCase { XCTAssertEqual(CoinType.bitcoin.derivationPathWithDerivation(derivation: Derivation.bitcoinLegacy), "m/44'/0'/0'/0/0") XCTAssertEqual(CoinType.solana.derivationPathWithDerivation(derivation: Derivation.solanaSolana), "m/44'/501'/0'/0'") } + + func testDeriveAddressFromPublicKeyAndDerivation() { + let pkData = Data(hexString: "0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798")! + let publicKey = PublicKey(data: pkData, type: .secp256k1)! + + let address = CoinType.bitcoin.deriveAddressFromPublicKeyAndDerivation(publicKey: publicKey, derivation: Derivation.bitcoinSegwit) + XCTAssertEqual(address, "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4") + } } diff --git a/swift/Tests/TransactionCompilerTests.swift b/swift/Tests/TransactionCompilerTests.swift index 05ff08f7457..f28a2665758 100644 --- a/swift/Tests/TransactionCompilerTests.swift +++ b/swift/Tests/TransactionCompilerTests.swift @@ -173,4 +173,13 @@ class TransactionCompilerTests: XCTestCase { XCTAssertEqual(output.encoded.count, 518) XCTAssertEqual(output.encoded.hexString, ExpectedTx) } + + // Test if `compileWithSignaturesAndPubKeyType` binding is available in Swift. + func testBitcoinCompileWithSignaturesAndPubKeyType() { + let txInputData = Data() + let signatureVec = DataVector() + let pubkeyVec = DataVector() + + let _ = TransactionCompiler.compileWithSignaturesAndPubKeyType(coinType: .bitcoin, txInputData: txInputData, signatures: signatureVec, publicKeys: pubkeyVec, pubKeyType: .secp256k1) + } }