Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Dec 4, 2018
2 parents 07545a9 + d5ae2e9 commit d746f59
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
23 changes: 21 additions & 2 deletions src/main/java/io/zold/api/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
* Beware that tests should be refactored to take care of file cleanup
* after each case that merges wallets.
*/
@SuppressWarnings({"PMD.ShortMethodName", "PMD.TooManyMethods"})
@SuppressWarnings({"PMD.ShortMethodName", "PMD.TooManyMethods",
"PMD.UnusedFormalParameter"})
public interface Wallet {
/**
* This wallet's ID: an unsigned 64-bit integer.
Expand Down Expand Up @@ -92,6 +93,13 @@ public interface Wallet {
/**
* A Fake {@link Wallet}.
* @since 1.0
* @todo #65:30min Complete Wallet implementations with id, public RSA
* key and network id. Wallets.create(Long, String, String) must
* create a Wallet with these strings set and a constructor must be
* added to all Walletl realizations (Wallet(final long id, final String
* pubkey, final String network, final Transaction... transactions). After
* completing these implementations fix tests that uses Wallets.create()
* and all Wallet realizations.
*/
final class Fake implements Wallet {

Expand All @@ -106,7 +114,7 @@ final class Fake implements Wallet {
private final Iterable<Transaction> transactions;

/**
* Ctor.
* Constructor.
* @param id The wallet id.
*/
public Fake(final long id) {
Expand All @@ -122,6 +130,17 @@ public Fake(final long id, final Transaction... transactions) {
this(id, new IterableOf<>(transactions));
}

/**
* Constructor.
* @param id The wallet id.
* @param pubkey The public RSA key of the wallet owner.
* @param network The network the walet belongs to.
* @checkstyle UnusedFormalParameter (2 lines)
*/
public Fake(final long id, final String pubkey, final String network) {
this(id);
}

/**
* Ctor.
* @param id The wallet id.
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/zold/api/Wallets.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,16 @@ public interface Wallets extends Iterable<Wallet> {
* @throws IOException If an error occurs.
*/
Wallet create() throws IOException;

/**
* Create a wallet.
*
* @param id The wallet id.
* @param pubkey The wallet public key.
* @param network The network the wallet belongs.
* @return The new wallet.
* @throws IOException If an error occurs.
*/
Wallet create(final long id, final String pubkey, final String
network) throws IOException;
}
15 changes: 12 additions & 3 deletions src/main/java/io/zold/api/WalletsIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ public WalletsIn(final Scalar<Path> pth, final String ext,
this.random = random;
}

// @todo #12:30min Create the new wallet in the path with all wallets.
// It should contain the correct content according to the
// white paper. Also add a the test to validate everything is ok.
@Override
public Wallet create() throws IOException {
final Path wpth = this.path.value().resolve(
Expand All @@ -139,6 +136,18 @@ public Wallet create() throws IOException {
return new Wallet.File(wpth);
}

@Override
// @todo #65:30min Create the new wallet in the path with all wallets.
// It should contain the correct content according to the
// white paper (network, protocol version, id and public RSA key). After
// this remove exception expect for tests on WalletsInTest.
public Wallet create(final long id, final String pubkey, final String
network) throws IOException {
throw new UnsupportedOperationException(
"WalletsIn.create(String, String, String) not supported"
);
}

@Override
public Iterator<Wallet> iterator() {
try {
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/io/zold/api/WalletsInTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ public void createsWalletInFolder() throws IOException {
);
}

@Test(expected = UnsupportedOperationException.class)
public void createsRightWallet() throws IOException {
final Path path = this.folder.newFolder().toPath();
final String network = "zold";
final String pubkey = "AAAAB3NzaC1yc2EAAAADAQABAAABAQC";
final long id = 1;
final Wallet actual = new WalletsIn(path).create(
id, pubkey, network
);
final Wallet expected = new Wallet.Fake(
id,
pubkey,
network
);
MatcherAssert.assertThat(
"Created wallet with different values than expected",
actual,
new IsEqual<>(expected)
);
}

@Test
public void doesNotOverwriteExistingWallet() throws Exception {
final Path path = this.folder.newFolder().toPath();
Expand Down

3 comments on commit d746f59

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on d746f59 Dec 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 12-1be65647 disappeared from src/main/java/io/zold/api/WalletsIn.java, that's why I closed #65. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on d746f59 Dec 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 65-14add99d discovered in src/main/java/io/zold/api/WalletsIn.java and submitted as #85. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on d746f59 Dec 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 65-64ffac10 discovered in src/main/java/io/zold/api/Wallet.java and submitted as #86. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.