|
1 | 1 | package org.tron.core;
|
2 | 2 |
|
| 3 | +import static org.junit.Assert.assertThrows; |
| 4 | + |
3 | 5 | import com.google.protobuf.Any;
|
4 | 6 | import com.google.protobuf.ByteString;
|
| 7 | +import java.nio.charset.StandardCharsets; |
5 | 8 | import lombok.extern.slf4j.Slf4j;
|
6 | 9 | import org.joda.time.DateTime;
|
7 | 10 | import org.junit.Assert;
|
|
24 | 27 | import org.tron.core.store.StoreFactory;
|
25 | 28 | import org.tron.protos.Protocol;
|
26 | 29 | import org.tron.protos.Protocol.AccountType;
|
| 30 | +import org.tron.protos.Protocol.Transaction; |
| 31 | +import org.tron.protos.Protocol.Transaction.Contract; |
| 32 | +import org.tron.protos.Protocol.Transaction.Contract.ContractType; |
| 33 | +import org.tron.protos.Protocol.Transaction.Result; |
| 34 | +import org.tron.protos.Protocol.Transaction.raw; |
27 | 35 | import org.tron.protos.contract.AssetIssueContractOuterClass.AssetIssueContract;
|
28 | 36 | import org.tron.protos.contract.AssetIssueContractOuterClass.TransferAssetContract;
|
29 | 37 | import org.tron.protos.contract.BalanceContract.TransferContract;
|
@@ -540,6 +548,32 @@ public void testUsingFee() throws Exception {
|
540 | 548 | dbManager.consumeBandwidth(trx, trace);
|
541 | 549 | }
|
542 | 550 |
|
| 551 | + @Test |
| 552 | + public void testConsumeBandwidthTooBigTransactionResultException() { |
| 553 | + TransferContract transferContract = |
| 554 | + TransferContract.newBuilder() |
| 555 | + .setAmount(10) |
| 556 | + .setOwnerAddress(ByteString.copyFromUtf8("aaa")) |
| 557 | + .setToAddress(ByteString.copyFromUtf8("bbb")) |
| 558 | + .build(); |
| 559 | + StringBuilder sb = new StringBuilder(); |
| 560 | + for (int i = 0; i < 6666; i++) { |
| 561 | + sb.append("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
| 562 | + } |
| 563 | + Transaction transaction = Transaction.newBuilder().setRawData(raw.newBuilder() |
| 564 | + .setData(ByteString.copyFrom(sb.toString().getBytes(StandardCharsets.UTF_8))) |
| 565 | + .addContract(Contract.newBuilder().setParameter(Any.pack(transferContract)) |
| 566 | + .setType(ContractType.TransferContract))) |
| 567 | + .addRet(Result.newBuilder().setAssetIssueID(sb.toString()).build()).build(); |
| 568 | + TransactionCapsule trx = new TransactionCapsule(transaction); |
| 569 | + trx.setInBlock(false); |
| 570 | + TransactionTrace trace = new TransactionTrace(trx, StoreFactory |
| 571 | + .getInstance(), new RuntimeImpl()); |
| 572 | + assertThrows( |
| 573 | + "Too big transaction result, TxId %s, the result size is %d bytes, maxResultSize %d", |
| 574 | + TooBigTransactionResultException.class, () -> dbManager.consumeBandwidth(trx, trace)); |
| 575 | + } |
| 576 | + |
543 | 577 | /**
|
544 | 578 | * sameTokenName close, consume success assetIssueCapsule.getOwnerAddress() !=
|
545 | 579 | * fromAccount.getAddress()) contract.getType() = TransferAssetContract
|
|
0 commit comments