Skip to content

Commit

Permalink
Add iOS and android tests to check if new methods available (#3267)
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan authored Jun 28, 2023
1 parent 84bbbc6 commit 59c634c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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")
}
}
8 changes: 8 additions & 0 deletions swift/Tests/CoinTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
9 changes: 9 additions & 0 deletions swift/Tests/TransactionCompilerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 59c634c

Please sign in to comment.