Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit f414e13

Browse files
authored
Merge branch 'danielclasen:master' into master
2 parents 88ae29a + 0865313 commit f414e13

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

src/main/java/cash/ird/walletd/IridiumAPI.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public interface IridiumAPI {
8181
String createAddress() throws IridiumWalletdException;
8282

8383
/**
84-
* Create a new address on the current wallet container with either a {@link cash.ird.walletd.model.request.PrivateKey} or {@link cash.ird.walletd.model.request.PublicKey}
84+
* Imports an existing address on the current wallet container with either a {@link cash.ird.walletd.model.request.PrivateKey} or {@link cash.ird.walletd.model.request.PublicKey}
8585
*
8686
* @return the new address
8787
* @throws IridiumWalletdException in case of an RPC Error

src/main/java/cash/ird/walletd/IridiumClient.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cash.ird.walletd.model.request.BlockRange;
77
import cash.ird.walletd.model.request.Key;
88
import cash.ird.walletd.model.response.*;
9+
import cash.ird.walletd.rpc.HttpClient;
910
import cash.ird.walletd.rpc.WalletdClient;
1011
import cash.ird.walletd.rpc.exception.IridiumWalletdException;
1112
import cash.ird.walletd.rpc.method.RequestMethod;
@@ -33,6 +34,10 @@ public IridiumClient(String url) {
3334
this.walletdClient = new WalletdClient(url);
3435
}
3536

37+
public IridiumClient(String url, HttpClient httpClient) {
38+
this.walletdClient = new WalletdClient(url, httpClient);
39+
}
40+
3641
@Override
3742
public boolean reset() throws IridiumWalletdException {
3843
return this.walletdClient.doRequest(RequestMethod.RESET, NoopResponse.class) != null;
@@ -87,9 +92,9 @@ public String createAddress(Key key) throws IridiumWalletdException {
8792
if (key != null) {
8893
Map<String, Object> params = buildParams();
8994
if (key.isPrivate()) {
90-
params.put("secretSpendKey", key.getValue());
95+
params.put("spendSecretKey", key.getValue());
9196
} else {
92-
params.put("publicSpendKey", key.getValue());
97+
params.put("spendPublicKey", key.getValue());
9398
}
9499

95100
return this.walletdClient.doRequest(RequestMethod.CREATE_ADDRESS, Collections.unmodifiableMap(params), AddressResponse.class);

src/test/groovy/cash/ird/walletd/IridiumClientTest.groovy

+28-9
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ class IridiumClientTest extends Specification {
3333
wallet1 = getClass().getResource("/iridium/wallet1/wallet.adr").readLines().first()
3434

3535
sut2 = new IridiumClient("localhost", 14009)
36-
wallet2 = getClass().getResource("/iridium/wallet2/wallet.adr").readLines().first()
3736

3837
waitForBalance(sut, wallet1, 1)
39-
// waitForBalance(sut2, wallet2, 0)
4038
waitForBlockHeightTotal(sut, 10)
4139
waitForBlockHeightTotal(sut2, 10)
4240
}
4341

42+
void setup() {
43+
wallet2 = sut2.createAddress()
44+
45+
def status = sut.getStatus()
46+
waitForBlockHeightTotal(sut2, status.getBlockCount().toInteger())
47+
}
48+
4449
void cleanupSpec() {
4550
sut.reset()
4651
sut2.reset()
@@ -139,6 +144,7 @@ class IridiumClientTest extends Specification {
139144
address != null
140145
}
141146

147+
@Ignore("ignored until we figure out how that is working in the core")
142148
def "CreateAddress with publicKey"() {
143149
when:
144150
String address = sut.createAddress(PublicKey.of("test123"))
@@ -147,12 +153,25 @@ class IridiumClientTest extends Specification {
147153
address != null
148154
}
149155

150-
def "CreateAddress with privateKey"() {
156+
def "Import wallet from viewSecretKey and spendSecretKey"() {
157+
given:
158+
def testAddress = sut.createAddress()
159+
def keyPair = sut.getSpendKeys(testAddress)
160+
def viewKey = sut.getViewKey()
161+
162+
151163
when:
152-
String address = sut.createAddress(PrivateKey.of("secr3t"))
164+
sut2.reset(viewKey)
165+
String address = sut2.createAddress(PrivateKey.of(keyPair.getSecretKey()))
153166

154167
then:
155-
address != null
168+
address == testAddress
169+
170+
when:
171+
def addresses = sut2.getAddresses()
172+
173+
then:
174+
addresses.size() == 1
156175
}
157176

158177
def "DeleteAddress"() {
@@ -520,14 +539,14 @@ class IridiumClientTest extends Specification {
520539
private static void waitForBalance(IridiumAPI api, String address, long threshold) {
521540
while (api.getBalance(address).availableBalance < threshold) {
522541
log.info("Waiting for valid balance >=$threshold on wallet $address...")
523-
sleep(1000)
542+
sleep(5000)
524543
}
525544
}
526545

527546
private static void waitForTransactionConfirmation(IridiumAPI api, String transactionHash) {
528547
while (api.getUnconfirmedTransactionHashes().contains(transactionHash)) {
529548
log.info("Waiting for tx $transactionHash to get confirmed...")
530-
sleep(1000)
549+
sleep(5000)
531550
}
532551
}
533552

@@ -536,15 +555,15 @@ class IridiumClientTest extends Specification {
536555
def currentHeight
537556
while ((currentHeight = api.getStatus().knownBlockCount) && currentHeight < desiredHeight) {
538557
log.info("Waiting for blockHeight>$desiredHeight, current blockHeight=$currentHeight...")
539-
sleep(1000)
558+
sleep(5000)
540559
}
541560
}
542561

543562
private static void waitForBlockHeightTotal(IridiumAPI api, int desiredHeight) {
544563
def currentHeight
545564
while ((currentHeight = api.getStatus().knownBlockCount) && currentHeight < desiredHeight) {
546565
log.info("Waiting for blockHeight>$desiredHeight, current blockHeight=$currentHeight...")
547-
sleep(1000)
566+
sleep(5000)
548567
}
549568
}
550569

0 commit comments

Comments
 (0)