Skip to content

Commit

Permalink
feat(ref-imp): #781 - lint
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacJChen committed Sep 22, 2020
1 parent c690412 commit 2f73838
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 32 deletions.
4 changes: 2 additions & 2 deletions lib/core/versions/latest/CreateOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class CreateOperation implements OperationModel {
const suffixData = {
deltaHash: operationObject.suffix_data.delta_hash,
recoveryCommitment: operationObject.suffix_data.recovery_commitment
}
};

// For compatibility with data pruning, we have to assume that `delta` may be unavailable,
// thus an operation with invalid `delta` needs to be processed as an operation with unavailable `delta`,
Expand Down Expand Up @@ -195,7 +195,7 @@ export default class CreateOperation implements OperationModel {

private static validateSuffixData (suffixData: any): void {
if (typeof suffixData !== 'object') {
throw new SidetreeError(ErrorCode.CreateOperationSuffixDataIsNotObject)
throw new SidetreeError(ErrorCode.CreateOperationSuffixDataIsNotObject);
}

const properties = Object.keys(suffixData);
Expand Down
8 changes: 4 additions & 4 deletions lib/core/versions/latest/Did.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default class Did {
createOperation = await Did.constructCreateOperationFromInitialState(initialState);
} else {
const initialStateEncodedJcs = Did.getInitialStateFromDidStringWithExtraColon(didString);
createOperation = Did.constructCreateOperationFromEncodedJCS(initialStateEncodedJcs);
createOperation = Did.constructCreateOperationFromEncodedJcs(initialStateEncodedJcs);
}

// NOTE: we cannot use the unique suffix directly from `createOperation.didUniqueSuffix` for comparison,
Expand Down Expand Up @@ -164,12 +164,12 @@ export default class Did {
return initialStateValue;
}

private static constructCreateOperationFromEncodedJCS (initialStateEncodedJcs: string): CreateOperation {
private static constructCreateOperationFromEncodedJcs (initialStateEncodedJcs: string): CreateOperation {
// Initial state should be in the format base64url(JCS(initialState))
const initialStateDecodedJcs = Encoder.decodeAsString(initialStateEncodedJcs);
let initialStateObject;
try {
initialStateObject = JSON.parse(initialStateDecodedJcs)
initialStateObject = JSON.parse(initialStateDecodedJcs);
} catch {
throw new SidetreeError(ErrorCode.DidInitialStateJcsIsNotJosn, 'long form initial state should be encoded jcs');
}
Expand All @@ -189,7 +189,7 @@ export default class Did {
/**
* Make sure initial state is JCS
*/
private static validateInitialState(initialStateEncodedJcs: string, initialStateObject: any): void {
private static validateInitialState (initialStateEncodedJcs: string, initialStateObject: any): void {
const expectedInitialState = Encoder.encode(JsonCanonicalizer.canonicalizeAsBuffer(initialStateObject));
if (expectedInitialState !== initialStateEncodedJcs) {
throw new SidetreeError(ErrorCode.DidInitialStateJcsIsNotJcs, 'make sure to jcs then encode the initial state');
Expand Down
4 changes: 4 additions & 0 deletions lib/core/versions/latest/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default class Operation {
}
}

/**
* validate delta and throw if invalid
* @param delta the delta to validate
*/
public static validateDelta (delta: any): void {
if (typeof delta !== 'object') {
throw new SidetreeError(ErrorCode.DeltaIsNotObject);
Expand Down
18 changes: 9 additions & 9 deletions tests/core/CreateOperation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ describe('CreateOperation', async () => {
recovery_commitment: 'something'
},
delta: 'this is not a valid delta'
}
};

spyOn(CreateOperation as any, 'validateSuffixData').and.callFake(()=> {
//do nothing
})
spyOn(CreateOperation as any, 'validateSuffixData').and.callFake(() => {
// do nothing
});

const result = CreateOperation.parseJcsObject(operationObject, Buffer.from('something'));
expect(result.delta).toBeUndefined();
Expand All @@ -44,18 +44,18 @@ describe('CreateOperation', async () => {
} catch (e) {
expect(e).toEqual(new SidetreeError(ErrorCode.CreateOperationMissingOrUnknownProperty));
}
})
});

it('should throw sidetree error if type is not create', () => {
const testObject = {type: 'notCreate', two: 2, three: 3};
const testObject = { type: 'notCreate', two: 2, three: 3 };
try {
CreateOperation.parseJcsObject(testObject, Buffer.from(JSON.stringify(testObject)));
fail('expect to throw sidetree error but did not');
} catch (e) {
expect(e).toEqual(new SidetreeError(ErrorCode.CreateOperationTypeIncorrect));
}
})
})
});
});
describe('computeDidUniqueSuffix()', async () => {
it('should pass test vector.', async (done) => {
const suffixDataString = 'AStringActingAsTheSuffixData';
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('CreateOperation', async () => {
expect(e).toEqual(new SidetreeError(ErrorCode.CreateOperationSuffixDataIsNotObject));
}
});
})
});

describe('parseSuffixData()', async () => {
// TODO SIP 2 #781 deprecates this. These tests can be siwtched over to validateSuffixData
Expand Down
12 changes: 6 additions & 6 deletions tests/core/Did.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ describe('DID', async () => {
it('should throw sidetree error if initial state is not an json', () => {
const testInitialState = Encoder.encode('notJson');
try {
Did['constructCreateOperationFromEncodedJCS'](testInitialState)
Did['constructCreateOperationFromEncodedJcs'](testInitialState);
fail('expect to throw sidetree error but did not');
} catch (e) {
expect(e).toEqual(new SidetreeError(ErrorCode.DidInitialStateJcsIsNotJosn, 'long form initial state should be encoded jcs'));
}
})
});

it('should throw sidetree error if initial state is not jcs', () => {
const testInitialState = Encoder.encode(JSON.stringify({z: 1, a: 2, b: 1}));
const testInitialState = Encoder.encode(JSON.stringify({ z: 1, a: 2, b: 1 }));
try {
Did['constructCreateOperationFromEncodedJCS'](testInitialState)
Did['constructCreateOperationFromEncodedJcs'](testInitialState);
fail('expect to throw sidetree error but did not');
} catch (e) {
expect(e).toEqual(new SidetreeError(ErrorCode.DidInitialStateJcsIsNotJcs, 'make sure to jcs then encode the initial state'));
}
})
})
});
});

describe('create()', async () => {
it('should create a short-form DID successfully.', async () => {
Expand Down
6 changes: 3 additions & 3 deletions tests/core/Operation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ describe('Operation', async () => {
it('should throw sidetree error if input is not an object', () => {
const input = 'this is not an object, this is a string';
try {
Operation.validateDelta(input)
Operation.validateDelta(input);
} catch (e) {
expect(e).toEqual(new SidetreeError(ErrorCode.DeltaIsNotObject));
}
})
})
});
});

describe('parseDelta()', async () => {
it('should throw if delta is not string', async () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/core/RequestHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('RequestHandler', () => {
const response = await requestHandler.handleResolveRequest(longFormFixture);
expect(response.status).toEqual(ResponseStatus.Succeeded);
expect(response).toEqual(longFormResultingDocument as any);
})
});

it('should process create operation from test vectors correctly', async () => {
const createOperationBuffer = Buffer.from(JSON.stringify(createFixture));
Expand Down Expand Up @@ -321,7 +321,7 @@ describe('RequestHandler', () => {
});

it('[Bug #817] should return status as `deactivated` if DID is deactivated.', async () => {
// Intentionally not
// Intentionally not
const document = { unused: 'unused' };
const mockedResolverReturnedDidState: DidState = {
document,
Expand Down
12 changes: 6 additions & 6 deletions tests/generators/OperationGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ export default class OperationGenerator {

/**
* generate a long form did
* @param recoveryPublicKey
* @param updatePublicKey
* @param otherPublicKeys
* @param serviceEndpoints
* @param recoveryPublicKey
* @param updatePublicKey
* @param otherPublicKeys
* @param serviceEndpoints
*/
public static async generateLongFormDid (
recoveryPublicKey?: JwkEs256k,
Expand Down Expand Up @@ -172,8 +172,8 @@ export default class OperationGenerator {
return {
longFormDid,
shortFormDid,
didUniqueSuffix,
didUniqueSuffix

};
}

Expand Down

0 comments on commit 2f73838

Please sign in to comment.