Skip to content

Commit

Permalink
Fix bug with OracleAggregator. Don't allow to push data twice
Browse files Browse the repository at this point in the history
  • Loading branch information
Alirun committed Dec 17, 2019
1 parent 48dc9e2 commit 60ff6f8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions contracts/Errors/OracleAggregatorErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
3 changes: 3 additions & 0 deletions contracts/OracleAggregator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions test/OracleAggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 60ff6f8

Please sign in to comment.