diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f1c5496..78185d43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements * Add aggregation of orderbooks for hash historical pricing [#496](https://github.com/provenance-io/explorer-service/issues/496) +### Bug Fixes +* Fix parsing of ibc json packet [#501](https://github.com/provenance-io/explorer-service/issues/501) ## [v5.6.0](https://github.com/provenance-io/explorer-service/releases/tag/v5.6.0) - 2023-07-05 ### Release Name: Niels Peter diff --git a/service/src/main/kotlin/io/provenance/explorer/domain/extensions/Extenstions.kt b/service/src/main/kotlin/io/provenance/explorer/domain/extensions/Extenstions.kt index 647f3f25..855fe8a9 100644 --- a/service/src/main/kotlin/io/provenance/explorer/domain/extensions/Extenstions.kt +++ b/service/src/main/kotlin/io/provenance/explorer/domain/extensions/Extenstions.kt @@ -158,7 +158,7 @@ fun BlockOuterClass.Block.height() = this.header.height.toInt() fun Long.get24HrBlockHeight(avgBlockTime: BigDecimal) = BigDecimal(24 * 60 * 60).divide(avgBlockTime, 0, RoundingMode.HALF_UP).let { this - it.toInt() } -fun String.toObjectNode() = OBJECT_MAPPER.readValue(StringEscapeUtils.unescapeJson(this), ObjectNode::class.java) +fun String.toObjectNode() = OBJECT_MAPPER.readValue(this, ObjectNode::class.java) fun Any?.stringify() = if (this == null) null else OBJECT_MAPPER.writeValueAsString(this) fun List.average() = this.fold(BigDecimal.ZERO, BigDecimal::add) diff --git a/service/src/test/kotlin/io/provenance/explorer/domain/extensions/ExtenstionsKtTest.kt b/service/src/test/kotlin/io/provenance/explorer/domain/extensions/ExtenstionsKtTest.kt index 34a46938..1ce50396 100644 --- a/service/src/test/kotlin/io/provenance/explorer/domain/extensions/ExtenstionsKtTest.kt +++ b/service/src/test/kotlin/io/provenance/explorer/domain/extensions/ExtenstionsKtTest.kt @@ -1,32 +1,34 @@ package io.provenance.explorer.domain.extensions +import org.junit.jupiter.api.Tag import org.junit.jupiter.api.Test -import org.junit.jupiter.api.Assertions.* -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.databind.node.ObjectNode -import org.apache.commons.lang3.StringEscapeUtils +import org.junit.jupiter.api.Assertions.assertEquals class ExtensionsKtTest { - @Test - fun toObjectNode() { -// // Given an input JSON string -// val inputJson = "{\"key\":\"value\"}" -// -// // Create an ObjectMapper for testing -// val objectMapper = ObjectMapper() -// -// // Escape the input JSON -// val escapedInput = StringEscapeUtils.escapeJson(inputJson) -// -// // Convert the escaped JSON to an ObjectNode -// val resultObjectNode = escapedInput.toObjectNode(objectMapper) -// -// // Create an expected ObjectNode -// val expectedObjectNode = objectMapper.createObjectNode() -// expectedObjectNode.put("key", "value") -// -// // Assert that the result ObjectNode is equal to the expected ObjectNode -// assertEquals(expectedObjectNode, resultObjectNode) + @Tag("junit-jupiter") + fun testToObjectNode() { + val inputJsonWithJsonStrObj = "{\"amount\":\"1\",\"denom\":\"psa.3zlqy2ecncvalbycokxnoh.stock\",\"memo\":\"{\\\"marker\\\":{\\\"transfer-auths\\\":[\\\"tp19zf8q9swrsspkdljumwh04zjac4nkfvju6ehl9\\\",\\\"tp1tk6fqws0su7fzp090edrauaa756mdyjfdw0507\\\",\\\"tp1a53udazy8ayufvy0s434pfwjcedzqv34vfvvyc\\\"],\\\"allow-force-transfer\\\":false}}\",\"receiver\":\"tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3\",\"sender\":\"tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3\"}" + val inputFormatedJsonWithJsonStrObj = "{\n" + + " \"amount\": \"1\",\n" + + " \"denom\": \"psa.3zlqy2ecncvalbycokxnoh.stock\",\n" + + " \"memo\": \"{\\\"marker\\\":{\\\"transfer-auths\\\":[\\\"tp19zf8q9swrsspkdljumwh04zjac4nkfvju6ehl9\\\",\\\"tp1tk6fqws0su7fzp090edrauaa756mdyjfdw0507\\\",\\\"tp1a53udazy8ayufvy0s434pfwjcedzqv34vfvvyc\\\"],\\\"allow-force-transfer\\\":false}}\",\n" + + " \"receiver\": \"tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3\",\n" + + " \"sender\": \"tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3\"\n" + + "}" + + val tests = mapOf( + "test input with string that has json string as value for memo" to inputJsonWithJsonStrObj, + "test input with formatted json and json string as value for memo" to inputFormatedJsonWithJsonStrObj + ) + + for ((testname, json) in tests) { + val actualJsonObj = json.toObjectNode() + assertEquals("tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3", actualJsonObj.get("receiver").asText(), testname) + assertEquals("tp12wyy028sd3yf3j0z950fq5p3zvzgpzgds3dqp3", actualJsonObj.get("sender").asText(), testname) + assertEquals("1", actualJsonObj.get("amount").asText(), testname) + assertEquals("psa.3zlqy2ecncvalbycokxnoh.stock", actualJsonObj.get("denom").asText(), testname) + assertEquals("{\"marker\":{\"transfer-auths\":[\"tp19zf8q9swrsspkdljumwh04zjac4nkfvju6ehl9\",\"tp1tk6fqws0su7fzp090edrauaa756mdyjfdw0507\",\"tp1a53udazy8ayufvy0s434pfwjcedzqv34vfvvyc\"],\"allow-force-transfer\":false}}", actualJsonObj.get("memo").asText(), testname) + } } -} \ No newline at end of file +}