|
7 | 7 |
|
8 | 8 | import static org.junit.Assert.assertEquals;
|
9 | 9 | import static org.junit.Assert.assertNotEquals;
|
| 10 | +import static org.junit.Assert.fail; |
10 | 11 |
|
11 | 12 | import androidx.test.filters.SmallTest;
|
12 | 13 |
|
|
15 | 16 | import org.junit.Test;
|
16 | 17 | import org.junit.runner.RunWith;
|
17 | 18 |
|
| 19 | +import org.chromium.brave_wallet.mojom.AccountInfo; |
| 20 | +import org.chromium.brave_wallet.mojom.BlockchainToken; |
18 | 21 | 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; |
19 | 27 | import org.chromium.chrome.browser.crypto_wallet.util.Utils;
|
20 | 28 | import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
21 | 29 |
|
@@ -215,4 +223,225 @@ public void getRopstenContractAddressTest() {
|
215 | 223 | assertEquals(
|
216 | 224 | Utils.getRopstenContractAddress("0xdef1c0ded9bec7f1a1670819833240f027b25eff"), "");
|
217 | 225 | }
|
| 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 | + } |
218 | 447 | }
|
0 commit comments