Add wallet protect method tests

Some of these 'method' tests make more than one gRPC call, but
they are for checking correctness of a single gRPC method,
and don't quite fall into the 'scenario' test category.
This commit is contained in:
ghubstan 2020-07-14 15:04:42 -03:00
parent 5df0b1ec4b
commit 2cf7915f25
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
2 changed files with 78 additions and 5 deletions

View File

@ -18,8 +18,10 @@
package bisq.apitest.method;
import bisq.proto.grpc.GetBalanceRequest;
import bisq.proto.grpc.LockWalletRequest;
import bisq.proto.grpc.RemoveWalletPasswordRequest;
import bisq.proto.grpc.SetWalletPasswordRequest;
import bisq.proto.grpc.UnlockWalletRequest;
@ -41,9 +43,25 @@ public class MethodTest extends ApiTestCase {
return RemoveWalletPasswordRequest.newBuilder().setPassword("password").build();
}
protected final UnlockWalletRequest createUnlockWalletRequest(String password, long timeout) {
return UnlockWalletRequest.newBuilder().setPassword(password).setTimeout(timeout).build();
}
protected final LockWalletRequest createLockWalletRequest() {
return LockWalletRequest.newBuilder().build();
}
// Convenience methods for calling frequently used & thoroughly tested gRPC services.
protected final long getBalance() {
return grpcStubs.walletsService.getBalance(createBalanceRequest()).getBalance();
}
protected final void unlockWallet(String password, long timeout) {
grpcStubs.walletsService.unlockWallet(createUnlockWalletRequest(password, timeout));
}
protected final void lockWallet() {
grpcStubs.walletsService.lockWallet(createLockWalletRequest());
}
}

View File

@ -28,8 +28,8 @@ public class WalletProtectionTest extends MethodTest {
@Test
@Order(1)
public void testSetWalletPassword() {
var setPasswordRequest = createSetWalletPasswordRequest("password");
grpcStubs.walletsService.setWalletPassword(setPasswordRequest);
var request = createSetWalletPasswordRequest("password");
grpcStubs.walletsService.setWalletPassword(request);
}
@Test
@ -42,10 +42,65 @@ public class WalletProtectionTest extends MethodTest {
@Test
@Order(3)
public void testUnlockWalletFor4Seconds() {
var request = createUnlockWalletRequest("password", 4);
grpcStubs.walletsService.unlockWallet(request);
getBalance(); // should not throw 'wallet locked' exception
sleep(4500); // let unlock timeout expire
exceptionRule.expect(StatusRuntimeException.class);
exceptionRule.expectMessage("UNKNOWN: wallet is locked");
getBalance();
}
@Test
@Order(4)
public void testGetBalanceAfterUnlockTimeExpiryShouldThrowException() {
var request = createUnlockWalletRequest("password", 3);
grpcStubs.walletsService.unlockWallet(request);
sleep(4000); // let unlock timeout expire
exceptionRule.expect(StatusRuntimeException.class);
exceptionRule.expectMessage("UNKNOWN: wallet is locked");
getBalance();
}
@Test
@Order(5)
public void testLockWalletBeforeUnlockTimeoutExpiry() {
unlockWallet("password", 60);
var request = createLockWalletRequest();
grpcStubs.walletsService.lockWallet(request);
exceptionRule.expect(StatusRuntimeException.class);
exceptionRule.expectMessage("UNKNOWN: wallet is locked");
getBalance();
}
@Test
@Order(6)
public void testLockWalletWhenWalletAlreadyLockedShouldThrowException() {
exceptionRule.expect(StatusRuntimeException.class);
exceptionRule.expectMessage("UNKNOWN: wallet is already locked");
var request = createLockWalletRequest();
grpcStubs.walletsService.lockWallet(request);
}
@Test
@Order(7)
public void testUnlockWalletTimeoutOverride() {
unlockWallet("password", 2);
sleep(500); // override unlock timeout after 0.5s
unlockWallet("password", 6);
sleep(5000);
getBalance(); // getbalance 5s after resetting unlock timeout to 6s
}
@Test
@Order(8)
public void testRemoveWalletPassword() {
var removePasswordRequest = createRemoveWalletPasswordRequest("password");
grpcStubs.walletsService.removeWalletPassword(removePasswordRequest);
getBalance(); // should not throw exception
var request = createRemoveWalletPasswordRequest("password");
grpcStubs.walletsService.removeWalletPassword(request);
getBalance(); // should not throw 'wallet locked' exception
}
@AfterClass