Skip to content

Commit 76886fe

Browse files
committed
[ETCM-921] rlp encoding and decoding test for Seq[SignedTransaction]
1 parent 1bfd580 commit 76886fe

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/test/scala/io/iohk/ethereum/domain/TransactionSpec.scala

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
1010
import io.iohk.ethereum.ObjectGenerators
1111
import io.iohk.ethereum.crypto.ECDSASignature
1212
import io.iohk.ethereum.network.p2p.messages.BaseETH6XMessages.SignedTransactions
13+
import io.iohk.ethereum.rlp.RLPList
1314
import io.iohk.ethereum.security.SecureRandomBuilder
1415
import io.iohk.ethereum.utils.Config
1516
import io.iohk.ethereum.utils.Hex
@@ -27,7 +28,7 @@ class TransactionSpec
2728
forAll(signedTxGen(secureRandom, None)) { (originalSignedTransaction: SignedTransaction) =>
2829
// encode it
2930
import SignedTransactions.SignedTransactionEnc
30-
val encodedSignedTransaction = originalSignedTransaction.toBytes
31+
val encodedSignedTransaction: Array[Byte] = originalSignedTransaction.toBytes
3132

3233
// decode it
3334
import SignedTransactions.SignedTransactionDec
@@ -37,6 +38,40 @@ class TransactionSpec
3738
}
3839
}
3940

41+
"rlp encoding then decoding transactions sequence" should "give back the initial transactions sequence" in {
42+
43+
forAll(signedTxSeqGen(2, secureRandom, None)) { (originalSignedTransactionSeq: Seq[SignedTransaction]) =>
44+
// encode it
45+
import SignedTransactions.SignedTransactionsEnc
46+
47+
// SignedTransactionsEnc is the Sequence version of SignedTransactionEnc
48+
// the SignedTransactionsEnc.toBytes calls
49+
// -> SignedTransactionsEnc.toRLPEncodable which maps over
50+
// -> SignedTransactionEnc.toRLPEncodable (single signed transaction encoder)
51+
// without going through the SignedTransactionEnc.toByte, which is the actual part where the 01 prefix is inserted
52+
val encodedSignedTransactionSeq: Array[Byte] = SignedTransactions(originalSignedTransactionSeq).toBytes
53+
54+
// decode it
55+
import SignedTransactions.SignedTransactionsDec
56+
// likewise, the SignedTransactionsDec.toSignedTransactions maps over
57+
// -> SignedTransactionRlpEncodableDec.toSignedTransaction (single signed transaction)
58+
// while ignoring the SignedTransactionDec(Array[Byte]), which is responsible to parse the prefix if available
59+
val SignedTransactions(decodedSignedTransactionSeq) = encodedSignedTransactionSeq.toSignedTransactions
60+
61+
// The test is working because both encoding and decoding are skipping the prefix part,
62+
// and the rlp encoded transaction is different enough to recognize a LegacyTransaction from a TX1
63+
64+
// I see two problems:
65+
// - the encoding is not compatible with other clients
66+
// - this is not working for receipt, where legacy and tx1 receipt payload are the same. As such we can't
67+
// distinguish which one it is without the prefix
68+
69+
// The root cause seems to be that the prefix stuff is done on a byte[] level,
70+
// whereas RLPList are working on RLPEncodable
71+
decodedSignedTransactionSeq shouldEqual originalSignedTransactionSeq
72+
}
73+
}
74+
4075
"Transaction type 01" should "be correctly serialized to rlp" in {
4176

4277
// binary values have be taken directly from core-geth own tests

0 commit comments

Comments
 (0)