Skip to content

Commit

Permalink
feat(ref-imp): #781 - address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacJChen committed Oct 10, 2020
2 parents 638d696 + c033e11 commit c9592bc
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 49 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
],
"rules": {
"dot-notation": ["off"],
"func-style": ["error", "expression"],
"max-len": ["error", { "code": 160, "ignoreStrings": true }],
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
"no-unused-vars": "off",
Expand Down
2 changes: 1 addition & 1 deletion lib/bitcoin/MongoDbBlockMetadataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class MongoDbBlockMetadataStore extends MongoDbStore implements I
$and: [
{ height: { $gte: fromInclusiveHeight } },
{ height: { $lt: toExclusiveHeight } }
]
]
});

// Add sort to query.
Expand Down
2 changes: 1 addition & 1 deletion lib/common/MongoDbTransactionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export default class MongoDbTransactionStore implements ITransactionStore {
$and: [
{ transactionTime: { $gte: Long.fromNumber(inclusiveBeginTransactionTime) } },
{ transactionTime: { $lt: Long.fromNumber(exclusiveEndTransactionTime) } }
]
]
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/core/versions/latest/BatchWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default class BatchWriter implements IBatchWriter {
const maxNumberOfOpsAllowedByLock = ValueTimeLockVerifier.calculateMaxNumberOfOperationsAllowed(valueTimeLock, this.versionMetadataFetcher);

if (maxNumberOfOpsAllowedByLock > maxNumberOfOpsAllowedByProtocol) {
// tslint:disable-next-line: max-line-length
// eslint-disable-next-line max-len
console.info(`Maximum number of operations allowed by value time lock: ${maxNumberOfOpsAllowedByLock}; Maximum number of operations allowed by protocol: ${maxNumberOfOpsAllowedByProtocol}`);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/core/versions/latest/TransactionSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class TransactionSelector implements ITransactionSelector {
// only 1 transaction is allowed per writer
if (writerToTransactionNumberMap.has(transaction.writer)) {
const acceptedTransactionNumber = writerToTransactionNumberMap.get(transaction.writer);
// tslint:disable-next-line:max-line-length
// eslint-disable-next-line max-len
console.info(`Multiple transactions found in transaction time ${currentTransactionTime} from writer ${transaction.writer}, considering transaction ${acceptedTransactionNumber} and ignoring ${transaction.transactionNumber}`);
} else {
transactionsPriorityQueue.push(transaction);
Expand Down
2 changes: 1 addition & 1 deletion lib/core/versions/latest/ValueTimeLockVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class ValueTimeLockVerifier {
sidetreeTransactionTime >= valueTimeLock.unlockTransactionTime) {
throw new SidetreeError(
ErrorCode.ValueTimeLockVerifierTransactionTimeOutsideLockRange,
// tslint:disable-next-line: max-line-length
// eslint-disable-next-line max-len
`Sidetree transaction block: ${sidetreeTransactionTime}; lock start time: ${valueTimeLock.lockTransactionTime}; unlock time: ${valueTimeLock.unlockTransactionTime}`);
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/bitcoin/BitcoinClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,6 @@ describe('BitcoinClient', async () => {
const createScriptSpy = spyOn(BitcoinClient as any, 'createFreezeScript').and.returnValue(mockRedeemScript);
const utilFuncSpy = spyOn(bitcoinClient as any, 'createSpendTransactionFromFrozenTransaction').and.returnValue(mockFreezeTxn2);

// tslint:disable-next-line: max-line-length
const [actualTxn, redeemScript] = await bitcoinClient['createSpendToFreezeTransaction'](mockFreezeTxn1, mockFreezeUntilPreviousBlock, mockFreezeUntilBlock);
expect(actualTxn).toEqual(mockFreezeTxn2);
expect(redeemScript).toEqual(mockRedeemScript);
Expand Down
31 changes: 14 additions & 17 deletions tests/bitcoin/BitcoinProcessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ describe('BitcoinProcessor', () => {
};
// return as many as page size
const transactions: TransactionModel[] = createTransactions(BitcoinProcessor['pageSizeInBlocks'], bitcoinProcessor['genesisBlockNumber'], true);
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake((() => {
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake(() => {
return Promise.resolve(transactions);
}));
});

const actual = await bitcoinProcessor.transactions();
expect(verifyMock).toHaveBeenCalledTimes(1); // called after data was retrieved
Expand All @@ -333,9 +333,9 @@ describe('BitcoinProcessor', () => {
hash: 'some hash',
previousHash: 'previous hash'
};
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake((() => {
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake(() => {
return Promise.resolve(transactions);
}));
});

const actual = await bitcoinProcessor.transactions();
expect(verifyMock).toHaveBeenCalledTimes(1);
Expand All @@ -355,9 +355,9 @@ describe('BitcoinProcessor', () => {
hash: 'some hash',
previousHash: 'previous hash'
};
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake((() => {
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake(() => {
return Promise.resolve(transactions);
}));
});

const actual = await bitcoinProcessor.transactions();
expect(verifyMock).toHaveBeenCalledTimes(1);
Expand All @@ -377,9 +377,9 @@ describe('BitcoinProcessor', () => {
hash: 'some hash',
previousHash: 'previous hash'
};
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake((() => {
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake(() => {
return Promise.resolve(transactions);
}));
});

const actual = await bitcoinProcessor.transactions();
expect(verifyMock).toHaveBeenCalledTimes(1);
Expand All @@ -398,9 +398,9 @@ describe('BitcoinProcessor', () => {
hash: 'some hash',
previousHash: 'previous hash'
};
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake(((begin) => {
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake((begin) => {
return Promise.resolve(createTransactions(10, begin, false));
}));
});

const actual = await bitcoinProcessor.transactions();
expect(verifyMock).toHaveBeenCalledTimes(1);
Expand All @@ -419,9 +419,9 @@ describe('BitcoinProcessor', () => {
hash: 'some hash',
previousHash: 'previous hash'
};
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake((() => {
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake(() => {
return Promise.resolve([]);
}));
});

const actual = await bitcoinProcessor.transactions();
expect(verifyMock).toHaveBeenCalledTimes(1);
Expand All @@ -448,9 +448,9 @@ describe('BitcoinProcessor', () => {
return Promise.resolve(true);
});
const transactions = createTransactions(BitcoinProcessor['pageSizeInBlocks'], expectedHeight, true);
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake((() => {
const laterThanMock = spyOn(bitcoinProcessor['transactionStore'], 'getTransactionsStartingFrom').and.callFake(() => {
return Promise.resolve(transactions);
}));
});

const actual = await bitcoinProcessor.transactions(expectedTransactionNumber, expectedHash);
expect(verifyMock).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -1026,7 +1026,6 @@ describe('BitcoinProcessor', () => {
});

it('should throw if asked to start processing before genesis', async (done) => {
// tslint:disable-next-line: max-line-length
const tipSpy = spyOn(bitcoinProcessor['bitcoinClient'], 'getCurrentBlockHeight' as any).and.returnValue(Promise.resolve(testConfig.genesisBlockNumber + 1));
const processMock = spyOn(bitcoinProcessor, 'processBlock' as any);

Expand Down Expand Up @@ -1281,9 +1280,7 @@ describe('BitcoinProcessor', () => {
spyOn(bitcoinProcessor['bitcoinClient'], 'getBlock').and.returnValue(Promise.resolve(blockData));

const mockSidetreeTxnModels: TransactionModel[] = [
// tslint:disable-next-line: max-line-length
{ anchorString: 'anchor1', transactionTimeHash: 'timehash1', transactionTime: 100, transactionNumber: 200, transactionFeePaid: 300, normalizedTransactionFee: 400, writer: 'writer1' },
// tslint:disable-next-line: max-line-length
{ anchorString: 'anchor2', transactionTimeHash: 'timehash2', transactionTime: 150, transactionNumber: 250, transactionFeePaid: 350, normalizedTransactionFee: 450, writer: 'writer2' }
];

Expand Down
2 changes: 0 additions & 2 deletions tests/bitcoin/SpendingMonitor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ describe('SpendingMonitor', () => {
const bitcoinFeeSpendingCutoffPeriodInBlocks = 100;
const bitcoinFeeSpendingCutoffInSatoshis = BitcoinClient.convertBtcToSatoshis(3); // 3 * BitcoinProcessor['satoshiPerBitcoin'];
const mockTxns: TransactionModel[] = [
// tslint:disable-next-line: max-line-length
{ transactionNumber: 12345, transactionTime: 10, transactionTimeHash: 'hash1', anchorString: 'anchor_string1', transactionFeePaid: 100, normalizedTransactionFee: 90, writer: 'writer1' },
// tslint:disable-next-line: max-line-length
{ transactionNumber: 67890, transactionTime: 11, transactionTimeHash: 'hash2', anchorString: 'anchor_string2', transactionFeePaid: 110, normalizedTransactionFee: 95, writer: 'writer2' }
];

Expand Down
2 changes: 1 addition & 1 deletion tests/core/AnchorFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ describe('AnchorFile', async () => {

expect(anchorFile.model.map_file_uri).toEqual(mapFileHash);
expect(anchorFile.model.operations.create![0].suffix_data).toEqual({
delta_hash: createOperation.suffixData.deltaHash, recovery_commitment: createOperation.suffixData.recoveryCommitment
delta_hash: createOperation.suffixData.deltaHash, recovery_commitment: createOperation.suffixData.recoveryCommitment
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion tests/core/DownloadManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ICas from '../../lib/core/interfaces/ICas';
import DownloadManager from '../../lib/core/DownloadManager';
import ICas from '../../lib/core/interfaces/ICas';
import MockCas from '../mocks/MockCas';
import timeSpan = require('time-span');

Expand Down
2 changes: 1 addition & 1 deletion tests/core/MapFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import JasmineSidetreeErrorValidator from '../JasmineSidetreeErrorValidator';
import MapFile from '../../lib/core/versions/latest/MapFile';
import MapFileModel from '../../lib/core/versions/latest/models/MapFileModel';
import Multihash from '../../lib/core/versions/latest/Multihash';
import SidetreeError from '../../lib/common/SidetreeError';
import OperationGenerator from '../generators/OperationGenerator';
import SidetreeError from '../../lib/common/SidetreeError';

describe('MapFile', async () => {
describe('parse()', async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/core/MongoDbTransactionStore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Config from '../../lib/core/models/Config';
import ITransactionStore from '../../lib/core/interfaces/ITransactionStore';
import { MongoClient } from 'mongodb';
import MongoDb from '../common/MongoDb';
import MongoDbTransactionStore from '../../lib/common/MongoDbTransactionStore';
import TransactionModel from '../../lib/common/models/TransactionModel';
import { MongoClient } from 'mongodb';

/**
* Creates a MongoDbTransactionStore and initializes it.
Expand Down
2 changes: 1 addition & 1 deletion tests/core/MongoDbUnresolvableTransactionStore.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Config from '../../lib/core/models/Config';
import { MongoClient } from 'mongodb';
import MongoDb from '../common/MongoDb';
import MongoDbUnresolvableTransactionStore from '../../lib/core/MongoDbUnresolvableTransactionStore';
import TransactionModel from '../../lib/common/models/TransactionModel';
import { MongoClient } from 'mongodb';

/**
* Creates a MongoDbUnresolvableTransactionStore and initializes it.
Expand Down
2 changes: 1 addition & 1 deletion tests/core/Operation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Encoder from '../../lib/core/versions/latest/Encoder';
import ErrorCode from '../../lib/core/versions/latest/ErrorCode';
import Operation from '../../lib/core/versions/latest/Operation';
import Multihash from '../../lib/core/versions/latest/Multihash';
import Operation from '../../lib/core/versions/latest/Operation';
import SidetreeError from '../../lib/common/SidetreeError';

describe('Operation', async () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/core/OperationProcessor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import AnchoredOperationModel from '../../lib/core/models/AnchoredOperationModel';
import CreateOperation from '../../lib/core/versions/latest/CreateOperation';
import DeactivateOperation from '../../lib/core/versions/latest/DeactivateOperation';
import DidState from '../../lib/core/models/DidState';
import Document from '../../lib/core/versions/latest/Document';
import DocumentModel from '../../lib/core/versions/latest/models/DocumentModel';
import DidState from '../../lib/core/models/DidState';
import ErrorCode from '../../lib/core/versions/latest/ErrorCode';
import IOperationStore from '../../lib/core/interfaces/IOperationStore';
import IOperationProcessor from '../../lib/core/interfaces/IOperationProcessor';
import IOperationStore from '../../lib/core/interfaces/IOperationStore';
import IVersionManager from '../../lib/core/interfaces/IVersionManager';
import Jwk from '../../lib/core/versions/latest/util/Jwk';
import JwkEs256k from '../../lib/core/models/JwkEs256k';
Expand Down
9 changes: 4 additions & 5 deletions tests/core/RequestHandler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as crypto from 'crypto';

import * as createFixture from '../fixtures/create/create.json';
import * as crypto from 'crypto';
import * as deactivateFixture from '../fixtures/deactivate/deactivate.json';
import * as legacyLongFormResultingDocument from '../fixtures/legacyLongFormDid/resultingDocument.json';
import * as longFormResultingDocument from '../fixtures/longFormDid/resultingDocument.json';
Expand All @@ -11,11 +10,11 @@ import AnchoredOperationModel from '../../lib/core/models/AnchoredOperationModel
import BatchScheduler from '../../lib/core/BatchScheduler';
import BatchWriter from '../../lib/core/versions/latest/BatchWriter';
import ChunkFile from '../../lib/core/versions/latest/ChunkFile';
import Compressor from '../../lib/core/versions/latest/util/Compressor';
import Config from '../../lib/core/models/Config';
import CreateOperation from '../../lib/core/versions/latest/CreateOperation';
import Did from '../../lib/core/versions/latest/Did';
import DidState from '../../lib/core/models/DidState';
import Compressor from '../../lib/core/versions/latest/util/Compressor';
import Config from '../../lib/core/models/Config';
import ErrorCode from '../../lib/core/versions/latest/ErrorCode';
import ICas from '../../lib/core/interfaces/ICas';
import IOperationStore from '../../lib/core/interfaces/IOperationStore';
Expand Down Expand Up @@ -205,7 +204,7 @@ describe('RequestHandler', () => {
createOperationRequest.delta = {
update_commitment: largeBuffer.toString(),
patches: []
}
};

const createOperationBuffer = Buffer.from(JSON.stringify(createOperationRequest));
const response = await requestHandler.handleOperationRequest(createOperationBuffer);
Expand Down
6 changes: 3 additions & 3 deletions tests/core/Resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ describe('Resolver', () => {
// Generate 3 anchored recover operations with the same reveal value but different anchored time.
const recoveryOperation1Data = await OperationGenerator.generateRecoverOperation({
didUniqueSuffix: createOperationData.createOperation.didUniqueSuffix,
recoveryPrivateKey: createOperationData.recoveryPrivateKey
recoveryPrivateKey: createOperationData.recoveryPrivateKey
});
const recoveryOperation2Data = await OperationGenerator.generateRecoverOperation({
didUniqueSuffix: createOperationData.createOperation.didUniqueSuffix,
recoveryPrivateKey: createOperationData.recoveryPrivateKey
recoveryPrivateKey: createOperationData.recoveryPrivateKey
});
const recoveryOperation3Data = await OperationGenerator.generateRecoverOperation({
didUniqueSuffix: createOperationData.createOperation.didUniqueSuffix,
recoveryPrivateKey: createOperationData.recoveryPrivateKey
recoveryPrivateKey: createOperationData.recoveryPrivateKey
});
const recoveryOperation1 = OperationGenerator.createAnchoredOperationModelFromOperationModel(recoveryOperation1Data.recoverOperation, 2, 2, 2);
const recoveryOperation2 = OperationGenerator.createAnchoredOperationModelFromOperationModel(recoveryOperation2Data.recoverOperation, 3, 3, 3);
Expand Down
2 changes: 1 addition & 1 deletion tests/core/TransactionProcessor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AnchoredDataSerializer from '../../lib/core/versions/latest/AnchoredDataSerializer';
import AnchorFile from '../../lib/core/versions/latest/AnchorFile';
import AnchoredDataSerializer from '../../lib/core/versions/latest/AnchoredDataSerializer';
import ChunkFile from '../../lib/core/versions/latest/ChunkFile';
import Compressor from '../../lib/core/versions/latest/util/Compressor';
import DownloadManager from '../../lib/core/DownloadManager';
Expand Down
7 changes: 5 additions & 2 deletions tests/core/versions/test-version-1/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import ResponseModel from '../../../../lib/common/models/ResponseModel';
*/
export default class RequestHandler implements IRequestHandler {

// tslint:disable-next-line: max-line-length
public constructor (private resolver: Resolver, private operationQueue: IOperationQueue, private didMethodName: string, private supportedAlgorithms: number[]) {
public constructor (
private resolver: Resolver,
private operationQueue: IOperationQueue,
private didMethodName: string,
private supportedAlgorithms: number[]) {
console.debug(this.resolver, this.operationQueue, this.didMethodName, this.supportedAlgorithms);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/generators/TestVectorGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export default class TestVectorGenerator {
nextUpdateCommitmentHash,
patches
)

// derive a recover operation from the create operation
const [newRecoveryPublicKey] = await Jwk.generateEs256kKeyPair();
const [newSigningPublicKey] = await OperationGenerator.generateKeyPair('keyAfterRecover');

const [documentKey] = await OperationGenerator.generateKeyPair('newDocumentKey');
const newServiceEndpoints = OperationGenerator.generateServiceEndpoints(['newId']);

const recoverOperationRequest = await OperationGenerator.generateRecoverOperationRequest(
createOperationData.createOperation.didUniqueSuffix,
createOperationData.recoveryPrivateKey,
Expand All @@ -49,8 +49,8 @@ export default class TestVectorGenerator {
);

const deactivateRequest = await OperationGenerator.createDeactivateOperationRequest(createOperationData.createOperation.didUniqueSuffix, createOperationData.recoveryPrivateKey);


const createRequestString = JSON.stringify(createOperationData.operationRequest, null, 2);
const updateRequestString = JSON.stringify(updateRequest, null, 2);
const recoverRequestString = JSON.stringify(recoverOperationRequest, null, 2);
Expand Down

0 comments on commit c9592bc

Please sign in to comment.