Skip to content

Commit

Permalink
feature: rc20 wip
Browse files Browse the repository at this point in the history
Signed-off-by: Timur Guskov <[email protected]>
  • Loading branch information
gv-timur committed Oct 30, 2023
1 parent e97769c commit dd2dcc8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
10 changes: 5 additions & 5 deletions modules/block/src/main/kotlin/jp/co/soramitsu/iroha2/Serde.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1052,13 +1052,13 @@ private fun mintBurnSerialize(
.cast<Expression.Raw>().value
.cast<Value.Numeric>().numericValue
val fieldData = when (rawValue) {
is NumericValue.U32 -> NumericValue.U32::class.simpleName to rawValue.u32
is NumericValue.U64 -> NumericValue.U64::class.simpleName to rawValue.u64
is NumericValue.U128 -> NumericValue.U128::class.simpleName to rawValue.u128
is NumericValue.Fixed -> NumericValue.Fixed::class.simpleName to rawValue.fixed.fixedPointOfI64
is NumericValue.U32 -> NumericValue.U32::class.simpleName to "${rawValue.u32}_${NumericValue.U32::class.simpleName?.lowercase()}"
is NumericValue.U64 -> NumericValue.U64::class.simpleName to "${rawValue.u64}_${NumericValue.U64::class.simpleName?.lowercase()}"
is NumericValue.U128 -> NumericValue.U128::class.simpleName to "${rawValue.u128}_${NumericValue.U128::class.simpleName?.lowercase()}"
is NumericValue.Fixed -> NumericValue.Fixed::class.simpleName to rawValue.fixed.fixedPointOfI64.toString()
else -> throw IrohaSdkException("Grant InstructionExpr serialization error")
}
gen.writeObjectField(fieldData.first, fieldData.second)
gen.writeObjectField("object", fieldData.second)
gen.writeObjectField("destination_id", destinationId)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package jp.co.soramitsu.iroha2

import jp.co.soramitsu.iroha2.generated.AssetDefinitionId
import jp.co.soramitsu.iroha2.generated.AssetId
import jp.co.soramitsu.iroha2.generated.RawGenesisBlock
import jp.co.soramitsu.iroha2.transaction.Instructions
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -45,4 +47,39 @@ class SerializerTest {
val json = JSON_SERDE.writeValueAsString(genesis).trimIndent()
assertEquals(expectedJson, json)
}

@Test
fun `should serialize mint asset genesis block`() {
val genesis = Genesis(
RawGenesisBlock(
listOf(
Instructions.mintAsset(
AssetId(
AssetDefinitionId("xor".asName(), "wonderland".asDomainId()),
"alice${ACCOUNT_ID_DELIMITER}wonderland".asAccountId(),
),
100,
),
).let { listOf(it) },
Genesis.executorMode,
),
)
val expectedJson = """
{
"block" : {
"transactions" : [ [ {
"Mint" : {
"object" : "100_u32",
"destination_id" : {
"AssetId" : "xor#wonderland#alice@wonderland"
}
}
} ] ],
"executor" : "executor.wasm"
}
}
""".trimIndent()
val json = JSON_SERDE.writeValueAsString(genesis).trimIndent()
assertEquals(expectedJson, json)
}
}
10 changes: 6 additions & 4 deletions modules/client/src/test/resources/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
},
{
"Grant": {
"PermissionToken": {
"definition_id": "CanSetKeyValueInUserAccount",
"payload": {
"account_id": "alice@wonderland"
"object": {
"PermissionToken": {
"definition_id": "CanSetKeyValueInUserAccount",
"payload": {
"account_id": "alice@wonderland"
}
}
},
"destination_id": {
Expand Down

0 comments on commit dd2dcc8

Please sign in to comment.