diff --git a/modules/client/src/test/kotlin/jp/co/soramitsu/iroha2/InstructionsTest.kt b/modules/client/src/test/kotlin/jp/co/soramitsu/iroha2/InstructionsTest.kt index ac963a53..7c542ccc 100644 --- a/modules/client/src/test/kotlin/jp/co/soramitsu/iroha2/InstructionsTest.kt +++ b/modules/client/src/test/kotlin/jp/co/soramitsu/iroha2/InstructionsTest.kt @@ -12,8 +12,11 @@ import jp.co.soramitsu.iroha2.generated.AssetDefinitionId import jp.co.soramitsu.iroha2.generated.AssetId import jp.co.soramitsu.iroha2.generated.AssetValue import jp.co.soramitsu.iroha2.generated.AssetValueType +import jp.co.soramitsu.iroha2.generated.BatchedResponseOfValue +import jp.co.soramitsu.iroha2.generated.BatchedResponseV1OfValue import jp.co.soramitsu.iroha2.generated.DomainId import jp.co.soramitsu.iroha2.generated.IdBox +import jp.co.soramitsu.iroha2.generated.InstructionExpr import jp.co.soramitsu.iroha2.generated.Metadata import jp.co.soramitsu.iroha2.generated.Name import jp.co.soramitsu.iroha2.generated.PermissionToken @@ -66,6 +69,9 @@ import java.math.RoundingMode import java.security.SecureRandom import java.time.Instant import java.util.UUID +import kotlin.reflect.full.callSuspend +import kotlin.reflect.full.declaredMemberFunctions +import kotlin.reflect.jvm.isAccessible import kotlin.test.assertEquals import kotlin.test.assertFails import kotlin.test.assertFailsWith @@ -936,6 +942,51 @@ class InstructionsTest : IrohaTest() { } } + @Test + @WithIroha([DefaultGenesis::class], fetchSize = 111) + fun `iroha respond with given fetch size`(): Unit = runBlocking { + val fetchSize = 111 + repeat(2) { i -> + val isi = mutableListOf() + val tx = TransactionBuilder { + account(ALICE_ACCOUNT_ID) + } + repeat(100) { j -> + val definitionId = AssetDefinitionId("ASSET_${j}_$i".asName(), DEFAULT_DOMAIN_ID) + isi.add(Instructions.registerAssetDefinition(definitionId, AssetValueType.Store())) + isi.add( + Instructions.setKeyValue( + AssetId(definitionId, ALICE_ACCOUNT_ID), + randomAlphabetic(10).asName(), + randomAlphabetic(100).asValue(), + ), + ) + } + tx.instructions(isi) + + client.sendTransaction { tx.buildSigned(ALICE_KEYPAIR) }.let { + withTimeout(txTimeout) { + it.await() + } + } + } + + val query = QueryBuilder.findAllAssets() + .account(ALICE_ACCOUNT_ID) + .buildSigned(ALICE_KEYPAIR) + val method = Iroha2Client::class.declaredMemberFunctions.firstOrNull { it.name == "sendQueryRequest" } + + val response = method?.let { + it.isAccessible = true + it.callSuspend(client, query, null, null, null, null) + } + val vec = response?.cast()?.batchedResponseV1OfValue + ?.cast()?.batch + ?.cast()?.vec + + assertEquals(fetchSize, vec?.size) + } + @Test @WithIroha([DefaultGenesis::class]) @Feature("Domains") diff --git a/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaConfig.kt b/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaConfig.kt index 4eb9240f..d367c1af 100644 --- a/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaConfig.kt +++ b/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaConfig.kt @@ -42,6 +42,7 @@ class IrohaConfig( var waitStrategy: Boolean = true, var submitGenesis: Boolean = true, var envs: Map = emptyMap(), + var fetchSize: Int = 10, ) { companion object { const val P2P_PORT_IDX = 0 diff --git a/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaContainer.kt b/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaContainer.kt index 2df4d251..2be68021 100644 --- a/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaContainer.kt +++ b/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaContainer.kt @@ -54,6 +54,7 @@ open class IrohaContainer : GenericContainer { .withEnv("TORII_P2P_ADDR", "${config.alias}:$p2pPort") .withEnv("TORII_API_URL", "${config.alias}:$apiPort") .withEnv("TORII_TELEMETRY_URL", "${config.alias}:$telemetryPort") + .withEnv("TORII_FETCH_SIZE", config.fetchSize.toString()) .withEnv("WSV_WASM_RUNTIME_CONFIG", "{\"FUEL_LIMIT\":20000000, \"MAX_MEMORY\": 524288000}") .also { container -> config.envs.forEach { (k, v) -> container.withEnv(k, v) } } .withExposedPorts(p2pPort, apiPort, telemetryPort) diff --git a/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaRunnerExtension.kt b/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaRunnerExtension.kt index 891b1813..f3e28fa8 100644 --- a/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaRunnerExtension.kt +++ b/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/IrohaRunnerExtension.kt @@ -228,23 +228,24 @@ class IrohaRunnerExtension : InvocationInterceptor, BeforeEachCallback { async { val p2pPort = portsList[n][IrohaConfig.P2P_PORT_IDX] val container = IrohaContainer { - networkToJoin = network + this.networkToJoin = network when { withIroha.source.isNotEmpty() -> genesisPath = withIroha.source else -> genesis = withIroha.sources.map { it.createInstance() }.toSingle() } - alias = IrohaContainer.NETWORK_ALIAS + p2pPort - keyPair = keyPairs[n] + this.alias = IrohaContainer.NETWORK_ALIAS + p2pPort + this.keyPair = keyPairs[n] this.genesisKeyPair = genesisKeyPair - trustedPeers = peerIds - ports = portsList[n] - envs = withIroha.configs.associate { config -> + this.trustedPeers = peerIds + this.ports = portsList[n] + this.fetchSize = withIroha.fetchSize + this.envs = withIroha.configs.associate { config -> config.split(IROHA_CONFIG_DELIMITER).let { it.first() to it.last() } } // only first peer should have --submit-genesis in peer start command - submitGenesis = n == 0 + this.submitGenesis = n == 0 } container.start() containers.add(container) diff --git a/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/WithIroha.kt b/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/WithIroha.kt index dce8846a..159b1e03 100644 --- a/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/WithIroha.kt +++ b/modules/test-tools/src/main/kotlin/jp/co/soramitsu/iroha2/testengine/WithIroha.kt @@ -22,6 +22,7 @@ annotation class WithIroha( val configs: Array = [], val source: String = "", val amount: Int = 1, + val fetchSize: Int = 10, ) @MustBeDocumented