/
TestNEARSigner.kt
42 lines (35 loc) · 1.75 KB
/
TestNEARSigner.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.trustwallet.core.app.blockchains.solana
import com.google.protobuf.ByteString
import com.trustwallet.core.app.utils.toHexByteArray
import java.util.Base64
import org.junit.Assert.assertEquals
import org.junit.Test
import wallet.core.jni.Base58
import wallet.core.java.AnySigner
import wallet.core.jni.CoinType
import wallet.core.jni.proto.NEAR
import wallet.core.jni.proto.NEAR.SigningOutput
class TestNEARSigner {
init {
System.loadLibrary("TrustWalletCore")
}
@Test
fun testTransferSign() {
val transferAction = NEAR.Transfer.newBuilder().apply {
deposit = ByteString.copyFrom("01000000000000000000000000000000".toHexByteArray())
}.build()
val signingInput = NEAR.SigningInput.newBuilder().apply {
signerId = "test.near"
nonce = 1
receiverId = "whatever.near"
addActionsBuilder().apply {
transfer = transferAction
}
blockHash = ByteString.copyFrom(Base58.decodeNoCheck("244ZQ9cgj3CQ6bWBdytfrJMuMQ1jdXLFGnr4HhvtCTnM"))
privateKey = ByteString.copyFrom(Base58.decodeNoCheck("3hoMW1HvnRLSFCLZnvPzWeoGwtdHzke34B2cTHM8rhcbG3TbuLKtShTv3DvyejnXKXKBiV7YPkLeqUHN1ghnqpFv").sliceArray(0..31))
}.build()
val output = AnySigner.sign(signingInput, CoinType.NEAR, SigningOutput.parser())
val expectedBase64String = "CQAAAHRlc3QubmVhcgCRez0mjUtY9/7BsVC9aNab4+5dTMOYVeNBU4Rlu3eGDQEAAAAAAAAADQAAAHdoYXRldmVyLm5lYXIPpHP9JpAd8pa+atxMxN800EDvokNSJLaYaRDmMML+9gEAAAADAQAAAAAAAAAAAAAAAAAAAACWmoMzIYbul1Xkg5MlUlgG4Ymj0tK7S0dg6URD6X4cTyLe7vAFmo6XExAO2m4ZFE2n6KDvflObIHCLodjQIb0B"
assertEquals(Base64.getEncoder().encodeToString(output.signedTransaction.toByteArray()), expectedBase64String)
}
}