Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from cybermag/feature/ledger-ios-tests
Browse files Browse the repository at this point in the history
Feature/ledger ios tests
  • Loading branch information
cybermag authored Jun 6, 2017
2 parents 2ff62a4 + 788c015 commit f110a48
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 133 deletions.
31 changes: 11 additions & 20 deletions wrappers/ios/libsovrin-pod/libsovrin-demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
3E0FCFD41EE6E15800E26EEE /* libPods-libsovrin-demo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E0FCFD31EE6E15800E26EEE /* libPods-libsovrin-demo.a */; };
3E0FCFD61EE6E15C00E26EEE /* libsovrin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E0FCFD51EE6E15C00E26EEE /* libsovrin.framework */; };
3E0FCFD71EE6E16C00E26EEE /* libsovrin.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3E0FCFD51EE6E15C00E26EEE /* libsovrin.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3E0FCFDC1EE6E21B00E26EEE /* libPods-libsovrin-demo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E0FCFD31EE6E15800E26EEE /* libPods-libsovrin-demo.a */; };
3E0FCFDD1EE6E21E00E26EEE /* libsovrin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E0FCFD51EE6E15C00E26EEE /* libsovrin.framework */; };
3E0FCFDE1EE6E22700E26EEE /* libsovrin.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3E0FCFD51EE6E15C00E26EEE /* libsovrin.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3E2A7F8A1EC36186006194EC /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E2A7F891EC36186006194EC /* main.m */; };
3E2A7F8D1EC36186006194EC /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3E2A7F8C1EC36186006194EC /* AppDelegate.mm */; };
3E2A7F901EC36186006194EC /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3E2A7F8F1EC36186006194EC /* ViewController.m */; };
Expand All @@ -34,6 +28,8 @@
84881A871EE1BBDE001B5302 /* SignusUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84881A861EE1BBDE001B5302 /* SignusUtils.mm */; };
84881A8A1EE53E1B001B5302 /* Pool.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84881A891EE53E1B001B5302 /* Pool.mm */; };
84881A8C1EE553E5001B5302 /* LedgerUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84881A8B1EE553E5001B5302 /* LedgerUtils.mm */; };
84881A991EE6EA93001B5302 /* libsovrin.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84881A981EE6EA93001B5302 /* libsovrin.framework */; };
84881A9A1EE6EA93001B5302 /* libsovrin.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 84881A981EE6EA93001B5302 /* libsovrin.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -47,32 +43,30 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
3E0FCFD01EE6E12100E26EEE /* CopyFiles */ = {
3ED5BE501EC4985500881380 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 12;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
3E0FCFD71EE6E16C00E26EEE /* libsovrin.framework in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
3ED5BE501EC4985500881380 /* CopyFiles */ = {
84881A971EE6EA83001B5302 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
3E0FCFDE1EE6E22700E26EEE /* libsovrin.framework in CopyFiles */,
84881A9A1EE6EA93001B5302 /* libsovrin.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
070B273A719A0DC38A316D73 /* Pods-libsovrin-demo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-libsovrin-demo.release.xcconfig"; path = "Pods/Target Support Files/Pods-libsovrin-demo/Pods-libsovrin-demo.release.xcconfig"; sourceTree = "<group>"; };
3E0FCFD31EE6E15800E26EEE /* libPods-libsovrin-demo.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libPods-libsovrin-demo.a"; path = "../../../../../../Library/Developer/Xcode/DerivedData/libsovrin-fpqoyzkovibgszalhhmmnlcetkfp/Build/Products/Debug-iphoneos/libPods-libsovrin-demo.a"; sourceTree = "<group>"; };
3E0FCFD51EE6E15C00E26EEE /* libsovrin.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = libsovrin.framework; path = "../../../../../../Library/Developer/Xcode/DerivedData/libsovrin-fpqoyzkovibgszalhhmmnlcetkfp/Build/Products/Debug-iphoneos/libsovrin.framework"; sourceTree = "<group>"; };
3E2A7F851EC36186006194EC /* libsovrin-demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "libsovrin-demo.app"; sourceTree = BUILT_PRODUCTS_DIR; };
3E2A7F891EC36186006194EC /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
3E2A7F8B1EC36186006194EC /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -107,6 +101,7 @@
84881A891EE53E1B001B5302 /* Pool.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Pool.mm; sourceTree = "<group>"; };
84881A8B1EE553E5001B5302 /* LedgerUtils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LedgerUtils.mm; sourceTree = "<group>"; };
84881A8D1EE553F9001B5302 /* LedgerUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LedgerUtils.h; sourceTree = "<group>"; };
84881A981EE6EA93001B5302 /* libsovrin.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = libsovrin.framework; sourceTree = BUILT_PRODUCTS_DIR; };
A49C6DA8781C6A9455450851 /* Pods-libsovrin-demo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-libsovrin-demo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-libsovrin-demo/Pods-libsovrin-demo.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -115,17 +110,14 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3E0FCFD61EE6E15C00E26EEE /* libsovrin.framework in Frameworks */,
3E0FCFD41EE6E15800E26EEE /* libPods-libsovrin-demo.a in Frameworks */,
84881A991EE6EA93001B5302 /* libsovrin.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
3E2A7F9B1EC36187006194EC /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3E0FCFDD1EE6E21E00E26EEE /* libsovrin.framework in Frameworks */,
3E0FCFDC1EE6E21B00E26EEE /* libPods-libsovrin-demo.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -135,6 +127,7 @@
3E2A7F7C1EC36186006194EC = {
isa = PBXGroup;
children = (
84881A981EE6EA93001B5302 /* libsovrin.framework */,
3E2A7F871EC36186006194EC /* libsovrin-demo */,
3E2A7FA11EC36187006194EC /* libsovrin-demoTests */,
3E2A7F861EC36186006194EC /* Products */,
Expand Down Expand Up @@ -241,8 +234,6 @@
84DF55ECAD03C4B4CEE16BD1 /* Frameworks */ = {
isa = PBXGroup;
children = (
3E0FCFD51EE6E15C00E26EEE /* libsovrin.framework */,
3E0FCFD31EE6E15800E26EEE /* libPods-libsovrin-demo.a */,
);
name = Frameworks;
sourceTree = "<group>";
Expand All @@ -269,7 +260,7 @@
3E2A7F831EC36186006194EC /* Resources */,
B01B1FF1729B4A65C01EC15D /* [CP] Embed Pods Frameworks */,
E6EB6F49635D20DFFF587CE2 /* [CP] Copy Pods Resources */,
3E0FCFD01EE6E12100E26EEE /* CopyFiles */,
84881A971EE6EA83001B5302 /* Embed Frameworks */,
);
buildRules = (
);
Expand Down
4 changes: 4 additions & 0 deletions wrappers/ios/libsovrin-pod/libsovrin-demoTests/Anoncreds.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ -(void) testAnoncredsWorksForSingleIssuerSingleProverTest
XCTAssertNotNil(revocRegUpdateJson, @"revocRegUpdateJson is nil!");
NSLog(@"xclaimJson: %@", xclaimJson);
NSLog(@"revocRegUpdateJson: %@", revocRegUpdateJson);
// TODO: revocRegUpdateJson is empty

// 9. Prover store received Claim

// TODO: 110 error
res = [[AnoncredsUtils sharedInstance] proverStoreClaim: proverWalletHandle
claimsJson: xclaimJson];

Expand Down Expand Up @@ -399,6 +401,7 @@ -(void) testAnoncredsWorksForMultiplyIssuerSingleProver

//13. Prover store received GVT Claim

// TODO: 110 error
res = [[AnoncredsUtils sharedInstance] proverStoreClaim:proverWalletHandle
claimsJson:gvtClaimJson];

Expand Down Expand Up @@ -753,6 +756,7 @@ -(void) testAnoncredsWorksForSingleIssuerMultiplyClaimsSingleProver

//11. Prover store received GVT Claim

// TODO: 110 error
res = [[AnoncredsUtils sharedInstance] proverStoreClaim:proverWalletHandle
claimsJson:gvtClaimJson];

Expand Down
65 changes: 22 additions & 43 deletions wrappers/ios/libsovrin-pod/libsovrin-demoTests/Ledger.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,56 +129,32 @@ - (void) testNymRequestsWorks
NSLog(@"trusteePk = %@", trusteePk);

// 4. Create my did
// NSString* myDid = nil;
// NSString* myVerKey = nil;
// NSString* myPk = nil;
//
// NSString* myDidJson = [NSString stringWithFormat:@"{"\
// "\"seed\":\"000000000000000000000000My1\"" \
// "}"];
//
// res = [[SignusUtils sharedInstance] createMyDid:walletHandle
// myDidJson:myDidJson
// myDid:&myDid
// myVerkey:&myVerKey
// myPk:&myPk];
// XCTAssertEqual(res.code, Success, @"SignusUtils::createMyDid() failed");
// XCTAssertNotNil(myDid, @"myDid is nil!");
// // XCTAssertNotNil(myVerKey, @"myVerKey is nil!"); // can be nil?
// XCTAssertNotNil(myPk, @"myPk is nil!");
NSString* myDid = nil;
NSString* myVerKey = nil;
NSString* myPk = nil;

NSString* myDidJson = [NSString stringWithFormat:@"{"\
"\"seed\":\"000000000000000000000000My1\"" \
"}"];
XCTestExpectation* completionExpectation = [[ XCTestExpectation alloc] initWithDescription: @"completion finished"];

__block NSString *myDid = nil;
__block NSString *myVerkey = nil;
__block NSString *myPk = nil;
ret = [SovrinSignus createAndStoreMyDid: walletHandle
didJSON: myDidJson
completion: ^(NSError *error, NSString *did, NSString *verkey, NSString *pk)
{
XCTAssertEqual(error.code, Success, "createAndStoreMyDid() got error in completion");
NSLog(@"myDid:");
NSLog(@"did = %@", did);
NSLog(@"verkey = %@", verkey);
NSLog(@"pk = %@", pk);
myDid = did;
myVerkey = verkey;
myPk = pk;
[completionExpectation fulfill];
}];

[self waitForExpectations: @[completionExpectation] timeout:[TestUtils defaultTimeout]];
XCTAssertEqual(ret.code, Success, @"createAndStoreMyDid() failed!");
"\"seed\":\"000000000000000000000000My1\"" \
"}"];

// TODO: thread '<unnamed>' panicked at 'destination and source slices have different lengths', src/libcore/slice.rs:519

ret = [[SignusUtils sharedInstance] createMyDid:walletHandle
myDidJson:myDidJson
myDid:&myDid
myVerkey:&myVerKey
myPk:&myPk];
XCTAssertEqual(ret.code, Success, @"SignusUtils::createMyDid() failed");
XCTAssertNotNil(myDid, @"myDid is nil!");
XCTAssertNotNil(myVerKey, @"myVerKey is nil!");
XCTAssertNotNil(myPk, @"myPk is nil!");

// 5. Build nym request

NSString *nymRequest = nil;
ret = [[LedgerUtils sharedInstance] buildNymRequest:trusteeDid
targetDid:myDid
verkey:myVerkey
verkey:myVerKey
xref:@""
data:@""
role:@""
Expand Down Expand Up @@ -264,8 +240,11 @@ - (void) testAttributeRequestsWorks
NSString* myPk = nil;

NSString* myDidJson = [NSString stringWithFormat:@"{"\
"\"seed\":\"000000000000000000000000My1\"," \
"\"seed\":\"000000000000000000000000My1\"" \
"}"];

// TODO: thread '<unnamed>' panicked at 'destination and source slices have different lengths', src/libcore/slice.rs:519
// note: Run with `RUST_BACKTRACE=1` for a backtrace.
res = [[SignusUtils sharedInstance] createMyDid:walletHandle
myDidJson:myDidJson
myDid:&myDid
Expand Down
95 changes: 95 additions & 0 deletions wrappers/ios/libsovrin-pod/libsovrin-demoTests/Pool.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,99 @@ - (void) testCreatePoolLedgerConfigWorks
[TestUtils cleanupStorage];
};

- (void) testOpenPoolLedgerWorks
{
[TestUtils cleanupStorage];

NSString *name = @"pool_open";

NSError *ret = [[PoolUtils sharedInstance] createPoolLedgerConfig:name];
XCTAssertEqual(ret.code, Success, @"PoolUtils::createPoolLedgerConfig() failed!");

SovrinHandle poolHandle = 0;
ret = [[PoolUtils sharedInstance] openPoolLedger:name config:nil poolHandler:&poolHandle];
XCTAssertEqual(ret.code, Success, @"PoolUtils::openPoolLedger() failed!");

[TestUtils cleanupStorage];
}

- (void)testOpenPoolLedgerWorksForTwice
{
[TestUtils cleanupStorage];
NSString *poolName = @"pool_open_twice";

NSError *ret = [[PoolUtils sharedInstance] createPoolLedgerConfig:poolName];
XCTAssertEqual(ret.code, Success, @"PoolUtils::createPoolLedgerConfig() failed!");

SovrinHandle poolHandle = 0;
ret = [[PoolUtils sharedInstance] openPoolLedger:poolName
config:nil
poolHandler:&poolHandle];
XCTAssertEqual(ret.code, Success, @"PoolUtils::openPoolLedger() failed!");

ret = [[PoolUtils sharedInstance] openPoolLedger:poolName
config:nil
poolHandler:&poolHandle];
// TODO: PoolLedgerInvalidConfiguration is returned.
XCTAssertEqual(ret.code, PoolLedgerInvalidPoolHandle, @"PoolUtils::openPoolLedger() failed!");

[TestUtils cleanupStorage];
}

- (void) testSovrinSubmitRequestWorks
{
[TestUtils cleanupStorage];
NSString *poolName = @"test_submit_tx";

// 1. Create pool ledger config
NSError *ret = [[PoolUtils sharedInstance] createPoolLedgerConfig:poolName];
XCTAssertEqual(ret.code, Success, @"PoolUtils::createPoolLedgerConfig() failed!");

// 2. Open pool ledger
SovrinHandle poolHandle = 0;
ret = [[PoolUtils sharedInstance] openPoolLedger:poolName
config:nil
poolHandler:&poolHandle];
XCTAssertEqual(ret.code, Success, @"PoolUtils::openPoolLedger() failed!");


NSString *request = [NSString stringWithFormat:@"{"\
"\"reqId\":\"1491566332010860\"," \
"\"identifier\":\"Th7MpTaRZVRYnPiabds81Y\"," \
"\"operation\":{"\
"\"type\":\"105\","\
"\"dest\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\"},"\
"\"signature\":\"4o86XfkiJ4e2r3J6Ufoi17UU3W5Zi9sshV6FjBjkVw4sgEQFQov9dxqDEtLbAJAWffCWd5KfAk164QVo7mYwKkiV\"" \
"}"];

NSString *responseJson;
// TODO: 110 error, response is empty
ret = [[PoolUtils sharedInstance] sendRequest:poolHandle
request:request
response:&responseJson];
XCTAssertEqual(ret.code, Success, @"PoolUtils::sendRequest() failed!");
NSLog(@"responseJson: %@", responseJson);

NSDictionary *actualReply = [NSDictionary fromString:responseJson];

// Configure expected reply
NSMutableDictionary *expecredReply = [NSMutableDictionary new];
expecredReply[@"op"] = @"REPLY"; // "REPLY".to_string(),

NSMutableDictionary *replyResult = [NSMutableDictionary new];
replyResult[@"req_id"] = @"1491566332010860";
replyResult[@"data"] = [NSString stringWithFormat:@"{"\
"\"dest\":\"FYmoFw55GeQH7SRFa37dkx1d2dZ3zUF8ckg7wmL7ofN4\"," \
"\"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\"," \
"\"role\":\"2\"," \
"\"verkey\":null" \
"}"];
replyResult[@"identifier"] = @"Th7MpTaRZVRYnPiabds81Y";

// Actual reply
XCTAssertEqual(actualReply, expecredReply, @"replies are not equal!");

[TestUtils cleanupStorage];
}

@end
5 changes: 3 additions & 2 deletions wrappers/ios/libsovrin-pod/libsovrin-demoTests/PoolUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

- (NSString *)createPoolConfig:(NSString *)poolName;

- (NSError *)openPoolLedger:(NSString *)configName
config:(NSString *)config;
- (NSError *)openPoolLedger:(NSString*)poolName
config:(NSString*)config
poolHandler:(SovrinHandle*)handle;

- (NSError *)sendRequest:(SovrinHandle)poolHandle
request:(NSString *)request
Expand Down
Loading

0 comments on commit f110a48

Please sign in to comment.