@Test public void nemesisBlockCannotBeLoadedFromInvalidBlob() { // Arrange: final byte[] buffer = loadNemesisBlockBlobObject(); final byte[] badBuffer1 = ByteBuffer.allocate(3 + buffer.length).put("bad".getBytes()).put(buffer).array(); final byte[] badBuffer2 = ByteBuffer.allocate(3 + buffer.length) .put(Arrays.copyOfRange(buffer, 0, 100)) .put("bad".getBytes()) .put(Arrays.copyOfRange(buffer, 100, buffer.length)) .array(); // Act: ExceptionAssert.assertThrows( v -> NemesisBlock.fromBlobObject( NEMESIS_BLOCK_INFO, badBuffer1, new DeserializationContext(new MockAccountLookup())), IllegalArgumentException.class); ExceptionAssert.assertThrows( v -> NemesisBlock.fromBlobObject( NEMESIS_BLOCK_INFO, badBuffer2, new DeserializationContext(new MockAccountLookup())), SerializationException.class); }
@Test public void getCannotReturnClosedWallet() { // Arrange: final TestContext context = new TestContext(); // Act: context.walletServices.open(context.pair); context.walletServices.close(context.pair.getName()); // Act: ExceptionAssert.assertThrowsNccException( v -> context.walletServices.get(context.pair.getName()), NccException.Code.WALLET_IS_NOT_OPEN); }
@Test public void openFailsIfCachedWalletPasswordIsIncorrect() { // Arrange: final TestContext context = new TestContext(); context.walletServices.open(context.pair); // cache the wallet Mockito.when(context.repository.load(context.descriptor)) .thenThrow( new WalletStorageException(WalletStorageException.Code.WALLET_PASSWORD_INCORRECT)); // Act: ExceptionAssert.assertThrowsWalletStorageException( v -> context.walletServices.open(context.pair), WalletStorageException.Code.WALLET_PASSWORD_INCORRECT); }
@Test public void nemesisBlockCannotBeLoadedFromBlobWithIncorrectType() { // Arrange (set type to 1): final byte[] buffer = loadNemesisBlockBlobObject(); buffer[0] = 1; buffer[1] = 0; buffer[2] = 0; buffer[3] = 0; // Act: ExceptionAssert.assertThrows( v -> NemesisBlock.fromBlobObject( NEMESIS_BLOCK_INFO, buffer, new DeserializationContext(new MockAccountLookup())), IllegalArgumentException.class); }
@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); }