|
1 | 1 | package org.tron.core.db;
|
2 | 2 |
|
| 3 | +import static org.junit.Assert.assertThrows; |
3 | 4 | import static org.tron.common.utils.Commons.adjustAssetBalanceV2;
|
4 | 5 | import static org.tron.common.utils.Commons.adjustBalance;
|
5 | 6 | import static org.tron.common.utils.Commons.adjustTotalShieldedPoolValue;
|
|
8 | 9 |
|
9 | 10 | import com.google.common.collect.Maps;
|
10 | 11 | import com.google.common.collect.Sets;
|
| 12 | +import com.google.protobuf.Any; |
11 | 13 | import com.google.protobuf.ByteString;
|
12 | 14 | import java.io.IOException;
|
| 15 | +import java.nio.charset.StandardCharsets; |
13 | 16 | import java.util.ArrayList;
|
14 | 17 | import java.util.Arrays;
|
15 | 18 | import java.util.List;
|
|
85 | 88 | import org.tron.protos.Protocol.Block;
|
86 | 89 | import org.tron.protos.Protocol.Transaction;
|
87 | 90 | import org.tron.protos.Protocol.Transaction.Contract.ContractType;
|
| 91 | +import org.tron.protos.Protocol.Transaction.raw; |
88 | 92 | import org.tron.protos.contract.AccountContract;
|
89 | 93 | import org.tron.protos.contract.AssetIssueContractOuterClass;
|
90 | 94 | import org.tron.protos.contract.BalanceContract.TransferContract;
|
@@ -1114,4 +1118,37 @@ public void testExpireTransaction() {
|
1114 | 1118 | Assert.fail();
|
1115 | 1119 | }
|
1116 | 1120 | }
|
| 1121 | + |
| 1122 | + @Test |
| 1123 | + public void testTooBigTransaction() { |
| 1124 | + TransferContract transferContract = |
| 1125 | + TransferContract.newBuilder() |
| 1126 | + .setAmount(10) |
| 1127 | + .setOwnerAddress(ByteString.copyFromUtf8("aaa")) |
| 1128 | + .setToAddress(ByteString.copyFromUtf8("bbb")) |
| 1129 | + .build(); |
| 1130 | + StringBuilder sb = new StringBuilder(); |
| 1131 | + for (int i = 0; i < 6666; i++) { |
| 1132 | + sb.append("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 1133 | + } |
| 1134 | + Transaction transaction = Transaction.newBuilder().setRawData(raw.newBuilder() |
| 1135 | + .setData(ByteString.copyFrom(sb.toString().getBytes(StandardCharsets.UTF_8))) |
| 1136 | + .addContract(Transaction.Contract.newBuilder().setParameter(Any.pack(transferContract)) |
| 1137 | + .setType(ContractType.TransferContract))).build(); |
| 1138 | + TransactionCapsule trx = new TransactionCapsule(transaction); |
| 1139 | + trx.setInBlock(false); |
| 1140 | + assertThrows( |
| 1141 | + "Too big transaction with result, " |
| 1142 | + + "TxId 1c05e9fca6a2d0c366ed4430456527eb40198e70c8b20f5ceca4739c68a79af8, " |
| 1143 | + + "the size is 533483 bytes, maxTxSize 512000", |
| 1144 | + TooBigTransactionException.class, ()-> dbManager.validateCommon(trx)); |
| 1145 | + |
| 1146 | + trx.setInBlock(true); |
| 1147 | + assertThrows( |
| 1148 | + "Too big transaction, " |
| 1149 | + + "TxId 1c05e9fca6a2d0c366ed4430456527eb40198e70c8b20f5ceca4739c68a79af8, " |
| 1150 | + + "the size is 1066643 bytes, maxTxSize 512000", |
| 1151 | + TooBigTransactionException.class, ()-> dbManager.validateCommon(trx)); |
| 1152 | + |
| 1153 | + } |
1117 | 1154 | }
|
0 commit comments