Skip to content

Commit

Permalink
add ethereum & ipfs information to getStatus storage
Browse files Browse the repository at this point in the history
  • Loading branch information
vrolland committed Apr 7, 2020
1 parent 27e569b commit 53eb1cd
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/ethereum-storage/src/ethereum-metadata-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class EthereumMetadataCache {
public async getDataIds(): Promise<string[]> {
const listDataIds: string[] | undefined = await this.listDataIds.get('list');
if (!listDataIds) {
throw Error(`listDataIds must be defined ${listDataIds}`);
return [];
}
return listDataIds;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/ethereum-storage/src/ethereum-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,21 @@ export default class EthereumStorage implements StorageTypes.IStorage {
public async _getStatus(detailed: boolean = false): Promise<any> {
const dataIds = await this.ethereumMetadataCache.getDataIds();
const dataIdsWithReason = await this.dataIdsIgnored.getDataIdsWithReasons();

const ethereum = this.smartContractManager.getConfig();
const ipfs = this.ipfsManager.getConfig();

return {
dataIds: {
count: dataIds.length,
values: detailed ? dataIds : undefined,
},
ethereum,
ignoredDataIds: {
count: Object.keys(dataIdsWithReason).length,
values: detailed ? dataIdsWithReason : undefined,
},
ipfs,
};
}

Expand Down
16 changes: 16 additions & 0 deletions packages/ethereum-storage/src/ipfs-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,22 @@ export default class IpfsManager {
);
}

/**
* Gets current configuration
*
* @return the current configuration attributes
*/
public getConfig(): any {
return {
delayBetweenRetries: this.errorHandlingConfig.delayBetweenRetries,
host: this.ipfsConnection.host,
maxRetries: this.errorHandlingConfig.maxRetries,
port: this.ipfsConnection.port,
protocol: this.ipfsConnection.protocol,
timeout: this.ipfsConnection.timeout,
};
}

/**
* Get the javascript network module used to send request to ipfs
* @param protocol Protocol used to send ipfs requests
Expand Down
18 changes: 18 additions & 0 deletions packages/ethereum-storage/src/smart-contract-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,24 @@ export default class SmartContractManager {
return eventsWithMetaData;
}

/**
* Gets current configuration
*
* @return the current configuration attributes
*/
public getConfig(): any {
return {
creationBlockNumberHashStorage: this.creationBlockNumberHashStorage,
currentProvider: this.eth.currentProvider.host,
hashStorageAddress: this.hashStorageAddress,
hashSubmitterAddress: this.hashSubmitterAddress,
maxConcurrency: this.maxConcurrency,
maxRetries: this.maxRetries,
networkName: this.networkName,
retryDelay: this.retryDelay,
};
}

/**
* Get events inside storage smart contract for a specified block range
* Some web3 providers, including Infura, send error if the past event number for a specific range is over 1000
Expand Down
31 changes: 31 additions & 0 deletions packages/ethereum-storage/test/ethereum-storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -810,4 +810,35 @@ describe('EthereumStorage', () => {
assert.isNumber(result.lastTimestamp);
});
});

describe('_getStatus()', () => {
it('can get status', async () => {
ethereumStorage = new EthereumStorage('localhost', ipfsGatewayConnection, web3Connection);
await ethereumStorage.initialize();
await ethereumStorage.append(content1);
await ethereumStorage.getData();

const status = await ethereumStorage._getStatus();
expect(status.dataIds.count, 'config wrong').to.gte(0);
expect(status.ignoredDataIds.count, 'config wrong').to.gte(0);
expect(status.ethereum, 'config wrong').to.deep.equal({
creationBlockNumberHashStorage: 0,
currentProvider: 'http://localhost:8545',
hashStorageAddress: '0x345ca3e014aaf5dca488057592ee47305d9b3e10',
hashSubmitterAddress: '0xf25186b5081ff5ce73482ad761db0eb0d25abfbf',
maxConcurrency: 5,
maxRetries: undefined,
networkName: 'private',
retryDelay: undefined,
});
expect(status.ipfs, 'config wrong').to.deep.equal({
delayBetweenRetries: 500,
host: 'localhost',
maxRetries: 3,
port: 5001,
protocol: 'http',
timeout: 1000,
});
});
});
});
13 changes: 13 additions & 0 deletions packages/ethereum-storage/test/smartcontract-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ describe('SmartContractManager', () => {
smartContractManager.ethereumBlocks.maxRetries = 0;
});

it('can get config', async () => {
expect(smartContractManager.getConfig(), 'config wrong').to.deep.equal({
creationBlockNumberHashStorage: 0,
currentProvider: 'http://localhost:8545',
hashStorageAddress: '0x345ca3e014aaf5dca488057592ee47305d9b3e10',
hashSubmitterAddress: '0xf25186b5081ff5ce73482ad761db0eb0d25abfbf',
maxConcurrency: Number.MAX_SAFE_INTEGER,
maxRetries: undefined,
networkName: 'private',
retryDelay: undefined,
});
});

it('getMainAccount should return the main account', async () => {
const accounts = await eth.getAccounts();
const mainAccount = await smartContractManager.getMainAccount();
Expand Down

0 comments on commit 53eb1cd

Please sign in to comment.