Skip to content

Commit df42d6b

Browse files
authored
[ETH]: Adds UserOp Hash Encoding and Signing tests as well (#4314)
* [ETH]: Adds Kotlin tests for EIP-7702 Auth and UserOpV07 * Adds userhash encoding and signing as well
1 parent f044ce6 commit df42d6b

File tree

1 file changed

+26
-3
lines changed
  • android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/ethereum

1 file changed

+26
-3
lines changed

android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/ethereum/TestBarz.kt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,17 @@ class TestBarz {
258258

259259
@Test
260260
fun testBarzTransferAccountDeployedV07() {
261+
val chainIdByteArray = "0x7A69".toHexByteArray() // 31337
262+
val wallet = "0x174a240e5147D02dE4d7724D5D3E1c1bF11cE029"
263+
261264
val transfer = Ethereum.Transaction.Transfer.newBuilder().apply {
262265
amount = ByteString.copyFrom("0x2386f26fc10000".toHexByteArray())
263266
data = ByteString.EMPTY
264267
}.build()
265268

266269
val userOpV07 = Ethereum.UserOperationV0_7.newBuilder().apply {
267270
entryPoint = "0x0000000071727De22E5E9d8BAf0edAc6f37da032"
268-
sender = "0x174a240e5147D02dE4d7724D5D3E1c1bF11cE029"
271+
sender = wallet
269272
preVerificationGas = ByteString.copyFrom("0xF4240".toHexByteArray()) // 1000000
270273
verificationGasLimit = ByteString.copyFrom("0x186A0".toHexByteArray()) // 100000
271274
factory = "0xf471789937856d80e589f5996cf8b0511ddd9de4"
@@ -282,7 +285,7 @@ class TestBarz {
282285
// Create signing input
283286
val signingInput = Ethereum.SigningInput.newBuilder().apply {
284287
privateKey = ByteString.copyFrom(PrivateKey("3c90badc15c4d35733769093d3733501e92e7f16e101df284cee9a310d36c483".toHexByteArray()).data())
285-
chainId = ByteString.copyFrom("0x7A69".toHexByteArray()) // 31337
288+
chainId = ByteString.copyFrom(chainIdByteArray) // 31337
286289
nonce = ByteString.copyFrom("0x00".toHexByteArray())
287290
txMode = Ethereum.TransactionMode.UserOp
288291
gasLimit = ByteString.copyFrom("0x186A0".toHexByteArray()) // 100000
@@ -303,6 +306,26 @@ class TestBarz {
303306
"0xf177858c1c500e51f38ffe937bed7e4d3a8678725900be4682d3ce04d97071eb",
304307
Numeric.toHexString(output.preHash.toByteArray())
305308
)
306-
}
307309

310+
val version = "v0.1.0"
311+
val typeHash = "0x4f51e7a567f083a31264743067875fc6a7ae45c32c5bd71f6a998c4625b13867"
312+
val domainSeparatorHash = "0x293ce8821a350a49f08b53d14e10112c36c7fbf3b8eb7078497893f3ea477f6b"
313+
val hash = "0xf177858c1c500e51f38ffe937bed7e4d3a8678725900be4682d3ce04d97071eb"
314+
315+
val encodedHash = WCBarz.getEncodedHash(chainIdByteArray, wallet, version, typeHash, domainSeparatorHash, hash)
316+
assertEquals(
317+
"0x59ebb8c4e48c115eeaf2ea7d3a0802754462761c5019df8d2a38effb226191d5",
318+
Numeric.toHexString(encodedHash)
319+
)
320+
321+
val privateKey = "0x947dd69af402e7f48da1b845dfc1df6be593d01a0d8274bd03ec56712e7164e8"
322+
val signedHash = WCBarz.getSignedHash(
323+
"0x59ebb8c4e48c115eeaf2ea7d3a0802754462761c5019df8d2a38effb226191d5",
324+
privateKey
325+
)
326+
assertEquals(
327+
"0x34a7792a140f52358925a57bca8ea936d70133b285396040ac0507597ed5c70a3148964ba1e0b32b8f59fbd9c098a4ec2b9ae5e5739ce4aeccae0f73279d50da1b",
328+
Numeric.toHexString(signedHash)
329+
)
330+
}
308331
}

0 commit comments

Comments
 (0)