Skip to content

Commit

Permalink
Address code review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
  • Loading branch information
mirgee committed Jul 8, 2021
1 parent c3b1e6a commit 0fdbe5b
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 193 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ members = [
debug = true
panic = 'unwind'
incremental = false

[profile.dev]
split-debuginfo = "unpacked"
4 changes: 2 additions & 2 deletions agents/node/vcxagent-core/src/services/service-connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { getMessagesForConnection } = require('../utils/messages')
const {
updateMessages,
Connection,
InviterStateType
ConnectionStateType
} = require('@hyperledger/node-vcx-wrapper')
const { pollFunction } = require('../common')

Expand Down Expand Up @@ -50,7 +50,7 @@ module.exports.createServiceConnections = function createServiceConnections ({ l

async function _progressConnectionToAcceptedState (connection, attemptsThreshold, timeoutMs) {
async function progressToAcceptedState () {
if (await connection.updateState() !== InviterStateType.Completed) {
if (await connection.updateState() !== ConnectionStateType.Finished) {
return { result: undefined, isFinished: false }
} else {
return { result: null, isFinished: true }
Expand Down
4 changes: 2 additions & 2 deletions agents/node/vcxagent-core/src/services/service-cred-holder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {filterOffersByCredentialName} = require('../utils/credentials')
const { filterOffersByAttr } = require('../utils/credentials')
const { filterOffersBySchema } = require('../utils/credentials')
const {
StateType,
HolderStateType,
Credential
} = require('@hyperledger/node-vcx-wrapper')
const { pollFunction } = require('../common')
Expand Down Expand Up @@ -50,7 +50,7 @@ module.exports.createServiceCredHolder = function createServiceCredHolder ({ log
async function waitForCredential (connectionId, holderCredentialId, attemptsThreshold = 10, timeoutMs = 2000) {
const connection = await loadConnection(connectionId)
const credential = await loadHolderCredential(holderCredentialId)
await _progressCredentialToState(credential, connection, 2, attemptsThreshold, timeoutMs)
await _progressCredentialToState(credential, connection, HolderStateType.Finished, attemptsThreshold, timeoutMs)
logger.info('Credential has been received.')
await saveHolderCredential(holderCredentialId, credential)
return getCredentialData(holderCredentialId)
Expand Down
4 changes: 2 additions & 2 deletions agents/node/vcxagent-core/test/utils/alice.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-env jest */
const { createVcxAgent } = require('../../src/index')
const { InviteeStateType, ProverStateType } = require('@hyperledger/node-vcx-wrapper')
const { ConnectionStateType, ProverStateType } = require('@hyperledger/node-vcx-wrapper')

module.exports.createAlice = async function createAlice () {
const agentName = `alice-${Math.floor(new Date() / 1000)}`
Expand All @@ -26,7 +26,7 @@ module.exports.createAlice = async function createAlice () {

await vcxAgent.serviceConnections.inviteeConnectionAcceptFromInvitation(connectionId, invite)
const connection = await vcxAgent.serviceConnections.getVcxConnection(connectionId)
expect(await connection.getState()).toBe(InviteeStateType.Requested)
expect(await connection.getState()).toBe(ConnectionStateType.Requested)

await vcxAgent.agentShutdownVcx()
}
Expand Down
6 changes: 3 additions & 3 deletions agents/node/vcxagent-core/test/utils/faber.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env jest */
const { buildRevocationDetails } = require('../../src')
const { createVcxAgent, getSampleSchemaData } = require('../../src')
const { InviterStateType, IssuerStateType, VerifierStateType } = require('@hyperledger/node-vcx-wrapper')
const { ConnectionStateType, IssuerStateType, VerifierStateType } = require('@hyperledger/node-vcx-wrapper')
const { getAliceSchemaAttrs, getFaberCredDefName, getFaberProofData } = require('./data')

module.exports.createFaber = async function createFaber () {
Expand Down Expand Up @@ -30,7 +30,7 @@ module.exports.createFaber = async function createFaber () {
const invite = await vcxAgent.serviceConnections.inviterConnectionCreate(connectionId, undefined)
logger.info(`Faber generated invite:\n${invite}`)
const connection = await vcxAgent.serviceConnections.getVcxConnection(connectionId)
expect(await connection.getState()).toBe(InviterStateType.Invited)
expect(await connection.getState()).toBe(ConnectionStateType.Invited)

await vcxAgent.agentShutdownVcx()

Expand All @@ -41,7 +41,7 @@ module.exports.createFaber = async function createFaber () {
logger.info('Faber is going to generate invite')
await vcxAgent.agentInitVcx()

expect(await vcxAgent.serviceConnections.connectionUpdate(connectionId)).toBe(InviterStateType.Responded)
expect(await vcxAgent.serviceConnections.connectionUpdate(connectionId)).toBe(ConnectionStateType.Responded)

await vcxAgent.agentShutdownVcx()
}
Expand Down
8 changes: 4 additions & 4 deletions agents/node/vcxagent-core/test/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { createFaber } = require('./faber')
const { createAlice } = require('./alice')
const { StateType } = require('@hyperledger/node-vcx-wrapper')
const { ConnectionStateType } = require('@hyperledger/node-vcx-wrapper')

module.exports.createPairedAliceAndFaber = async function createPairedAliceAndFaber () {
const alice = await createAlice()
const faber = await createFaber()
const invite = await faber.createInvite()
await alice.acceptInvite(invite)
await faber.updateConnection(StateType.RequestReceived)
await alice.updateConnection(StateType.Accepted)
await faber.updateConnection(StateType.Accepted)
await faber.updateConnection(ConnectionStateType.Responded)
await alice.updateConnection(ConnectionStateType.Finished)
await faber.updateConnection(ConnectionStateType.Finished)
return { alice, faber }
}
2 changes: 1 addition & 1 deletion ci/indy-pool.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ARG python3_orderedset_ver=2.0
ARG python3_psutil_ver=5.4.3
ARG python3_pympler_ver=0.5

RUN apt-get update -y && apt-get install -y --allow-unauthenticated \
RUN apt-get update -y && apt-get install -y \
python3-pyzmq=${python3_pyzmq_ver} \
indy-plenum=${indy_plenum_ver} \
indy-node=${indy_node_ver} \
Expand Down
15 changes: 0 additions & 15 deletions libvcx/src/api_lib/api_c/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,21 +1063,6 @@ mod tests {
assert!(handle > 0);
}

#[test]
#[cfg(feature = "general_test")]
fn test_vcx_credential_send_request() {
let _setup = SetupMocks::init();

let handle = credential::credential_create_with_offer("test_send_request", ARIES_CREDENTIAL_OFFER).unwrap();
assert_eq!(credential::get_state(handle).unwrap(), HolderState::OfferReceived as u32);

let connection_handle = connection::tests::build_test_connection_inviter_requested();

let cb = return_types_u32::Return_U32::new().unwrap();
assert_eq!(vcx_credential_send_request(cb.command_handle, handle, connection_handle, 0, Some(cb.get_callback())), error::SUCCESS.code_num);
cb.receive(TimeoutUtils::some_medium()).unwrap();
}

#[test]
#[cfg(feature = "general_test")]
fn test_vcx_credential_get_new_offers() {
Expand Down
6 changes: 3 additions & 3 deletions libvcx/src/aries/handlers/issuance/holder/holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ impl Holder {
Ok(())
}

pub fn update_state(&mut self, connection: &Connection) -> VcxResult<u32> {
pub fn update_state(&mut self, connection: &Connection) -> VcxResult<HolderState> {
trace!("Holder::update_state >>> ");
if self.is_terminal_state() { return Ok(self.get_state().into()); }
if self.is_terminal_state() { return Ok(self.get_state()); }
let send_message = connection.send_message_closure()?;

let messages = connection.get_messages()?;
if let Some((uid, msg)) = self.find_message_to_handle(messages) {
self.step(msg.into(), Some(&send_message))?;
connection.update_message_status(uid)?;
}
Ok(self.get_state().into())
Ok(self.get_state())
}
}
8 changes: 4 additions & 4 deletions libvcx/src/aries/handlers/issuance/issuer/issuer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ impl Issuer {
Ok(())
}

pub fn update_state(&mut self, connection: &Connection) -> VcxResult<u32> {
trace!("Issuer::update_state >>> ");
if self.is_terminal_state() { return Ok(self.get_state().into()); }
pub fn update_state(&mut self, connection: &Connection) -> VcxResult<IssuerState> {
trace!("Issuer::update_state >>>");
if self.is_terminal_state() { return Ok(self.get_state()); }
let send_message = connection.send_message_closure()?;

let messages = connection.get_messages()?;
if let Some((uid, msg)) = self.find_message_to_handle(messages) {
self.step(msg.into(), Some(&send_message))?;
connection.update_message_status(uid)?;
}
Ok(self.get_state().into())
Ok(self.get_state())
}
}
25 changes: 2 additions & 23 deletions wrappers/node/src/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,33 +105,12 @@ export enum VCXCode {
INVALID_REDIRECT_DETAILS = 1104,
NO_AGENT_INFO = 1106,
}
export enum StateType {
None = 0,
Initialized = 1,
OfferSent = 2,
RequestReceived = 3,
Accepted = 4,
Unfulfilled = 5,
Expired = 6,
Revoked = 7,
Redirected = 8,
Rejected = 9,
}

export enum InviterStateType {
export enum ConnectionStateType {
Null = 0,
Invited = 1,
Requested = 2,
Responded = 3,
Completed = 4
}

export enum InviteeStateType {
Null = 0,
Invited = 1,
Requested = 2,
Responded = 3,
Completed = 4
Finished = 4,
}

export enum HolderStateType {
Expand Down
12 changes: 6 additions & 6 deletions wrappers/node/src/api/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ref from 'ref-napi';
import { VCXInternalError } from '../errors';
import { rustAPI } from '../rustlib';
import { createFFICallbackPromise, ICbRef } from '../utils/ffi-helpers';
import { ISerializedData, StateType } from './common';
import { ISerializedData } from './common';
import { VCXBaseWithState } from './vcx-base-with-state';
import { PtrBuffer } from './utils';

Expand Down Expand Up @@ -105,7 +105,7 @@ export interface IConnectionData {
endpoint: string;
uuid: string;
wallet: string;
state: StateType;
state: number;
}

/**
Expand Down Expand Up @@ -335,14 +335,14 @@ export class Connection extends VCXBaseWithState<IConnectionData> {
cb,
);
if (rc) {
resolve(StateType.None);
resolve(0);
}
},
(resolve, reject) =>
ffi.Callback(
'void',
['uint32', 'uint32', 'uint32'],
(handle: number, err: number, _state: StateType) => {
(handle: number, err: number, _state: number) => {
if (err) {
reject(err);
}
Expand Down Expand Up @@ -373,14 +373,14 @@ export class Connection extends VCXBaseWithState<IConnectionData> {
(resolve, reject, cb) => {
const rc = this._updateStFn(commandHandle, this.handle, cb);
if (rc) {
resolve(StateType.None);
resolve(0);
}
},
(resolve, reject) =>
ffi.Callback(
'void',
['uint32', 'uint32', 'uint32'],
(handle: number, err: number, _state: StateType) => {
(handle: number, err: number, _state: number) => {
if (err) {
reject(err);
}
Expand Down
28 changes: 0 additions & 28 deletions wrappers/node/src/api/issuer-credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,6 @@ export class IssuerCredential extends VCXBaseWithState<IIssuerCredentialData> {
* Sends the credential to the end user.
*
* Credential is made up of the data sent during Credential Offer
* ```
* connection = await connectionCreateConnect()
* issuerCredential = await issuerCredentialCreate()
* await issuerCredential.sendOffer(connection)
* await issuerCredential.updateState()
* assert.equal(await issuerCredential.getState(), StateType.RequestReceived)
* await issuerCredential.sendCredential(connection)
* ```
*
*/
public async sendCredential(connection: Connection): Promise<void> {
try {
Expand Down Expand Up @@ -326,15 +317,6 @@ export class IssuerCredential extends VCXBaseWithState<IIssuerCredentialData> {
* Gets the credential message for sending to connection.
*
* Credential is made up of the data sent during Credential Offer
* ```
* connection = await connectionCreateConnect()
* issuerCredential = await issuerCredentialCreate()
* await issuerCredential.sendOffer(connection)
* await issuerCredential.updateState()
* assert.equal(await issuerCredential.getState(), StateType.RequestReceived)
* await issuerCredential.getCredentialMsg()
* ```
*
*/
public async getCredentialMsg(myPwDid: string): Promise<string> {
try {
Expand Down Expand Up @@ -371,16 +353,6 @@ export class IssuerCredential extends VCXBaseWithState<IIssuerCredentialData> {
* Revokes credential.
*
* Credential is made up of the data sent during Credential Offer
* ```
* connection = await connectionCreateConnect()
* issuerCredential = await issuerCredentialCreate()
* await issuerCredential.sendOffer(connection)
* await issuerCredential.updateState()
* assert.equal(await issuerCredential.getState(), StateType.RequestReceived)
* await issuerCredential.sendCredential(connection)
* await issuerCredential.revokeCredential()
* ```
*
*/
public async revokeCredential(): Promise<void> {
try {
Expand Down
Loading

0 comments on commit 0fdbe5b

Please sign in to comment.