|
74 | 74 | import org.tron.core.config.args.Args; |
75 | 75 | import org.tron.core.exception.ContractExeException; |
76 | 76 | import org.tron.core.exception.ContractValidateException; |
| 77 | +import org.tron.core.exception.MaintenanceClearingException; |
77 | 78 | import org.tron.core.exception.NonUniqueObjectException; |
78 | 79 | import org.tron.core.store.DynamicPropertiesStore; |
79 | 80 | import org.tron.core.utils.ProposalUtil.ProposalType; |
@@ -858,30 +859,37 @@ public void testGetDelegatedResourceV2() { |
858 | 859 |
|
859 | 860 | @Test |
860 | 861 | public void testGetPaginatedNowWitnessList_CornerCase() { |
861 | | - GrpcAPI.WitnessList witnessList = wallet.getPaginatedNowWitnessList(-100, 0); |
862 | | - Assert.assertTrue("Should return an empty witness list when offset is negative", |
863 | | - witnessList == null); |
864 | | - |
865 | | - witnessList = wallet.getPaginatedNowWitnessList(100, 0); |
866 | | - Assert.assertTrue("Should return an empty witness list when limit is 0", |
867 | | - witnessList == null); |
868 | | - |
869 | | - String fakeWitnessAddressPrefix = "fake_witness"; |
870 | | - int fakeNumberOfWitnesses = 1000 + 10; |
871 | | - // Mock additional witnesses with vote counts greater than 1000 |
872 | | - for (int i = 0; i < fakeNumberOfWitnesses; i++) { |
873 | | - saveWitnessWith(fakeWitnessAddressPrefix + i, 200); |
874 | | - } |
| 862 | + try { |
| 863 | + // To avoid throw MaintenanceClearingException |
| 864 | + dbManager.getChainBaseManager().getDynamicPropertiesStore().saveStateFlag(0); |
| 865 | + |
| 866 | + GrpcAPI.WitnessList witnessList = wallet.getPaginatedNowWitnessList(-100, 0); |
| 867 | + Assert.assertTrue("Should return an empty witness list when offset is negative", |
| 868 | + witnessList == null); |
| 869 | + |
| 870 | + witnessList = wallet.getPaginatedNowWitnessList(100, 0); |
| 871 | + Assert.assertTrue("Should return an empty witness list when limit is 0", |
| 872 | + witnessList == null); |
| 873 | + |
| 874 | + String fakeWitnessAddressPrefix = "fake_witness"; |
| 875 | + int fakeNumberOfWitnesses = 1000 + 10; |
| 876 | + // Mock additional witnesses with vote counts greater than 1000 |
| 877 | + for (int i = 0; i < fakeNumberOfWitnesses; i++) { |
| 878 | + saveWitnessWith(fakeWitnessAddressPrefix + i, 200); |
| 879 | + } |
875 | 880 |
|
876 | | - witnessList = wallet.getPaginatedNowWitnessList(0, 1000000); |
877 | | - // Check the returned witness list should contain 1000 witnesses with descending vote count |
878 | | - Assert.assertTrue("Witness list should contain 1000 witnesses", |
879 | | - witnessList.getWitnessesCount() == 1000); |
| 881 | + witnessList = wallet.getPaginatedNowWitnessList(0, 1000000); |
| 882 | + // Check the returned witness list should contain 1000 witnesses with descending vote count |
| 883 | + Assert.assertTrue("Witness list should contain 1000 witnesses", |
| 884 | + witnessList.getWitnessesCount() == 1000); |
880 | 885 |
|
881 | | - // clean up, delete the fake witnesses |
882 | | - for (int i = 0; i < fakeNumberOfWitnesses; i++) { |
883 | | - chainBaseManager.getWitnessStore() |
884 | | - .delete(ByteString.copyFromUtf8(fakeWitnessAddressPrefix + i).toByteArray()); |
| 886 | + // clean up, delete the fake witnesses |
| 887 | + for (int i = 0; i < fakeNumberOfWitnesses; i++) { |
| 888 | + chainBaseManager.getWitnessStore() |
| 889 | + .delete(ByteString.copyFromUtf8(fakeWitnessAddressPrefix + i).toByteArray()); |
| 890 | + } |
| 891 | + } catch (MaintenanceClearingException e) { |
| 892 | + Assert.fail(e.getMessage()); |
885 | 893 | } |
886 | 894 | } |
887 | 895 |
|
@@ -914,7 +922,14 @@ public void testGetPaginatedNowWitnessList() { |
914 | 922 | chainBaseManager.getVotesStore().put(votesCapsule.createDbKey(), votesCapsule); |
915 | 923 |
|
916 | 924 | logger.info("now request paginated witness list with 0 offset and 10 limit:"); |
917 | | - GrpcAPI.WitnessList witnessList2 = wallet.getPaginatedNowWitnessList(0, 10); |
| 925 | + GrpcAPI.WitnessList witnessList2 = null; |
| 926 | + try { |
| 927 | + // To avoid throw MaintenanceClearingException |
| 928 | + dbManager.getChainBaseManager().getDynamicPropertiesStore().saveStateFlag(0); |
| 929 | + witnessList2 = wallet.getPaginatedNowWitnessList(0, 10); |
| 930 | + } catch (MaintenanceClearingException e) { |
| 931 | + Assert.fail(e.getMessage()); |
| 932 | + } |
918 | 933 | // Check the returned witness list should contain 10 witnesses with descending vote count |
919 | 934 | Assert.assertTrue("Witness list should contain 10 witnesses", |
920 | 935 | witnessList2.getWitnessesCount() == 10); |
|
0 commit comments