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

Balance values are Long rather than Int #143

Merged

Conversation

galderz
Copy link
Contributor

@galderz galderz commented Jul 26, 2023

I run the LDK node 0.1.0 Kotlin test standalone and it was failing with:

org.opentest4j.AssertionFailedError: expected: kotlin.UInt@602e0143<100000> but was: kotlin.ULong@2c07545f<100000>
Expected :100000
Actual   :100000
<Click to see difference>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1142)
	at org.mendrugo.korko.LdkNodeTest.testFullLifecycle(LdkNodeTest.kt:85)

According to the decompiled class:

public open fun spendableOnchainBalanceSats(): kotlin.ULong { /* compiled code */ }

@tnull
Copy link
Collaborator

tnull commented Jul 27, 2023

Mh, could you provide what steps you took to arrive at the above error? For me, this works without issue:

./scripts/uniffi_bindgen_generate_kotlin.sh
cd bindings/kotlin/ldk-node-jvm/
./gradlew test

Kotlin docs state regarding this:

  • u and U tag is for unsigned literals. The exact type is determined based on the expected type.
  • uL and UL explicitly tag literal as unsigned long

So I don't really understand why uL would be necessary here?

@galderz
Copy link
Contributor Author

galderz commented Jul 27, 2023

Tried this with Java 17 and it works:

./scripts/uniffi_bindgen_generate_kotlin.sh
cd bindings/kotlin/ldk-node-jvm/
./gradlew test

Though I see things like this:

'compileJava' task (current target is 17) and 'compileKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
By default will become an error since Gradle 8.0+! Read more: https://kotl.in/gradle/jvm/target-validation

I thought maybe the difference is in the Kotlin version since you're using 1.7.10 and my project is using 1.8.22, but I tried your project with 1.8.22 and seems to work fine again.

So, I don't really know why the difference right now. I'm neither a Kotlin nor Gradle expert. Feel free to close the PR.

@galderz
Copy link
Contributor Author

galderz commented Jul 27, 2023

I do think it would be good practice to have types aligned when comparing them. IOW, if the API returns a Long, compare it with a Long, and if it returns an Int, compare with an Int.

Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a bit dubious why this would be required, but as it's just making things a bit more precise, why not.

@tnull tnull merged commit b018920 into lightningdevkit:main Jul 27, 2023
1 of 3 checks passed
@galderz
Copy link
Contributor Author

galderz commented Jul 27, 2023

Still a bit dubious why this would be required.

Hmmm, I think the assertEquals being invoked here is the one that takes Object rather than Java primitives, so you can replicate the same issue with plain Java by doing:

assertEquals(Integer.valueOf(100000), Long.valueOf(100000L));

Which fails with:

org.opentest4j.AssertionFailedError: expected: java.lang.Integer@29774679<100000> but was: java.lang.Long@3ffc5af1<100000>
Expected :100000
Actual   :100000

I don't understand how this can work when ./gradlew test is executed in the ldk-node-jvm/lib module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants