Skip to content

Commit

Permalink
[Solana]: Add Android, iOS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Nov 27, 2024
1 parent cd7c9cc commit 8a67502
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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()))
}
}
13 changes: 13 additions & 0 deletions swift/Tests/Blockchains/SolanaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

0 comments on commit 8a67502

Please sign in to comment.