From 8a6750295a1363c56bddb4c78c10d24aa21cc195 Mon Sep 17 00:00:00 2001 From: Satoshi Otomakan Date: Wed, 27 Nov 2024 19:36:33 +0100 Subject: [PATCH] [Solana]: Add Android, iOS tests --- .../solana/TestSolanaMessageSigner.kt | 44 +++++++++++++++++++ swift/Tests/Blockchains/SolanaTests.swift | 13 ++++++ 2 files changed, 57 insertions(+) create mode 100644 android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/solana/TestSolanaMessageSigner.kt diff --git a/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/solana/TestSolanaMessageSigner.kt b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/solana/TestSolanaMessageSigner.kt new file mode 100644 index 00000000000..b4eb3752fc7 --- /dev/null +++ b/android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/solana/TestSolanaMessageSigner.kt @@ -0,0 +1,44 @@ +package com.trustwallet.core.app.blockchains.solana + +import com.google.protobuf.ByteString +import com.trustwallet.core.app.utils.toHex +import com.trustwallet.core.app.utils.toHexByteArray +import org.junit.Assert.assertEquals +import org.junit.Test +import wallet.core.jni.Base58 +import wallet.core.java.AnySigner +import wallet.core.jni.CoinType.SOLANA +import wallet.core.jni.MessageSigner +import wallet.core.jni.proto.Common.SigningError +import wallet.core.jni.proto.Solana + +class TestSolanaMessageSigner { + init { + System.loadLibrary("TrustWalletCore") + } + + @Test + fun testMessageSign() { + val signingInput = Solana.MessageSigningInput.newBuilder().apply { + privateKey = ByteString.copyFrom("44f480ca27711895586074a14c552e58cc52e66a58edb6c58cf9b9b7295d4a2d".toHexByteArray()) + message = "Hello world" + }.build() + + val outputData = MessageSigner.sign(SOLANA, signingInput.toByteArray()) + val output = Solana.MessageSigningOutput.parseFrom(outputData) + + assertEquals(output.error, SigningError.OK) + assertEquals(output.signature, "2iBZ6zrQRKHcbD8NWmm552gU5vGvh1dk3XV4jxnyEdRKm8up8AeQk1GFr9pJokSmchw7i9gMtNyFBdDt8tBxM1cG") + } + + @Test + fun testMessageVerify() { + val verifyingInput = Solana.MessageVerifyingInput.newBuilder().apply { + publicKey = ByteString.copyFrom("ee6d61a89fc8f9909585a996bb0d2b2ac69ae23b5acf39a19f32631239ba06f9".toHexByteArray()) + signature = "2iBZ6zrQRKHcbD8NWmm552gU5vGvh1dk3XV4jxnyEdRKm8up8AeQk1GFr9pJokSmchw7i9gMtNyFBdDt8tBxM1cG" + message = "Hello world" + }.build() + + assert(MessageSigner.verify(SOLANA, verifyingInput.toByteArray())) + } +} \ No newline at end of file diff --git a/swift/Tests/Blockchains/SolanaTests.swift b/swift/Tests/Blockchains/SolanaTests.swift index 9c6287ddef3..bb8f996363c 100644 --- a/swift/Tests/Blockchains/SolanaTests.swift +++ b/swift/Tests/Blockchains/SolanaTests.swift @@ -329,4 +329,17 @@ class SolanaTests: XCTestCase { // https://explorer.solana.com/tx/2ho7wZUXbDNz12xGfsXg2kcNMqkBAQjv7YNXNcVcuCmbC4p9FZe9ELeM2gMjq9MKQPpmE3nBW5pbdgwVCfNLr1h8 XCTAssertEqual(output.encoded, "AVUye82Mv+/aWeU2G+B6Nes365mUU2m8iqcGZn/8kFJvw4wY6AgKGG+vJHaknHlCDwE1yi1SIMVUUtNCOm3kHg8BAAIEODI+iWe7g68B9iwCy8bFkJKvsIEj350oSOpcv4gNnv/st+6qmqipl9lwMK6toB9TiL7LrJVfij+pKwr+pUKxfwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwZGb+UhFzL/7K26csOb57yM5bvF9xJrLEObOkAAAAAboZ09wD3Y5HNUl7aN8bwpCqowev1hMu7fSgziLswUSgMDAAUCECcAAAICAAEMAgAAAOgDAAAAAAAAAwAJA+gDAAAAAAAA") } + + func testSignUserMessage() throws { + let privateKey = Data(hexString: "44f480ca27711895586074a14c552e58cc52e66a58edb6c58cf9b9b7295d4a2d")! + + let input = SolanaMessageSigningInput.with { + $0.privateKey = privateKey + $0.message = "Hello world" + } + let outputData = MessageSigner.sign(coin: .solana, input: try input.serializedData())! + let output = try SolanaMessageSigningOutput(serializedData: outputData) + XCTAssertEqual(output.error, .ok) + XCTAssertEqual(output.signature, "2iBZ6zrQRKHcbD8NWmm552gU5vGvh1dk3XV4jxnyEdRKm8up8AeQk1GFr9pJokSmchw7i9gMtNyFBdDt8tBxM1cG") + } }