Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Aug 11, 2018
2 parents 50f250c + 2f2ba60 commit 156d5b5
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/main/java/io/zold/api/CpTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
* Computed Transaction.
*
* @since 1.0
* @todo #29:30min Implement the computation of the transaction string
* based on the white paper. The unit test should also be updated to
* ensure it works as expected.
* @todo #54:30min Implement the computation of the transaction string
* based on the white paper. The unit tests should also be updated to
* ensure it works as expected and test for
* returnSignatureForNegativeTransaction must be implemented.
*/
public final class CpTransaction extends TransactionEnvelope {

Expand Down
21 changes: 21 additions & 0 deletions src/main/java/io/zold/api/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public interface Wallet {
*/
Iterable<Transaction> ledger();

/**
* This wallet's RSA key.
* @return This wallet's RSA key.
*/
String key();

/**
* A Fake {@link Wallet}.
*
Expand Down Expand Up @@ -112,6 +118,11 @@ public Wallet merge(final Wallet other) {
public Iterable<Transaction> ledger() {
return new IterableOf<>();
}

@Override
public String key() {
return Long.toString(this.id);
}
}

/**
Expand Down Expand Up @@ -185,5 +196,15 @@ public Iterable<Transaction> ledger() {
)
);
}

// @todo #54:30min Implement key method. This should return the
// public RSA key of the wallet owner in Base64. Also add a unit test
// to replace WalletTest.keyIsNotYetImplemented().
@Override
public String key() {
throw new UnsupportedOperationException(
"key() not yet supported"
);
}
}
}
59 changes: 56 additions & 3 deletions src/test/java/io/zold/api/CpTransactionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
package io.zold.api;

import java.io.IOException;
import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.StringContains;
import org.junit.Ignore;
import org.junit.Test;

/**
Expand All @@ -35,8 +39,57 @@
* @checkstyle MagicNumberCheck (500 lines)
*/
public final class CpTransactionTest {
@Test(expected = IOException.class)
public void cpTransactionIsNotYetImplemented() throws IOException {
new CpTransaction(1, 1234).amount();

@Test
@Ignore
public void returnAmount() throws IOException {
final long amount = 256;
MatcherAssert.assertThat(
"Cannot return amount",
new CpTransaction(amount, 1024).amount(),
new IsEqual<>(256)
);
}

@Test
@Ignore
public void returnSignatureForPositiveTransaction() throws IOException {
final long id = 1024;
MatcherAssert.assertThat(
"Cannot return signature",
new CpTransaction(256, id).signature(),
new IsEqual<>("1024")
);
}

@Test(expected = UnsupportedOperationException.class)
public void returnSignatureForNegativeTransaction() throws IOException {
throw new UnsupportedOperationException(
"returnSignatureForNegativeTransaction() not yet implemented"
);
}

@Test
@Ignore
public void returnPrefix() throws IOException {
final long id = 1024;
final Wallet wallet = new Wallet.Fake(id);
MatcherAssert.assertThat(
"Cannot return prefix",
wallet.key(),
new StringContains(new CpTransaction(256, id).prefix())
);
}

@Test
@Ignore
public void returnBeneficiary() throws IOException {
final long id = 1024;
final Wallet wallet = new Wallet.Fake(id);
MatcherAssert.assertThat(
"Cannot return beneficiary",
new CpTransaction(256, id).bnf(),
new IsEqual<>(wallet.key())
);
}
}
5 changes: 5 additions & 0 deletions src/test/java/io/zold/api/WalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ public void walletShouldBeAbleToReturnLedger() throws Exception {
);
}

@Test(expected = UnsupportedOperationException.class)
public void keyIsNotYetImplemented() throws IOException {
new Wallet.File(this.folder.newFile().toPath()).key();
}

private Path wallet(final long id) {
return this.wallet(Long.toHexString(id));
}
Expand Down

0 comments on commit 156d5b5

Please sign in to comment.