-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refactor apitest for api calls to any daemon type #4525
Merged
sqrrm
merged 9 commits into
bisq-network:master
from
ghubstan:2-refactor-apitest-grpcstubs
Sep 16, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
359037a
Move version service proto def to bottom of grpc.proto
ghubstan 15b6044
Add dispute agents service proto def to grpc.proto
ghubstan bbf4f09
Add core impl for registering dispute agents
ghubstan 3386b43
Add GrpcDisputeAgentsService to GrpcServer
ghubstan 304047e
Create GrpcDisputeAgentsService stub
ghubstan 899bea8
Replace "localhost" strings with InetAddress.getLoopbackAddress calls
ghubstan 148a0f1
Refactor test cases to use arbitrary grpc stubs
ghubstan 8384dd8
Add api dispute agent registration test case
ghubstan 3f0394f
Bump version to 1.3.8
ghubstan 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
This file contains 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 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 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 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 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 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
108 changes: 108 additions & 0 deletions
108
apitest/src/test/java/bisq/apitest/method/RegisterDisputeAgentsTest.java
This file contains 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,108 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.apitest.method; | ||
|
||
import bisq.proto.grpc.RegisterDisputeAgentRequest; | ||
|
||
import io.grpc.StatusRuntimeException; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
|
||
import static bisq.apitest.config.BisqAppConfig.arbdaemon; | ||
import static bisq.common.app.DevEnv.DEV_PRIVILEGE_PRIV_KEY; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.junit.jupiter.api.MethodOrderer.OrderAnnotation; | ||
|
||
|
||
@SuppressWarnings("ResultOfMethodCallIgnored") | ||
@Slf4j | ||
@TestMethodOrder(OrderAnnotation.class) | ||
public class RegisterDisputeAgentsTest extends MethodTest { | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
try { | ||
setUpScaffold("bitcoind,seednode,arbdaemon"); | ||
} catch (Exception ex) { | ||
fail(ex); | ||
} | ||
} | ||
|
||
@Test | ||
@Order(1) | ||
public void testRegisterArbitratorShouldThrowException() { | ||
var req = | ||
createRegisterDisputeAgentRequest("arbitrator"); | ||
Throwable exception = assertThrows(StatusRuntimeException.class, () -> | ||
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req)); | ||
assertEquals("INVALID_ARGUMENT: arbitrators must be registered in a Bisq UI", | ||
exception.getMessage()); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
public void testInvalidDisputeAgentTypeArgShouldThrowException() { | ||
var req = | ||
createRegisterDisputeAgentRequest("badagent"); | ||
Throwable exception = assertThrows(StatusRuntimeException.class, () -> | ||
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req)); | ||
assertEquals("INVALID_ARGUMENT: unknown dispute agent type badagent", | ||
exception.getMessage()); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
public void testInvalidRegistrationKeyArgShouldThrowException() { | ||
var req = RegisterDisputeAgentRequest.newBuilder() | ||
.setDisputeAgentType("refundagent") | ||
.setRegistrationKey("invalid" + DEV_PRIVILEGE_PRIV_KEY).build(); | ||
Throwable exception = assertThrows(StatusRuntimeException.class, () -> | ||
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req)); | ||
assertEquals("INVALID_ARGUMENT: invalid registration key", | ||
exception.getMessage()); | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
public void testRegisterMediator() { | ||
var req = | ||
createRegisterDisputeAgentRequest("mediator"); | ||
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req); | ||
} | ||
|
||
@Test | ||
@Order(5) | ||
public void testRegisterRefundAgent() { | ||
var req = | ||
createRegisterDisputeAgentRequest("refundagent"); | ||
grpcStubs(arbdaemon).disputeAgentsService.registerDisputeAgent(req); | ||
} | ||
|
||
@AfterAll | ||
public static void tearDown() { | ||
tearDownScaffold(); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying on string matching for tests makes them fragile. At a minimum we should probably add a note for strings that are used in this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix this in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think this happens quite a bit in other tests as well iirc. Not urgent, but good to have a better solution for the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This string matching problem has bitten me a few times, when I misspelled "bitciond" in some test case setups.
PR 4540 fixes it.