File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed
core/src/test/java/org/web3j/protocol/core
main/java/org/web3j/crypto
test/java/org/web3j/crypto Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -1181,6 +1181,21 @@ void testTransactionChainId() {
1181
1181
Transaction transaction = new Transaction ();
1182
1182
transaction .setV (0x25 );
1183
1183
assertEquals (transaction .getChainId (), (1L ));
1184
+
1185
+ Transaction transaction2 = new Transaction ();
1186
+ transaction2 .setV (0x24 );
1187
+ assertEquals (transaction2 .getChainId (), (0L ));
1188
+ }
1189
+
1190
+ @ Test
1191
+ void testTransactionWithoutChainId () {
1192
+ Transaction transaction1 = new Transaction ();
1193
+ transaction1 .setV (0x1b ); // 27
1194
+ assertEquals (transaction1 .getChainId (), null );
1195
+
1196
+ Transaction transaction2 = new Transaction ();
1197
+ transaction2 .setV (0x1c ); // 28
1198
+ assertEquals (transaction2 .getChainId (), null );
1184
1199
}
1185
1200
1186
1201
@ Test
Original file line number Diff line number Diff line change @@ -77,9 +77,9 @@ public static String generateTransactionHashHexEncoded(
77
77
* @param v recovery identifier
78
78
* @return Chain id
79
79
*/
80
- public static long deriveChainId (long v ) {
80
+ public static Long deriveChainId (long v ) {
81
81
if (v == LOWER_REAL_V || v == (LOWER_REAL_V + 1 )) {
82
- return 0L ;
82
+ return null ;
83
83
}
84
84
return (v - CHAIN_ID_INC ) / 2 ;
85
85
}
Original file line number Diff line number Diff line change 15
15
import org .junit .jupiter .api .Test ;
16
16
17
17
import static org .junit .jupiter .api .Assertions .assertEquals ;
18
+ import static org .junit .jupiter .api .Assertions .assertNull ;
18
19
import static org .web3j .crypto .TransactionUtils .generateTransactionHashHexEncoded ;
19
20
20
21
public class TransactionUtilsTest {
@@ -60,10 +61,10 @@ void deriveChainIdWhenLegacySignature() {
60
61
long v1 = 27 ;
61
62
long v2 = 28 ;
62
63
63
- long chainId_1 = TransactionUtils .deriveChainId (v1 );
64
- long chainId_2 = TransactionUtils .deriveChainId (v2 );
64
+ Long chainId_1 = TransactionUtils .deriveChainId (v1 );
65
+ Long chainId_2 = TransactionUtils .deriveChainId (v2 );
65
66
66
- assertEquals ( 0 , chainId_1 );
67
- assertEquals ( 0 , chainId_2 );
67
+ assertNull ( chainId_1 );
68
+ assertNull ( chainId_2 );
68
69
}
69
70
}
You can’t perform that action at this time.
0 commit comments