Skip to content

Commit 2bf1de3

Browse files
feat(biz): Allow to call Biz.execute when EOA is delegated already (#4351)
* fix(biz): Allow to call `Biz.execute` when EOA is delegated already * feature(biz): Adopt C++ tests * feat(biz): Add and fix android tests * feat(biz): Fix ios tests * chore(aa): Rename `Execute` and `Batch` to `AAExecute` and `AABatch` correspondingly * chore(scw): Rename `AABatch` and `AAExecute` to `SCWalletBatch` and `SCWalletExecute`
1 parent 4b63b63 commit 2bf1de3

File tree

6 files changed

+456
-150
lines changed

6 files changed

+456
-150
lines changed

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

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ class TestBarz {
117117
}.build()
118118

119119
transaction = Ethereum.Transaction.newBuilder().apply {
120-
transfer = Ethereum.Transaction.Transfer.newBuilder().apply {
121-
amount = ByteString.copyFrom("0x2386f26fc10000".toHexByteArray())
120+
scwExecute = Ethereum.Transaction.SCWalletExecute.newBuilder().apply {
121+
transaction = Ethereum.Transaction.newBuilder().apply {
122+
transfer = Ethereum.Transaction.Transfer.newBuilder().apply {
123+
amount = ByteString.copyFrom("0x2386f26fc10000".toHexByteArray())
124+
}.build()
125+
}.build()
122126
}.build()
123127
}.build()
124128
}
@@ -159,8 +163,12 @@ class TestBarz {
159163
}.build()
160164

161165
transaction = Ethereum.Transaction.newBuilder().apply {
162-
transfer = Ethereum.Transaction.Transfer.newBuilder().apply {
163-
amount = ByteString.copyFrom("0x2386f26fc10000".toHexByteArray())
166+
scwExecute = Ethereum.Transaction.SCWalletExecute.newBuilder().apply {
167+
transaction = Ethereum.Transaction.newBuilder().apply {
168+
transfer = Ethereum.Transaction.Transfer.newBuilder().apply {
169+
amount = ByteString.copyFrom("0x2386f26fc10000".toHexByteArray())
170+
}.build()
171+
}.build()
164172
}.build()
165173
}.build()
166174
}
@@ -204,14 +212,14 @@ class TestBarz {
204212
}.build()
205213

206214
transaction = Ethereum.Transaction.newBuilder().apply {
207-
batch = Ethereum.Transaction.Batch.newBuilder().apply {
215+
scwBatch = Ethereum.Transaction.SCWalletBatch.newBuilder().apply {
208216
addAllCalls(listOf(
209-
Ethereum.Transaction.Batch.BatchedCall.newBuilder().apply {
217+
Ethereum.Transaction.SCWalletBatch.BatchedCall.newBuilder().apply {
210218
address = "0x03bBb5660B8687C2aa453A0e42dCb6e0732b1266"
211219
amount = ByteString.copyFrom("0x00".toHexByteArray())
212220
payload = ByteString.copyFrom(approveCall)
213221
}.build(),
214-
Ethereum.Transaction.Batch.BatchedCall.newBuilder().apply {
222+
Ethereum.Transaction.SCWalletBatch.BatchedCall.newBuilder().apply {
215223
address = "0x03bBb5660B8687C2aa453A0e42dCb6e0732b1266"
216224
amount = ByteString.copyFrom("0x00".toHexByteArray())
217225
payload = ByteString.copyFrom(transferCall)
@@ -254,15 +262,16 @@ class TestBarz {
254262
maxInclusionFeePerGas = ByteString.copyFrom("0x3b9aca00".toHexByteArray())
255263

256264
transaction = Ethereum.Transaction.newBuilder().apply {
257-
batch = Ethereum.Transaction.Batch.newBuilder().apply {
265+
scwBatch = Ethereum.Transaction.SCWalletBatch.newBuilder().apply {
266+
walletType = Ethereum.SCWalletType.Biz
258267
addAllCalls(listOf(
259-
Ethereum.Transaction.Batch.BatchedCall.newBuilder().apply {
268+
Ethereum.Transaction.SCWalletBatch.BatchedCall.newBuilder().apply {
260269
// TWT
261270
address = "0x4B0F1812e5Df2A09796481Ff14017e6005508003"
262271
amount = ByteString.copyFrom("0x00".toHexByteArray())
263272
payload = ByteString.copyFrom(transferPayload1)
264273
}.build(),
265-
Ethereum.Transaction.Batch.BatchedCall.newBuilder().apply {
274+
Ethereum.Transaction.SCWalletBatch.BatchedCall.newBuilder().apply {
266275
// TWT
267276
address = "0x4B0F1812e5Df2A09796481Ff14017e6005508003"
268277
amount = ByteString.copyFrom("0x00".toHexByteArray())
@@ -272,7 +281,6 @@ class TestBarz {
272281
}.build()
273282
}.build()
274283

275-
userOperationMode = Ethereum.SCAccountType.Biz
276284
eip7702Authority = Ethereum.Authority.newBuilder().apply {
277285
address = "0x117BC8454756456A0f83dbd130Bb94D793D3F3F7"
278286
}.build()
@@ -284,6 +292,42 @@ class TestBarz {
284292
assertEquals(Numeric.toHexString(output.encoded.toByteArray()), "0x04f9030f3812843b9aca00843b9aca00830186a0945132829820b44dc3e8586cec926a16fca0a5608480b9024434fcd5be00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001200000000000000000000000004b0f1812e5df2a09796481ff14017e6005508003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000002ef648d7c03412b832726fd4683e2625dea047ba00000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000004b0f1812e5df2a09796481ff14017e6005508003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000095dc01ebd10b6dccf1cc329af1a3f73806117c2e0000000000000000000000000000000000000000000000000001c6bf5263400000000000000000000000000000000000000000000000000000000000c0f85cf85a3894117bc8454756456a0f83dbd130bb94d793d3f3f71380a0073afc661c158a2dccf4183f87e1e4d62b4d406af418cfd69959368ec9bec2a6a064292fd61d4d16b840470a86fc4f7a89413f9126d897f2268eb76a1d887c6d7a01a0e8bcbd96323c9d3e67b74366b2f43299100996d9e8874a6fd87186ac8f580d4ca07c25b4f0619af77fb953e8f0e4372bfbee62616ad419697516108eeb9bcebb28")
285293
}
286294

295+
// https://bscscan.com/tx/0x6f8b2c8d50e8bb543d7124703b75d9e495832116a1a61afabf40b9b0ac43c980
296+
@Test
297+
fun testSignEnvelopedBiz() {
298+
val signingInput = Ethereum.SigningInput.newBuilder()
299+
signingInput.apply {
300+
privateKey = ByteString.copyFrom(PrivateKey("0xe762e91cc4889a9fce79b2d2ffc079f86c48331f57b2cd16a33bee060fe448e1".toHexByteArray()).data())
301+
chainId = ByteString.copyFrom("0x38".toHexByteArray())
302+
nonce = ByteString.copyFrom("0x02".toHexByteArray())
303+
txMode = TransactionMode.Enveloped
304+
305+
gasLimit = ByteString.copyFrom("0x186a0".toHexByteArray())
306+
maxFeePerGas = ByteString.copyFrom("0x3b9aca00".toHexByteArray())
307+
maxInclusionFeePerGas = ByteString.copyFrom("0x3b9aca00".toHexByteArray())
308+
309+
transaction = Ethereum.Transaction.newBuilder().apply {
310+
scwExecute = Ethereum.Transaction.SCWalletExecute.newBuilder().apply {
311+
walletType = Ethereum.SCWalletType.Biz
312+
transaction = Ethereum.Transaction.newBuilder().apply {
313+
erc20Transfer = Ethereum.Transaction.ERC20Transfer.newBuilder().apply {
314+
to = "0x95dc01ebd10b6dccf1cc329af1a3f73806117c2e"
315+
amount = ByteString.copyFrom("0xb5e620f48000".toHexByteArray())
316+
}.build()
317+
}.build()
318+
}.build()
319+
}.build()
320+
321+
// TWT token.
322+
toAddress = "0x4B0F1812e5Df2A09796481Ff14017e6005508003"
323+
}
324+
325+
val output = AnySigner.sign(signingInput.build(), ETHEREUM, SigningOutput.parser())
326+
327+
assertEquals(Numeric.toHexString(output.preHash.toByteArray()), "0x60260356568ae70838bd80085b971e1e4ebe42046688fd8511a268986e522121")
328+
assertEquals(Numeric.toHexString(output.encoded.toByteArray()), "0x02f901503802843b9aca00843b9aca00830186a0946e860086bba8fdeafb553815af0f09a854cc887a80b8e4b61d27f60000000000000000000000004b0f1812e5df2a09796481ff14017e6005508003000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000095dc01ebd10b6dccf1cc329af1a3f73806117c2e0000000000000000000000000000000000000000000000000000b5e620f4800000000000000000000000000000000000000000000000000000000000c080a0fb45762a262f4c32090576e9de087482d25cd00b6ea2522eb7d5a40f435acdbaa0151dbd48a4f4bf06080313775fe32ececd68869d721518a92bf292e4a84322f9")
329+
}
330+
287331
@Test
288332
fun testAuthorizationHash() {
289333
val chainId = "0x01".toHexByteArray()
@@ -351,7 +395,11 @@ class TestBarz {
351395
toAddress = "0x61061fCAE11fD5461535e134EfF67A98CFFF44E9"
352396

353397
transaction = Ethereum.Transaction.newBuilder().apply {
354-
this.transfer = transfer
398+
scwExecute = Ethereum.Transaction.SCWalletExecute.newBuilder().apply {
399+
transaction = Ethereum.Transaction.newBuilder().apply {
400+
this.transfer = transfer
401+
}.build()
402+
}.build()
355403
}.build()
356404

357405
userOperationV07 = userOpV07

0 commit comments

Comments
 (0)