Repository navigation
feat(sdk): once-per-identity token distribution in the mobile example apps #4829
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d9a55a
feat(sdk): once-per-identity token distribution in the mobile example…
QuantumExplorer 452c2e8
fix(sdk): once-per-identity claims on Android default to the eligible…
QuantumExplorer 5708e55
fix(sdk): once-per-identity claims on iOS default to the eligible kind
QuantumExplorer c5dbccf
fix(sdk): recognise the already-claimed code 40722 as a number of its…
QuantumExplorer 58e63b5
fix(sdk): offer only the claim kinds the identity is eligible for on …
QuantumExplorer f29028b
fix(sdk): offer only the claim kinds the identity is eligible for on iOS
QuantumExplorer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...t/java/org/dashfoundation/example/services/tokens/TokenMaterializerOncePerIdentityTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package org.dashfoundation.example.services.tokens | ||
|
|
||
| import org.dashfoundation.dashsdk.persistence.entities.DataContractEntity | ||
| import org.dashfoundation.dashsdk.persistence.entities.TokenEntity | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertFalse | ||
| import org.junit.Assert.assertNotNull | ||
| import org.junit.Assert.assertNull | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Test | ||
|
|
||
| /** | ||
| * [TokenMaterializer] coverage for the `oncePerIdentityDistribution` block | ||
| * (protocol version 14): the raw block lands in | ||
| * [TokenEntity.oncePerIdentityDistribution], flips `hasDistribution`, and | ||
| * [TokenOncePerIdentityDistribution.parse] reads the u64 amount back as a | ||
| * decimal string whether the contract encoded it as a number or a string. | ||
| */ | ||
| class TokenMaterializerOncePerIdentityTest { | ||
|
|
||
| private val contractId = ByteArray(32) { 0xCD.toByte() } | ||
|
|
||
| private fun contract(distributionRules: String): DataContractEntity = DataContractEntity( | ||
| id = contractId, | ||
| name = "Fixture", | ||
| serializedContract = | ||
| """{"tokens":{"0":{"baseSupply":0,"distributionRules":$distributionRules}}}""" | ||
| .encodeToByteArray(), | ||
| networkRaw = 0, | ||
| ) | ||
|
|
||
| private fun parseSingleToken(distributionRules: String): TokenEntity { | ||
| val tokens = TokenMaterializer.parse(contract(distributionRules)) | ||
| assertEquals(1, tokens.size) | ||
| return tokens.single() | ||
| } | ||
|
|
||
| private fun block(amount: String): String = | ||
| """{"oncePerIdentityDistribution":{"${'$'}formatVersion":"0","amount":$amount}}""" | ||
|
|
||
| @Test | ||
| fun `numeric amount is persisted raw and parses to a decimal string`() { | ||
| val token = parseSingleToken(block("5000")) | ||
|
|
||
| val raw = token.oncePerIdentityDistribution | ||
| assertNotNull(raw) | ||
| assertTrue(token.hasDistribution) | ||
| assertEquals("5000", TokenOncePerIdentityDistribution.parse(raw)?.amount) | ||
| } | ||
|
|
||
| @Test | ||
| fun `string amount parses to the same decimal string`() { | ||
| val token = parseSingleToken(block("\"12345\"")) | ||
|
|
||
| assertEquals( | ||
| "12345", | ||
| TokenOncePerIdentityDistribution.parse(token.oncePerIdentityDistribution)?.amount, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `amounts above Long MAX_VALUE survive verbatim as number and as string`() { | ||
| val huge = "18446744073709551615" // UInt64.max | ||
|
|
||
| val asNumber = parseSingleToken(block(huge)) | ||
| assertEquals( | ||
| huge, | ||
| TokenOncePerIdentityDistribution.parse(asNumber.oncePerIdentityDistribution)?.amount, | ||
| ) | ||
|
|
||
| val asString = parseSingleToken(block("\"$huge\"")) | ||
| assertEquals( | ||
| huge, | ||
| TokenOncePerIdentityDistribution.parse(asString.oncePerIdentityDistribution)?.amount, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `absent block leaves the column null and hasDistribution false`() { | ||
| val token = parseSingleToken("""{"mintingAllowChoosingDestination":true}""") | ||
|
|
||
| assertNull(token.oncePerIdentityDistribution) | ||
| assertFalse(token.hasDistribution) | ||
| } | ||
|
|
||
| @Test | ||
| fun `block alongside a pre-programmed distribution keeps both`() { | ||
| val preProgrammed = | ||
| """{"${'$'}formatVersion":"0","distributions":{"1750000000000":{"abc":1}}}""" | ||
| val token = parseSingleToken( | ||
| """{"preProgrammedDistribution":$preProgrammed,""" + | ||
| """"oncePerIdentityDistribution":{"${'$'}formatVersion":"0","amount":9}}""", | ||
| ) | ||
|
|
||
| assertNotNull(token.preProgrammedDistribution) | ||
| assertEquals( | ||
| "9", | ||
| TokenOncePerIdentityDistribution.parse(token.oncePerIdentityDistribution)?.amount, | ||
| ) | ||
| assertTrue(token.hasDistribution) | ||
| } | ||
|
|
||
| @Test | ||
| fun `parse rejects a block without a valid amount`() { | ||
| assertNull(TokenOncePerIdentityDistribution.parse("""{"${'$'}formatVersion":"0"}""")) | ||
| assertNull(TokenOncePerIdentityDistribution.parse("""{"amount":"abc"}""")) | ||
| assertNull(TokenOncePerIdentityDistribution.parse("""{"amount":-1}""")) | ||
| assertNull(TokenOncePerIdentityDistribution.parse("""{"amount":1.5}""")) | ||
| assertNull(TokenOncePerIdentityDistribution.parse("not json")) | ||
| assertNull(TokenOncePerIdentityDistribution.parse("")) | ||
| assertNull(TokenOncePerIdentityDistribution.parse(null)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `V0-wrapped block is unwrapped`() { | ||
| assertEquals("7", TokenOncePerIdentityDistribution.parse("""{"V0":{"amount":7}}""")?.amount) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.