From 8258d1611e109e1644c4fc112c9c72037dbbabf3 Mon Sep 17 00:00:00 2001 From: ahnaguib Date: Thu, 30 May 2019 17:18:44 -0700 Subject: [PATCH 1/3] Add ProviderReportPushed log --- contracts/MedianOracle.sol | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contracts/MedianOracle.sol b/contracts/MedianOracle.sol index 52b4200..ce2591b 100644 --- a/contracts/MedianOracle.sol +++ b/contracts/MedianOracle.sol @@ -35,6 +35,7 @@ contract MedianOracle is Ownable, IOracle { event ProviderAdded(address provider); event ProviderRemoved(address provider); event ReportTimestampOutOfRange(address provider); + event ProviderReportPushed(address provider, uint256 payload); // The number of seconds after which the report is deemed expired. uint256 public reportExpirationTimeSec; @@ -129,6 +130,8 @@ contract MedianOracle is Ownable, IOracle { reports[index_past].timestamp = now; reports[index_past].payload = payload; + + emit ProviderReportPushed(providerAddress, payload); } /** From 33607ef067e2d45adfdd44d8bc3411ec67cbb555 Mon Sep 17 00:00:00 2001 From: ahnaguib Date: Fri, 31 May 2019 12:11:20 -0700 Subject: [PATCH 2/3] Add ProviderReportPushed log --- contracts/MedianOracle.sol | 4 ++-- test/unit/median_oracle.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/contracts/MedianOracle.sol b/contracts/MedianOracle.sol index ce2591b..f983eb4 100644 --- a/contracts/MedianOracle.sol +++ b/contracts/MedianOracle.sol @@ -35,7 +35,7 @@ contract MedianOracle is Ownable, IOracle { event ProviderAdded(address provider); event ProviderRemoved(address provider); event ReportTimestampOutOfRange(address provider); - event ProviderReportPushed(address provider, uint256 payload); + event ProviderReportPushed(address provider, uint256 payload, uint256 timestamp); // The number of seconds after which the report is deemed expired. uint256 public reportExpirationTimeSec; @@ -131,7 +131,7 @@ contract MedianOracle is Ownable, IOracle { reports[index_past].timestamp = now; reports[index_past].payload = payload; - emit ProviderReportPushed(providerAddress, payload); + emit ProviderReportPushed(providerAddress, payload, now); } /** diff --git a/test/unit/median_oracle.js b/test/unit/median_oracle.js index 16938b6..c51fcc0 100644 --- a/test/unit/median_oracle.js +++ b/test/unit/median_oracle.js @@ -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) { From 00502949b375df52a047a29bd75c8e7ed8b19685 Mon Sep 17 00:00:00 2001 From: ahnaguib Date: Fri, 31 May 2019 14:56:42 -0700 Subject: [PATCH 3/3] Add ProviderReportPushed log --- contracts/MedianOracle.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/MedianOracle.sol b/contracts/MedianOracle.sol index f983eb4..bce5046 100644 --- a/contracts/MedianOracle.sol +++ b/contracts/MedianOracle.sol @@ -35,7 +35,7 @@ contract MedianOracle is Ownable, IOracle { event ProviderAdded(address provider); event ProviderRemoved(address provider); event ReportTimestampOutOfRange(address provider); - event ProviderReportPushed(address provider, uint256 payload, uint256 timestamp); + event ProviderReportPushed(address indexed provider, uint256 payload, uint256 timestamp); // The number of seconds after which the report is deemed expired. uint256 public reportExpirationTimeSec;