Skip to content

Commit 3aa94e0

Browse files
committed
test(tvm): add unit test for suicide action
1 parent 4058702 commit 3aa94e0

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

framework/src/test/java/org/tron/common/runtime/vm/OperationsTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,29 @@ public void testSuicideCost() throws ContractValidateException {
888888
Assert.assertEquals(0, EnergyCost.getSuicideCost2(program));
889889
}
890890

891+
@Test
892+
public void testSuicideAction() throws ContractValidateException {
893+
invoke = new ProgramInvokeMockImpl(
894+
StoreFactory.getInstance(),
895+
new byte[0],
896+
Hex.decode("41471fd3ad3e9eeadeec4608b92d16ce6b500704cc"));
897+
898+
program = new Program(null, null, invoke,
899+
new InternalTransaction(
900+
Protocol.Transaction.getDefaultInstance(),
901+
InternalTransaction.TrxType.TRX_UNKNOWN_TYPE));
902+
903+
VMConfig.initAllowEnergyAdjustment(1);
904+
byte prePrefixByte = DecodeUtil.addressPreFixByte;
905+
DecodeUtil.addressPreFixByte = Constant.ADD_PRE_FIX_BYTE_MAINNET;
906+
907+
program.suicide(new DataWord(
908+
dbManager.getAccountStore().getBlackhole().getAddress().toByteArray()));
909+
910+
DecodeUtil.addressPreFixByte = prePrefixByte;
911+
VMConfig.initAllowEnergyAdjustment(0);
912+
}
913+
891914
@Test
892915
public void testVoteWitnessCost() throws ContractValidateException {
893916
// Build stack environment, the stack from top to bottom is 0x00, 0x80, 0x00, 0x80

framework/src/test/java/org/tron/core/actuator/utils/ProposalUtilTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Arrays;
66
import java.util.HashMap;
77
import java.util.List;
8+
import java.util.Map;
89
import javax.annotation.Resource;
910
import lombok.extern.slf4j.Slf4j;
1011
import org.junit.Assert;
@@ -13,18 +14,15 @@
1314
import org.tron.common.BaseTest;
1415
import org.tron.common.utils.ByteArray;
1516
import org.tron.common.utils.ForkController;
16-
import org.tron.core.ChainBaseManager;
1717
import org.tron.core.Constant;
1818
import org.tron.core.capsule.BytesCapsule;
1919
import org.tron.core.capsule.ProposalCapsule;
2020
import org.tron.core.config.Parameter;
2121
import org.tron.core.config.Parameter.ForkBlockVersionEnum;
2222
import org.tron.core.config.args.Args;
2323
import org.tron.core.consensus.ProposalService;
24-
import org.tron.core.db.Manager;
2524
import org.tron.core.exception.ContractValidateException;
2625
import org.tron.core.store.DynamicPropertiesStore;
27-
import org.tron.core.store.StoreFactory;
2826
import org.tron.core.utils.ProposalUtil;
2927
import org.tron.core.utils.ProposalUtil.ProposalType;
3028

@@ -440,10 +438,9 @@ private void testEnergyAdjustmentProposal() {
440438
}
441439

442440
ProposalCapsule proposalCapsule = new ProposalCapsule(ByteString.empty(), 0);
443-
proposalCapsule.setParameters(new HashMap<Long, Long>(){{
444-
put(81L, 1L);
445-
}});
446-
441+
Map<Long, Long> parameter = new HashMap<>();
442+
parameter.put(81L, 1L);
443+
proposalCapsule.setParameters(parameter);
447444
ProposalService.process(dbManager, proposalCapsule);
448445

449446
try {

0 commit comments

Comments
 (0)