-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WalletConnect/BNB]: Add Android test
- Loading branch information
1 parent
2492dfc
commit 3c65772
Showing
2 changed files
with
46 additions
and
9 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...Test/java/com/trustwallet/core/app/blockchains/binance/TestBinanceWalletConnectSigning.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.trustwallet.core.app.blockchains.binance | ||
|
||
import com.google.protobuf.ByteString | ||
import com.trustwallet.core.app.utils.toHexBytes | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import wallet.core.jni.proto.Binance.SigningOutput | ||
import wallet.core.jni.proto.WalletConnect | ||
import wallet.core.jni.* | ||
import wallet.core.jni.CoinType.BINANCE | ||
import wallet.core.java.AnySigner | ||
import wallet.core.jni.proto.Common | ||
|
||
class TestBinanceWalletConnectSigning { | ||
init { | ||
System.loadLibrary("TrustWalletCore") | ||
} | ||
|
||
@Test | ||
fun testSignBinanceTransactionFromWalletConnectRequest() { | ||
val parsingInput = WalletConnect.ParseRequestInput.newBuilder().apply { | ||
method = WalletConnect.Method.CosmosSignAmino | ||
payload = "{\"signerAddress\":\"bnb1grpf0955h0ykzq3ar5nmum7y6gdfl6lxfn46h2\",\"signDoc\":{\"account_number\":\"19\",\"chain_id\":\"chain-bnb\",\"memo\":\"\",\"data\":null,\"msgs\":[{\"inputs\":[{\"address\":\"bnb1grpf0955h0ykzq3ar5nmum7y6gdfl6lxfn46h2\",\"coins\":[{\"amount\":1001000000,\"denom\":\"BNB\"}]}],\"outputs\":[{\"address\":\"bnb13zeh6hs97d5eu2s5qerguhv8ewwue6u4ywa6yf\",\"coins\":[{\"amount\":1001000000,\"denom\":\"BNB\"}]}]}],\"sequence\":\"23\",\"source\":\"1\"}}" | ||
}.build() | ||
|
||
val parsingOutputBytes = WalletConnectRequest.parse(BINANCE, parsingInput.toByteArray()) | ||
val parsingOutput = WalletConnect.ParseRequestOutput.parseFrom(parsingOutputBytes) | ||
|
||
assertEquals(parsingOutput.error, Common.SigningError.OK) | ||
|
||
val inpu = parsingOutput.binance.toBuilder().apply { | ||
privateKey = ByteString.copyFrom("95949f757db1f57ca94a5dff23314accbe7abee89597bf6a3c7382c84d7eb832".toHexBytes()) | ||
}.build() | ||
|
||
// sign and encode resulting input | ||
val output = AnySigner.sign(inpu, BINANCE, SigningOutput.parser()) | ||
|
||
assertEquals(output.error, Common.SigningError.OK) | ||
assertEquals(output.signatureJson, "{\"pub_key\":{\"type\":\"tendermint/PubKeySecp256k1\",\"value\":\"Amo1kgCI2Yw4iMpoxT38k/RWRgJgbLuH8P5e5TPbOOUC\"},\"signature\":\"PCTHhMa7+Z1U/6uxU+3LbTxKd0k231xypdMolyVvjgYvMg+0dTMC+wqW8IxHWXTSDt/Ronu+7ac1h/WN3JWJdQ==\"}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters