Skip to content

Commit

Permalink
feature: get executor from test resource folder (#402)
Browse files Browse the repository at this point in the history
* feature: get executor from test resource folder

Signed-off-by: Timur Guskov <[email protected]>

* feature: get executor from custom path

Signed-off-by: Timur Guskov <[email protected]>

* feature: added test

Signed-off-by: Timur Guskov <[email protected]>

---------

Signed-off-by: Timur Guskov <[email protected]>
Co-authored-by: Timur Guskov <[email protected]>
  • Loading branch information
gv-timur and gv-timur authored Jan 23, 2024
1 parent 3d8f56b commit 7734582
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package jp.co.soramitsu.iroha2

import jp.co.soramitsu.iroha2.client.Iroha2Client
import jp.co.soramitsu.iroha2.generated.AssetDefinitionId
import jp.co.soramitsu.iroha2.generated.AssetValueType
import jp.co.soramitsu.iroha2.query.QueryBuilder
import jp.co.soramitsu.iroha2.testengine.ALICE_ACCOUNT_ID
import jp.co.soramitsu.iroha2.testengine.BOB_ACCOUNT_ID
import jp.co.soramitsu.iroha2.testengine.DEFAULT_DOMAIN_ID
import jp.co.soramitsu.iroha2.testengine.DefaultGenesis
import jp.co.soramitsu.iroha2.testengine.IrohaContainer
import jp.co.soramitsu.iroha2.testengine.IrohaTest
import jp.co.soramitsu.iroha2.testengine.WithIroha
import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class GenesisTest : IrohaTest<Iroha2Client>() {
companion object {
Expand Down Expand Up @@ -36,6 +41,19 @@ class GenesisTest : IrohaTest<Iroha2Client>() {
client.checkAliceAndBobExists()
}

@Test
@WithIroha([DefaultGenesis::class], executorSource = "src/test/resources/executor.wasm")
fun `custom executor path`(): Unit = runBlocking {
val definitionId = AssetDefinitionId("XSTUSD".asName(), DEFAULT_DOMAIN_ID)
client.tx { registerAssetDefinition(definitionId, AssetValueType.Quantity()) }

QueryBuilder.findAssetDefinitionById(definitionId)
.account(super.account)
.buildSigned(super.keyPair)
.let { query -> client.sendQuery(query) }
.also { assetDefinition -> assertEquals(assetDefinition.id, definitionId) }
}

private suspend fun Iroha2Client.checkAliceAndBobExists() {
QueryBuilder.findAllAccounts()
.account(ALICE_ACCOUNT_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class IrohaConfig(
var submitGenesis: Boolean = true,
var envs: Map<String, String> = emptyMap(),
var fetchSize: Int = 10,
var executorPath: String? = null,
) {
companion object {
const val P2P_PORT_IDX = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import java.time.Duration
import java.util.UUID.randomUUID
import kotlin.io.path.Path
import kotlin.io.path.absolute
import kotlin.io.path.readBytes

/**
* Docker container for Iroha
Expand Down Expand Up @@ -72,8 +73,14 @@ open class IrohaContainer : GenericContainer<IrohaContainer> {
config.genesis?.writeToFile(genesisFileLocation)
config.genesisPath?.also { path -> Files.copy(Path(path).toAbsolutePath(), genesisFileLocation) }

getResource(DEFAULT_EXECUTOR_FILE_NAME).readBytes().let { content ->
executorFileLocation.toFile().writeBytes(content)
if (config.executorPath != null) {
Path(config.executorPath!!).toAbsolutePath().readBytes().let { content ->
executorFileLocation.toFile().writeBytes(content)
}
} else {
getResource(DEFAULT_EXECUTOR_FILE_NAME).readBytes().let { content ->
executorFileLocation.toFile().writeBytes(content)
}
}
getResource(DEFAULT_CONFIG_FILE_NAME).readBytes().let { content ->
configFileLocation.toFile().writeBytes(content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ class IrohaRunnerExtension : InvocationInterceptor, BeforeEachCallback {
}
// only first peer should have --submit-genesis in peer start command
this.submitGenesis = n == 0
if (withIroha.executorSource.isNotEmpty()) {
this.executorPath = withIroha.executorSource
}
}
container.start()
containers.add(container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ annotation class WithIroha(
val source: String = "",
val amount: Int = 1,
val fetchSize: Int = 10,
val executorSource: String = "",
)

@MustBeDocumented
Expand Down

0 comments on commit 7734582

Please sign in to comment.