From 082bae900ee1469013e9bb16dc47e1804fe66af7 Mon Sep 17 00:00:00 2001 From: "Sergei Makarov (LCL)" Date: Thu, 24 Oct 2019 22:21:58 -0400 Subject: [PATCH 1/7] Remove getService() from TestKit --- .../com/exonum/binding/testkit/TestKit.java | 17 --- .../binding/testkit/TestKitExtensionTest.java | 2 +- .../exonum/binding/testkit/TestKitTest.java | 112 ++++-------------- .../TestKitTestWithArtifactsCreated.java | 17 +++ 4 files changed, 39 insertions(+), 109 deletions(-) diff --git a/exonum-java-binding/testkit/src/main/java/com/exonum/binding/testkit/TestKit.java b/exonum-java-binding/testkit/src/main/java/com/exonum/binding/testkit/TestKit.java index 140b36dd9b..c5f0e554f5 100644 --- a/exonum-java-binding/testkit/src/main/java/com/exonum/binding/testkit/TestKit.java +++ b/exonum-java-binding/testkit/src/main/java/com/exonum/binding/testkit/TestKit.java @@ -169,23 +169,6 @@ public static TestKit forService(ServiceArtifactId artifactId, String artifactFi .build(); } - /** - * Returns an instance of a service with the given service name and service class. Only - * user-defined services can be requested, i.e., it is not possible to get an instance of a - * built-in service such as the time oracle. - * - * @return the service instance or null if there is no service with such id - * @throws IllegalArgumentException if the service with given id was not found or could not be - * cast to given class - */ - public T getService(String serviceName, Class serviceClass) { - Service service = serviceRuntime.getServiceInstanceByName(serviceName); - checkArgument(service.getClass().equals(serviceClass), - "Service (name=%s, class=%s) cannot be cast to %s", - serviceName, service.getClass().getCanonicalName(), serviceClass.getCanonicalName()); - return serviceClass.cast(service); - } - /** * Creates a block with the given transaction(s). Transactions are applied in the lexicographical * order of their hashes. In-pool transactions will be ignored. diff --git a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitExtensionTest.java b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitExtensionTest.java index 175351e197..30a183989a 100644 --- a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitExtensionTest.java +++ b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitExtensionTest.java @@ -121,7 +121,7 @@ void beforeEachTestKitInject(TestKit testKit) { instantiatedTestKit = testKit; // Check that TestKit was instantiated with a correct service - TestService service = testKit.getService(SERVICE_NAME, TestService.class); + checkIfServiceEnabled(testKit, SERVICE_NAME, SERVICE_ID); // Check that main TestKit node is a validator assertThat(testKit.getEmulatedNode().getNodeType()).isEqualTo(EmulatedNodeType.VALIDATOR); diff --git a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java index 7140177b92..acf25dbd35 100644 --- a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java +++ b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java @@ -20,6 +20,7 @@ import static com.exonum.binding.testkit.TestService.THROWING_VALUE; import static com.exonum.binding.testkit.TestService.constructAfterCommitTransaction; import static com.exonum.binding.testkit.TestTransaction.BODY_CHARSET; +import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -33,14 +34,11 @@ import com.exonum.binding.core.blockchain.Block; import com.exonum.binding.core.blockchain.Blockchain; import com.exonum.binding.core.proxy.Cleaner; -import com.exonum.binding.core.runtime.DispatcherSchema; -import com.exonum.binding.core.service.Node; import com.exonum.binding.core.storage.database.Snapshot; import com.exonum.binding.core.storage.database.View; import com.exonum.binding.core.storage.indices.MapIndex; import com.exonum.binding.core.storage.indices.ProofMapIndexProxy; import com.exonum.binding.core.transaction.RawTransaction; -import com.exonum.binding.messages.Runtime.InstanceSpec; import com.exonum.binding.testkit.TestProtoMessages.TestConfiguration; import com.exonum.binding.time.TimeSchema; import com.google.common.collect.ImmutableList; @@ -195,10 +193,9 @@ void createTestKitWithCustomConfiguration() { .withService(ARTIFACT_ID, SERVICE_NAME, SERVICE_ID, testConfiguration) .withArtifactsDirectory(artifactsDirectory) .build()) { - TestService service = testKit.getService(SERVICE_NAME, TestService.class); // Check that configuration value is used in initialization Snapshot view = testKit.getSnapshot(); - TestSchema testSchema = service.createDataSchema(view); + TestSchema testSchema = new TestSchema(view, SERVICE_ID); ProofMapIndexProxy testProofMap = testSchema.testMap(); Map testMap = toMap(testProofMap); Map expected = ImmutableMap.of( @@ -262,16 +259,9 @@ void createTestKitWithTimeService() { private void checkTestServiceInitialization(TestKit testKit, String serviceName, int serviceId) { // Check that service appears in dispatcher schema checkIfServiceEnabled(testKit, serviceName, serviceId); - TestService service = testKit.getService(serviceName, TestService.class); - // Check that TestService API is mounted - Node serviceNode = service.getNode(); - EmulatedNode emulatedTestKitNode = testKit.getEmulatedNode(); - assertThat(serviceNode.getPublicKey()) - .isEqualTo(emulatedTestKitNode.getServiceKeyPair().getPublicKey()); - // Check that initialization changed database state Snapshot view = testKit.getSnapshot(); - TestSchema testSchema = service.createDataSchema(view); + TestSchema testSchema = new TestSchema(view, serviceId); ProofMapIndexProxy testProofMap = testSchema.testMap(); Map testMap = toMap(testProofMap); Map expected = ImmutableMap.of( @@ -286,30 +276,12 @@ private void checkTestServiceInitialization(TestKit testKit, String serviceName, private void checkTestService2Initialization(TestKit testKit, String serviceName, int serviceId) { // Check that service appears in dispatcher schema checkIfServiceEnabled(testKit, serviceName, serviceId); - TestService2 service = testKit.getService(serviceName, TestService2.class); - // Check that TestService2 API is mounted - Node serviceNode = service.getNode(); - EmulatedNode emulatedTestKitNode = testKit.getEmulatedNode(); - assertThat(serviceNode.getPublicKey()) - .isEqualTo(emulatedTestKitNode.getServiceKeyPair().getPublicKey()); - // Check that genesis block was committed Snapshot view = testKit.getSnapshot(); Blockchain blockchain = Blockchain.newInstance(view); assertThat(blockchain.getBlockHashes().size()).isEqualTo(1L); } - private void checkIfServiceEnabled(TestKit testKit, String serviceName, int serviceId) { - View view = testKit.getSnapshot(); - MapIndex serviceInstances = - new DispatcherSchema(view).serviceInstances(); - assertThat(serviceInstances.containsKey(serviceName)).isTrue(); - - InstanceSpec serviceSpec = serviceInstances.get(serviceName); - int actualServiceId = serviceSpec.getId(); - assertThat(actualServiceId).isEqualTo(serviceId); - } - @Test void createTestKitWithSeveralValidators() { short validatorCount = 2; @@ -354,20 +326,6 @@ void setInvalidValidatorCount() { assertThrows(exceptionType, () -> testKitBuilder.withValidators(invalidValidatorCount)); } - @Test - void getServiceWithWrongClassThrows(TestKit testKit) { - Class exceptionType = IllegalArgumentException.class; - assertThrows(exceptionType, - () -> testKit.getService(SERVICE_NAME, TestService2.class)); - } - - @Test - void getServiceWithWrongNameThrows(TestKit testKit) { - Class exceptionType = IllegalArgumentException.class; - assertThrows(exceptionType, () -> testKit.getService("Invalid service name", - TestService.class)); - } - @Test void createTestKitMoreThanMaxServiceNumber() { Class exceptionType = IllegalArgumentException.class; @@ -439,6 +397,24 @@ void createBlockWithTransactionIgnoresInPoolTransactions(TestKit testKit) { assertThat(inPoolTransactions).hasSize(2); } + @Test + void getTransactionPool(TestKit testKit) { + // Create two blocks with no transactions + Block block1 = testKit.createBlock(); + Block block2 = testKit.createBlockWithTransactions(); + // Two blocks were created, so two afterCommit transactions should be submitted into pool + List transactionsInPool = testKit.getTransactionPool(); + RawTransaction afterCommitTransaction1 = + constructAfterCommitTransaction(SERVICE_ID, block1.getHeight()); + RawTransaction afterCommitTransaction2 = + constructAfterCommitTransaction(SERVICE_ID, block2.getHeight()); + List rawTransactionsInPool = transactionsInPool.stream() + .map(RawTransaction::fromMessage) + .collect(toList()); + assertThat(rawTransactionsInPool) + .containsExactlyInAnyOrder(afterCommitTransaction1, afterCommitTransaction2); + } + @Test void createBlockWithSingleTransaction(TestKit testKit) { TransactionMessage message = constructTestTransactionMessage("Test message"); @@ -467,52 +443,6 @@ void createBlockWithTransactions(TestKit testKit) { view, block, message, message2)); } - @Test - void nodeSubmittedTransactionsArePlacedInPool(TestKit testKit) { - TestService service = testKit.getService(SERVICE_NAME, TestService.class); - - TransactionMessage message = constructTestTransactionMessage("Test message", testKit); - RawTransaction rawTransaction = RawTransaction.fromMessage(message); - service.getNode().submitTransaction(rawTransaction); - - List transactionsInPool = - testKit.findTransactionsInPool(tx -> tx.getServiceId() == SERVICE_ID); - assertThat(transactionsInPool).isEqualTo(ImmutableList.of(message)); - } - - @Test - void getTransactionPool(TestKit testKit) { - TestService service = testKit.getService(SERVICE_NAME, TestService.class); - - TransactionMessage message = constructTestTransactionMessage("Test message", testKit); - RawTransaction rawTransaction = RawTransaction.fromMessage(message); - TransactionMessage message2 = constructTestTransactionMessage("Test message 2", testKit); - RawTransaction rawTransaction2 = RawTransaction.fromMessage(message2); - - service.getNode().submitTransaction(rawTransaction); - service.getNode().submitTransaction(rawTransaction2); - - List transactionsInPool = testKit.getTransactionPool(); - assertThat(transactionsInPool).containsExactlyInAnyOrder(message, message2); - } - - @Test - void findTransactionsInPool(TestKit testKit) { - TestService service = testKit.getService(SERVICE_NAME, TestService.class); - - TransactionMessage message = constructTestTransactionMessage("Test message", testKit); - RawTransaction rawTransaction = RawTransaction.fromMessage(message); - TransactionMessage message2 = constructTestTransactionMessage("Test message 2", testKit); - RawTransaction rawTransaction2 = RawTransaction.fromMessage(message2); - service.getNode().submitTransaction(rawTransaction); - service.getNode().submitTransaction(rawTransaction2); - - List transactionsInPool = - testKit.findTransactionsInPool( - tx -> tx.getPayload().equals(message.getPayload())); - assertThat(transactionsInPool).containsExactly(message); - } - @Test void createBlockWithTransactionsVarargs(TestKit testKit) { TransactionMessage message = constructTestTransactionMessage("Test message"); diff --git a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTestWithArtifactsCreated.java b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTestWithArtifactsCreated.java index f6552a31cc..324a0247b4 100644 --- a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTestWithArtifactsCreated.java +++ b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTestWithArtifactsCreated.java @@ -16,7 +16,13 @@ package com.exonum.binding.testkit; +import static org.assertj.core.api.Assertions.assertThat; + +import com.exonum.binding.core.runtime.DispatcherSchema; import com.exonum.binding.core.runtime.ServiceArtifactId; +import com.exonum.binding.core.storage.database.View; +import com.exonum.binding.core.storage.indices.MapIndex; +import com.exonum.binding.messages.Runtime.InstanceSpec; import com.exonum.binding.test.runtime.ServiceArtifactBuilder; import com.exonum.binding.testkit.TestProtoMessages.TestConfiguration; import java.io.IOException; @@ -72,6 +78,17 @@ static void createInvalidArtifact(Path directory, String filename) throws IOExce TestSchema.class); } + static void checkIfServiceEnabled(TestKit testKit, String serviceName, int serviceId) { + View view = testKit.getSnapshot(); + MapIndex serviceInstances = + new DispatcherSchema(view).serviceInstances(); + assertThat(serviceInstances.containsKey(serviceName)).isTrue(); + + InstanceSpec serviceSpec = serviceInstances.get(serviceName); + int actualServiceId = serviceSpec.getId(); + assertThat(actualServiceId).isEqualTo(serviceId); + } + private static void createArtifact(Path artifactLocation, ServiceArtifactId serviceArtifactId, Class serviceModule, Class... artifactClasses) throws IOException { From 1676a14aced175c1d524d073483024ff5face8e6 Mon Sep 17 00:00:00 2001 From: "Sergei Makarov (LCL)" Date: Thu, 24 Oct 2019 22:56:11 -0400 Subject: [PATCH 2/7] Minor fix --- .../test/java/com/exonum/binding/testkit/TestKitTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java index acf25dbd35..41897814f1 100644 --- a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java +++ b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java @@ -399,16 +399,15 @@ void createBlockWithTransactionIgnoresInPoolTransactions(TestKit testKit) { @Test void getTransactionPool(TestKit testKit) { - // Create two blocks with no transactions + // Create two blocks with no transactions, so two afterCommit transactions are stored in + // the transaction pool Block block1 = testKit.createBlock(); Block block2 = testKit.createBlockWithTransactions(); - // Two blocks were created, so two afterCommit transactions should be submitted into pool - List transactionsInPool = testKit.getTransactionPool(); RawTransaction afterCommitTransaction1 = constructAfterCommitTransaction(SERVICE_ID, block1.getHeight()); RawTransaction afterCommitTransaction2 = constructAfterCommitTransaction(SERVICE_ID, block2.getHeight()); - List rawTransactionsInPool = transactionsInPool.stream() + List rawTransactionsInPool = testKit.getTransactionPool().stream() .map(RawTransaction::fromMessage) .collect(toList()); assertThat(rawTransactionsInPool) From 3d84e002936fe36fd3383e12897258d52cab0b04 Mon Sep 17 00:00:00 2001 From: "Sergei Makarov (LCL)" Date: Thu, 24 Oct 2019 23:09:30 -0400 Subject: [PATCH 3/7] Remove getNode() methods --- .../src/test/java/com/exonum/binding/testkit/TestService.java | 4 ---- .../test/java/com/exonum/binding/testkit/TestService2.java | 4 ---- 2 files changed, 8 deletions(-) diff --git a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestService.java b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestService.java index cc48305360..993fcf2928 100644 --- a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestService.java +++ b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestService.java @@ -48,10 +48,6 @@ public TestService(ServiceInstanceSpec serviceSpec) { this.serviceInstanceId = serviceSpec.getId(); } - Node getNode() { - return node; - } - @Override protected TestSchema createDataSchema(View view) { return new TestSchema(view, serviceInstanceId); diff --git a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestService2.java b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestService2.java index 2ba3f95cdf..b5b766902d 100644 --- a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestService2.java +++ b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestService2.java @@ -35,10 +35,6 @@ public TestService2(ServiceInstanceSpec serviceSpec) { this.serviceInstanceId = serviceSpec.getId(); } - Node getNode() { - return node; - } - @Override protected TestSchema createDataSchema(View view) { return new TestSchema(view, serviceInstanceId); From cab6698f1f42c29108f62e605e39b6727c810ba2 Mon Sep 17 00:00:00 2001 From: "Sergei Makarov (LCL)" Date: Fri, 25 Oct 2019 17:15:30 -0400 Subject: [PATCH 4/7] Review fixes --- .../binding/core/runtime/ServiceRuntime.java | 16 ---------------- .../runtime/ServiceRuntimeIntegrationTest.java | 18 ------------------ .../exonum/binding/testkit/TestKitTest.java | 6 ------ 3 files changed, 40 deletions(-) diff --git a/exonum-java-binding/core/src/main/java/com/exonum/binding/core/runtime/ServiceRuntime.java b/exonum-java-binding/core/src/main/java/com/exonum/binding/core/runtime/ServiceRuntime.java index 9719279c9a..9d2b7ba2f8 100644 --- a/exonum-java-binding/core/src/main/java/com/exonum/binding/core/runtime/ServiceRuntime.java +++ b/exonum-java-binding/core/src/main/java/com/exonum/binding/core/runtime/ServiceRuntime.java @@ -28,7 +28,6 @@ import com.exonum.binding.core.runtime.ServiceRuntimeProtos.ServiceStateHashes; import com.exonum.binding.core.service.BlockCommittedEvent; import com.exonum.binding.core.service.Node; -import com.exonum.binding.core.service.Service; import com.exonum.binding.core.storage.database.Fork; import com.exonum.binding.core.storage.database.Snapshot; import com.exonum.binding.core.transaction.TransactionContext; @@ -374,21 +373,6 @@ public void connectServiceApis(int[] serviceIds, Node node) { } } - /** - * Get service instance by its name. - * - * @throws IllegalArgumentException if there is no service with such name - */ - public Service getServiceInstanceByName(String serviceName) { - synchronized (lock) { - return findService(serviceName) - .map(ServiceWrapper::getService) - .orElseThrow(() -> - new IllegalArgumentException("No service with such name in the Java runtime: " - + serviceName)); - } - } - /** * Verifies that an Exonum raw transaction can be correctly converted to an executable * transaction of given service. diff --git a/exonum-java-binding/core/src/test/java/com/exonum/binding/core/runtime/ServiceRuntimeIntegrationTest.java b/exonum-java-binding/core/src/test/java/com/exonum/binding/core/runtime/ServiceRuntimeIntegrationTest.java index 291c806723..f812cf948b 100644 --- a/exonum-java-binding/core/src/test/java/com/exonum/binding/core/runtime/ServiceRuntimeIntegrationTest.java +++ b/exonum-java-binding/core/src/test/java/com/exonum/binding/core/runtime/ServiceRuntimeIntegrationTest.java @@ -44,7 +44,6 @@ import com.exonum.binding.core.service.BlockCommittedEvent; import com.exonum.binding.core.service.Configuration; import com.exonum.binding.core.service.Node; -import com.exonum.binding.core.service.Service; import com.exonum.binding.core.storage.database.Database; import com.exonum.binding.core.storage.database.Fork; import com.exonum.binding.core.storage.database.Snapshot; @@ -510,23 +509,6 @@ void connectServiceApisSingleService() { verify(serviceWrapper).createPublicApiHandlers(node, serviceRouter); verify(server).mountSubRouter(API_ROOT_PATH + "/" + serviceApiPath, serviceRouter); } - - @Test - void getServiceInstanceByName() { - Service service = mock(Service.class); - when(serviceWrapper.getService()).thenReturn(service); - assertThat(serviceRuntime.getServiceInstanceByName(TEST_NAME)).isEqualTo(service); - } - - @Test - void getServiceInstanceByNameUnknownService() { - String invalidServiceName = "Wrong service name"; - Exception e = assertThrows(IllegalArgumentException.class, - () -> serviceRuntime.getServiceInstanceByName(invalidServiceName)); - String expectedMessage = - String.format("No service with such name in the Java runtime: %s", invalidServiceName); - assertThat(e).hasMessageContaining(expectedMessage); - } } private static byte[] anyConfiguration() { diff --git a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java index 41897814f1..b1c4b98b09 100644 --- a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java +++ b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java @@ -458,12 +458,6 @@ private TransactionMessage constructTestTransactionMessage(String payload) { return constructTestTransactionMessage(payload, KEY_PAIR); } - private TransactionMessage constructTestTransactionMessage(String payload, TestKit testKit) { - EmulatedNode emulatedNode = testKit.getEmulatedNode(); - KeyPair emulatedNodeKeyPair = emulatedNode.getServiceKeyPair(); - return constructTestTransactionMessage(payload, emulatedNodeKeyPair); - } - private TransactionMessage constructTestTransactionMessage(String payload, KeyPair keyPair) { return TransactionMessage.builder() .serviceId(SERVICE_ID) From 859f5fe8a9e74d04d14d7b514b00b55e9d8215fb Mon Sep 17 00:00:00 2001 From: "Sergei Makarov (LCL)" Date: Fri, 25 Oct 2019 22:17:07 -0400 Subject: [PATCH 5/7] Add validator public key test --- .../com/exonum/binding/testkit/TestKitTest.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java index b1c4b98b09..7404d5af40 100644 --- a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java +++ b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java @@ -39,6 +39,8 @@ import com.exonum.binding.core.storage.indices.MapIndex; import com.exonum.binding.core.storage.indices.ProofMapIndexProxy; import com.exonum.binding.core.transaction.RawTransaction; +import com.exonum.binding.messages.Blockchain.Config; +import com.exonum.binding.messages.Blockchain.ValidatorKeys; import com.exonum.binding.testkit.TestProtoMessages.TestConfiguration; import com.exonum.binding.time.TimeSchema; import com.google.common.collect.ImmutableList; @@ -514,7 +516,19 @@ void getValidatorEmulatedNode(TestKit testKit) { EmulatedNode node = testKit.getEmulatedNode(); assertThat(node.getNodeType()).isEqualTo(EmulatedNodeType.VALIDATOR); assertThat(node.getValidatorId()).isNotEmpty(); - assertThat(node.getServiceKeyPair()).isNotNull(); + + Snapshot view = testKit.getSnapshot(); + Blockchain blockchain = Blockchain.newInstance(view); + Config configuration = blockchain.getConsensusConfiguration(); + + // Check the public service key of the emulated node is included + List serviceKeys = configuration.getValidatorKeysList().stream() + .map(ValidatorKeys::getServiceKey) + .map(key -> PublicKey.fromBytes(key.getData().toByteArray())) + .collect(toList()); + PublicKey emulatedNodeServiceKey = node.getServiceKeyPair().getPublicKey(); + List expectedKeys = ImmutableList.of(emulatedNodeServiceKey); + assertThat(serviceKeys).isEqualTo(expectedKeys); } @Test From 4f8dee64c70362923e917878274067c34525cf15 Mon Sep 17 00:00:00 2001 From: "Sergei Makarov (LCL)" Date: Sat, 26 Oct 2019 00:55:17 -0400 Subject: [PATCH 6/7] Minor fix --- .../com/exonum/binding/testkit/TestKitTest.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java index 7404d5af40..bd35e73579 100644 --- a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java +++ b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java @@ -261,25 +261,28 @@ void createTestKitWithTimeService() { private void checkTestServiceInitialization(TestKit testKit, String serviceName, int serviceId) { // Check that service appears in dispatcher schema checkIfServiceEnabled(testKit, serviceName, serviceId); - // Check that initialization changed database state Snapshot view = testKit.getSnapshot(); + // Check that genesis block was committed + checkGenesisBlockCommit(view); + + // Check that initialization changed database state TestSchema testSchema = new TestSchema(view, serviceId); ProofMapIndexProxy testProofMap = testSchema.testMap(); Map testMap = toMap(testProofMap); Map expected = ImmutableMap.of( TestService.INITIAL_ENTRY_KEY, CONFIGURATION_VALUE); assertThat(testMap).isEqualTo(expected); - - // Check that genesis block was committed - Blockchain blockchain = Blockchain.newInstance(view); - assertThat(blockchain.getBlockHashes().size()).isEqualTo(1L); } private void checkTestService2Initialization(TestKit testKit, String serviceName, int serviceId) { // Check that service appears in dispatcher schema checkIfServiceEnabled(testKit, serviceName, serviceId); + // Check that genesis block was committed - Snapshot view = testKit.getSnapshot(); + checkGenesisBlockCommit(testKit.getSnapshot()); + } + + private void checkGenesisBlockCommit(Snapshot view) { Blockchain blockchain = Blockchain.newInstance(view); assertThat(blockchain.getBlockHashes().size()).isEqualTo(1L); } From 2b1a67b332232272c2ced733e3b50ee720289e55 Mon Sep 17 00:00:00 2001 From: "Sergei Makarov (LCL)" Date: Mon, 28 Oct 2019 18:15:22 -0400 Subject: [PATCH 7/7] Add a comment --- .../src/test/java/com/exonum/binding/testkit/TestKitTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java index bd35e73579..99f6e63126 100644 --- a/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java +++ b/exonum-java-binding/testkit/src/test/java/com/exonum/binding/testkit/TestKitTest.java @@ -407,6 +407,8 @@ void getTransactionPool(TestKit testKit) { // Create two blocks with no transactions, so two afterCommit transactions are stored in // the transaction pool Block block1 = testKit.createBlock(); + // Use #createBlockWithTransactions() so that an empty block is created and first afterCommit + // transaction stays in pool Block block2 = testKit.createBlockWithTransactions(); RawTransaction afterCommitTransaction1 = constructAfterCommitTransaction(SERVICE_ID, block1.getHeight());