Skip to content

Commit

Permalink
Merge branch 'master' into fix-integration-test
Browse files Browse the repository at this point in the history
  • Loading branch information
vrolland committed Apr 3, 2020
2 parents 1caface + 7721cf2 commit 24a8551
Show file tree
Hide file tree
Showing 97 changed files with 9,642 additions and 649 deletions.
34 changes: 0 additions & 34 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ references:
- '-m'
- 'candy maple cake sugar pudding cream honey rich smooth crumble sweet treat'

orbs:
gcp-gcr: circleci/gcp-gcr@0.3.0
gcp: circleci/gcp-cli@1.3.0

jobs:
build:
docker:
Expand Down Expand Up @@ -478,33 +474,6 @@ jobs:
- run:
name: 'Publish Coverage'
command: 'yarn publish-coverage'
push-request-network-image:
executor: gcp/default
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- gcp/install
- gcp/initialize
- run:
name: 'gcloud docker auth'
command: gcloud auth configure-docker --project $GOOGLE_PROJECT_ID --quiet
- gcp-gcr/build-image:
image: request-network
registry-url: eu.gcr.io
tag: ${CIRCLE_SHA1:0:7}
- gcp-gcr/push-image:
image: request-network
registry-url: eu.gcr.io
tag: ${CIRCLE_SHA1:0:7}
- run:
name: Add Tag to image
command: |
export BRANCH_TAG_NAME=$(echo ${CIRCLE_BRANCH} | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9._-]//g')
gcloud container images add-tag \
eu.gcr.io/${GOOGLE_PROJECT_ID}/request-network:${CIRCLE_SHA1:0:7} \
eu.gcr.io/${GOOGLE_PROJECT_ID}/request-network:${BRANCH_TAG_NAME} \
--quiet
test-prototype-estimator:
docker:
- *node_image
Expand Down Expand Up @@ -571,9 +540,6 @@ jobs:

workflows:
version: 2
push-request-network-image:
jobs:
- push-request-network-image
build-and-test:
jobs:
- build
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/docs-deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy docs to staging

on:
push:
branches:
- master

jobs:
build-deploy-staging:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Use Node.js 10.x
uses: actions/setup-node@v1
with:
node-version: 10.15.3
- name: yarn install & build
run: |
yarn
yarn build
- uses: benjlevesque/s3-sync-action@master
env:
SOURCE_DIR: './packages/docs/build'
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_S3_BUCKET: ${{ secrets. AWS_S3_BUCKET_DOCS_STAGING }}
38 changes: 22 additions & 16 deletions packages/data-access/src/data-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,24 +176,29 @@ export default class DataAccess implements DataAccessTypes.IDataAccess {
});

// Store the data to the real storage
resultAppend.on('confirmed', (resultAppendConfirmed: StorageTypes.IAppendResult) => {
// update the timestamp with the confirmed one
this.transactionIndex.updateTimestamp(
resultAppendConfirmed.id,
resultAppendConfirmed.meta.timestamp,
);
resultAppend
.on('confirmed', (resultAppendConfirmed: StorageTypes.IAppendResult) => {
// update the timestamp with the confirmed one
this.transactionIndex.updateTimestamp(
resultAppendConfirmed.id,
resultAppendConfirmed.meta.timestamp,
);

const resultAfterConfirmation = {
meta: {
storageMeta: resultAppendConfirmed.meta,
topics,
transactionStorageLocation: resultAppendConfirmed.id,
},
result: {},
};
const resultAfterConfirmation = {
meta: {
storageMeta: resultAppendConfirmed.meta,
topics,
transactionStorageLocation: resultAppendConfirmed.id,
},
result: {},
};

result.emit('confirmed', resultAfterConfirmation);
});
result.emit('confirmed', resultAfterConfirmation);
})
.on('error', async error => {
await this.transactionIndex.removeTransaction(resultAppend.id);
result.emit('error', error);
});

// adds this transaction to the index, to enable retrieving it later.
await this.transactionIndex.addTransaction(
Expand Down Expand Up @@ -226,6 +231,7 @@ export default class DataAccess implements DataAccessTypes.IDataAccess {
channelId,
timestampBoundaries,
);

// Gets the block and meta from the storage location
const blockWithMetaList = await this.getBlockAndMetaFromStorageLocation(storageLocationList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ export default class TimestampByLocationTransactionIndex {
}
}

/**
* Removes timestamp indexed by location
*
* @param dataId dataId of the block
*/
public async removeIndexedDataId(dataId: string): Promise<void> {
await this.timestampByLocation.delete(dataId);
}

/**
* Function to update timestamp indexed by location
*
Expand All @@ -62,7 +71,7 @@ export default class TimestampByLocationTransactionIndex {
*/
public async getTimestampFromLocation(dataId: string): Promise<number | null> {
const timestamp = await this.timestampByLocation.get(dataId);
return timestamp ? timestamp : null;
return timestamp !== undefined ? timestamp : null;
}

/**
Expand Down
30 changes: 24 additions & 6 deletions packages/data-access/src/transaction-index/transaction-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ export default class TransactionIndex implements DataAccessTypes.ITransactionInd
await this.timestampByLocation.pushTimestampByLocation(dataId, timestamp);
}

/**
* Removes a transaction from the index
*
* @param dataId the dataId to remove
*/
public async removeTransaction(dataId: string): Promise<void> {
if (!this.locationByTopic) {
throw new Error('TransactionIndex must be initialized');
}

// remove the timestamp in the index
await this.timestampByLocation.removeIndexedDataId(dataId);
}

/**
* Update timestamp for a dataId
*
Expand Down Expand Up @@ -93,12 +107,16 @@ export default class TransactionIndex implements DataAccessTypes.ITransactionInd
channelId,
);

// if boundaries are passed, only return locations of transaction within these boundaries
if (timestampBoundaries) {
storageLocationList = await Bluebird.filter(storageLocationList, (dataId: string) =>
this.timestampByLocation.isDataInBoundaries(dataId, timestampBoundaries),
);
}
storageLocationList = await Bluebird.filter(storageLocationList, async (dataId: string) => {
// if the dataId has not been suppressed
const exist: boolean =
(await this.timestampByLocation.getTimestampFromLocation(dataId)) !== null;
// if boundaries are passed, only return locations of transaction within these boundaries
const inTimeBoundaries: boolean =
!timestampBoundaries ||
(await this.timestampByLocation.isDataInBoundaries(dataId, timestampBoundaries));
return exist && inTimeBoundaries;
});

return storageLocationList;
}
Expand Down
97 changes: 76 additions & 21 deletions packages/data-access/test/data-access.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ const getDataResult: StorageTypes.IEntriesWithLastTimestamp = {
lastTimestamp: 0,
};

const appendResult: StorageTypes.IAppendResult = Object.assign(new EventEmitter(), {
const appendResult: any = {
content: '',
id: dataIdBlock2tx,
meta: {
state: StorageTypes.ContentState.PENDING,
timestamp: 1,
},
});
};

const appendResultConfirmed = {
content: '',
Expand All @@ -107,14 +107,15 @@ const defaultFakeStorage: StorageTypes.IStorage = {
_ipfsAdd: chai.spy(),
append: chai.spy(
(): any => {
const appendResultWithEvent = Object.assign(new EventEmitter(), appendResult);
setTimeout(
() => {
appendResult.emit('confirmed', appendResultConfirmed);
appendResultWithEvent.emit('confirmed', appendResultConfirmed);
},
// tslint:disable-next-line:no-magic-numbers
10,
);
return appendResult;
return appendResultWithEvent;
},
),
getData: (): Promise<StorageTypes.IEntriesWithLastTimestamp> => defaultTestData,
Expand All @@ -137,11 +138,15 @@ let clock: sinon.SinonFakeTimers;

// tslint:disable:no-magic-numbers
/* tslint:disable:no-unused-expression */
describe('data-access', () => {
describe.only('data-access', () => {
beforeEach(async () => {
clock = sinon.useFakeTimers();
});

// afterEach(async () => {
// sinon.restore();
// });

describe('constructor', () => {
it('cannot initialize with getData without result', async () => {
const customFakeStorage = {
Expand Down Expand Up @@ -411,12 +416,11 @@ describe('data-access', () => {
const dataAccess = new DataAccess(defaultFakeStorage);
await dataAccess.initialize();

const errFunction = chai.spy();
const result = await dataAccess.persistTransaction(transactionMock1, arbitraryId1, [
arbitraryTopic1,
]);

clock.tick(11);
result.on('confirmed', resultConfirmed1 => {
result.on('error', errFunction).on('confirmed', resultConfirmed1 => {
expect(resultConfirmed1, 'result Confirmed wrong').to.deep.equal({
meta: {
storageMeta: {
Expand All @@ -430,6 +434,9 @@ describe('data-access', () => {
});
});

clock.tick(11);

expect(errFunction).to.not.be.called();
/* tslint:disable:object-literal-sort-keys */
/* tslint:disable:object-literal-key-quotes */
expect(defaultFakeStorage.append).to.have.been.called.with(
Expand All @@ -450,19 +457,14 @@ describe('data-access', () => {
],
}),
);
// expect(result, 'result wrong').to.deep.equal(
// Object.assign(new EventEmitter(), {
// meta: {
// storageMeta: {
// state: DataAccessTypes.TransactionState.PENDING,
// timestamp: 1,
// },
// topics: [arbitraryTopic1],
// transactionStorageLocation: dataIdBlock2tx,
// },
// result: {},
// }),
// );
expect(result.meta, 'result wrong').to.deep.equal({
storageMeta: {
state: DataAccessTypes.TransactionState.PENDING,
timestamp: 1,
},
topics: [arbitraryTopic1],
transactionStorageLocation: dataIdBlock2tx,
});
});

it('cannot persistTransaction() if not initialized', async () => {
Expand All @@ -487,6 +489,59 @@ describe('data-access', () => {
`The following topics are not well formatted: ["This topic is not formatted"]`,
);
});

it('cannot persistTransaction() and emit error if confirmation failed', async () => {
const mockStorageEmittingError: StorageTypes.IStorage = {
_ipfsAdd: chai.spy(),
append: chai.spy(
(): any => {
const appendResultWithEvent = Object.assign(new EventEmitter(), appendResult);
setTimeout(
() => {
appendResultWithEvent.emit('error', 'error for test purpose');
},
// tslint:disable-next-line:no-magic-numbers
10,
);
return appendResultWithEvent;
},
),
getData: (): Promise<StorageTypes.IEntriesWithLastTimestamp> => defaultTestData,
initialize: chai.spy(),
read: (param: string): any => {
const dataIdBlock2txFake: any = {
meta: {},
};
const resultRead: any = {
dataIdBlock2tx: dataIdBlock2txFake,
};
return resultRead[param];
},
readMany(params: string[]): Promise<any[]> {
return Promise.all(params.map(this.read));
},
};

const dataAccess = new DataAccess(mockStorageEmittingError);
await dataAccess.initialize();

const result = await dataAccess.persistTransaction(transactionMock1, arbitraryId1, [
arbitraryTopic1,
]);
result.on('error', error => {
expect(error, 'result Confirmed wrong').to.equal('error for test purpose');
});
clock.tick(11);

expect(result.meta, 'result wrong').to.deep.equal({
storageMeta: {
state: DataAccessTypes.TransactionState.PENDING,
timestamp: 1,
},
topics: [arbitraryTopic1],
transactionStorageLocation: dataIdBlock2tx,
});
});
});

it('synchronizeNewDataId() should throw an error if not initialized', async () => {
Expand Down
26 changes: 26 additions & 0 deletions packages/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader
docs/client/**
docs/guides/4-request-payment/1-multisig.md
docs/guides/5-request-client/2-erc20-payment-detection.md
docs/guides/5-request-client/3-eth-payment-detection.md
docs/guides/5-request-client/4-btc-payment-detection.md
docs/guides/5-request-client/5-declarative-payment-network.md

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
Loading

0 comments on commit 24a8551

Please sign in to comment.