diff --git a/contracts/Errors/OracleAggregatorErrors.sol b/contracts/Errors/OracleAggregatorErrors.sol index 1902ae8..9c321fa 100644 --- a/contracts/Errors/OracleAggregatorErrors.sol +++ b/contracts/Errors/OracleAggregatorErrors.sol @@ -6,4 +6,6 @@ contract OracleAggregatorErrors { string constant internal ERROR_ORACLE_AGGREGATOR_QUERY_WAS_ALREADY_MADE = "ORACLE_AGGREGATOR:QUERY_WAS_ALREADY_MADE"; string constant internal ERROR_ORACLE_AGGREGATOR_DATA_DOESNT_EXIST = "ORACLE_AGGREGATOR:DATA_DOESNT_EXIST"; + + string constant internal ERROR_ORACLE_AGGREGATOR_DATA_ALREADY_EXIST = "ORACLE_AGGREGATOR:DATA_ALREADY_EXIST"; } diff --git a/contracts/OracleAggregator.sol b/contracts/OracleAggregator.sol index b64547c..059bf0d 100644 --- a/contracts/OracleAggregator.sol +++ b/contracts/OracleAggregator.sol @@ -69,6 +69,9 @@ contract OracleAggregator is OracleAggregatorErrors, ReentrancyGuard { /// @param timestamp uint256 Timestamp of data /// @param data uint256 Data itself function __callback(uint256 timestamp, uint256 data) public { + // Don't allow to push data twice + require(!dataExist[msg.sender][timestamp], ERROR_ORACLE_AGGREGATOR_DATA_ALREADY_EXIST); + // Saving data dataCache[msg.sender][timestamp] = data; diff --git a/test/OracleAggregator.js b/test/OracleAggregator.js index d7db59c..46a8e97 100644 --- a/test/OracleAggregator.js +++ b/test/OracleAggregator.js @@ -53,6 +53,15 @@ contract('OracleAggregator', accounts => { assert.equal(result, data, 'Oracle didn\'t provided correct information') }) + it('should reject attempt to push data twice', async () => { + try { + await oracleAggregator.__callback(timestamp, data, { from: oracle }) + throw null + } catch (e) { + assert.ok(e.message.match(/ORACLE_AGGREGATOR:DATA_ALREADY_EXIST/), 'ORACLE_AGGREGATOR:DATA_ALREADY_EXIST') + } + }) + it('should correctly return fetchPrice from oracle', async () => { const result = await oracleAggregator.calculateFetchPrice.call(oracleIdMock.address) assert.equal(result, fetchPrice, 'Fetch price is not correct')