mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01:00
WalletTool: fix --date
option
Also adds tests for the `create` action.
This commit is contained in:
parent
d65aefd93e
commit
b8bfbcc658
2 changed files with 31 additions and 1 deletions
|
@ -86,6 +86,7 @@ import java.text.ParseException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -1213,7 +1214,7 @@ public class WalletTool implements Callable<Integer> {
|
||||||
if (unixtime != null)
|
if (unixtime != null)
|
||||||
return Optional.of(Instant.ofEpochSecond(unixtime));
|
return Optional.of(Instant.ofEpochSecond(unixtime));
|
||||||
else if (date != null)
|
else if (date != null)
|
||||||
return Optional.of(Instant.from(date));
|
return Optional.of(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||||
else
|
else
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,11 @@
|
||||||
package org.bitcoinj.wallettool;
|
package org.bitcoinj.wallettool;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import picocli.CommandLine;
|
import picocli.CommandLine;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
|
@ -26,6 +29,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
* Basic functional/integration tests of {@code wallet-tool}
|
* Basic functional/integration tests of {@code wallet-tool}
|
||||||
*/
|
*/
|
||||||
public class WalletToolTest {
|
public class WalletToolTest {
|
||||||
|
@TempDir
|
||||||
|
File tempDir;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void canConstruct() {
|
void canConstruct() {
|
||||||
|
@ -55,6 +60,30 @@ public class WalletToolTest {
|
||||||
assertEquals(0, exitCode);
|
assertEquals(0, exitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createNoFileSpecified() {
|
||||||
|
int exitCode = execute("create");
|
||||||
|
// TODO: currently a stacktrace, give user-friendly error
|
||||||
|
assertEquals(1, exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createMinimal(@TempDir File tempDir) {
|
||||||
|
String walletFile = tempDir.getPath() + "/wallet";
|
||||||
|
int exitCode = execute("create", "--wallet", walletFile);
|
||||||
|
|
||||||
|
assertEquals(0, exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createWithDate(@TempDir File tempDir) {
|
||||||
|
String walletFile = tempDir.getPath() + "/wallet";
|
||||||
|
String date = "2023-05-01";
|
||||||
|
int exitCode = execute("create", "--wallet", walletFile, "--date", date);
|
||||||
|
|
||||||
|
assertEquals(0, exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the wallet-tool via {@link CommandLine#execute(String...)}
|
* Run the wallet-tool via {@link CommandLine#execute(String...)}
|
||||||
* @param args command-line arguments
|
* @param args command-line arguments
|
||||||
|
|
Loading…
Add table
Reference in a new issue