mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Merge pull request #7003 from alvasw/fix_crash_on_missing_vin_0_prevout
TxValidator: Fix crash on missing vin[0].prevout
This commit is contained in:
commit
e9e62b9e48
@ -190,7 +190,13 @@ public class TxValidator {
|
||||
JsonArray jsonVout = getVinAndVout(jsonTxt).second;
|
||||
JsonObject jsonVin0 = jsonVin.get(0).getAsJsonObject();
|
||||
JsonObject jsonVout0 = jsonVout.get(0).getAsJsonObject();
|
||||
JsonElement jsonVIn0Value = jsonVin0.getAsJsonObject("prevout").get("value");
|
||||
|
||||
JsonObject jsonVin0PreVout = jsonVin0.getAsJsonObject("prevout");
|
||||
if (jsonVin0PreVout == null) {
|
||||
throw new JsonSyntaxException("vin[0].prevout missing");
|
||||
}
|
||||
|
||||
JsonElement jsonVIn0Value = jsonVin0PreVout.get("value");
|
||||
JsonElement jsonFeeValue = jsonVout0.get("value");
|
||||
if (jsonVIn0Value == null || jsonFeeValue == null) {
|
||||
throw new JsonSyntaxException("vin/vout missing data");
|
||||
|
@ -23,6 +23,7 @@ import bisq.core.provider.mempool.FeeValidationStatus;
|
||||
import bisq.core.provider.mempool.TxValidator;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
@ -121,6 +122,56 @@ public class MakerTxValidatorSanityCheckTests {
|
||||
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.NACK_JSON_ERROR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkFeeAddressBtcNoTooFewVin() throws IOException {
|
||||
JsonObject json = MakerTxValidatorSanityCheckTests.getValidBtcMakerFeeMempoolJsonResponse();
|
||||
json.add("vin", new JsonArray(0));
|
||||
assertThat(json.get("vin").getAsJsonArray().size(), is(0));
|
||||
|
||||
String jsonContent = new Gson().toJson(json);
|
||||
TxValidator txValidator1 = txValidator.parseJsonValidateMakerFeeTx(jsonContent,
|
||||
MakerTxValidatorSanityCheckTests.FEE_RECEIVER_ADDRESSES);
|
||||
|
||||
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.NACK_JSON_ERROR));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 1})
|
||||
void checkFeeAddressBtcNoTooFewVout(int numberOfVouts) throws IOException {
|
||||
JsonObject json = MakerTxValidatorSanityCheckTests.getValidBtcMakerFeeMempoolJsonResponse();
|
||||
|
||||
var jsonArray = new JsonArray(numberOfVouts);
|
||||
for (int i = 0; i < numberOfVouts; i++) {
|
||||
jsonArray.add(i);
|
||||
}
|
||||
json.add("vout", jsonArray);
|
||||
assertThat(json.get("vout").getAsJsonArray().size(), is(numberOfVouts));
|
||||
|
||||
String jsonContent = new Gson().toJson(json);
|
||||
TxValidator txValidator1 = txValidator.parseJsonValidateMakerFeeTx(jsonContent,
|
||||
MakerTxValidatorSanityCheckTests.FEE_RECEIVER_ADDRESSES);
|
||||
|
||||
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.NACK_JSON_ERROR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkFeeAmountMissingVinPreVout() throws IOException {
|
||||
JsonObject json = MakerTxValidatorSanityCheckTests.getValidBtcMakerFeeMempoolJsonResponse();
|
||||
JsonObject firstInput = json.get("vin").getAsJsonArray().get(0).getAsJsonObject();
|
||||
firstInput.remove("prevout");
|
||||
|
||||
boolean hasPreVout = json.get("vin").getAsJsonArray()
|
||||
.get(0).getAsJsonObject()
|
||||
.has("prevout");
|
||||
assertThat(hasPreVout, is(false));
|
||||
|
||||
String jsonContent = new Gson().toJson(json);
|
||||
TxValidator txValidator1 = txValidator.parseJsonValidateMakerFeeTx(jsonContent,
|
||||
MakerTxValidatorSanityCheckTests.FEE_RECEIVER_ADDRESSES);
|
||||
|
||||
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.NACK_JSON_ERROR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void responseHasDifferentTxId() throws IOException {
|
||||
String differentTxId = "abcde971ead7d03619e3a9eeaa771ed5adba14c448839e0299f857f7bb4ec07";
|
||||
|
@ -23,6 +23,7 @@ import bisq.core.provider.mempool.FeeValidationStatus;
|
||||
import bisq.core.provider.mempool.TxValidator;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
@ -121,6 +122,56 @@ public class TakerTxValidatorSanityCheckTests {
|
||||
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.NACK_JSON_ERROR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkFeeAddressBtcNoTooFewVin() throws IOException {
|
||||
JsonObject json = MakerTxValidatorSanityCheckTests.getValidBtcMakerFeeMempoolJsonResponse();
|
||||
json.add("vin", new JsonArray(0));
|
||||
assertThat(json.get("vin").getAsJsonArray().size(), is(0));
|
||||
|
||||
String jsonContent = new Gson().toJson(json);
|
||||
TxValidator txValidator1 = txValidator.parseJsonValidateMakerFeeTx(jsonContent,
|
||||
MakerTxValidatorSanityCheckTests.FEE_RECEIVER_ADDRESSES);
|
||||
|
||||
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.NACK_JSON_ERROR));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, 1})
|
||||
void checkFeeAddressBtcNoTooFewVout(int numberOfVouts) throws IOException {
|
||||
JsonObject json = MakerTxValidatorSanityCheckTests.getValidBtcMakerFeeMempoolJsonResponse();
|
||||
|
||||
var jsonArray = new JsonArray(numberOfVouts);
|
||||
for (int i = 0; i < numberOfVouts; i++) {
|
||||
jsonArray.add(i);
|
||||
}
|
||||
json.add("vout", jsonArray);
|
||||
assertThat(json.get("vout").getAsJsonArray().size(), is(numberOfVouts));
|
||||
|
||||
String jsonContent = new Gson().toJson(json);
|
||||
TxValidator txValidator1 = txValidator.parseJsonValidateMakerFeeTx(jsonContent,
|
||||
MakerTxValidatorSanityCheckTests.FEE_RECEIVER_ADDRESSES);
|
||||
|
||||
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.NACK_JSON_ERROR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkFeeAmountMissingVinPreVout() throws IOException {
|
||||
JsonObject json = MakerTxValidatorSanityCheckTests.getValidBtcMakerFeeMempoolJsonResponse();
|
||||
JsonObject firstInput = json.get("vin").getAsJsonArray().get(0).getAsJsonObject();
|
||||
firstInput.remove("prevout");
|
||||
|
||||
boolean hasPreVout = json.get("vin").getAsJsonArray()
|
||||
.get(0).getAsJsonObject()
|
||||
.has("prevout");
|
||||
assertThat(hasPreVout, is(false));
|
||||
|
||||
String jsonContent = new Gson().toJson(json);
|
||||
TxValidator txValidator1 = txValidator.parseJsonValidateMakerFeeTx(jsonContent,
|
||||
MakerTxValidatorSanityCheckTests.FEE_RECEIVER_ADDRESSES);
|
||||
|
||||
assertThat(txValidator1.getStatus(), is(FeeValidationStatus.NACK_JSON_ERROR));
|
||||
}
|
||||
|
||||
@Test
|
||||
void responseHasDifferentTxId() throws IOException {
|
||||
String differentTxId = "abcde971ead7d03619e3a9eeaa771ed5adba14c448839e0299f857f7bb4ec07";
|
||||
|
Loading…
Reference in New Issue
Block a user