Skip to content

Commit 1225ace

Browse files
committed
test(case): optimize case
1 parent 32f210d commit 1225ace

9 files changed

+457
-98
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package org.tron.core.actuator;
2+
3+
import com.google.protobuf.ByteString;
4+
import java.util.List;
5+
import org.junit.Assert;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
import org.tron.common.BaseTest;
9+
import org.tron.common.utils.ByteArray;
10+
import org.tron.core.Constant;
11+
import org.tron.core.Wallet;
12+
import org.tron.core.capsule.AccountCapsule;
13+
import org.tron.core.capsule.TransactionCapsule;
14+
import org.tron.core.config.args.Args;
15+
import org.tron.protos.Protocol.AccountType;
16+
import org.tron.protos.contract.BalanceContract.TransferContract;
17+
18+
public class ActuatorFactoryTest extends BaseTest {
19+
20+
private static final String OWNER_ADDRESS = Wallet.getAddressPreFixString()
21+
+ "548794500882809695a8a687866e76d4271a1abc";
22+
private static final String TO_ADDRESS = Wallet.getAddressPreFixString()
23+
+ "abd4b9367799eaa3197fecb144eb71de1e049abc";
24+
25+
static {
26+
Args.setParam(
27+
new String[] {
28+
"--output-directory", dbPath()
29+
},
30+
Constant.TEST_CONF
31+
);
32+
}
33+
34+
private TransferContract getContract(long count, String owneraddress, String toaddress) {
35+
return TransferContract.newBuilder()
36+
.setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(owneraddress)))
37+
.setToAddress(ByteString.copyFrom(ByteArray.fromHexString(toaddress)))
38+
.setAmount(count)
39+
.build();
40+
}
41+
42+
@Before
43+
public void createCapsule() {
44+
AccountCapsule ownerCapsule =
45+
new AccountCapsule(
46+
ByteString.copyFromUtf8("owner"),
47+
ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)),
48+
AccountType.Normal,
49+
10000L);
50+
AccountCapsule toAccountCapsule =
51+
new AccountCapsule(
52+
ByteString.copyFromUtf8("toAccount"),
53+
ByteString.copyFrom(ByteArray.fromHexString(TO_ADDRESS)),
54+
AccountType.Normal,
55+
10L);
56+
dbManager.getAccountStore().put(ownerCapsule.getAddress().toByteArray(), ownerCapsule);
57+
dbManager.getAccountStore().put(toAccountCapsule.getAddress().toByteArray(), toAccountCapsule);
58+
}
59+
60+
61+
@Test
62+
public void testCreateActuator() {
63+
TransferContract contract = getContract(10L, OWNER_ADDRESS, TO_ADDRESS);
64+
TransactionCapsule trx = new TransactionCapsule(contract,
65+
chainBaseManager.getAccountStore());
66+
List<Actuator> actList = ActuatorFactory.createActuator(trx, chainBaseManager);
67+
68+
Assert.assertEquals(1, actList.size());
69+
}
70+
71+
}

framework/src/test/java/org/tron/core/services/http/AccountPermissionUpdateServletTest.java

Lines changed: 0 additions & 88 deletions
This file was deleted.

framework/src/test/java/org/tron/core/services/http/ClearABIServletTest.java

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
package org.tron.core.services.http;
22

33
import static java.nio.charset.StandardCharsets.UTF_8;
4+
import static org.junit.Assert.assertTrue;
5+
import static org.junit.Assert.fail;
46
import static org.tron.common.utils.client.utils.HttpMethed.createRequest;
57

8+
import com.alibaba.fastjson.JSONObject;
9+
import com.google.protobuf.ByteString;
10+
11+
import java.io.UnsupportedEncodingException;
612
import javax.annotation.Resource;
713

814
import org.apache.http.client.methods.HttpPost;
15+
916
import org.junit.Assert;
1017
import org.junit.Test;
1118
import org.springframework.mock.web.MockHttpServletRequest;
1219
import org.springframework.mock.web.MockHttpServletResponse;
1320
import org.tron.common.BaseTest;
21+
import org.tron.common.utils.ByteArray;
1422
import org.tron.core.Constant;
23+
import org.tron.core.capsule.ContractCapsule;
1524
import org.tron.core.config.args.Args;
25+
import org.tron.protos.contract.SmartContractOuterClass;
1626

1727
public class ClearABIServletTest extends BaseTest {
1828

@@ -27,11 +37,39 @@ public class ClearABIServletTest extends BaseTest {
2737
@Resource
2838
private ClearABIServlet clearABIServlet;
2939

40+
private static final String SMART_CONTRACT_NAME = "smart_contract_test";
41+
private static String CONTRACT_ADDRESS = "A0B4750E2CD76E19DCA331BF5D089B71C3C2798548";
42+
private static String OWNER_ADDRESS;
43+
private static final long SOURCE_ENERGY_LIMIT = 10L;
44+
45+
46+
47+
private SmartContractOuterClass.SmartContract.Builder createContract(
48+
String contractAddress, String contractName) {
49+
OWNER_ADDRESS =
50+
"A099357684BC659F5166046B56C95A0E99F1265CBD";
51+
SmartContractOuterClass.SmartContract.Builder builder =
52+
SmartContractOuterClass.SmartContract.newBuilder();
53+
builder.setName(contractName);
54+
builder.setOriginAddress(ByteString.copyFrom(ByteArray.fromHexString(OWNER_ADDRESS)));
55+
builder.setContractAddress(ByteString.copyFrom(ByteArray.fromHexString(contractAddress)));
56+
builder.setOriginEnergyLimit(SOURCE_ENERGY_LIMIT);
57+
return builder;
58+
}
59+
3060
@Test
31-
public void testClear() {
32-
String jsonParam = "{\n"
33-
+ " \"owner_address\": \"41a7d8a35b260395c14aa456297662092ba3b76fc0\",\n"
34-
+ " \"contract_address\": \"417bcb781f4743afaacf9f9528f3ea903b3782339f\"\n"
61+
public void testClearABI() {
62+
chainBaseManager.getDynamicPropertiesStore()
63+
.saveAllowTvmConstantinople(1);
64+
SmartContractOuterClass.SmartContract.Builder contract =
65+
createContract(CONTRACT_ADDRESS, SMART_CONTRACT_NAME);
66+
chainBaseManager.getContractStore().put(
67+
ByteArray.fromHexString(CONTRACT_ADDRESS),
68+
new ContractCapsule(contract.build()));
69+
70+
String jsonParam = "{"
71+
+ " \"owner_address\": \"A099357684BC659F5166046B56C95A0E99F1265CBD\","
72+
+ " \"contract_address\": \"A0B4750E2CD76E19DCA331BF5D089B71C3C2798548\""
3573
+ "}";
3674
MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME);
3775
request.setContentType("application/json");
@@ -40,6 +78,15 @@ public void testClear() {
4078
MockHttpServletResponse response = new MockHttpServletResponse();
4179
clearABIServlet.doPost(request, response);
4280
Assert.assertEquals(200, response.getStatus());
81+
try {
82+
String contentAsString = response.getContentAsString();
83+
JSONObject result = JSONObject.parseObject(contentAsString);
84+
assertTrue(result.containsKey("raw_data"));
85+
assertTrue(result.containsKey("txID"));
86+
} catch (UnsupportedEncodingException e) {
87+
fail(e.getMessage());
88+
}
89+
4390
}
4491

4592
}

framework/src/test/java/org/tron/core/services/http/CreateAccountServletTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
package org.tron.core.services.http;
22

33
import static java.nio.charset.StandardCharsets.UTF_8;
4+
import static org.junit.Assert.fail;
45
import static org.tron.common.utils.client.utils.HttpMethed.createRequest;
56

7+
import com.alibaba.fastjson.JSONObject;
8+
import com.google.protobuf.ByteString;
9+
10+
import java.io.UnsupportedEncodingException;
611
import javax.annotation.Resource;
712

813
import org.apache.http.client.methods.HttpPost;
914
import org.junit.Assert;
15+
import org.junit.Before;
1016
import org.junit.Test;
1117
import org.springframework.mock.web.MockHttpServletRequest;
1218
import org.springframework.mock.web.MockHttpServletResponse;
1319
import org.tron.common.BaseTest;
20+
import org.tron.common.utils.ByteArray;
1421
import org.tron.core.Constant;
22+
import org.tron.core.capsule.AccountCapsule;
1523
import org.tron.core.config.args.Args;
24+
import org.tron.protos.Protocol;
1625

1726

1827
public class CreateAccountServletTest extends BaseTest {
@@ -28,11 +37,23 @@ public class CreateAccountServletTest extends BaseTest {
2837
@Resource
2938
private CreateAccountServlet createAccountServlet;
3039

40+
@Before
41+
public void init() {
42+
AccountCapsule accountCapsule = new AccountCapsule(
43+
ByteString.copyFrom(ByteArray
44+
.fromHexString("A099357684BC659F5166046B56C95A0E99F1265CD1")),
45+
ByteString.copyFromUtf8("owner"),
46+
Protocol.AccountType.forNumber(1));
47+
48+
chainBaseManager.getAccountStore().put(accountCapsule.createDbKey(),
49+
accountCapsule);
50+
}
51+
3152
@Test
3253
public void testCreate() {
3354
String jsonParam = "{"
34-
+ "\"owner_address\": \"41d1e7a6bc354106cb410e65ff8b181c600ff14292\","
35-
+ "\"account_address\": \"41e552f6487585c2b58bc2c9bb4492bc1f17132cd0\""
55+
+ "\"owner_address\": \"A099357684BC659F5166046B56C95A0E99F1265CD1\","
56+
+ "\"account_address\": \"A0B4750E2CD76E19DCA331BF5D089B71C3C2798541\""
3657
+ "}";
3758
MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME);
3859
request.setContentType("application/json");
@@ -42,5 +63,13 @@ public void testCreate() {
4263
createAccountServlet.doPost(request, response);
4364

4465
Assert.assertEquals(200, response.getStatus());
66+
try {
67+
String contentAsString = response.getContentAsString();
68+
JSONObject result = JSONObject.parseObject(contentAsString);
69+
Assert.assertTrue(result.containsKey("raw_data"));
70+
Assert.assertTrue(result.containsKey("txID"));
71+
} catch (UnsupportedEncodingException e) {
72+
fail(e.getMessage());
73+
}
4574
}
4675
}

framework/src/test/java/org/tron/core/services/http/CreateAssetIssueServletTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
package org.tron.core.services.http;
22

33
import static java.nio.charset.StandardCharsets.UTF_8;
4+
import static org.junit.Assert.fail;
45
import static org.tron.common.utils.client.utils.HttpMethed.createRequest;
56

7+
import com.alibaba.fastjson.JSONObject;
8+
import com.google.protobuf.ByteString;
9+
10+
import java.io.UnsupportedEncodingException;
611
import javax.annotation.Resource;
712

813
import org.apache.http.client.methods.HttpPost;
914
import org.junit.Assert;
15+
import org.junit.Before;
1016
import org.junit.Test;
1117
import org.springframework.mock.web.MockHttpServletRequest;
1218
import org.springframework.mock.web.MockHttpServletResponse;
1319
import org.tron.common.BaseTest;
20+
import org.tron.common.utils.ByteArray;
1421
import org.tron.core.Constant;
22+
import org.tron.core.capsule.AccountCapsule;
1523
import org.tron.core.config.args.Args;
24+
import org.tron.protos.Protocol;
1625

1726
public class CreateAssetIssueServletTest extends BaseTest {
1827

@@ -24,14 +33,26 @@ public class CreateAssetIssueServletTest extends BaseTest {
2433
);
2534
}
2635

27-
2836
@Resource
2937
private CreateAssetIssueServlet createAssetIssueServlet;
3038

39+
@Before
40+
public void init() {
41+
AccountCapsule accountCapsule = new AccountCapsule(
42+
ByteString.copyFrom(ByteArray
43+
.fromHexString("A099357684BC659F5166046B56C95A0E99F1265CD1")),
44+
ByteString.copyFromUtf8("owner"),
45+
Protocol.AccountType.forNumber(1));
46+
accountCapsule.setBalance(10000000000L);
47+
48+
chainBaseManager.getAccountStore().put(accountCapsule.createDbKey(),
49+
accountCapsule);
50+
}
51+
3152
@Test
3253
public void testCreate() {
3354
String jsonParam = "{"
34-
+ " \"owner_address\": \"41e552f6487585c2b58bc2c9bb4492bc1f17132cd0\","
55+
+ " \"owner_address\": \"A099357684BC659F5166046B56C95A0E99F1265CD1\","
3556
+ " \"name\": \"0x6173736574497373756531353330383934333132313538\","
3657
+ " \"abbr\": \"0x6162627231353330383934333132313538\","
3758
+ " \"total_supply\": 4321,"
@@ -55,6 +76,14 @@ public void testCreate() {
5576
MockHttpServletResponse response = new MockHttpServletResponse();
5677
createAssetIssueServlet.doPost(request, response);
5778
Assert.assertEquals(200, response.getStatus());
79+
try {
80+
String contentAsString = response.getContentAsString();
81+
JSONObject result = JSONObject.parseObject(contentAsString);
82+
Assert.assertTrue(result.containsKey("raw_data"));
83+
Assert.assertTrue(result.containsKey("txID"));
84+
} catch (UnsupportedEncodingException e) {
85+
fail(e.getMessage());
86+
}
5887

5988
}
6089

0 commit comments

Comments
 (0)