|
1 | 1 | package org.tron.core.actuator; |
2 | 2 |
|
3 | 3 | import static org.junit.Assert.fail; |
| 4 | +import static org.tron.core.config.Parameter.ChainConstant.FROZEN_PERIOD; |
4 | 5 |
|
5 | 6 | import com.google.protobuf.Any; |
6 | 7 | import com.google.protobuf.ByteString; |
|
15 | 16 | import org.junit.Test; |
16 | 17 | import org.tron.common.BaseTest; |
17 | 18 | import org.tron.common.utils.ByteArray; |
| 19 | +import org.tron.common.utils.ForkController; |
18 | 20 | import org.tron.core.Constant; |
19 | 21 | import org.tron.core.Wallet; |
20 | 22 | import org.tron.core.capsule.AccountCapsule; |
21 | 23 | import org.tron.core.capsule.AssetIssueCapsule; |
22 | 24 | import org.tron.core.capsule.TransactionResultCapsule; |
23 | 25 | import org.tron.core.config.Parameter.ForkBlockVersionConsts; |
| 26 | +import org.tron.core.config.Parameter.ForkBlockVersionEnum; |
24 | 27 | import org.tron.core.config.args.Args; |
25 | 28 | import org.tron.core.exception.ContractExeException; |
26 | 29 | import org.tron.core.exception.ContractValidateException; |
@@ -1868,6 +1871,53 @@ public void SameTokenNameCloseInvalidAccount() { |
1868 | 1871 |
|
1869 | 1872 | } |
1870 | 1873 |
|
| 1874 | + @Test |
| 1875 | + public void issueStartTimeTooBig() { |
| 1876 | + long maintenanceTimeInterval = dbManager.getDynamicPropertiesStore() |
| 1877 | + .getMaintenanceTimeInterval(); |
| 1878 | + long hardForkTime = |
| 1879 | + ((ForkBlockVersionEnum.VERSION_4_0_1.getHardForkTime() - 1) / maintenanceTimeInterval + 1) |
| 1880 | + * maintenanceTimeInterval; |
| 1881 | + dbManager.getDynamicPropertiesStore() |
| 1882 | + .saveLatestBlockHeaderTimestamp(hardForkTime + 1); |
| 1883 | + |
| 1884 | + // add more check after 4.8.1 |
| 1885 | + byte[] stats = new byte[27]; |
| 1886 | + Arrays.fill(stats, (byte) 1); |
| 1887 | + dbManager.getDynamicPropertiesStore() |
| 1888 | + .statsByVersion(ForkBlockVersionEnum.VERSION_4_8_1.getValue(), stats); |
| 1889 | + boolean flag = ForkController.instance().pass(ForkBlockVersionEnum.VERSION_4_8_1); |
| 1890 | + Assert.assertTrue(flag); |
| 1891 | + |
| 1892 | + TransactionResultCapsule ret = new TransactionResultCapsule(); |
| 1893 | + |
| 1894 | + // Start time is too big. If it's to large, the account.frozen_supply.expireTime will overflow |
| 1895 | + FrozenSupply frozenSupply = FrozenSupply.newBuilder().setFrozenDays(20).setFrozenAmount(100) |
| 1896 | + .build(); |
| 1897 | + long startTime = Long.MAX_VALUE - frozenSupply.getFrozenDays() * FROZEN_PERIOD + 1; |
| 1898 | + Any any = Any.pack( |
| 1899 | + AssetIssueContract.newBuilder() |
| 1900 | + .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS))) |
| 1901 | + .setName(ByteString.copyFromUtf8(NAME)).setTotalSupply(TOTAL_SUPPLY).setTrxNum(TRX_NUM) |
| 1902 | + .setNum(NUM) |
| 1903 | + .setStartTime(startTime) |
| 1904 | + .setEndTime(startTime + 24 * 3600 * 1000) |
| 1905 | + .setDescription(ByteString.copyFromUtf8(DESCRIPTION)) |
| 1906 | + .setUrl(ByteString.copyFromUtf8(URL)) |
| 1907 | + .setPrecision(3) |
| 1908 | + .addFrozenSupply(frozenSupply) |
| 1909 | + .build()); |
| 1910 | + AssetIssueActuator actuator = new AssetIssueActuator(); |
| 1911 | + actuator.setChainBaseManager(dbManager.getChainBaseManager()).setAny(any); |
| 1912 | + |
| 1913 | + AccountCapsule owner = dbManager.getAccountStore().get(ByteArray.fromHexString(OWNER_ADDRESS)); |
| 1914 | + owner.setBalance(10_000_000_000L); |
| 1915 | + dbManager.getAccountStore().put(owner.createDbKey(), owner); |
| 1916 | + |
| 1917 | + processAndCheckInvalid(actuator, ret, |
| 1918 | + "Start time and frozen days would cause expire time overflow", |
| 1919 | + "Start time and frozen days would cause expire time overflow"); |
| 1920 | + } |
1871 | 1921 |
|
1872 | 1922 | @Test |
1873 | 1923 | public void commonErrorCheck() { |
|
0 commit comments