Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete deprecated init functions, migrate tests #199

Merged
merged 9 commits into from
Nov 12, 2020
2 changes: 1 addition & 1 deletion demo/java/src/main/java/Alice.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void main(String[] args) throws Exception {
.put("$", "protocol_version", "2")
.put("$", "genesis_path", System.getProperty("user.dir") + "/genesis.txn").jsonString();
logger.info("#9 Initialize libvcx with new configuration\n" + prettyJson(vcxConfig));
VcxApi.vcxInitWithConfig(vcxConfig).get();
//todo: here vcx_init_core, vcx_pool_open, vcx_wallet_open should be used to initialize library state

logger.info("Input faber invitation details\nEnter your invite details:");
Scanner sc = new Scanner(System.in);
Expand Down
2 changes: 1 addition & 1 deletion demo/java/src/main/java/Faber.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void main(String[] args) throws Exception {
.put("$", "protocol_version", "2")
.put("$", "genesis_path", System.getProperty("user.dir") + "/genesis.txn").jsonString();
logger.info("#2 Using following agent provision to initialize VCX\n" + prettyJson(vcxConfig));
VcxApi.vcxInitWithConfig(vcxConfig).get();
// todo: here vcx_init_core, vcx_pool_open, vcx_wallet_open should be used to initialize library state

// define schema with actually needed
String version = getRandomInt(1, 99) + "." + getRandomInt(1, 99) + "." + getRandomInt(1, 99);
Expand Down
560 changes: 107 additions & 453 deletions libvcx/src/api/vcx.rs

Large diffs are not rendered by default.

33 changes: 25 additions & 8 deletions libvcx/src/utils/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ pub struct SetupWallet {
pub wallet_name: String,
pub wallet_key: String,
pub wallet_kdf: String,
skip_cleanup: bool
} // creates wallet with random name, configures wallet settings

pub struct SetupPoolConfig;
pub struct SetupPoolConfig {
skip_cleanup: bool
}

pub struct SetupLibraryWallet {
pub wallet_name: String,
Expand Down Expand Up @@ -162,15 +165,22 @@ impl SetupWallet {
create_wallet(&wallet_name, &wallet_key, &wallet_kdf, None, None, None).unwrap();
info!("SetupWallet:: init :: Wallet {} created", wallet_name);

SetupWallet { wallet_name, wallet_key, wallet_kdf }
SetupWallet { wallet_name, wallet_key, wallet_kdf, skip_cleanup: false }
}

pub fn skip_cleanup(mut self) -> SetupWallet{
self.skip_cleanup = true;
self
}
}

impl Drop for SetupWallet {
fn drop(&mut self) {
close_main_wallet();
delete_wallet(&self.wallet_name, &self.wallet_key, &self.wallet_kdf, None, None, None).unwrap();
reset_wallet_handle();
if self.skip_cleanup == false {
close_main_wallet();
delete_wallet(&self.wallet_name, &self.wallet_key, &self.wallet_kdf, None, None, None).unwrap();
reset_wallet_handle();
}
}
}

Expand All @@ -179,14 +189,21 @@ impl SetupPoolConfig {
create_test_ledger_config();
settings::set_config_value(settings::CONFIG_GENESIS_PATH, utils::get_temp_dir_path(settings::DEFAULT_GENESIS_PATH).to_str().unwrap());

SetupPoolConfig {}
SetupPoolConfig { skip_cleanup: false }
}

pub fn skip_cleanup(mut self) -> SetupPoolConfig {
self.skip_cleanup = true;
self
}
}

impl Drop for SetupPoolConfig {
fn drop(&mut self) {
delete_test_pool();
reset_pool_handle();
if self.skip_cleanup == false {
delete_test_pool();
reset_pool_handle();
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions wrappers/ios/vcx/ConnectMeVcx.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ extern void VcxWrapperCommonNumberStringCallback(vcx_command_handle_t xcommand_h

@interface ConnectMeVcx : NSObject

- (void)initWithConfig:(NSString *)config
completion:(void (^)(NSError *error))completion;

- (vcx_error_t) vcxInitCore:(NSString *)config;
- (void) vcxOpenWallet:(void (^)(NSError *error)) completion;
- (void) vcxOpenPool:(void (^)(NSError *error)) completion;
Expand Down
17 changes: 0 additions & 17 deletions wrappers/ios/vcx/ConnectMeVcx.m
Original file line number Diff line number Diff line change
Expand Up @@ -311,23 +311,6 @@ void VcxWrapperCommonNumberStringCallback(vcx_command_handle_t xcommand_handle,

@implementation ConnectMeVcx

- (void)initWithConfig:(NSString *)config
completion:(void (^)(NSError *error))completion
{
const char *config_char = [config cStringUsingEncoding:NSUTF8StringEncoding];
vcx_command_handle_t handle= [[VcxCallbacks sharedInstance] createCommandHandleFor:completion] ;
vcx_error_t ret = vcx_init_with_config(handle, config_char, VcxWrapperCommonCallback);
if( ret != 0 )
{
[[VcxCallbacks sharedInstance] deleteCommandHandleFor: handle];

dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"ERROR: initWithConfig: calling completion");
completion([NSError errorFromVcxError: ret]);
});
}
}

- (vcx_error_t) vcxInitCore:(NSString *)config
{
const char *config_char = [config cStringUsingEncoding:NSUTF8StringEncoding];
Expand Down
4 changes: 0 additions & 4 deletions wrappers/ios/vcx/include/libvcx.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,11 @@ vcx_error_t vcx_agent_provision_async(vcx_command_handle_t handle, const char *j
vcx_error_t vcx_agent_update_info(vcx_command_handle_t handle, const char *json, void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err));
//pub extern fn vcx_agent_update_info(command_handle : u32, json: *const c_char, cb: Option<extern fn(xcommand_handle: u32, err: u32, config: *const c_char)>) -> u32

vcx_error_t vcx_init_with_config(vcx_command_handle_t handle, const char *config, void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err));
vcx_error_t vcx_init_core(const char *config);
vcx_error_t vcx_open_pool(vcx_command_handle_t handle, void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err));
vcx_error_t vcx_open_wallet(vcx_command_handle_t handle, void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err));
vcx_error_t vcx_update_webhook_url(vcx_command_handle_t handle, const char *notification_webhook_url, void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err));

vcx_error_t vcx_init(vcx_command_handle_t handle, const char *config_path, void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err));
//pub extern fn vcx_init (command_handle: u32, config_path:*const c_char, cb: Option<extern fn(xcommand_handle: u32, err: u32)>) -> u32

vcx_error_t vcx_create_agent(vcx_command_handle_t handle, const char *config, void (*cb)(vcx_command_handle_t xhandle, vcx_error_t err, const char *xconfig));
vcx_error_t vcx_update_agent_info(vcx_command_handle_t handle, const char *info, void (*cb)(vcx_command_handle_t xhandle, vcx_error_t err));

Expand Down
3 changes: 1 addition & 2 deletions wrappers/ios/vcx/vcx-demo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
typedef unsigned int vcx_proof_handle_t;
typedef unsigned int vcx_command_handle_t;
typedef unsigned int vcx_bool_t;

vcx_error_t vcx_init(vcx_command_handle_t handle, const char *config_path,void (*cb)(vcx_command_handle_t command_handle, vcx_error_t err));

*/


Expand Down
5 changes: 0 additions & 5 deletions wrappers/ios/vcx/vcx-demoTests/RNIndy.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
//+(NSString*)findValue:(NSString*)values withKey:(NSString*)key;
//+(NSString*)replace:(NSString*)config findKey:(NSString*)key withValue:(NSString*)value;

-(void)simpleInit: (NSString *)config
completion:(void (^)(BOOL success))successful;
-(void)init: (NSString *)config
completion:(void (^)(BOOL success))successful;
-(void)getSerializedConnection: (NSInteger)connectionHandle
completion:(void (^)(BOOL success))successful;
-(void)deserializeConnection: (NSString *)serializedConnection
Expand All @@ -46,7 +42,6 @@
withConnectionHandle: (VcxHandle) connectionHandle
withPaymentHandle: (vcx_payment_handle_t) paymentHandle
completion:(void (^)(BOOL success))successful;
-(void)initWithConfig: (NSString *)config;
-(void)createOneTimeInfo: (NSString *)config
completion:(void (^)(BOOL success))successful;
-(void)createConnectionWithInvite: (NSString *)invitationId
Expand Down
70 changes: 0 additions & 70 deletions wrappers/ios/vcx/vcx-demoTests/RNIndy.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,58 +37,6 @@ +(NSString*)updateInitConfig:(NSString*)config
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

-(void)simpleInit: (NSString *)config
completion:(void (^)(BOOL success))successful
{

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, kNilOptions), ^{
[[[ConnectMeVcx alloc] init] initWithConfig:config completion:^(NSError *error) {
if (error != nil && error.code != 0 && error.code != 1044)
{
NSString *indyErrorCode = [NSString stringWithFormat:@"Error occurred while initializing vcx: %@ :: %ld", error.domain, (long)error.code];
NSLog(@"Value of indyErrorCode is: %@", indyErrorCode);
//return @false;
dispatch_async(dispatch_get_main_queue(), ^{
successful(NO);
});
}else{
NSLog(@"init was successful!");
//return @true;
dispatch_async(dispatch_get_main_queue(), ^{
successful(YES);
});
}
}];
});
}

-(void)init: (NSString *)config
completion:(void (^)(BOOL success))successful
{

config = [RNIndy updateInitConfig:config withValues:[self lastOneTimeInfo]];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, kNilOptions), ^{
[[[ConnectMeVcx alloc] init] initWithConfig:config completion:^(NSError *error) {
if (error != nil && error.code != 0 && error.code != 1044)
{
NSString *indyErrorCode = [NSString stringWithFormat:@"Error occurred while initializing vcx: %@ :: %ld", error.domain, (long)error.code];
NSLog(@"Value of indyErrorCode is: %@", indyErrorCode);
//return @false;
dispatch_async(dispatch_get_main_queue(), ^{
successful(NO);
});
}else{
NSLog(@"init was successful!");
//return @true;
dispatch_async(dispatch_get_main_queue(), ^{
successful(YES);
});
}
}];
});
}

-(void)getSerializedConnection: (NSInteger)connectionHandle
completion:(void (^)(BOOL success))successful
{
Expand Down Expand Up @@ -300,24 +248,6 @@ -(void)sendClaimRequest: (NSInteger) credentialHandle
});
}

-(void)initWithConfig: (NSString *)config
{
// TODO: call vcx_init_with_config of libvcx
// pass a config as json string
// callback would get an error code and a json string back in case of success
NSError *error = nil; // remove this line after integrating libvcx method
if (error != nil && error.code != 0)
{
NSString *indyErrorCode = [NSString stringWithFormat:@"%ld", (long)error.code];
//reject(indyErrorCode, @"Init failed with error", error);
NSLog(@"Value of indyErrorCode is: %@", indyErrorCode);
} else {
//resolve(@{});
NSLog(@"initWithConfig was successful!");
}
}


//[[[ConnectMeVcx alloc] init] agentProvisionAsync:config completion:^(NSError *error, NSString *oneTimeInfo) {
// NSLog(@"applicationDidBecomeActive callback:%@",oneTimeInfo);
// if (error != nil && error.code != 0)
Expand Down
4 changes: 0 additions & 4 deletions wrappers/java/src/main/java/com/evernym/sdk/vcx/LibVcx.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ public abstract class LibVcx {
*/
public interface API extends Library {

public int vcx_init_with_config(int command_handle, String config, Callback cb);
public int vcx_init(int command_handle, String config_path, Callback cb);
public int vcx_init_minimal(String config);

public int vcx_init_core(String config);
public int vcx_open_pool(int command_handle, Callback cb);
public int vcx_open_wallet(int command_handle, Callback cb);
Expand Down
52 changes: 0 additions & 52 deletions wrappers/java/src/main/java/com/evernym/sdk/vcx/vcx/VcxApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,6 @@ public void callback(int commandHandle, int err) {
}
};

private static Callback vcxInitCB = new Callback() {


@SuppressWarnings({"unused", "unchecked"})
public void callback(int xcommandHandle, int err) {
logger.debug("callback() called with: xcommandHandle = [" + xcommandHandle + "], err = [" + err + "]");
CompletableFuture<Integer> future = (CompletableFuture<Integer>) removeFuture(xcommandHandle);
if (!checkCallback(future, err)) return;
int result = err;
future.complete(result);
}
};

public static CompletableFuture<Integer> vcxInitWithConfig(String configJson) throws VcxException {
ParamGuard.notNullOrWhiteSpace(configJson, "config");
logger.debug("vcxInitWithConfig() called with: configJson = [****]");
CompletableFuture<Integer> future = new CompletableFuture<Integer>();
int commandHandle = addFuture(future);

int result = LibVcx.api.vcx_init_with_config(
commandHandle,
configJson,
cmdHandleErrCodeCB);
checkResult(result);

return future;
}

public static void vcxInitCore(String configJson) throws VcxException {
ParamGuard.notNullOrWhiteSpace(configJson, "configJson");
logger.debug("vcxInitCore() called with: configJson = [****]");
Expand Down Expand Up @@ -105,30 +77,6 @@ public static CompletableFuture<Integer> vcxUpdateWebhookUrl(String notification
return future;
}

public static CompletableFuture<Integer> vcxInit(String configPath) throws VcxException {
ParamGuard.notNullOrWhiteSpace(configPath, "configPath");
logger.debug("vcxInit() called with: configPath = [" + configPath + "]");
CompletableFuture<Integer> future = new CompletableFuture<Integer>();
int commandHandle = addFuture(future);

int result = LibVcx.api.vcx_init(
commandHandle, configPath,
vcxInitCB);
checkResult(result);
return future;
}

public static int vcxInitMinimal(String configJson) throws VcxException {
ParamGuard.notNullOrWhiteSpace(configJson, "config");
logger.debug("vcxInitMinimal() called with: configJson = [" + configJson + "]");

int result = LibVcx.api.vcx_init_minimal(
configJson);
checkResult(result);

return result;
}

public static int vcxShutdown(Boolean deleteWallet) throws VcxException {
logger.debug("vcxShutdown() called with: deleteWallet = [" + deleteWallet + "]");
int result = LibVcx.api.vcx_shutdown(deleteWallet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ConnectionApiTest {
void setup() throws Exception {
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
if (! TestHelper.vcxInitialized) {
TestHelper.getResultFromFuture(VcxApi.vcxInit(TestHelper.VCX_CONFIG_TEST_MODE));
VcxApi.vcxInitCore(TestHelper.VCX_CONFIG_TEST_MODE);
TestHelper.vcxInitialized = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CredentialApiTest {
void setup() throws Exception {
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
if (!TestHelper.vcxInitialized) {
TestHelper.getResultFromFuture(VcxApi.vcxInit(TestHelper.VCX_CONFIG_TEST_MODE));
VcxApi.vcxInitCore(TestHelper.VCX_CONFIG_TEST_MODE);
TestHelper.vcxInitialized = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private CredentialDefPrepareForEndorserResult prepareCredDefForEndorser() throws
void setup() throws Exception {
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
if (!TestHelper.vcxInitialized) {
TestHelper.getResultFromFuture(VcxApi.vcxInit(TestHelper.VCX_CONFIG_TEST_MODE));
VcxApi.vcxInitCore(TestHelper.VCX_CONFIG_TEST_MODE);
TestHelper.vcxInitialized = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class DisclosedProofApiTest {
void setup() throws Exception {
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
if (!TestHelper.vcxInitialized) {
TestHelper.getResultFromFuture(VcxApi.vcxInit(TestHelper.VCX_CONFIG_TEST_MODE));
VcxApi.vcxInitCore(TestHelper.VCX_CONFIG_TEST_MODE);
TestHelper.vcxInitialized = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ProofApiTest {
void setup() throws Exception {
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
if (!TestHelper.vcxInitialized) {
TestHelper.getResultFromFuture(VcxApi.vcxInit(TestHelper.VCX_CONFIG_TEST_MODE));
VcxApi.vcxInitCore(TestHelper.VCX_CONFIG_TEST_MODE);
TestHelper.vcxInitialized = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SchemaApiTest {
void setup() throws Exception {
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
if (!TestHelper.vcxInitialized) {
TestHelper.getResultFromFuture(VcxApi.vcxInit(TestHelper.VCX_CONFIG_TEST_MODE));
VcxApi.vcxInitCore(TestHelper.VCX_CONFIG_TEST_MODE);
TestHelper.vcxInitialized = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TokenApiTest {
void setup() throws Exception {
System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
if (!TestHelper.vcxInitialized) {
TestHelper.getResultFromFuture(VcxApi.vcxInit(TestHelper.VCX_CONFIG_TEST_MODE));
VcxApi.vcxInitCore(TestHelper.VCX_CONFIG_TEST_MODE);
TestHelper.vcxInitialized = true;
}
}
Expand Down
Loading