Skip to content

Commit bc73f97

Browse files
authored
Merge branch 'master' into feature/fix_query_language_translation_back_to_json
2 parents d3fd88b + ebb6c84 commit bc73f97

File tree

7 files changed

+30
-13
lines changed

7 files changed

+30
-13
lines changed

libindy/src/services/wallet/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,11 @@ impl WalletService {
239239
pub fn delete_wallet(&self, name: &str, credentials: &str) -> Result<(), WalletError> {
240240
trace!("delete_wallet >>> name: {:?}, credentials: {:?}", name, credentials);
241241

242-
let descriptor_json = _read_file(_wallet_descriptor_path(name))?; // FIXME: Better error!)?;
242+
let wallet_descriptor_path = _wallet_descriptor_path(name);
243+
if !wallet_descriptor_path.exists() {
244+
return Err(WalletError::NotFound("Wallet descriptor path does not exist.".to_string()));
245+
}
246+
let descriptor_json = _read_file(wallet_descriptor_path)?; // FIXME: Better error!)?;
243247
let descriptor: WalletDescriptor = WalletDescriptor::from_json(&descriptor_json)?;
244248

245249
let storage_types = self.storage_types.borrow();
@@ -271,7 +275,11 @@ impl WalletService {
271275
pub fn open_wallet(&self, name: &str, runtime_config: Option<&str>, credentials: &str) -> Result<i32, WalletError> {
272276
trace!("open_wallet >>> name: {:?}, runtime_config: {:?}, credentials: {:?}", name, runtime_config, credentials);
273277

274-
let descriptor_json = _read_file(_wallet_descriptor_path(name))?; // FIXME: Better error!)?;
278+
let wallet_descriptor_path = _wallet_descriptor_path(name);
279+
if !wallet_descriptor_path.exists() {
280+
return Err(WalletError::NotFound("Wallet descriptor path does not exist.".to_string()));
281+
}
282+
let descriptor_json = _read_file(wallet_descriptor_path)?;
275283
let descriptor: WalletDescriptor = WalletDescriptor::from_json(&descriptor_json)?;
276284

277285
let storage_types = self.storage_types.borrow();
@@ -911,6 +919,15 @@ mod tests {
911919
wallet_service.open_wallet("test_wallet", None, &_credentials()).unwrap();
912920
}
913921

922+
#[test]
923+
fn wallet_service_open_unknown_wallet() {
924+
_cleanup();
925+
926+
let wallet_service = WalletService::new();
927+
let res = wallet_service.open_wallet("test_wallet_unknown", None, &_credentials());
928+
assert_match!(Err(WalletError::NotFound(_)), res);
929+
}
930+
914931
#[test]
915932
fn wallet_service_open_works_for_plugged() {
916933
TestUtils::cleanup_indy_home();

libindy/tests/wallet.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ mod medium_cases {
318318
TestUtils::cleanup_storage();
319319

320320
let res = WalletUtils::delete_wallet(WALLET, None);
321-
assert_eq!(res.unwrap_err(), ErrorCode::CommonIOError);
321+
assert_eq!(res.unwrap_err(), ErrorCode::WalletNotFoundError);
322322

323323
TestUtils::cleanup_storage();
324324
}
@@ -330,7 +330,7 @@ mod medium_cases {
330330
WalletUtils::create_wallet(POOL, WALLET, None, None, None).unwrap();
331331
WalletUtils::delete_wallet(WALLET, None).unwrap();
332332
let res = WalletUtils::delete_wallet(WALLET, None);
333-
assert_eq!(res.unwrap_err(), ErrorCode::CommonIOError);
333+
assert_eq!(res.unwrap_err(), ErrorCode::WalletNotFoundError);
334334

335335
TestUtils::cleanup_storage();
336336
}
@@ -355,7 +355,7 @@ mod medium_cases {
355355
TestUtils::cleanup_storage();
356356

357357
let res = WalletUtils::open_wallet(WALLET, None, None);
358-
assert_eq!(res.unwrap_err(), ErrorCode::CommonIOError);
358+
assert_eq!(res.unwrap_err(), ErrorCode::WalletNotFoundError);
359359

360360
TestUtils::cleanup_storage();
361361
}

wrappers/ios/libindy-pod/Indy-demoTests/Case Tests/Wallet/WalletHighCases.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ - (void)testDeleteWalletWorksForClosed {
148148

149149
- (void)testDeleteWalletWorksForUnknown {
150150
NSError *ret = [[WalletUtils sharedInstance] deleteWalletWithName:@"testDeleteWalletWorksForUnknown"];
151-
XCTAssertEqual(ret.code, CommonIOError, @"WalletUtils:deleteWalletWithName() returned wrong error");
151+
XCTAssertEqual(ret.code, WalletNotFoundError, @"WalletUtils:deleteWalletWithName() returned wrong error");
152152
}
153153

154154
// MARK: - Open wallet
@@ -200,7 +200,7 @@ - (void)testOpenWalletWorksForNotCreatedWallet {
200200
NSError *ret = [[WalletUtils sharedInstance] openWalletWithName:[TestUtils wallet]
201201
config:nil
202202
outHandle:nil];
203-
XCTAssertEqual(ret.code, CommonIOError, @"WalletUtils:openWalletWithName() failed");
203+
XCTAssertEqual(ret.code, WalletNotFoundError, @"WalletUtils:openWalletWithName() failed");
204204
}
205205

206206
// MARK: - Close wallet

wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/DeleteWalletTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void testDeleteWalletWorksForOpened() throws Exception {
5151
@Test
5252
public void testDeleteWalletWorksForTwice() throws Exception {
5353
thrown.expect(ExecutionException.class);
54-
thrown.expectCause(isA(IOException.class));
54+
thrown.expectCause(isA(WalletNotFoundException.class));
5555

5656
Wallet.createWallet(POOL, WALLET, null, null, CREDENTIALS).get();
5757

@@ -74,7 +74,7 @@ public void testDeleteWalletWorksForPlugged() throws Exception {
7474
@Test
7575
public void testDeleteWalletWorksForNotCreated() throws Exception {
7676
thrown.expect(ExecutionException.class);
77-
thrown.expectCause(isA(IOException.class));
77+
thrown.expectCause(isA(WalletNotFoundException.class));
7878

7979
Wallet.deleteWallet(WALLET, CREDENTIALS).get();
8080
}

wrappers/java/src/test/java/org/hyperledger/indy/sdk/wallet/OpenWalletTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testOpenWalletWorksForPlugged() throws Exception {
6363
@Test
6464
public void testOpenWalletWorksForNotCreatedWallet() throws Exception {
6565
thrown.expect(ExecutionException.class);
66-
thrown.expectCause(isA(IOException.class));
66+
thrown.expectCause(isA(WalletNotFoundException.class));
6767

6868
Wallet.openWallet("openWalletWorksForNotCreatedWallet", null, CREDENTIALS).get();
6969
}

wrappers/python/tests/wallet/test_delete_wallet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def test_delete_wallet_works_for_twice(wallet_name, xwallet, credentials):
3737
with pytest.raises(IndyError) as e:
3838
await wallet.delete_wallet(wallet_name, credentials)
3939

40-
assert ErrorCode.CommonIOError == e.value.error_code
40+
assert ErrorCode.WalletNotFoundError == e.value.error_code
4141

4242

4343
# noinspection PyUnusedLocal
@@ -46,4 +46,4 @@ async def test_delete_wallet_works_for_not_created(wallet_name, path_home, crede
4646
with pytest.raises(IndyError) as e:
4747
await wallet.delete_wallet(wallet_name, credentials)
4848

49-
assert ErrorCode.CommonIOError == e.value.error_code
49+
assert ErrorCode.WalletNotFoundError == e.value.error_code

wrappers/python/tests/wallet/test_open_wallet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async def test_open_wallet_works(wallet_config, wallet_handle):
1515
async def test_open_wallet_works_for_not_created_wallet(credentials):
1616
with pytest.raises(IndyError) as e:
1717
await wallet.open_wallet('wallet_not_created', None, credentials)
18-
assert ErrorCode.CommonIOError == e.value.error_code
18+
assert ErrorCode.WalletNotFoundError == e.value.error_code
1919

2020

2121
@pytest.mark.asyncio

0 commit comments

Comments
 (0)