-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(api): add resource price API for solidity and PBFT #5451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
halibobo1205
merged 1 commit into
tronprotocol:develop
from
lxcmyf:feature/add_solidity_pbft_api
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...ain/java/org/tron/core/services/interfaceOnPBFT/http/GetBandwidthPricesOnPBFTServlet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package org.tron.core.services.interfaceOnPBFT.http; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Component; | ||
| import org.tron.core.services.http.GetBandwidthPricesServlet; | ||
| import org.tron.core.services.interfaceOnPBFT.WalletOnPBFT; | ||
|
|
||
| @Component | ||
| @Slf4j(topic = "API") | ||
| public class GetBandwidthPricesOnPBFTServlet extends GetBandwidthPricesServlet { | ||
|
|
||
| @Autowired | ||
| private WalletOnPBFT walletOnPBFT; | ||
|
|
||
| @Override | ||
| protected void doGet(HttpServletRequest request, HttpServletResponse response) { | ||
| walletOnPBFT.futureGet(() -> super.doGet(request, response)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doPost(HttpServletRequest request, HttpServletResponse response) { | ||
| walletOnPBFT.futureGet(() -> super.doPost(request, response)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
.../org/tron/core/services/interfaceOnSolidity/http/GetBandwidthPricesOnSolidityServlet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.tron.core.services.interfaceOnSolidity.http; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
| import javax.servlet.http.HttpServletResponse; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Component; | ||
| import org.tron.core.services.http.GetBandwidthPricesServlet; | ||
| import org.tron.core.services.interfaceOnSolidity.WalletOnSolidity; | ||
|
|
||
| @Component | ||
| @Slf4j(topic = "API") | ||
| public class GetBandwidthPricesOnSolidityServlet extends GetBandwidthPricesServlet { | ||
|
|
||
| @Autowired | ||
| private WalletOnSolidity walletOnSolidity; | ||
|
|
||
| @Override | ||
| protected void doGet(HttpServletRequest request, HttpServletResponse response) { | ||
| walletOnSolidity.futureGet(() -> super.doGet(request, response)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doPost(HttpServletRequest request, HttpServletResponse response) { | ||
| walletOnSolidity.futureGet(() -> super.doPost(request, response)); | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...java/org/tron/core/services/interfaceOnPBFT/http/GetBandwidthPricesOnPBFTServletTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package org.tron.core.services.interfaceOnPBFT.http; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
| import static org.tron.common.utils.client.utils.HttpMethed.createRequest; | ||
|
|
||
| import com.alibaba.fastjson.JSONObject; | ||
| import java.io.IOException; | ||
| import java.io.UnsupportedEncodingException; | ||
| import javax.annotation.Resource; | ||
| import org.apache.http.client.methods.HttpGet; | ||
| import org.apache.http.client.methods.HttpPost; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
| import org.springframework.mock.web.MockHttpServletRequest; | ||
| import org.springframework.mock.web.MockHttpServletResponse; | ||
| import org.tron.common.BaseTest; | ||
| import org.tron.core.Constant; | ||
| import org.tron.core.config.args.Args; | ||
|
|
||
| public class GetBandwidthPricesOnPBFTServletTest extends BaseTest { | ||
|
|
||
| @ClassRule | ||
| public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
| @Resource | ||
| private GetBandwidthPricesOnPBFTServlet getBandwidthPricesOnPBFTServlet; | ||
|
|
||
| @BeforeClass | ||
| public static void init() throws IOException { | ||
| Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGet() { | ||
| MockHttpServletRequest request = createRequest(HttpGet.METHOD_NAME); | ||
| MockHttpServletResponse response = new MockHttpServletResponse(); | ||
| getBandwidthPricesOnPBFTServlet.doPost(request, response); | ||
| try { | ||
| String contentAsString = response.getContentAsString(); | ||
| JSONObject result = JSONObject.parseObject(contentAsString); | ||
| assertTrue(result.containsKey("prices")); | ||
| } catch (UnsupportedEncodingException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testPost() { | ||
| MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME); | ||
| try { | ||
| MockHttpServletResponse response = new MockHttpServletResponse(); | ||
| getBandwidthPricesOnPBFTServlet.doPost(request, response); | ||
| String contentAsString = response.getContentAsString(); | ||
| JSONObject result = JSONObject.parseObject(contentAsString); | ||
| assertTrue(result.containsKey("prices")); | ||
| } catch (UnsupportedEncodingException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
...st/java/org/tron/core/services/interfaceOnPBFT/http/GetEnergyPricesOnPBFTServletTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package org.tron.core.services.interfaceOnPBFT.http; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
| import static org.tron.common.utils.client.utils.HttpMethed.createRequest; | ||
|
|
||
| import com.alibaba.fastjson.JSONObject; | ||
| import java.io.IOException; | ||
| import java.io.UnsupportedEncodingException; | ||
| import javax.annotation.Resource; | ||
| import org.apache.http.client.methods.HttpGet; | ||
| import org.apache.http.client.methods.HttpPost; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
| import org.springframework.mock.web.MockHttpServletRequest; | ||
| import org.springframework.mock.web.MockHttpServletResponse; | ||
| import org.tron.common.BaseTest; | ||
| import org.tron.core.Constant; | ||
| import org.tron.core.config.args.Args; | ||
|
|
||
| public class GetEnergyPricesOnPBFTServletTest extends BaseTest { | ||
|
|
||
| @ClassRule | ||
| public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
| @Resource | ||
| private GetEnergyPricesOnPBFTServlet getEnergyPricesOnPBFTServlet; | ||
|
|
||
| @BeforeClass | ||
| public static void init() throws IOException { | ||
| Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGet() { | ||
| MockHttpServletRequest request = createRequest(HttpGet.METHOD_NAME); | ||
| MockHttpServletResponse response = new MockHttpServletResponse(); | ||
| getEnergyPricesOnPBFTServlet.doPost(request, response); | ||
| try { | ||
| String contentAsString = response.getContentAsString(); | ||
| JSONObject result = JSONObject.parseObject(contentAsString); | ||
| assertTrue(result.containsKey("prices")); | ||
| } catch (UnsupportedEncodingException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testPost() { | ||
| MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME); | ||
| try { | ||
| MockHttpServletResponse response = new MockHttpServletResponse(); | ||
| getEnergyPricesOnPBFTServlet.doPost(request, response); | ||
| String contentAsString = response.getContentAsString(); | ||
| JSONObject result = JSONObject.parseObject(contentAsString); | ||
| assertTrue(result.containsKey("prices")); | ||
| } catch (UnsupportedEncodingException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
62 changes: 62 additions & 0 deletions
62
.../tron/core/services/interfaceOnSolidity/http/GetBandwidthPricesOnSolidityServletTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package org.tron.core.services.interfaceOnSolidity.http; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
| import static org.tron.common.utils.client.utils.HttpMethed.createRequest; | ||
|
|
||
| import com.alibaba.fastjson.JSONObject; | ||
| import java.io.IOException; | ||
| import java.io.UnsupportedEncodingException; | ||
| import javax.annotation.Resource; | ||
| import org.apache.http.client.methods.HttpGet; | ||
| import org.apache.http.client.methods.HttpPost; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
| import org.springframework.mock.web.MockHttpServletRequest; | ||
| import org.springframework.mock.web.MockHttpServletResponse; | ||
| import org.tron.common.BaseTest; | ||
| import org.tron.core.Constant; | ||
| import org.tron.core.config.args.Args; | ||
|
|
||
| public class GetBandwidthPricesOnSolidityServletTest extends BaseTest { | ||
|
|
||
| @ClassRule | ||
| public static final TemporaryFolder temporaryFolder = new TemporaryFolder(); | ||
| @Resource | ||
| private GetBandwidthPricesOnSolidityServlet getBandwidthPricesOnSolidityServlet; | ||
|
|
||
| @BeforeClass | ||
| public static void init() throws IOException { | ||
| Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGet() { | ||
| MockHttpServletRequest request = createRequest(HttpGet.METHOD_NAME); | ||
| MockHttpServletResponse response = new MockHttpServletResponse(); | ||
| getBandwidthPricesOnSolidityServlet.doPost(request, response); | ||
| try { | ||
| String contentAsString = response.getContentAsString(); | ||
| JSONObject result = JSONObject.parseObject(contentAsString); | ||
| assertTrue(result.containsKey("prices")); | ||
| } catch (UnsupportedEncodingException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testPost() { | ||
| MockHttpServletRequest request = createRequest(HttpPost.METHOD_NAME); | ||
| try { | ||
| MockHttpServletResponse response = new MockHttpServletResponse(); | ||
| getBandwidthPricesOnSolidityServlet.doPost(request, response); | ||
| String contentAsString = response.getContentAsString(); | ||
| JSONObject result = JSONObject.parseObject(contentAsString); | ||
| assertTrue(result.containsKey("prices")); | ||
| } catch (UnsupportedEncodingException e) { | ||
| fail(e.getMessage()); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.