3
3
4
4
using FluentAssertions ;
5
5
using Nethermind . Core ;
6
+ using Nethermind . Core . Extensions ;
6
7
using Nethermind . Core . Test . Builders ;
7
8
using Nethermind . Serialization . Rlp ;
8
9
using NUnit . Framework ;
@@ -11,37 +12,59 @@ namespace Nethermind.Optimism.Test;
11
12
12
13
public class RlpDecoderTests
13
14
{
15
+ private TxDecoder _decoder = null ! ;
16
+
17
+ [ SetUp ]
18
+ public void Setup ( )
19
+ {
20
+ _decoder = TxDecoder . Instance ;
21
+ _decoder . RegisterDecoder ( new OptimismTxDecoder < Transaction > ( ) ) ;
22
+ _decoder . RegisterDecoder ( new OptimismLegacyTxDecoder ( ) ) ;
23
+ }
24
+
14
25
[ Test ]
15
26
public void Can_decode_non_null_Transaction ( )
16
27
{
17
- TxDecoder decoder = TxDecoder . Instance ;
18
- decoder . RegisterDecoder ( new OptimismTxDecoder < Transaction > ( ) ) ;
19
-
20
28
Transaction tx = Build . A . Transaction . WithType ( TxType . DepositTx ) . TestObject ;
21
29
22
- RlpStream rlpStream = new ( decoder . GetLength ( tx , RlpBehaviors . None ) ) ;
23
- decoder . Encode ( rlpStream , tx ) ;
30
+ RlpStream rlpStream = new ( _decoder . GetLength ( tx , RlpBehaviors . None ) ) ;
31
+ _decoder . Encode ( rlpStream , tx ) ;
24
32
rlpStream . Reset ( ) ;
25
33
26
- Transaction ? decodedTx = decoder . Decode ( rlpStream ) ;
34
+ Transaction ? decodedTx = _decoder . Decode ( rlpStream ) ;
27
35
28
36
decodedTx . Should ( ) . NotBeNull ( ) ;
29
37
}
30
38
31
39
[ Test ]
32
40
public void Can_decode_non_null_Transaction_through_Rlp ( )
33
41
{
34
- TxDecoder decoder = TxDecoder . Instance ;
35
- decoder . RegisterDecoder ( new OptimismTxDecoder < Transaction > ( ) ) ;
42
+ _decoder . RegisterDecoder ( new OptimismTxDecoder < Transaction > ( ) ) ;
36
43
37
44
Transaction tx = Build . A . Transaction . WithType ( TxType . DepositTx ) . TestObject ;
38
45
39
- RlpStream rlpStream = new ( decoder . GetLength ( tx , RlpBehaviors . None ) ) ;
40
- decoder . Encode ( rlpStream , tx ) ;
46
+ RlpStream rlpStream = new ( _decoder . GetLength ( tx , RlpBehaviors . None ) ) ;
47
+ _decoder . Encode ( rlpStream , tx ) ;
41
48
rlpStream . Reset ( ) ;
42
49
43
50
Transaction ? decodedTx = Rlp . Decode < Transaction ? > ( rlpStream ) ;
44
51
45
52
decodedTx . Should ( ) . NotBeNull ( ) ;
46
53
}
54
+
55
+ [ Test ]
56
+ public void Can_decode_Legacy_Empty_Signature ( )
57
+ {
58
+ _decoder . RegisterDecoder ( new OptimismTxDecoder < Transaction > ( ) ) ;
59
+
60
+ // See: https://github.com/NethermindEth/nethermind/issues/7880
61
+ var hexBytes =
62
+ "f901c9830571188083030d4094420000000000000000000000000000000000000780b901a4cbd4ece9000000000000000000000000420000000000000000000000000000000000001000000000000000000000000099c9fc46f92e8a1c0dec1b1747d010903e884be10000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000005711800000000000000000000000000000000000000000000000000000000000000e4662a633a000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000094b008aa00579c1307b0ef2c499ad98a8ce58e58000000000000000000000000117274dde02bc94006185af87d78beab28ceae06000000000000000000000000117274dde02bc94006185af87d78beab28ceae06000000000000000000000000000000000000000000000000000000000c3d8b8000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000808080" ;
63
+ var bytes = Bytes . FromHexString ( hexBytes ) ;
64
+ var context = bytes . AsRlpValueContext ( ) ;
65
+
66
+ var transaction = _decoder . Decode ( ref context ) ;
67
+
68
+ transaction . Should ( ) . NotBeNull ( ) ;
69
+ }
47
70
}
0 commit comments