From 7b349d00b6bea98f9fd5cd266ac1783369291a21 Mon Sep 17 00:00:00 2001 From: Tim Kernell Date: Mon, 14 Feb 2022 11:04:12 -0600 Subject: [PATCH 1/2] fix getCurrentValue issue when value count is zero --- contracts/UsingTellor.sol | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/contracts/UsingTellor.sol b/contracts/UsingTellor.sol index 26069ca..9accf7a 100644 --- a/contracts/UsingTellor.sol +++ b/contracts/UsingTellor.sol @@ -38,6 +38,9 @@ contract UsingTellor { ) { uint256 _count = tellor.getNewValueCountbyQueryId(_queryId); + if (_count == 0) { + return (false, bytes(""), 0); + } uint256 _time = tellor.getTimestampbyQueryIdandIndex( _queryId, _count - 1 @@ -71,7 +74,7 @@ contract UsingTellor { ); if (!_found) return (false, bytes(""), 0); uint256 _time = tellor.getTimestampbyQueryIdandIndex(_queryId, _index); - _value = tellor.retrieveData(_queryId, _time); + _value = tellor.retrieveData(_queryId, _time); if (keccak256(_value) != keccak256(bytes(""))) return (true, _value, _time); return (false, bytes(""), 0); From ea1fb8dc55af9e0afa8577027dc41d7197642260 Mon Sep 17 00:00:00 2001 From: Tim Kernell Date: Mon, 14 Feb 2022 11:12:56 -0600 Subject: [PATCH 2/2] update test --- test/usingTellorTest.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/usingTellorTest.js b/test/usingTellorTest.js index e40a084..8fd6195 100644 --- a/test/usingTellorTest.js +++ b/test/usingTellorTest.js @@ -75,6 +75,10 @@ describe("UsingTellor", function() { expect(currentVal3[0]) expect(currentVal3[1]).to.equal(h.bytes("houdini")) expect(currentVal3[2]).to.equal(blocky3.timestamp) + currentVal4 = await bench.getCurrentValue(h.uintTob32(2)) + expect(!currentVal4[0]) + expect(currentVal4[1]).to.equal('0x') + expect(currentVal4[2]).to.equal(0) }) it("getIndexForDataBefore()", async function() {