mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 15:10:44 +01:00
Refactor:
- Rename XmrProofInfo to XmrTxProofModel
This commit is contained in:
parent
87070531dd
commit
a758880211
6 changed files with 54 additions and 54 deletions
|
@ -187,7 +187,7 @@ public class XmrAutoConfirmationManager {
|
||||||
List<String> serviceAddresses = preferences.getAutoConfirmSettings().serviceAddresses;
|
List<String> serviceAddresses = preferences.getAutoConfirmSettings().serviceAddresses;
|
||||||
txProofResultsPending.put(trade.getId(), serviceAddresses.size()); // need result from each service address
|
txProofResultsPending.put(trade.getId(), serviceAddresses.size()); // need result from each service address
|
||||||
for (String serviceAddress : serviceAddresses) {
|
for (String serviceAddress : serviceAddresses) {
|
||||||
XmrProofInfo xmrProofInfo = new XmrProofInfo(
|
XmrTxProofModel xmrTxProofModel = new XmrTxProofModel(
|
||||||
txHash,
|
txHash,
|
||||||
txKey,
|
txKey,
|
||||||
address,
|
address,
|
||||||
|
@ -195,10 +195,10 @@ public class XmrAutoConfirmationManager {
|
||||||
trade.getDate(),
|
trade.getDate(),
|
||||||
confirmsRequired,
|
confirmsRequired,
|
||||||
serviceAddress);
|
serviceAddress);
|
||||||
xmrTransferProofService.requestProof(xmrProofInfo,
|
xmrTransferProofService.requestProof(xmrTxProofModel,
|
||||||
result -> {
|
result -> {
|
||||||
if (!handleProofResult(result, trade))
|
if (!handleProofResult(result, trade))
|
||||||
xmrTransferProofService.terminateRequest(xmrProofInfo);
|
xmrTransferProofService.terminateRequest(xmrTxProofModel);
|
||||||
},
|
},
|
||||||
(errorMsg, throwable) -> {
|
(errorMsg, throwable) -> {
|
||||||
log.warn(errorMsg);
|
log.warn(errorMsg);
|
||||||
|
|
|
@ -45,7 +45,7 @@ class XmrTransferProofRequest {
|
||||||
private final ListeningExecutorService executorService = Utilities.getListeningExecutorService(
|
private final ListeningExecutorService executorService = Utilities.getListeningExecutorService(
|
||||||
"XmrTransferProofRequester", 3, 5, 10 * 60);
|
"XmrTransferProofRequester", 3, 5, 10 * 60);
|
||||||
private final XmrTxProofHttpClient httpClient;
|
private final XmrTxProofHttpClient httpClient;
|
||||||
private final XmrProofInfo xmrProofInfo;
|
private final XmrTxProofModel xmrTxProofModel;
|
||||||
private final Consumer<XmrTxProofResult> resultHandler;
|
private final Consumer<XmrTxProofResult> resultHandler;
|
||||||
private final FaultHandler faultHandler;
|
private final FaultHandler faultHandler;
|
||||||
|
|
||||||
|
@ -58,16 +58,16 @@ class XmrTransferProofRequest {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
XmrTransferProofRequest(Socks5ProxyProvider socks5ProxyProvider,
|
XmrTransferProofRequest(Socks5ProxyProvider socks5ProxyProvider,
|
||||||
XmrProofInfo xmrProofInfo,
|
XmrTxProofModel xmrTxProofModel,
|
||||||
Consumer<XmrTxProofResult> resultHandler,
|
Consumer<XmrTxProofResult> resultHandler,
|
||||||
FaultHandler faultHandler) {
|
FaultHandler faultHandler) {
|
||||||
this.httpClient = new XmrTxProofHttpClient(socks5ProxyProvider);
|
this.httpClient = new XmrTxProofHttpClient(socks5ProxyProvider);
|
||||||
this.httpClient.setBaseUrl("http://" + xmrProofInfo.getServiceAddress());
|
this.httpClient.setBaseUrl("http://" + xmrTxProofModel.getServiceAddress());
|
||||||
if (xmrProofInfo.getServiceAddress().matches("^192.*|^localhost.*")) {
|
if (xmrTxProofModel.getServiceAddress().matches("^192.*|^localhost.*")) {
|
||||||
log.info("Ignoring Socks5 proxy for local net address: {}", xmrProofInfo.getServiceAddress());
|
log.info("Ignoring Socks5 proxy for local net address: {}", xmrTxProofModel.getServiceAddress());
|
||||||
this.httpClient.setIgnoreSocks5Proxy(true);
|
this.httpClient.setIgnoreSocks5Proxy(true);
|
||||||
}
|
}
|
||||||
this.xmrProofInfo = xmrProofInfo;
|
this.xmrTxProofModel = xmrTxProofModel;
|
||||||
this.resultHandler = resultHandler;
|
this.resultHandler = resultHandler;
|
||||||
this.faultHandler = faultHandler;
|
this.faultHandler = faultHandler;
|
||||||
this.terminated = false;
|
this.terminated = false;
|
||||||
|
@ -91,14 +91,14 @@ class XmrTransferProofRequest {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ListenableFuture<XmrTxProofResult> future = executorService.submit(() -> {
|
ListenableFuture<XmrTxProofResult> future = executorService.submit(() -> {
|
||||||
Thread.currentThread().setName("XmrTransferProofRequest-" + xmrProofInfo.getUID());
|
Thread.currentThread().setName("XmrTransferProofRequest-" + xmrTxProofModel.getUID());
|
||||||
String param = "/api/outputs?txhash=" + xmrProofInfo.getTxHash() +
|
String param = "/api/outputs?txhash=" + xmrTxProofModel.getTxHash() +
|
||||||
"&address=" + xmrProofInfo.getRecipientAddress() +
|
"&address=" + xmrTxProofModel.getRecipientAddress() +
|
||||||
"&viewkey=" + xmrProofInfo.getTxKey() +
|
"&viewkey=" + xmrTxProofModel.getTxKey() +
|
||||||
"&txprove=1";
|
"&txprove=1";
|
||||||
log.info("Requesting from {} with param {}", httpClient.getBaseUrl(), param);
|
log.info("Requesting from {} with param {}", httpClient.getBaseUrl(), param);
|
||||||
String json = httpClient.requestWithGET(param, "User-Agent", "bisq/" + Version.VERSION);
|
String json = httpClient.requestWithGET(param, "User-Agent", "bisq/" + Version.VERSION);
|
||||||
XmrTxProofResult autoConfirmResult = XmrTxProofParser.parse(xmrProofInfo, json);
|
XmrTxProofResult autoConfirmResult = XmrTxProofParser.parse(xmrTxProofModel, json);
|
||||||
log.info("Response json {} resulted in autoConfirmResult {}", json, autoConfirmResult);
|
log.info("Response json {} resulted in autoConfirmResult {}", json, autoConfirmResult);
|
||||||
return autoConfirmResult;
|
return autoConfirmResult;
|
||||||
});
|
});
|
||||||
|
|
|
@ -42,10 +42,10 @@ class XmrTransferProofService {
|
||||||
socks5ProxyProvider = provider;
|
socks5ProxyProvider = provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
void requestProof(XmrProofInfo xmrProofInfo,
|
void requestProof(XmrTxProofModel xmrTxProofModel,
|
||||||
Consumer<XmrTxProofResult> resultHandler,
|
Consumer<XmrTxProofResult> resultHandler,
|
||||||
FaultHandler faultHandler) {
|
FaultHandler faultHandler) {
|
||||||
String uid = xmrProofInfo.getUID();
|
String uid = xmrTxProofModel.getUID();
|
||||||
if (map.containsKey(uid)) {
|
if (map.containsKey(uid)) {
|
||||||
log.warn("We started a proof request for uid {} already", uid);
|
log.warn("We started a proof request for uid {} already", uid);
|
||||||
return;
|
return;
|
||||||
|
@ -54,7 +54,7 @@ class XmrTransferProofService {
|
||||||
|
|
||||||
XmrTransferProofRequest requester = new XmrTransferProofRequest(
|
XmrTransferProofRequest requester = new XmrTransferProofRequest(
|
||||||
socks5ProxyProvider,
|
socks5ProxyProvider,
|
||||||
xmrProofInfo,
|
xmrTxProofModel,
|
||||||
result -> {
|
result -> {
|
||||||
if (result.isSuccessState()) {
|
if (result.isSuccessState()) {
|
||||||
cleanup(uid);
|
cleanup(uid);
|
||||||
|
@ -69,8 +69,8 @@ class XmrTransferProofService {
|
||||||
requester.request();
|
requester.request();
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminateRequest(XmrProofInfo xmrProofInfo) {
|
void terminateRequest(XmrTxProofModel xmrTxProofModel) {
|
||||||
String uid = xmrProofInfo.getUID();
|
String uid = xmrTxProofModel.getUID();
|
||||||
XmrTransferProofRequest requester = map.getOrDefault(uid, null);
|
XmrTransferProofRequest requester = map.getOrDefault(uid, null);
|
||||||
if (requester != null) {
|
if (requester != null) {
|
||||||
log.info("Terminating API request for request with uid {}", uid);
|
log.info("Terminating API request for request with uid {}", uid);
|
||||||
|
|
|
@ -24,7 +24,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Value
|
@Value
|
||||||
class XmrProofInfo {
|
class XmrTxProofModel {
|
||||||
private final String txHash;
|
private final String txHash;
|
||||||
private final String txKey;
|
private final String txKey;
|
||||||
private final String recipientAddress;
|
private final String recipientAddress;
|
||||||
|
@ -33,7 +33,7 @@ class XmrProofInfo {
|
||||||
private final int confirmsRequired;
|
private final int confirmsRequired;
|
||||||
private final String serviceAddress;
|
private final String serviceAddress;
|
||||||
|
|
||||||
XmrProofInfo(
|
XmrTxProofModel(
|
||||||
String txHash,
|
String txHash,
|
||||||
String txKey,
|
String txKey,
|
||||||
String recipientAddress,
|
String recipientAddress,
|
|
@ -33,8 +33,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
class XmrTxProofParser {
|
class XmrTxProofParser {
|
||||||
static XmrTxProofResult parse(XmrProofInfo xmrProofInfo, String jsonTxt) {
|
static XmrTxProofResult parse(XmrTxProofModel xmrTxProofModel, String jsonTxt) {
|
||||||
String txHash = xmrProofInfo.getTxHash();
|
String txHash = xmrTxProofModel.getTxHash();
|
||||||
try {
|
try {
|
||||||
JsonObject json = new Gson().fromJson(jsonTxt, JsonObject.class);
|
JsonObject json = new Gson().fromJson(jsonTxt, JsonObject.class);
|
||||||
if (json == null) {
|
if (json == null) {
|
||||||
|
@ -59,7 +59,7 @@ class XmrTxProofParser {
|
||||||
if (jsonAddress == null) {
|
if (jsonAddress == null) {
|
||||||
return new XmrTxProofResult(XmrTxProofResult.State.API_INVALID, "Missing address field");
|
return new XmrTxProofResult(XmrTxProofResult.State.API_INVALID, "Missing address field");
|
||||||
} else {
|
} else {
|
||||||
String expectedAddressHex = CryptoNoteUtils.convertToRawHex(xmrProofInfo.getRecipientAddress());
|
String expectedAddressHex = CryptoNoteUtils.convertToRawHex(xmrTxProofModel.getRecipientAddress());
|
||||||
if (!jsonAddress.getAsString().equalsIgnoreCase(expectedAddressHex)) {
|
if (!jsonAddress.getAsString().equalsIgnoreCase(expectedAddressHex)) {
|
||||||
log.warn("address {}, expected: {}", jsonAddress.getAsString(), expectedAddressHex);
|
log.warn("address {}, expected: {}", jsonAddress.getAsString(), expectedAddressHex);
|
||||||
return new XmrTxProofResult(XmrTxProofResult.State.ADDRESS_INVALID, null);
|
return new XmrTxProofResult(XmrTxProofResult.State.ADDRESS_INVALID, null);
|
||||||
|
@ -82,8 +82,8 @@ class XmrTxProofParser {
|
||||||
if (jsonViewkey == null) {
|
if (jsonViewkey == null) {
|
||||||
return new XmrTxProofResult(XmrTxProofResult.State.API_INVALID, "Missing viewkey field");
|
return new XmrTxProofResult(XmrTxProofResult.State.API_INVALID, "Missing viewkey field");
|
||||||
} else {
|
} else {
|
||||||
if (!jsonViewkey.getAsString().equalsIgnoreCase(xmrProofInfo.getTxKey())) {
|
if (!jsonViewkey.getAsString().equalsIgnoreCase(xmrTxProofModel.getTxKey())) {
|
||||||
log.warn("viewkey {}, expected: {}", jsonViewkey.getAsString(), xmrProofInfo.getTxKey());
|
log.warn("viewkey {}, expected: {}", jsonViewkey.getAsString(), xmrTxProofModel.getTxKey());
|
||||||
return new XmrTxProofResult(XmrTxProofResult.State.TX_KEY_INVALID, null);
|
return new XmrTxProofResult(XmrTxProofResult.State.TX_KEY_INVALID, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ class XmrTxProofParser {
|
||||||
if (jsonTimestamp == null) {
|
if (jsonTimestamp == null) {
|
||||||
return new XmrTxProofResult(XmrTxProofResult.State.API_INVALID, "Missing tx_timestamp field");
|
return new XmrTxProofResult(XmrTxProofResult.State.API_INVALID, "Missing tx_timestamp field");
|
||||||
} else {
|
} else {
|
||||||
long tradeDateSeconds = xmrProofInfo.getTradeDate().getTime() / 1000;
|
long tradeDateSeconds = xmrTxProofModel.getTradeDate().getTime() / 1000;
|
||||||
long difference = tradeDateSeconds - jsonTimestamp.getAsLong();
|
long difference = tradeDateSeconds - jsonTimestamp.getAsLong();
|
||||||
// Accept up to 2 hours difference. Some tolerance is needed if users clock is out of sync
|
// Accept up to 2 hours difference. Some tolerance is needed if users clock is out of sync
|
||||||
if (difference > TimeUnit.HOURS.toSeconds(2) && !DevEnv.isDevMode()) {
|
if (difference > TimeUnit.HOURS.toSeconds(2) && !DevEnv.isDevMode()) {
|
||||||
|
@ -124,8 +124,8 @@ class XmrTxProofParser {
|
||||||
if (out.get("match").getAsBoolean()) {
|
if (out.get("match").getAsBoolean()) {
|
||||||
anyMatchFound = true;
|
anyMatchFound = true;
|
||||||
long jsonAmount = out.get("amount").getAsLong();
|
long jsonAmount = out.get("amount").getAsLong();
|
||||||
if (jsonAmount == xmrProofInfo.getAmount() || DevEnv.isDevMode()) { // any amount ok in dev mode
|
if (jsonAmount == xmrTxProofModel.getAmount() || DevEnv.isDevMode()) { // any amount ok in dev mode
|
||||||
int confirmsRequired = xmrProofInfo.getConfirmsRequired();
|
int confirmsRequired = xmrTxProofModel.getConfirmsRequired();
|
||||||
if (confirmations < confirmsRequired)
|
if (confirmations < confirmsRequired)
|
||||||
// we return TX_NOT_CONFIRMED which will cause a retry later
|
// we return TX_NOT_CONFIRMED which will cause a retry later
|
||||||
return new XmrTxProofResult(XmrTxProofResult.State.TX_NOT_CONFIRMED, confirmations, confirmsRequired);
|
return new XmrTxProofResult(XmrTxProofResult.State.TX_NOT_CONFIRMED, confirmations, confirmsRequired);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class XmrTxProofParserTest {
|
public class XmrTxProofParserTest {
|
||||||
private XmrProofInfo xmrProofInfo;
|
private XmrTxProofModel xmrTxProofModel;
|
||||||
private String recipientAddressHex = "e957dac72bcec80d59b2fecacfa7522223b6a5df895b7e388e60297e85f3f867b42f43e8d9f086a99a997704ceb92bd9cd99d33952de90c9f5f93c82c62360ae";
|
private String recipientAddressHex = "e957dac72bcec80d59b2fecacfa7522223b6a5df895b7e388e60297e85f3f867b42f43e8d9f086a99a997704ceb92bd9cd99d33952de90c9f5f93c82c62360ae";
|
||||||
private String txHash = "488e48ab0c7e69028d19f787ec57fd496ff114caba9ab265bfd41a3ea0e4687d";
|
private String txHash = "488e48ab0c7e69028d19f787ec57fd496ff114caba9ab265bfd41a3ea0e4687d";
|
||||||
private String txKey = "6c336e52ed537676968ee319af6983c80b869ca6a732b5962c02748b486f8f0f";
|
private String txKey = "6c336e52ed537676968ee319af6983c80b869ca6a732b5962c02748b486f8f0f";
|
||||||
|
@ -25,7 +25,7 @@ public class XmrTxProofParserTest {
|
||||||
int confirmsRequired = 10;
|
int confirmsRequired = 10;
|
||||||
String serviceAddress = "127.0.0.1:8081";
|
String serviceAddress = "127.0.0.1:8081";
|
||||||
|
|
||||||
xmrProofInfo = new XmrProofInfo(
|
xmrTxProofModel = new XmrTxProofModel(
|
||||||
txHash,
|
txHash,
|
||||||
txKey,
|
txKey,
|
||||||
recipientAddress,
|
recipientAddress,
|
||||||
|
@ -37,44 +37,44 @@ public class XmrTxProofParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testKey() {
|
public void testKey() {
|
||||||
assertTrue(xmrProofInfo.getUID().contains(xmrProofInfo.getTxHash()));
|
assertTrue(xmrTxProofModel.getUID().contains(xmrTxProofModel.getTxHash()));
|
||||||
assertTrue(xmrProofInfo.getUID().contains(xmrProofInfo.getServiceAddress()));
|
assertTrue(xmrTxProofModel.getUID().contains(xmrTxProofModel.getServiceAddress()));
|
||||||
assertFalse(xmrProofInfo.getUID().contains(xmrProofInfo.getRecipientAddress()));
|
assertFalse(xmrTxProofModel.getUID().contains(xmrTxProofModel.getRecipientAddress()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonRoot() {
|
public void testJsonRoot() {
|
||||||
// checking what happens when bad input is provided
|
// checking what happens when bad input is provided
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo,
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel,
|
||||||
"invalid json data").getState() == XmrTxProofResult.State.API_INVALID);
|
"invalid json data").getState() == XmrTxProofResult.State.API_INVALID);
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo,
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel,
|
||||||
"").getState() == XmrTxProofResult.State.API_INVALID);
|
"").getState() == XmrTxProofResult.State.API_INVALID);
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo,
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel,
|
||||||
"[]").getState() == XmrTxProofResult.State.API_INVALID);
|
"[]").getState() == XmrTxProofResult.State.API_INVALID);
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo,
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel,
|
||||||
"{}").getState() == XmrTxProofResult.State.API_INVALID);
|
"{}").getState() == XmrTxProofResult.State.API_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonTopLevel() {
|
public void testJsonTopLevel() {
|
||||||
// testing the top level fields: data and status
|
// testing the top level fields: data and status
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo,
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel,
|
||||||
"{'data':{'title':''},'status':'fail'}" )
|
"{'data':{'title':''},'status':'fail'}" )
|
||||||
.getState() == XmrTxProofResult.State.TX_NOT_FOUND);
|
.getState() == XmrTxProofResult.State.TX_NOT_FOUND);
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo,
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel,
|
||||||
"{'data':{'title':''},'missingstatus':'success'}" )
|
"{'data':{'title':''},'missingstatus':'success'}" )
|
||||||
.getState() == XmrTxProofResult.State.API_INVALID);
|
.getState() == XmrTxProofResult.State.API_INVALID);
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo,
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel,
|
||||||
"{'missingdata':{'title':''},'status':'success'}" )
|
"{'missingdata':{'title':''},'status':'success'}" )
|
||||||
.getState() == XmrTxProofResult.State.API_INVALID);
|
.getState() == XmrTxProofResult.State.API_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonAddress() {
|
public void testJsonAddress() {
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo,
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel,
|
||||||
"{'data':{'missingaddress':'irrelevant'},'status':'success'}" )
|
"{'data':{'missingaddress':'irrelevant'},'status':'success'}" )
|
||||||
.getState() == XmrTxProofResult.State.API_INVALID);
|
.getState() == XmrTxProofResult.State.API_INVALID);
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo,
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel,
|
||||||
"{'data':{'address':'e957dac7'},'status':'success'}" )
|
"{'data':{'address':'e957dac7'},'status':'success'}" )
|
||||||
.getState() == XmrTxProofResult.State.ADDRESS_INVALID);
|
.getState() == XmrTxProofResult.State.ADDRESS_INVALID);
|
||||||
}
|
}
|
||||||
|
@ -82,11 +82,11 @@ public class XmrTxProofParserTest {
|
||||||
@Test
|
@Test
|
||||||
public void testJsonTxHash() {
|
public void testJsonTxHash() {
|
||||||
String missing_tx_hash = "{'data':{'address':'" + recipientAddressHex + "'}, 'status':'success'}";
|
String missing_tx_hash = "{'data':{'address':'" + recipientAddressHex + "'}, 'status':'success'}";
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, missing_tx_hash).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, missing_tx_hash).getState()
|
||||||
== XmrTxProofResult.State.API_INVALID);
|
== XmrTxProofResult.State.API_INVALID);
|
||||||
|
|
||||||
String invalid_tx_hash = "{'data':{'address':'" + recipientAddressHex + "', 'tx_hash':'488e48'}, 'status':'success'}";
|
String invalid_tx_hash = "{'data':{'address':'" + recipientAddressHex + "', 'tx_hash':'488e48'}, 'status':'success'}";
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, invalid_tx_hash).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, invalid_tx_hash).getState()
|
||||||
== XmrTxProofResult.State.TX_HASH_INVALID);
|
== XmrTxProofResult.State.TX_HASH_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,13 +94,13 @@ public class XmrTxProofParserTest {
|
||||||
public void testJsonTxKey() {
|
public void testJsonTxKey() {
|
||||||
String missing_tx_key = "{'data':{'address':'" + recipientAddressHex + "', " +
|
String missing_tx_key = "{'data':{'address':'" + recipientAddressHex + "', " +
|
||||||
"'tx_hash':'" + txHash + "'}, 'status':'success'}";
|
"'tx_hash':'" + txHash + "'}, 'status':'success'}";
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, missing_tx_key).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, missing_tx_key).getState()
|
||||||
== XmrTxProofResult.State.API_INVALID);
|
== XmrTxProofResult.State.API_INVALID);
|
||||||
|
|
||||||
String invalid_tx_key = "{'data':{'address':'" + recipientAddressHex + "', " +
|
String invalid_tx_key = "{'data':{'address':'" + recipientAddressHex + "', " +
|
||||||
"'tx_hash':'" + txHash + "', " +
|
"'tx_hash':'" + txHash + "', " +
|
||||||
"'viewkey':'cdce04'}, 'status':'success'}";
|
"'viewkey':'cdce04'}, 'status':'success'}";
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, invalid_tx_key).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, invalid_tx_key).getState()
|
||||||
== XmrTxProofResult.State.TX_KEY_INVALID);
|
== XmrTxProofResult.State.TX_KEY_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,14 +109,14 @@ public class XmrTxProofParserTest {
|
||||||
String missing_tx_timestamp = "{'data':{'address':'" + recipientAddressHex + "', " +
|
String missing_tx_timestamp = "{'data':{'address':'" + recipientAddressHex + "', " +
|
||||||
"'tx_hash':'" + txHash + "'," +
|
"'tx_hash':'" + txHash + "'," +
|
||||||
"'viewkey':'" + txKey + "'}, 'status':'success'}";
|
"'viewkey':'" + txKey + "'}, 'status':'success'}";
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, missing_tx_timestamp).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, missing_tx_timestamp).getState()
|
||||||
== XmrTxProofResult.State.API_INVALID);
|
== XmrTxProofResult.State.API_INVALID);
|
||||||
|
|
||||||
String invalid_tx_timestamp = "{'data':{'address':'" + recipientAddressHex + "', " +
|
String invalid_tx_timestamp = "{'data':{'address':'" + recipientAddressHex + "', " +
|
||||||
"'tx_hash':'" + txHash + "', " +
|
"'tx_hash':'" + txHash + "', " +
|
||||||
"'viewkey':'" + txKey + "'," +
|
"'viewkey':'" + txKey + "'," +
|
||||||
"'tx_timestamp':'12345'}, 'status':'success'}";
|
"'tx_timestamp':'12345'}, 'status':'success'}";
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, invalid_tx_timestamp).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, invalid_tx_timestamp).getState()
|
||||||
== XmrTxProofResult.State.TRADE_DATE_NOT_MATCHING);
|
== XmrTxProofResult.State.TRADE_DATE_NOT_MATCHING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,26 +134,26 @@ public class XmrTxProofParserTest {
|
||||||
"'viewkey':'" + txKey + "', " +
|
"'viewkey':'" + txKey + "', " +
|
||||||
"'tx_timestamp':'" + Long.toString(epochDate) + "'}" +
|
"'tx_timestamp':'" + Long.toString(epochDate) + "'}" +
|
||||||
"}";
|
"}";
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, json).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, json).getState()
|
||||||
== XmrTxProofResult.State.PROOF_OK);
|
== XmrTxProofResult.State.PROOF_OK);
|
||||||
json = json.replaceFirst("777", "0");
|
json = json.replaceFirst("777", "0");
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, json).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, json).getState()
|
||||||
== XmrTxProofResult.State.TX_NOT_CONFIRMED);
|
== XmrTxProofResult.State.TX_NOT_CONFIRMED);
|
||||||
json = json.replaceFirst("100000000000", "100000000001");
|
json = json.replaceFirst("100000000000", "100000000001");
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, json).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, json).getState()
|
||||||
== XmrTxProofResult.State.AMOUNT_NOT_MATCHING);
|
== XmrTxProofResult.State.AMOUNT_NOT_MATCHING);
|
||||||
|
|
||||||
// Revert change of amount
|
// Revert change of amount
|
||||||
json = json.replaceFirst("100000000001", "100000000000");
|
json = json.replaceFirst("100000000001", "100000000000");
|
||||||
json = json.replaceFirst("'match':true", "'match':false");
|
json = json.replaceFirst("'match':true", "'match':false");
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, json).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, json).getState()
|
||||||
== XmrTxProofResult.State.NO_MATCH_FOUND);
|
== XmrTxProofResult.State.NO_MATCH_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonFail() {
|
public void testJsonFail() {
|
||||||
String failedJson = "{\"data\":null,\"message\":\"Cant parse tx hash: a\",\"status\":\"error\"}";
|
String failedJson = "{\"data\":null,\"message\":\"Cant parse tx hash: a\",\"status\":\"error\"}";
|
||||||
assertTrue(XmrTxProofParser.parse(xmrProofInfo, failedJson).getState()
|
assertTrue(XmrTxProofParser.parse(xmrTxProofModel, failedJson).getState()
|
||||||
== XmrTxProofResult.State.API_INVALID);
|
== XmrTxProofResult.State.API_INVALID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue