Skip to content
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

Error parsing ibc hooks memo object #503

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import io.provenance.explorer.model.base.Bech32
import io.provenance.explorer.model.base.toBech32Data
import io.provenance.explorer.model.base.toMAddress
import net.pearx.kasechange.splitToWords
import org.apache.commons.text.StringEscapeUtils
import org.joda.time.DateTime
import org.joda.time.DateTimeZone
import tendermint.types.BlockOuterClass
Expand Down Expand Up @@ -158,7 +157,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<BigDecimal>.average() = this.fold(BigDecimal.ZERO, BigDecimal::add)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.provenance.explorer.domain.extensions

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test

class ExtensionsKtTest {
@Test
@Tag("junit-jupiter")
fun `test toObjectNode properly converts json strings to objecs`() {
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)
}
}
}
Loading