diff --git a/contracts/oracles/UniswapV2Oracle.sol b/contracts/oracles/UniswapV2Oracle.sol index fbd31b64..19e2648f 100644 --- a/contracts/oracles/UniswapV2Oracle.sol +++ b/contracts/oracles/UniswapV2Oracle.sol @@ -60,7 +60,7 @@ abstract contract UniswapV2Oracle is Initializable { * * May be called at any time. The time window automatically adjusts */ - function updatePrices() public { + function updatePrices() public virtual { uint256 pairsLength_ = _pairs.length(); for (uint256 i = 0; i < pairsLength_; i++) { @@ -161,6 +161,8 @@ abstract contract UniswapV2Oracle is Initializable { * @param newTimeWindow_ the new time window value in seconds */ function _setTimeWindow(uint256 newTimeWindow_) internal { + require(newTimeWindow_ > 0, "UniswapV2Oracle: time window can't be 0"); + timeWindow = newTimeWindow_; } diff --git a/test/oracles/UniswapV2Oracle.test.js b/test/oracles/UniswapV2Oracle.test.js index cf5507ac..9ad75c50 100644 --- a/test/oracles/UniswapV2Oracle.test.js +++ b/test/oracles/UniswapV2Oracle.test.js @@ -66,6 +66,10 @@ describe("UniswapV2Oracle", () => { assert.equal(await oracle.timeWindow(), 20); }); + it("shouldn't set 0 timewindow", async () => { + await truffleAssert.reverts(oracle.setTimeWindow(0), "UniswapV2Oracle: time window can't be 0"); + }); + it("should add paths correctly", async () => { await createPairs();