|
48 | 48 | import org.tron.api.GrpcAPI.ProposalList;
|
49 | 49 | import org.tron.common.BaseTest;
|
50 | 50 | import org.tron.common.crypto.ECKey;
|
| 51 | +import org.tron.common.parameter.CommonParameter; |
51 | 52 | import org.tron.common.utils.ByteArray;
|
52 | 53 | import org.tron.common.utils.Utils;
|
53 | 54 | import org.tron.core.actuator.DelegateResourceActuator;
|
|
72 | 73 | import org.tron.core.store.DynamicPropertiesStore;
|
73 | 74 | import org.tron.core.utils.ProposalUtil.ProposalType;
|
74 | 75 | import org.tron.core.utils.TransactionUtil;
|
| 76 | +import org.tron.core.vm.config.ConfigLoader; |
| 77 | +import org.tron.core.vm.config.VMConfig; |
75 | 78 | import org.tron.core.vm.program.Program;
|
76 | 79 | import org.tron.protos.Protocol;
|
77 | 80 | import org.tron.protos.Protocol.Block;
|
@@ -1043,6 +1046,79 @@ public void testGetAssetIssueByName() {
|
1043 | 1046 | chainBaseManager.getDynamicPropertiesStore().saveAllowSameTokenName(0);
|
1044 | 1047 | }
|
1045 | 1048 |
|
| 1049 | + @Test |
| 1050 | + @SneakyThrows |
| 1051 | + public void testTriggerConstant() { |
| 1052 | + boolean preDebug = CommonParameter.getInstance().debug; |
| 1053 | + CommonParameter.getInstance().debug = true; |
| 1054 | + ConfigLoader.disable = true; |
| 1055 | + VMConfig.initAllowTvmTransferTrc10(1); |
| 1056 | + VMConfig.initAllowTvmConstantinople(1); |
| 1057 | + VMConfig.initAllowTvmShangHai(1); |
| 1058 | + |
| 1059 | + String contractAddress = |
| 1060 | + Wallet.getAddressPreFixString() + "1A622D84ed49f01045f5f1a5AfcEb9c57e9cC3cc"; |
| 1061 | + |
| 1062 | + AccountCapsule accountCap = new AccountCapsule( |
| 1063 | + ByteString.copyFrom(ByteArray.fromHexString(contractAddress)), |
| 1064 | + Protocol.AccountType.Normal); |
| 1065 | + dbManager.getAccountStore().put(accountCap.createDbKey(), accountCap); |
| 1066 | + |
| 1067 | + SmartContractOuterClass.SmartContract smartContract = |
| 1068 | + SmartContractOuterClass.SmartContract.newBuilder().build(); |
| 1069 | + ContractCapsule contractCap = new ContractCapsule(smartContract); |
| 1070 | + dbManager.getContractStore().put(ByteArray.fromHexString(contractAddress), contractCap); |
| 1071 | + |
| 1072 | + String codeString = "608060405234801561000f575f80fd5b50d3801561001b575f80fd5b50d280156100" |
| 1073 | + + "27575f80fd5b506004361061004c575f3560e01c80638da5cb5b14610050578063f8a8fd6d1461006e57" |
| 1074 | + + "5b5f80fd5b61005861008c565b6040516100659190610269565b60405180910390f35b6100766100af565b" |
| 1075 | + + "6040516100839190610269565b60405180910390f35b5f8054906101000a900473ffffffffffffffffffff" |
| 1076 | + + "ffffffffffffffffffff1681565b5f60017fbe0166938e2ea2f3f3e0746fdaf46e25c4d8de37ce56d70400" |
| 1077 | + + "cf284c80d47bbe601b7f10afab946e2be82aa3e4280cf24e2cab294911c3beb06ca9dd7ead06081265d07f" |
| 1078 | + + "1e1855bcdc3ed57c6f3c3874cde035782427d1236e2d819bd16c75676ecc003a6040515f81526020016040" |
| 1079 | + + "52604051610133949392919061038f565b6020604051602081039080840390855afa158015610153573d5f" |
| 1080 | + + "803e3d5ffd5b505050602060405103515f806101000a81548173ffffffffffffffffffffffffffffffffff" |
| 1081 | + + "ffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550734c95a52686a9b3" |
| 1082 | + + "ff9cf787b94b8549a988334c5773ffffffffffffffffffffffffffffffffffffffff165f8054906101000a" |
| 1083 | + + "900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffff" |
| 1084 | + + "ffff1614610205575f80fd5b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff" |
| 1085 | + + "16905090565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6102538261" |
| 1086 | + + "022a565b9050919050565b61026381610249565b82525050565b5f60208201905061027c5f83018461025a" |
| 1087 | + + "565b92915050565b5f819050919050565b5f819050919050565b5f815f1b9050919050565b5f6102b96102" |
| 1088 | + + "b46102af84610282565b610294565b61028b565b9050919050565b6102c98161029f565b82525050565b5f" |
| 1089 | + + "819050919050565b5f60ff82169050919050565b5f819050919050565b5f6103076103026102fd846102cf" |
| 1090 | + + "565b6102e4565b6102d8565b9050919050565b610317816102ed565b82525050565b5f819050919050565b" |
| 1091 | + + "5f61034061033b6103368461031d565b610294565b61028b565b9050919050565b61035081610326565b82" |
| 1092 | + + "525050565b5f819050919050565b5f61037961037461036f84610356565b610294565b61028b565b905091" |
| 1093 | + + "9050565b6103898161035f565b82525050565b5f6080820190506103a25f8301876102c0565b6103af6020" |
| 1094 | + + "83018661030e565b6103bc6040830185610347565b6103c96060830184610380565b9594505050505056fe" |
| 1095 | + + "a26474726f6e58221220e967690f9c06386434cbe4d8dd6dce394130f190d17621cbd4ae4cabdef4ad7964" |
| 1096 | + + "736f6c63430008140033"; |
| 1097 | + CodeCapsule codeCap = new CodeCapsule(ByteArray.fromHexString(codeString)); |
| 1098 | + dbManager.getCodeStore().put(ByteArray.fromHexString(contractAddress), codeCap); |
| 1099 | + |
| 1100 | + SmartContractOuterClass.TriggerSmartContract contract = |
| 1101 | + SmartContractOuterClass.TriggerSmartContract.newBuilder() |
| 1102 | + .setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(contractAddress))) |
| 1103 | + .setContractAddress(ByteString.copyFrom(ByteArray.fromHexString(contractAddress))) |
| 1104 | + .setData(ByteString.copyFrom(ByteArray.fromHexString("f8a8fd6d"))) |
| 1105 | + .build(); |
| 1106 | + TransactionCapsule trxCap = wallet.createTransactionCapsule(contract, |
| 1107 | + ContractType.TriggerSmartContract); |
| 1108 | + |
| 1109 | + GrpcAPI.TransactionExtention.Builder trxExtBuilder = GrpcAPI.TransactionExtention.newBuilder(); |
| 1110 | + GrpcAPI.Return.Builder retBuilder = GrpcAPI.Return.newBuilder(); |
| 1111 | + |
| 1112 | + Transaction tx = wallet.triggerConstantContract(contract, trxCap, trxExtBuilder, retBuilder); |
| 1113 | + Assert.assertEquals(Transaction.Result.code.SUCESS, tx.getRet(0).getRet()); |
| 1114 | + |
| 1115 | + VMConfig.initAllowTvmTransferTrc10(0); |
| 1116 | + VMConfig.initAllowTvmConstantinople(0); |
| 1117 | + VMConfig.initAllowTvmShangHai(0); |
| 1118 | + ConfigLoader.disable = false; |
| 1119 | + CommonParameter.getInstance().debug = preDebug; |
| 1120 | + } |
| 1121 | + |
1046 | 1122 | @Test
|
1047 | 1123 | @SneakyThrows
|
1048 | 1124 | public void testEstimateEnergy() {
|
|
0 commit comments