Skip to content

Commit 32f210d

Browse files
committed
test(case): add transaction test cases
1 parent bc701de commit 32f210d

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.tron.core.db;
2+
3+
import com.google.protobuf.ByteString;
4+
import javax.annotation.Resource;
5+
import org.junit.Assert;
6+
import org.junit.Test;
7+
import org.tron.common.BaseTest;
8+
import org.tron.common.utils.ByteArray;
9+
import org.tron.common.utils.Sha256Hash;
10+
import org.tron.core.Constant;
11+
import org.tron.core.capsule.BlockCapsule;
12+
import org.tron.core.capsule.BytesCapsule;
13+
import org.tron.core.config.args.Args;
14+
import org.tron.core.exception.ItemNotFoundException;
15+
16+
public class BlockIndexStoreTest extends BaseTest {
17+
18+
@Resource
19+
private BlockIndexStore blockIndexStore;
20+
21+
static {
22+
Args.setParam(
23+
new String[]{
24+
"--output-directory", dbPath()
25+
},
26+
Constant.TEST_CONF
27+
);
28+
}
29+
30+
private BlockCapsule getBlockCapsule(long number) {
31+
return new BlockCapsule(number, Sha256Hash.ZERO_HASH,
32+
System.currentTimeMillis(), ByteString.EMPTY);
33+
}
34+
35+
@Test
36+
public void testPut() {
37+
BlockCapsule blockCapsule = getBlockCapsule(1);
38+
blockIndexStore.put(blockCapsule.getBlockId());
39+
byte[] key = ByteArray.fromLong(blockCapsule.getBlockId().getNum());
40+
Assert.assertTrue(blockIndexStore.has(key));
41+
}
42+
43+
@Test
44+
public void testGet() throws ItemNotFoundException {
45+
BlockCapsule blockCapsule = getBlockCapsule(1);
46+
blockIndexStore.put(blockCapsule.getBlockId());
47+
byte[] key = ByteArray.fromLong(blockCapsule.getBlockId().getNum());
48+
BytesCapsule bytesCapsule = blockIndexStore.get(key);
49+
Assert.assertNotNull(bytesCapsule);
50+
}
51+
52+
@Test
53+
public void testDelete() throws ItemNotFoundException {
54+
BlockCapsule blockCapsule = getBlockCapsule(1);
55+
blockIndexStore.put(blockCapsule.getBlockId());
56+
byte[] key = ByteArray.fromLong(blockCapsule.getBlockId().getNum());
57+
BytesCapsule bytesCapsule = blockIndexStore.get(key);
58+
Assert.assertNotNull(bytesCapsule);
59+
60+
blockIndexStore.delete(key);
61+
BytesCapsule capsule = blockIndexStore.getUnchecked(key);
62+
Assert.assertNull(capsule.getData());
63+
}
64+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.tron.core.services.http;
2+
3+
import static java.nio.charset.StandardCharsets.UTF_8;
4+
import static org.tron.common.utils.client.utils.HttpMethed.createRequest;
5+
6+
import javax.annotation.Resource;
7+
import org.apache.http.client.methods.HttpPost;
8+
import org.junit.Assert;
9+
import org.junit.Test;
10+
import org.springframework.mock.web.MockHttpServletRequest;
11+
import org.springframework.mock.web.MockHttpServletResponse;
12+
import org.tron.common.BaseTest;
13+
import org.tron.core.Constant;
14+
import org.tron.core.config.args.Args;
15+
16+
public class GetTransactionInfoByBlockNumServletTest extends BaseTest {
17+
18+
@Resource
19+
private GetTransactionInfoByBlockNumServlet getTransactionInfoByBlockNumServlet;
20+
21+
static {
22+
Args.setParam(
23+
new String[]{
24+
"--output-directory", dbPath(),
25+
}, Constant.TEST_CONF
26+
);
27+
}
28+
29+
@Test
30+
public void testGetTransactionInfoByBlockNum() {
31+
String jsonParam = "{\"num\" : 100}";
32+
MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME);
33+
request.setContentType("application/json");
34+
request.setContent(jsonParam.getBytes(UTF_8));
35+
MockHttpServletResponse response = new MockHttpServletResponse();
36+
37+
getTransactionInfoByBlockNumServlet.doPost(request, response);
38+
Assert.assertEquals(200, response.getStatus());
39+
}
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.tron.core.services.http;
2+
3+
import static java.nio.charset.StandardCharsets.UTF_8;
4+
import static org.tron.common.utils.client.utils.HttpMethed.createRequest;
5+
6+
import javax.annotation.Resource;
7+
import org.apache.http.client.methods.HttpPost;
8+
import org.junit.Assert;
9+
import org.junit.Test;
10+
import org.springframework.mock.web.MockHttpServletRequest;
11+
import org.springframework.mock.web.MockHttpServletResponse;
12+
import org.tron.common.BaseTest;
13+
import org.tron.core.Constant;
14+
import org.tron.core.config.args.Args;
15+
16+
public class GetTransactionInfoByIdServletTest extends BaseTest {
17+
18+
@Resource
19+
private GetTransactionInfoByIdServlet getTransactionInfoByIdServlet;
20+
21+
static {
22+
Args.setParam(
23+
new String[]{
24+
"--output-directory", dbPath(),
25+
}, Constant.TEST_CONF
26+
);
27+
}
28+
29+
@Test
30+
public void testGetInfoById() {
31+
String jsonParam = "{\"value\" : "
32+
+ "\"309b6fa3d01353e46f57dd8a8f276"
33+
+ "11f98e392b50d035cef213f2c55225a8bd2\"}";
34+
MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME);
35+
request.setContentType("application/json");
36+
request.setContent(jsonParam.getBytes(UTF_8));
37+
MockHttpServletResponse response = new MockHttpServletResponse();
38+
39+
getTransactionInfoByIdServlet.doPost(request, response);
40+
Assert.assertEquals(200, response.getStatus());
41+
}
42+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.tron.core.services.http;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.tron.common.utils.client.utils.HttpMethed.createRequest;
5+
6+
import javax.annotation.Resource;
7+
8+
import org.apache.http.client.methods.HttpGet;
9+
import org.junit.Test;
10+
import org.springframework.mock.web.MockHttpServletRequest;
11+
import org.springframework.mock.web.MockHttpServletResponse;
12+
import org.tron.common.BaseTest;
13+
import org.tron.core.Constant;
14+
import org.tron.core.config.args.Args;
15+
16+
17+
public class GetTransactionListFromPendingServletTest extends BaseTest {
18+
19+
@Resource
20+
private GetTransactionListFromPendingServlet getTransactionListFromPendingServlet;
21+
22+
static {
23+
Args.setParam(
24+
new String[]{
25+
"--output-directory", dbPath(),
26+
}, Constant.TEST_CONF
27+
);
28+
}
29+
30+
@Test
31+
public void testGet() {
32+
MockHttpServletRequest request = createRequest(HttpGet.METHOD_NAME);
33+
MockHttpServletResponse response = new MockHttpServletResponse();
34+
getTransactionListFromPendingServlet.doPost(request, response);
35+
assertEquals(200, response.getStatus());
36+
}
37+
38+
}

0 commit comments

Comments
 (0)