Skip to content

Commit 3e737fa

Browse files
authored
Merge pull request #12737 from brave/pr12735_android_crash_blockchaintoken_1.38.x
Android crash blockchaintoken (uplift to 1.38.x)
2 parents 421a75e + 23fb390 commit 3e737fa

File tree

4 files changed

+240
-0
lines changed

4 files changed

+240
-0
lines changed

android/java/apk_for_test.flags

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
# needed for checking of existence for bytecode manipulation
99
-keepnames class org.chromium.chrome.browser.settings.MainSettings
1010

11+
# Do not obfuscate the above classes as we check on fields in tests
12+
-keep class org.chromium.brave_wallet.mojom.BlockchainToken { *; }
13+
-keep class org.chromium.brave_wallet.mojom.SwapParams { *; }
14+
-keep class org.chromium.brave_wallet.mojom.AccountInfo { *; }
15+
-keep class org.chromium.brave_wallet.mojom.TxData { *; }
16+
-keep class org.chromium.brave_wallet.mojom.GasEstimation1559 { *; }
17+
-keep class org.chromium.brave_wallet.mojom.TxData1559 { *; }
18+
-keep class org.chromium.brave_wallet.mojom.NetworkInfo { *; }
19+
1120
-keep class org.chromium.chrome.browser.bookmarks.BookmarkBridge {
1221
*** extensiveBookmarkChangesBeginning(...);
1322
*** extensiveBookmarkChangesEnded(...);

android/java/org/chromium/chrome/browser/crypto_wallet/fragments/EditVisibleAssetsBottomSheetDialogFragment.java

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ public void onClick(View v) {
250250
token.isErc721 = false;
251251
token.symbol = tokenSymbolEdit.getText().toString();
252252
token.decimals = 18;
253+
token.chainId = mChainId;
253254
try {
254255
token.decimals =
255256
Integer.valueOf(tokenDecimalsEdit.getText().toString());

android/java/org/chromium/chrome/browser/crypto_wallet/util/Utils.java

+1
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ public static BlockchainToken createEthereumBlockchainToken() {
974974
eth.contractAddress = "";
975975
eth.logo = "eth.png";
976976
eth.decimals = 18;
977+
eth.chainId = "";
977978
return eth;
978979
}
979980

android/javatests/org/chromium/chrome/browser/brave_wallet/BraveWalletUtilsTest.java

+229
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static org.junit.Assert.assertEquals;
99
import static org.junit.Assert.assertNotEquals;
10+
import static org.junit.Assert.fail;
1011

1112
import androidx.test.filters.SmallTest;
1213

@@ -15,7 +16,14 @@
1516
import org.junit.Test;
1617
import org.junit.runner.RunWith;
1718

19+
import org.chromium.brave_wallet.mojom.AccountInfo;
20+
import org.chromium.brave_wallet.mojom.BlockchainToken;
1821
import org.chromium.brave_wallet.mojom.BraveWalletConstants;
22+
import org.chromium.brave_wallet.mojom.GasEstimation1559;
23+
import org.chromium.brave_wallet.mojom.NetworkInfo;
24+
import org.chromium.brave_wallet.mojom.SwapParams;
25+
import org.chromium.brave_wallet.mojom.TxData;
26+
import org.chromium.brave_wallet.mojom.TxData1559;
1927
import org.chromium.chrome.browser.crypto_wallet.util.Utils;
2028
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
2129

@@ -215,4 +223,225 @@ public void getRopstenContractAddressTest() {
215223
assertEquals(
216224
Utils.getRopstenContractAddress("0xdef1c0ded9bec7f1a1670819833240f027b25eff"), "");
217225
}
226+
227+
@Test
228+
@SmallTest
229+
public void validateBlockchainTokenTest() {
230+
BlockchainToken testToken = new BlockchainToken();
231+
java.lang.reflect.Field[] fields = testToken.getClass().getDeclaredFields();
232+
for (java.lang.reflect.Field f : fields) {
233+
try {
234+
java.lang.Class t = f.getType();
235+
java.lang.Object v = f.get(testToken);
236+
if (!t.isPrimitive()) {
237+
String varName = f.getName();
238+
if (varName.equals("contractAddress") || varName.equals("name")
239+
|| varName.equals("logo") || varName.equals("symbol")
240+
|| varName.equals("chainId")) {
241+
continue;
242+
}
243+
if (v == null) {
244+
String message = "Check that " + varName + " is initialized everywhere "
245+
+ "in Java files, where BlockchainToken object is created . It "
246+
+ "could be safely added to the above if to skip that var on checks "
247+
+ "after that.";
248+
fail(message);
249+
}
250+
}
251+
} catch (Exception exc) {
252+
// Exception appears on private field members. We just skip them as we are
253+
// interested in public members of a mojom structure
254+
}
255+
}
256+
}
257+
258+
@Test
259+
@SmallTest
260+
public void validateSwapParamsTest() {
261+
SwapParams testStruct = new SwapParams();
262+
java.lang.reflect.Field[] fields = testStruct.getClass().getDeclaredFields();
263+
for (java.lang.reflect.Field f : fields) {
264+
try {
265+
java.lang.Class t = f.getType();
266+
java.lang.Object v = f.get(testStruct);
267+
if (!t.isPrimitive()) {
268+
String varName = f.getName();
269+
if (varName.equals("takerAddress") || varName.equals("sellAmount")
270+
|| varName.equals("buyAmount") || varName.equals("buyToken")
271+
|| varName.equals("sellToken") || varName.equals("gasPrice")) {
272+
continue;
273+
}
274+
if (v == null) {
275+
String message = "Check that " + varName + " is initialized everywhere "
276+
+ "in Java files, where SwapParams object is created . It "
277+
+ "could be safely added to the above if to skip that var on checks "
278+
+ "after that.";
279+
fail(message);
280+
}
281+
}
282+
} catch (Exception exc) {
283+
// Exception appears on private field members. We just skip them as we are
284+
// interested in public members of a mojom structure
285+
}
286+
}
287+
}
288+
289+
@Test
290+
@SmallTest
291+
public void validateAccountInfoTest() {
292+
AccountInfo testStruct = new AccountInfo();
293+
java.lang.reflect.Field[] fields = testStruct.getClass().getDeclaredFields();
294+
for (java.lang.reflect.Field f : fields) {
295+
try {
296+
java.lang.Class t = f.getType();
297+
java.lang.Object v = f.get(testStruct);
298+
if (!t.isPrimitive()) {
299+
String varName = f.getName();
300+
if (varName.equals("address") || varName.equals("name")
301+
|| varName.equals("hardware")) {
302+
continue;
303+
}
304+
if (v == null) {
305+
String message = "Check that " + varName + " is initialized everywhere "
306+
+ "in Java files, where AccountInfo object is created . It "
307+
+ "could be safely added to the above if to skip that var on checks "
308+
+ "after that.";
309+
fail(message);
310+
}
311+
}
312+
} catch (Exception exc) {
313+
// Exception appears on private field members. We just skip them as we are
314+
// interested in public members of a mojom structure
315+
}
316+
}
317+
}
318+
319+
@Test
320+
@SmallTest
321+
public void validateTxDataTest() {
322+
TxData testStruct = new TxData();
323+
java.lang.reflect.Field[] fields = testStruct.getClass().getDeclaredFields();
324+
for (java.lang.reflect.Field f : fields) {
325+
try {
326+
java.lang.Class t = f.getType();
327+
java.lang.Object v = f.get(testStruct);
328+
if (!t.isPrimitive()) {
329+
String varName = f.getName();
330+
if (varName.equals("nonce") || varName.equals("gasPrice")
331+
|| varName.equals("gasLimit") || varName.equals("to")
332+
|| varName.equals("value") || varName.equals("data")) {
333+
continue;
334+
}
335+
if (v == null) {
336+
String message = "Check that " + varName + " is initialized everywhere "
337+
+ "in Java files, where TxData object is created . It "
338+
+ "could be safely added to the above if to skip that var on checks "
339+
+ "after that.";
340+
fail(message);
341+
}
342+
}
343+
} catch (Exception exc) {
344+
// Exception appears on private field members. We just skip them as we are
345+
// interested in public members of a mojom structure
346+
}
347+
}
348+
}
349+
350+
@Test
351+
@SmallTest
352+
public void validateGasEstimation1559Test() {
353+
GasEstimation1559 testStruct = new GasEstimation1559();
354+
java.lang.reflect.Field[] fields = testStruct.getClass().getDeclaredFields();
355+
for (java.lang.reflect.Field f : fields) {
356+
try {
357+
java.lang.Class t = f.getType();
358+
java.lang.Object v = f.get(testStruct);
359+
if (!t.isPrimitive()) {
360+
String varName = f.getName();
361+
if (varName.equals("slowMaxPriorityFeePerGas")
362+
|| varName.equals("slowMaxFeePerGas")
363+
|| varName.equals("avgMaxPriorityFeePerGas")
364+
|| varName.equals("avgMaxFeePerGas")
365+
|| varName.equals("fastMaxPriorityFeePerGas")
366+
|| varName.equals("fastMaxFeePerGas")
367+
|| varName.equals("baseFeePerGas")) {
368+
continue;
369+
}
370+
if (v == null) {
371+
String message = "Check that " + varName + " is initialized everywhere "
372+
+ "in Java files, where GasEstimation1559 object is created . It "
373+
+ "could be safely added to the above if to skip that var on checks "
374+
+ "after that.";
375+
fail(message);
376+
}
377+
}
378+
} catch (Exception exc) {
379+
// Exception appears on private field members. We just skip them as we are
380+
// interested in public members of a mojom structure
381+
}
382+
}
383+
}
384+
385+
@Test
386+
@SmallTest
387+
public void validateTxData1559Test() {
388+
TxData1559 testStruct = new TxData1559();
389+
java.lang.reflect.Field[] fields = testStruct.getClass().getDeclaredFields();
390+
for (java.lang.reflect.Field f : fields) {
391+
try {
392+
java.lang.Class t = f.getType();
393+
java.lang.Object v = f.get(testStruct);
394+
if (!t.isPrimitive()) {
395+
String varName = f.getName();
396+
if (varName.equals("baseData") || varName.equals("chainId")
397+
|| varName.equals("maxPriorityFeePerGas")
398+
|| varName.equals("maxFeePerGas") || varName.equals("gasEstimation")) {
399+
continue;
400+
}
401+
if (v == null) {
402+
String message = "Check that " + varName + " is initialized everywhere "
403+
+ "in Java files, where TxData1559 object is created . It "
404+
+ "could be safely added to the above if to skip that var on checks "
405+
+ "after that.";
406+
fail(message);
407+
}
408+
}
409+
} catch (Exception exc) {
410+
// Exception appears on private field members. We just skip them as we are
411+
// interested in public members of a mojom structure
412+
}
413+
}
414+
}
415+
416+
@Test
417+
@SmallTest
418+
public void validateNetworkInfoTest() {
419+
NetworkInfo testStruct = new NetworkInfo();
420+
java.lang.reflect.Field[] fields = testStruct.getClass().getDeclaredFields();
421+
for (java.lang.reflect.Field f : fields) {
422+
try {
423+
java.lang.Class t = f.getType();
424+
java.lang.Object v = f.get(testStruct);
425+
if (!t.isPrimitive()) {
426+
String varName = f.getName();
427+
if (varName.equals("chainId") || varName.equals("chainName")
428+
|| varName.equals("blockExplorerUrls") || varName.equals("iconUrls")
429+
|| varName.equals("rpcUrls") || varName.equals("symbol")
430+
|| varName.equals("symbolName") || varName.equals("data")) {
431+
continue;
432+
}
433+
if (v == null) {
434+
String message = "Check that " + varName + " is initialized everywhere "
435+
+ "in Java files, where NetworkInfo object is created . It "
436+
+ "could be safely added to the above if to skip that var on checks "
437+
+ "after that.";
438+
fail(message);
439+
}
440+
}
441+
} catch (Exception exc) {
442+
// Exception appears on private field members. We just skip them as we are
443+
// interested in public members of a mojom structure
444+
}
445+
}
446+
}
218447
}

0 commit comments

Comments
 (0)