@Test public void openWriteCanOpenFileThatExists() throws IOException { // Arrange: final TEntityFileDescriptor descriptor = this.createDescriptor(TEST_FILE); // Act: try (final OutputStream os = descriptor.openWrite()) { // Assert: Assert.assertThat(os, IsNull.notNullValue()); } }
@Test public void openWriteCanOpenFileThatDoesNotExist() throws IOException { // Arrange: final File file = new File(TEST_FILE_DIRECTORY, "imaginary-write.bar"); final TEntityFileDescriptor descriptor = this.createDescriptor(file); // Act: try (final OutputStream os = descriptor.openWrite()) { // Assert: Assert.assertThat(os, IsNull.notNullValue()); } }
@Test public void addressConstantIsConsistentWithNemesisBlock() { // Arrange: final Block block = this.loadNemesisBlock(); final Address blockAddress = block.getSigner().getAddress(); // Assert: Assert.assertThat(blockAddress, IsEqual.equalTo(NEMESIS_BLOCK_INFO.getAddress())); Assert.assertThat( blockAddress.getPublicKey(), IsEqual.equalTo(NEMESIS_BLOCK_INFO.getAddress().getPublicKey())); Assert.assertThat(blockAddress.getPublicKey(), IsNull.notNullValue()); }
@Test public void cannotReturnWalletAccountInClosedWallet() { // Arrange: final WalletAccount account = new WalletAccount(); final TestContext context = new TestContext(); context.originalWallet.addOtherAccount(account); // Act: context.walletServices.open(context.pair); context.walletServices.close(context.pair.getName()); final WalletAccount resultAccount = context.walletServices.tryFindOpenAccount(account.getAddress()); // Assert: Assert.assertThat(resultAccount, IsNull.nullValue()); }
@Test public void nemesisTransactionSignersHavePublicKeys() { // Arrange: final Block block = this.loadNemesisBlock(); // Act: final Set<Address> signerAddresses = block .getTransactions() .stream() .map(t -> t.getSigner().getAddress()) .collect(Collectors.toSet()); // Assert: for (final Address address : signerAddresses) { Assert.assertThat(address.getPublicKey(), IsNull.notNullValue()); } }
@Test public void renamedWalletIsNotAccessibleByOldName() { // Arrange: final WalletNamePasswordPair pair2 = createPair("n2", "p"); final WalletDescriptor descriptor2 = createDescriptor("n2"); final TestContext context = new TestContext(); Mockito.when(context.descriptorFactory.createNew(pair2, FILE_EXTENSION)) .thenReturn(descriptor2); // Act: context.walletServices.open(context.pair); context.walletServices.move(context.pair, pair2); // Assert: Assert.assertThat(context.walletServices.get(new WalletName("n2")), IsNull.notNullValue()); ExceptionAssert.assertThrowsNccException( v -> context.walletServices.get(new WalletName("n")), NccException.Code.WALLET_IS_NOT_OPEN); }
@Test public void nemesisBlockCanBeCreated() { // Act: final Block block = this.loadNemesisBlock(); // Assert: Assert.assertThat( block.getSigner().getAddress(), IsEqual.equalTo(NEMESIS_BLOCK_INFO.getAddress())); Assert.assertThat(block.getType(), IsEqual.equalTo(-1)); Assert.assertThat(block.getVersion(), IsEqual.equalTo(EXPECTED_VERSION)); Assert.assertThat(block.getTimeStamp(), IsEqual.equalTo(TimeInstant.ZERO)); // 2 multisig aggregate transactions Assert.assertThat( block.getTotalFee(), IsEqual.equalTo(EXPECTED_MULTISIG_AGGREGATE_FEE.multiply(2))); Assert.assertThat(block.getPreviousBlockHash(), IsEqual.equalTo(Hash.ZERO)); Assert.assertThat(block.getHeight(), IsEqual.equalTo(BlockHeight.ONE)); Assert.assertThat(block.getTransactions().size(), IsEqual.equalTo(NUM_NEMESIS_TRANSACTIONS)); Assert.assertThat(block.getDifficulty(), IsEqual.equalTo(BlockDifficulty.INITIAL_DIFFICULTY)); Assert.assertThat(block.getGenerationHash(), IsNull.notNullValue()); }