Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Add ProviderReportPushed log #69

Merged
merged 3 commits into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions contracts/MedianOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ contract MedianOracle is Ownable, IOracle {
event ProviderAdded(address provider);
event ProviderRemoved(address provider);
event ReportTimestampOutOfRange(address provider);
event ProviderReportPushed(address indexed provider, uint256 payload, uint256 timestamp);

// The number of seconds after which the report is deemed expired.
uint256 public reportExpirationTimeSec;
Expand Down Expand Up @@ -129,6 +130,8 @@ contract MedianOracle is Ownable, IOracle {

reports[index_past].timestamp = now;
reports[index_past].payload = payload;

emit ProviderReportPushed(providerAddress, payload, now);
}

/**
Expand Down
11 changes: 10 additions & 1 deletion test/unit/median_oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ contract('MedianOracle:pushReport', async function (accounts) {
it('should only push from authorized source', async function () {
expect(await chain.isEthException(oracle.pushReport(1000000000000000000, { from: A }))).to.be.true;
oracle.addProvider(A, { from: deployer });
await oracle.pushReport(1000000000000000000, { from: A });
r = await oracle.pushReport(1000000000000000000, { from: A });
// should fail if reportDelaySec did not pass since the previous push
expect(await chain.isEthException(oracle.pushReport(1000000000000000000, { from: A }))).to.be.true;
});
it('should emit ProviderReportPushed message', async function () {
const logs = r.logs;
const event = logs[0];
expect(event.event).to.eq('ProviderReportPushed');
expect(event.args.provider).to.eq(A);
event.args.payload.should.be.bignumber.eq(1000000000000000000);
const block = await chain.web3.eth.getBlock(logs[0].blockNumber);
event.args.timestamp.should.be.bignumber.eq(block.timestamp);
});
});

contract('MedianOracle:addProvider:accessControl', async function (accounts) {
Expand Down