From 5731edc1611945dd75cd10082c42c0a3785abc59 Mon Sep 17 00:00:00 2001 From: Ethan Bennett Date: Tue, 11 Aug 2020 13:59:28 -0400 Subject: [PATCH] Get past logs for polling votes --- .../src/GovPollingService.js | 10 ++++++++++ .../test/GovPollingService.test.js | 17 +++++++++++++++++ packages/dai-plugin-governance/umd/index.js | 2 +- packages/dai-plugin-governance/umd/index.js.map | 2 +- yarn.lock | 2 +- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/dai-plugin-governance/src/GovPollingService.js b/packages/dai-plugin-governance/src/GovPollingService.js index 9ce1ed81e..69585af58 100644 --- a/packages/dai-plugin-governance/src/GovPollingService.js +++ b/packages/dai-plugin-governance/src/GovPollingService.js @@ -65,6 +65,16 @@ export default class GovPollingService extends PrivateService { return this.get('smartContract').getContractByName(BATCH_POLLING); } + // For networks without Spock, e.g. the testchain + async getVoteLogs(from = 0, to = 'latest') { + const web3 = this.get('smartContract').get('web3'); + return web3.getPastLogs({ + address: this._batchPollingContract().address, + from, + to + }); + } + //--- cache queries async getPoll(multiHash) { diff --git a/packages/dai-plugin-governance/test/GovPollingService.test.js b/packages/dai-plugin-governance/test/GovPollingService.test.js index cf864f7c1..57bbaf0e2 100644 --- a/packages/dai-plugin-governance/test/GovPollingService.test.js +++ b/packages/dai-plugin-governance/test/GovPollingService.test.js @@ -262,3 +262,20 @@ test('ranked choice tally with multiple rounds', async () => { JSON.stringify(dummyBallotMultipleRoundsExpect) ); }); + +test('can get vote logs from contract', async () => { + const START_DATE = Math.floor(new Date().getTime() / 1000) + 100; + const END_DATE = START_DATE + 5000; + const MULTI_HASH = 'dummy hash'; + const URL = 'dummy url'; + const option = [1]; + const pollId = await govPollingService.createPoll( + START_DATE, + END_DATE, + MULTI_HASH, + URL + ); + await govPollingService.vote([pollId], [option]); + const voteLogs = await govPollingService.getVoteLogs(); + expect(voteLogs[0].topics.length).toBe(4); +}); diff --git a/packages/dai-plugin-governance/umd/index.js b/packages/dai-plugin-governance/umd/index.js index 1cbec9b5e..3156d745a 100644 --- a/packages/dai-plugin-governance/umd/index.js +++ b/packages/dai-plugin-governance/umd/index.js @@ -1,3 +1,3 @@ /*! For license information please see index.js.LICENSE.txt */ -!function webpackUniversalModuleDefinition(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports["@makerdao/dai-plugin-governance"]=r():t["@makerdao/dai-plugin-governance"]=r()}(window,(function(){return function(t){var r={};function __webpack_require__(i){if(r[i])return r[i].exports;var a=r[i]={i:i,l:!1,exports:{}};return t[i].call(a.exports,a,a.exports,__webpack_require__),a.l=!0,a.exports}return __webpack_require__.m=t,__webpack_require__.c=r,__webpack_require__.d=function(t,r,i){__webpack_require__.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:i})},__webpack_require__.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},__webpack_require__.t=function(t,r){if(1&r&&(t=__webpack_require__(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(__webpack_require__.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var a in t)__webpack_require__.d(i,a,function(r){return t[r]}.bind(null,a));return i},__webpack_require__.n=function(t){var r=t&&t.__esModule?function getDefault(){return t.default}:function getModuleExports(){return t};return __webpack_require__.d(r,"a",r),r},__webpack_require__.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},__webpack_require__.p="",__webpack_require__(__webpack_require__.s=109)}([function(t,r){t.exports=function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}},function(t,r){t.exports=function _classCallCheck(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}},function(t,r){function _defineProperties(t,r){for(var i=0;i0})).forEach((function(t,r){for(var i=0;i2&&void 0!==arguments[2]?arguments[2]:[];if((0,u.default)(this,ServiceBase),r||(r=this.constructor.role),this.constructor.dependencies&&(i=this.constructor.dependencies),void 0===p.default[t])throw new Error("Invalid ServiceType: "+t);_defineLifeCycleMethods.call(this,t),this._serviceManager=_buildServiceManager.call(this,t,r,i),_installLifeCycleHooks.call(this,this._serviceManager),_guardLifeCycleMethods.call(this)}return(0,c.default)(ServiceBase,[{key:"manager",value:function manager(){return this._serviceManager}},{key:"get",value:function get(t){return this._serviceManager.dependency(t)}}]),ServiceBase}();r.default=y},function(t,r,i){var a=i(60)(Object,"create");t.exports=a},function(t,r,i){var a=i(61),u=i(186),c=i(187),l=a?a.toStringTag:void 0;t.exports=function baseGetTag(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":l&&l in Object(t)?u(t):c(t)}},function(t,r,i){var a=i(199);t.exports=function assocIndexOf(t,r){for(var i=t.length;i--;)if(a(t[i][0],r))return i;return-1}},function(t,r,i){var a=i(205);t.exports=function getMapData(t,r){var i=t.__data__;return a(r)?i["string"==typeof r?"string":"hash"]:i.map}},function(t,r){t.exports=function isObjectLike(t){return null!=t&&"object"==typeof t}},function(t,r,i){var a=i(113);t.exports=function(t,r,i){if(a(t),void 0===r)return t;switch(i){case 1:return function(i){return t.call(r,i)};case 2:return function(i,a){return t.call(r,i,a)};case 3:return function(i,a,u){return t.call(r,i,a,u)}}return function(){return t.apply(r,arguments)}}},function(t,r,i){var a=i(20);t.exports=function(t,r){if(!a(t))return t;var i,u;if(r&&"function"==typeof(i=t.toString)&&!a(u=i.call(t)))return u;if("function"==typeof(i=t.valueOf)&&!a(u=i.call(t)))return u;if(!r&&"function"==typeof(i=t.toString)&&!a(u=i.call(t)))return u;throw TypeError("Can't convert object to primitive value")}},function(t,r){var i={}.toString;t.exports=function(t){return i.call(t).slice(8,-1)}},function(t,r){t.exports=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t}},function(t,r){var i=Math.ceil,a=Math.floor;t.exports=function(t){return isNaN(t=+t)?0:(t>0?a:i)(t)}},function(t,r,i){var a=i(47)("keys"),u=i(33);t.exports=function(t){return a[t]||(a[t]=u(t))}},function(t,r,i){var a=i(4),u=i(12),c=u["__core-js_shared__"]||(u["__core-js_shared__"]={});(t.exports=function(t,r){return c[t]||(c[t]=void 0!==r?r:{})})("versions",[]).push({version:a.version,mode:i(32)?"pure":"global",copyright:"© 2019 Denis Pushkarev (zloirock.ru)"})},function(t,r){t.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(t,r){r.f=Object.getOwnPropertySymbols},function(t,r,i){var a=i(122)(!0);i(78)(String,"String",(function(t){this._t=String(t),this._i=0}),(function(){var t,r=this._t,i=this._i;return i>=r.length?{value:void 0,done:!0}:(t=a(r,i),this._i+=t.length,{value:t,done:!1})}))},function(t,r,i){var a=i(16),u=i(124),c=i(48),l=i(46)("IE_PROTO"),Empty=function(){},createDict=function(){var t,r=i(69)("iframe"),a=c.length;for(r.style.display="none",i(125).appendChild(r),r.src="javascript:",(t=r.contentWindow.document).open(),t.write("