Skip to content

Commit 8774b65

Browse files
committed
fix Transaction.getChainId when v=27 must return null
1 parent d952334 commit 8774b65

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

core/src/test/java/org/web3j/protocol/core/ResponseTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,21 @@ void testTransactionChainId() {
11811181
Transaction transaction = new Transaction();
11821182
transaction.setV(0x25);
11831183
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);
11841199
}
11851200

11861201
@Test

crypto/src/main/java/org/web3j/crypto/TransactionUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public static String generateTransactionHashHexEncoded(
7777
* @param v recovery identifier
7878
* @return Chain id
7979
*/
80-
public static long deriveChainId(long v) {
80+
public static Long deriveChainId(long v) {
8181
if (v == LOWER_REAL_V || v == (LOWER_REAL_V + 1)) {
82-
return 0L;
82+
return null;
8383
}
8484
return (v - CHAIN_ID_INC) / 2;
8585
}

crypto/src/test/java/org/web3j/crypto/TransactionUtilsTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.junit.jupiter.api.Test;
1616

1717
import static org.junit.jupiter.api.Assertions.assertEquals;
18+
import static org.junit.jupiter.api.Assertions.assertNull;
1819
import static org.web3j.crypto.TransactionUtils.generateTransactionHashHexEncoded;
1920

2021
public class TransactionUtilsTest {
@@ -60,10 +61,10 @@ void deriveChainIdWhenLegacySignature() {
6061
long v1 = 27;
6162
long v2 = 28;
6263

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);
6566

66-
assertEquals(0, chainId_1);
67-
assertEquals(0, chainId_2);
67+
assertNull(chainId_1);
68+
assertNull(chainId_2);
6869
}
6970
}

0 commit comments

Comments
 (0)