@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 nemesisBlockIsVerifiable() { // Arrange: final Block block = this.loadNemesisBlock(); // Assert: Assert.assertThat(block.verify(), IsEqual.equalTo(true)); }
@Test public void shouldReturnUnparsableClassIfErrorOccursWhileParsing() { ClassParser parser = mock(ClassParser.class); when(parser.getClass("MyClassName")).thenThrow(new RuntimeException(new NotFoundException(""))); builder = new JavaClassBuilder(parser); Assert.assertThat(builder.createClass("MyClassName"), instanceOf(UnparsableClass.class)); }
@Test public void generationHashConstantIsConsistentWithNemesisBlock() { // Arrange: final Block block = this.loadNemesisBlock(); // Assert: Assert.assertThat( block.getGenerationHash(), IsEqual.equalTo(NEMESIS_BLOCK_INFO.getGenerationHash())); }
@Test public void nemesisTransactionsAreVerifiable() { // Arrange: final Block block = this.loadNemesisBlock(); // Assert: for (final Transaction transaction : block.getTransactions()) { Assert.assertThat(transaction.verify(), IsEqual.equalTo(true)); } }
@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()); }
@Test public void nemesisTransactionsHaveCorrectFees() { // Arrange: final Block block = this.loadNemesisBlock(); // Assert: for (final Transaction transaction : block.getTransactions()) { final Amount expectedFee = TransactionTypes.TRANSFER == transaction.getType() ? Amount.ZERO : NemGlobals.getTransactionFeeCalculator().calculateMinimumFee(transaction); Assert.assertThat(transaction.getFee(), IsEqual.equalTo(expectedFee)); } }
@Test public void amountConstantIsConsistentWithNemesisBlock() { // Act: Amount totalAmount = Amount.ZERO; final Block block = this.loadNemesisBlock(); for (final Transaction transaction : block.getTransactions()) { if (transaction instanceof TransferTransaction) { totalAmount = totalAmount.add(((TransferTransaction) transaction).getAmount()); } } // Assert: Assert.assertThat(totalAmount, IsEqual.equalTo(NEMESIS_BLOCK_INFO.getAmount())); }
@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 nemesisAddressesAreValid() { // Arrange: final Block block = this.loadNemesisBlock(); // Act: final Set<Address> allAddresses = block .getTransactions() .stream() .flatMap(t -> t.getAccounts().stream().map(Account::getAddress)) .collect(Collectors.toSet()); // Assert: for (final Address address : allAddresses) { Assert.assertThat(address.toString(), address.isValid(), IsEqual.equalTo(true)); } }