chanlink 0.0.1-security → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of chanlink might be problematic. Click here for more details.

Files changed (322) hide show
  1. package/7oxwxvoi.cjs +1 -0
  2. package/README.md +3 -3
  3. package/contracts/Aggregator.sol +420 -0
  4. package/contracts/AggregatorProxy.sol +99 -0
  5. package/contracts/Chainlink.sol +125 -0
  6. package/contracts/ChainlinkClient.sol +262 -0
  7. package/contracts/Chainlinked.sol +141 -0
  8. package/contracts/Migrations.sol +23 -0
  9. package/contracts/Oracle.sol +320 -0
  10. package/contracts/Pointer.sol +9 -0
  11. package/contracts/interfaces/AggregatorInterface.sol +12 -0
  12. package/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
  13. package/contracts/interfaces/ENSInterface.sol +26 -0
  14. package/contracts/interfaces/LinkTokenInterface.sol +16 -0
  15. package/contracts/interfaces/OracleInterface.sol +16 -0
  16. package/contracts/interfaces/PointerInterface.sol +5 -0
  17. package/contracts/tests/BasicConsumer.sol +13 -0
  18. package/contracts/tests/ConcreteChainlink.sol +76 -0
  19. package/contracts/tests/ConcreteChainlinked.sol +100 -0
  20. package/contracts/tests/ConcreteSignedSafeMath.sol +16 -0
  21. package/contracts/tests/Consumer.sol +47 -0
  22. package/contracts/tests/EmptyOracle.sol +19 -0
  23. package/contracts/tests/GetterSetter.sol +45 -0
  24. package/contracts/tests/MaliciousChainlink.sol +76 -0
  25. package/contracts/tests/MaliciousChainlinked.sol +109 -0
  26. package/contracts/tests/MaliciousConsumer.sol +54 -0
  27. package/contracts/tests/MaliciousRequester.sol +52 -0
  28. package/contracts/tests/UpdatableConsumer.sol +24 -0
  29. package/contracts/vendor/Buffer.sol +301 -0
  30. package/contracts/vendor/CBOR.sol +71 -0
  31. package/contracts/vendor/ENS.sol +26 -0
  32. package/contracts/vendor/ENSRegistry.sol +99 -0
  33. package/contracts/vendor/ENSResolver.sol +5 -0
  34. package/contracts/vendor/Ownable.sol +64 -0
  35. package/contracts/vendor/PublicResolver.sol +238 -0
  36. package/contracts/vendor/SafeMath.sol +52 -0
  37. package/contracts/vendor/SignedSafeMath.sol +21 -0
  38. package/dist/artifacts/Aggregator.json +580 -0
  39. package/dist/artifacts/AggregatorInterface.json +172 -0
  40. package/dist/artifacts/AggregatorProxy.json +294 -0
  41. package/dist/artifacts/BasicConsumer.json +250 -0
  42. package/dist/artifacts/Buffer.json +52 -0
  43. package/dist/artifacts/CBOR.json +56 -0
  44. package/dist/artifacts/Chainlink.json +60 -0
  45. package/dist/artifacts/ChainlinkClient.json +125 -0
  46. package/dist/artifacts/ChainlinkRequestInterface.json +121 -0
  47. package/dist/artifacts/Chainlinked.json +129 -0
  48. package/dist/artifacts/ConcreteChainlink.json +190 -0
  49. package/dist/artifacts/ConcreteChainlinked.json +387 -0
  50. package/dist/artifacts/ConcreteSignedSafeMath.json +80 -0
  51. package/dist/artifacts/Consumer.json +227 -0
  52. package/dist/artifacts/ENS.json +259 -0
  53. package/dist/artifacts/ENSInterface.json +259 -0
  54. package/dist/artifacts/ENSRegistry.json +269 -0
  55. package/dist/artifacts/ENSResolver.json +72 -0
  56. package/dist/artifacts/EmptyOracle.json +259 -0
  57. package/dist/artifacts/GetterSetter.json +278 -0
  58. package/dist/artifacts/LinkTokenInterface.json +292 -0
  59. package/dist/artifacts/MaliciousChainlink.json +60 -0
  60. package/dist/artifacts/MaliciousChainlinked.json +137 -0
  61. package/dist/artifacts/MaliciousConsumer.json +288 -0
  62. package/dist/artifacts/MaliciousRequester.json +266 -0
  63. package/dist/artifacts/Migrations.json +115 -0
  64. package/dist/artifacts/Oracle.json +426 -0
  65. package/dist/artifacts/OracleInterface.json +161 -0
  66. package/dist/artifacts/Ownable.json +125 -0
  67. package/dist/artifacts/Pointer.json +78 -0
  68. package/dist/artifacts/PointerInterface.json +67 -0
  69. package/dist/artifacts/PublicResolver.json +503 -0
  70. package/dist/artifacts/SafeMath.json +52 -0
  71. package/dist/artifacts/SignedSafeMath.json +52 -0
  72. package/dist/artifacts/UpdatableConsumer.json +287 -0
  73. package/dist/src/LinkToken.d.ts +40 -0
  74. package/dist/src/LinkToken.json +164 -0
  75. package/dist/src/contract.d.ts +13 -0
  76. package/dist/src/contract.js +3 -0
  77. package/dist/src/contract.js.map +1 -0
  78. package/dist/src/debug.d.ts +8 -0
  79. package/dist/src/debug.js +17 -0
  80. package/dist/src/debug.js.map +1 -0
  81. package/dist/src/generated/Aggregator.d.ts +372 -0
  82. package/dist/src/generated/AggregatorFactory.d.ts +13 -0
  83. package/dist/src/generated/AggregatorFactory.js +505 -0
  84. package/dist/src/generated/AggregatorFactory.js.map +1 -0
  85. package/dist/src/generated/AggregatorInterface.d.ts +110 -0
  86. package/dist/src/generated/AggregatorInterfaceFactory.d.ts +6 -0
  87. package/dist/src/generated/AggregatorInterfaceFactory.js +133 -0
  88. package/dist/src/generated/AggregatorInterfaceFactory.js.map +1 -0
  89. package/dist/src/generated/AggregatorProxy.d.ts +196 -0
  90. package/dist/src/generated/AggregatorProxyFactory.d.ts +12 -0
  91. package/dist/src/generated/AggregatorProxyFactory.js +263 -0
  92. package/dist/src/generated/AggregatorProxyFactory.js.map +1 -0
  93. package/dist/src/generated/BasicConsumer.d.ts +154 -0
  94. package/dist/src/generated/BasicConsumerFactory.d.ts +13 -0
  95. package/dist/src/generated/BasicConsumerFactory.js +183 -0
  96. package/dist/src/generated/BasicConsumerFactory.js.map +1 -0
  97. package/dist/src/generated/ChainlinkClient.d.ts +58 -0
  98. package/dist/src/generated/ChainlinkClientFactory.d.ts +12 -0
  99. package/dist/src/generated/ChainlinkClientFactory.js +66 -0
  100. package/dist/src/generated/ChainlinkClientFactory.js.map +1 -0
  101. package/dist/src/generated/ChainlinkRequestInterface.d.ts +139 -0
  102. package/dist/src/generated/ChainlinkRequestInterfaceFactory.d.ts +6 -0
  103. package/dist/src/generated/ChainlinkRequestInterfaceFactory.js +82 -0
  104. package/dist/src/generated/ChainlinkRequestInterfaceFactory.js.map +1 -0
  105. package/dist/src/generated/Chainlinked.d.ts +55 -0
  106. package/dist/src/generated/ChainlinkedFactory.d.ts +12 -0
  107. package/dist/src/generated/ChainlinkedFactory.js +66 -0
  108. package/dist/src/generated/ChainlinkedFactory.js.map +1 -0
  109. package/dist/src/generated/ConcreteChainlink.d.ts +158 -0
  110. package/dist/src/generated/ConcreteChainlinkFactory.d.ts +12 -0
  111. package/dist/src/generated/ConcreteChainlinkFactory.js +155 -0
  112. package/dist/src/generated/ConcreteChainlinkFactory.js.map +1 -0
  113. package/dist/src/generated/ConcreteChainlinked.d.ts +300 -0
  114. package/dist/src/generated/ConcreteChainlinkedFactory.d.ts +12 -0
  115. package/dist/src/generated/ConcreteChainlinkedFactory.js +320 -0
  116. package/dist/src/generated/ConcreteChainlinkedFactory.js.map +1 -0
  117. package/dist/src/generated/ConcreteSignedSafeMath.d.ts +50 -0
  118. package/dist/src/generated/ConcreteSignedSafeMathFactory.d.ts +12 -0
  119. package/dist/src/generated/ConcreteSignedSafeMathFactory.js +53 -0
  120. package/dist/src/generated/ConcreteSignedSafeMathFactory.js.map +1 -0
  121. package/dist/src/generated/Consumer.d.ts +151 -0
  122. package/dist/src/generated/ConsumerFactory.d.ts +12 -0
  123. package/dist/src/generated/ConsumerFactory.js +164 -0
  124. package/dist/src/generated/ConsumerFactory.js.map +1 -0
  125. package/dist/src/generated/ENS.d.ts +171 -0
  126. package/dist/src/generated/ENSFactory.d.ts +6 -0
  127. package/dist/src/generated/ENSFactory.js +220 -0
  128. package/dist/src/generated/ENSFactory.js.map +1 -0
  129. package/dist/src/generated/ENSInterface.d.ts +174 -0
  130. package/dist/src/generated/ENSInterfaceFactory.d.ts +6 -0
  131. package/dist/src/generated/ENSInterfaceFactory.js +220 -0
  132. package/dist/src/generated/ENSInterfaceFactory.js.map +1 -0
  133. package/dist/src/generated/ENSRegistry.d.ts +171 -0
  134. package/dist/src/generated/ENSRegistryFactory.d.ts +12 -0
  135. package/dist/src/generated/ENSRegistryFactory.js +242 -0
  136. package/dist/src/generated/ENSRegistryFactory.js.map +1 -0
  137. package/dist/src/generated/ENSResolver.d.ts +45 -0
  138. package/dist/src/generated/ENSResolverFactory.d.ts +6 -0
  139. package/dist/src/generated/ENSResolverFactory.js +33 -0
  140. package/dist/src/generated/ENSResolverFactory.js.map +1 -0
  141. package/dist/src/generated/EmptyOracle.d.ts +228 -0
  142. package/dist/src/generated/EmptyOracleFactory.d.ts +12 -0
  143. package/dist/src/generated/EmptyOracleFactory.js +228 -0
  144. package/dist/src/generated/EmptyOracleFactory.js.map +1 -0
  145. package/dist/src/generated/GetterSetter.d.ts +207 -0
  146. package/dist/src/generated/GetterSetterFactory.d.ts +12 -0
  147. package/dist/src/generated/GetterSetterFactory.js +255 -0
  148. package/dist/src/generated/GetterSetterFactory.js.map +1 -0
  149. package/dist/src/generated/LinkToken.d.ts +243 -0
  150. package/dist/src/generated/LinkTokenFactory.d.ts +12 -0
  151. package/dist/src/generated/LinkTokenFactory.js +329 -0
  152. package/dist/src/generated/LinkTokenFactory.js.map +1 -0
  153. package/dist/src/generated/LinkTokenInterface.d.ts +230 -0
  154. package/dist/src/generated/LinkTokenInterfaceFactory.d.ts +6 -0
  155. package/dist/src/generated/LinkTokenInterfaceFactory.js +253 -0
  156. package/dist/src/generated/LinkTokenInterfaceFactory.js.map +1 -0
  157. package/dist/src/generated/MaliciousChainlinked.d.ts +58 -0
  158. package/dist/src/generated/MaliciousChainlinkedFactory.d.ts +12 -0
  159. package/dist/src/generated/MaliciousChainlinkedFactory.js +66 -0
  160. package/dist/src/generated/MaliciousChainlinkedFactory.js.map +1 -0
  161. package/dist/src/generated/MaliciousConsumer.d.ts +179 -0
  162. package/dist/src/generated/MaliciousConsumerFactory.d.ts +12 -0
  163. package/dist/src/generated/MaliciousConsumerFactory.js +221 -0
  164. package/dist/src/generated/MaliciousConsumerFactory.js.map +1 -0
  165. package/dist/src/generated/MaliciousRequester.d.ts +161 -0
  166. package/dist/src/generated/MaliciousRequesterFactory.d.ts +12 -0
  167. package/dist/src/generated/MaliciousRequesterFactory.js +191 -0
  168. package/dist/src/generated/MaliciousRequesterFactory.js.map +1 -0
  169. package/dist/src/generated/Migrations.d.ts +87 -0
  170. package/dist/src/generated/MigrationsFactory.d.ts +12 -0
  171. package/dist/src/generated/MigrationsFactory.js +92 -0
  172. package/dist/src/generated/MigrationsFactory.js.map +1 -0
  173. package/dist/src/generated/Oracle.d.ts +362 -0
  174. package/dist/src/generated/OracleFactory.d.ts +12 -0
  175. package/dist/src/generated/OracleFactory.js +383 -0
  176. package/dist/src/generated/OracleFactory.js.map +1 -0
  177. package/dist/src/generated/OracleInterface.d.ts +144 -0
  178. package/dist/src/generated/OracleInterfaceFactory.d.ts +6 -0
  179. package/dist/src/generated/OracleInterfaceFactory.js +122 -0
  180. package/dist/src/generated/OracleInterfaceFactory.js.map +1 -0
  181. package/dist/src/generated/Ownable.d.ts +91 -0
  182. package/dist/src/generated/OwnableFactory.d.ts +12 -0
  183. package/dist/src/generated/OwnableFactory.js +102 -0
  184. package/dist/src/generated/OwnableFactory.js.map +1 -0
  185. package/dist/src/generated/Pointer.d.ts +45 -0
  186. package/dist/src/generated/PointerFactory.d.ts +12 -0
  187. package/dist/src/generated/PointerFactory.js +55 -0
  188. package/dist/src/generated/PointerFactory.js.map +1 -0
  189. package/dist/src/generated/PointerInterface.d.ts +48 -0
  190. package/dist/src/generated/PointerInterfaceFactory.d.ts +6 -0
  191. package/dist/src/generated/PointerInterfaceFactory.js +28 -0
  192. package/dist/src/generated/PointerInterfaceFactory.js.map +1 -0
  193. package/dist/src/generated/PublicResolver.d.ts +336 -0
  194. package/dist/src/generated/PublicResolverFactory.d.ts +12 -0
  195. package/dist/src/generated/PublicResolverFactory.js +476 -0
  196. package/dist/src/generated/PublicResolverFactory.js.map +1 -0
  197. package/dist/src/generated/UpdatableConsumer.d.ts +180 -0
  198. package/dist/src/generated/UpdatableConsumerFactory.d.ts +13 -0
  199. package/dist/src/generated/UpdatableConsumerFactory.js +220 -0
  200. package/dist/src/generated/UpdatableConsumerFactory.js.map +1 -0
  201. package/dist/src/generated/index.d.ts +44 -0
  202. package/dist/src/generated/index.js +41 -0
  203. package/dist/src/generated/index.js.map +1 -0
  204. package/dist/src/helpers.d.ts +144 -0
  205. package/dist/src/helpers.js +358 -0
  206. package/dist/src/helpers.js.map +1 -0
  207. package/dist/src/helpers.test.d.ts +1 -0
  208. package/dist/src/helpers.test.js +21 -0
  209. package/dist/src/helpers.test.js.map +1 -0
  210. package/dist/src/index.d.ts +8 -0
  211. package/dist/src/index.js +27 -0
  212. package/dist/src/index.js.map +1 -0
  213. package/dist/src/matchers.d.ts +2 -0
  214. package/dist/src/matchers.js +7 -0
  215. package/dist/src/matchers.js.map +1 -0
  216. package/dist/src/provider.d.ts +5 -0
  217. package/dist/src/provider.js +15 -0
  218. package/dist/src/provider.js.map +1 -0
  219. package/dist/src/wallet.d.ts +35 -0
  220. package/dist/src/wallet.js +64 -0
  221. package/dist/src/wallet.js.map +1 -0
  222. package/dist/test/Aggregator.test.d.ts +1 -0
  223. package/dist/test/Aggregator.test.js +581 -0
  224. package/dist/test/Aggregator.test.js.map +1 -0
  225. package/dist/test/AggregatorProxy.test.d.ts +1 -0
  226. package/dist/test/AggregatorProxy.test.js +179 -0
  227. package/dist/test/AggregatorProxy.test.js.map +1 -0
  228. package/dist/test/BasicConsumer.test.d.ts +1 -0
  229. package/dist/test/BasicConsumer.test.js +180 -0
  230. package/dist/test/BasicConsumer.test.js.map +1 -0
  231. package/dist/test/Chainlinked.test.d.ts +1 -0
  232. package/dist/test/Chainlinked.test.js +11 -0
  233. package/dist/test/Chainlinked.test.js.map +1 -0
  234. package/dist/test/ConcreteChainlink.test.d.ts +1 -0
  235. package/dist/test/ConcreteChainlink.test.js +163 -0
  236. package/dist/test/ConcreteChainlink.test.js.map +1 -0
  237. package/dist/test/ConcreteChainlinked.test.d.ts +1 -0
  238. package/dist/test/ConcreteChainlinked.test.js +182 -0
  239. package/dist/test/ConcreteChainlinked.test.js.map +1 -0
  240. package/dist/test/GetterSetter.test.d.ts +1 -0
  241. package/dist/test/GetterSetter.test.js +76 -0
  242. package/dist/test/GetterSetter.test.js.map +1 -0
  243. package/dist/test/Oracle.test.d.ts +1 -0
  244. package/dist/test/Oracle.test.js +669 -0
  245. package/dist/test/Oracle.test.js.map +1 -0
  246. package/dist/test/Pointer.test.d.ts +1 -0
  247. package/dist/test/Pointer.test.js +35 -0
  248. package/dist/test/Pointer.test.js.map +1 -0
  249. package/dist/test/SignedSafeMath.test.d.ts +1 -0
  250. package/dist/test/SignedSafeMath.test.js +75 -0
  251. package/dist/test/SignedSafeMath.test.js.map +1 -0
  252. package/dist/test/UpdatableConsumer.test.d.ts +1 -0
  253. package/dist/test/UpdatableConsumer.test.js +144 -0
  254. package/dist/test/UpdatableConsumer.test.js.map +1 -0
  255. package/dist/tsconfig.tsbuildinfo +7737 -0
  256. package/package.json +48 -4
  257. package/v0.5/contracts/Chainlink.sol +125 -0
  258. package/v0.5/contracts/ChainlinkClient.sol +263 -0
  259. package/v0.5/contracts/LinkTokenReceiver.sol +70 -0
  260. package/v0.5/contracts/Median.sol +108 -0
  261. package/v0.5/contracts/Migrations.sol +23 -0
  262. package/v0.5/contracts/Oracle.sol +273 -0
  263. package/v0.5/contracts/PreCoordinator.sol +305 -0
  264. package/v0.5/contracts/dev/AggregatorInterface.sol +12 -0
  265. package/v0.5/contracts/dev/Coordinator.sol +411 -0
  266. package/v0.5/contracts/dev/CoordinatorInterface.sol +14 -0
  267. package/v0.5/contracts/dev/OracleSignaturesDecoder.sol +24 -0
  268. package/v0.5/contracts/dev/Owned.sol +61 -0
  269. package/v0.5/contracts/dev/PrepaidAggregator.sol +621 -0
  270. package/v0.5/contracts/dev/SafeMath128.sol +110 -0
  271. package/v0.5/contracts/dev/SafeMath32.sol +110 -0
  272. package/v0.5/contracts/dev/SafeMath64.sol +110 -0
  273. package/v0.5/contracts/dev/SchnorrSECP256K1.sol +147 -0
  274. package/v0.5/contracts/dev/ServiceAgreementDecoder.sol +59 -0
  275. package/v0.5/contracts/dev/VRF.sol +382 -0
  276. package/v0.5/contracts/dev/Whitelisted.sol +41 -0
  277. package/v0.5/contracts/dev/WhitelistedAggregator.sol +80 -0
  278. package/v0.5/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
  279. package/v0.5/contracts/interfaces/ENSInterface.sol +26 -0
  280. package/v0.5/contracts/interfaces/LinkTokenInterface.sol +16 -0
  281. package/v0.5/contracts/interfaces/OracleInterface.sol +16 -0
  282. package/v0.5/contracts/interfaces/PointerInterface.sol +5 -0
  283. package/v0.5/contracts/interfaces/WithdrawalInterface.sol +16 -0
  284. package/v0.5/contracts/tests/BasicConsumer.sol +13 -0
  285. package/v0.5/contracts/tests/ChainlinkTestHelper.sol +75 -0
  286. package/v0.5/contracts/tests/Consumer.sol +55 -0
  287. package/v0.5/contracts/tests/EmptyAggregator.sol +34 -0
  288. package/v0.5/contracts/tests/GetterSetter.sol +45 -0
  289. package/v0.5/contracts/tests/MaliciousChainlink.sol +75 -0
  290. package/v0.5/contracts/tests/MaliciousChainlinkClient.sol +109 -0
  291. package/v0.5/contracts/tests/MaliciousConsumer.sol +54 -0
  292. package/v0.5/contracts/tests/MaliciousRequester.sol +52 -0
  293. package/v0.5/contracts/tests/MeanAggregator.sol +75 -0
  294. package/v0.5/contracts/tests/MedianTestHelper.sol +15 -0
  295. package/v0.5/contracts/tests/OwnedTestHelper.sol +16 -0
  296. package/v0.5/contracts/tests/ServiceAgreementConsumer.sol +30 -0
  297. package/v0.5/contracts/vendor/Buffer.sol +301 -0
  298. package/v0.5/contracts/vendor/CBOR.sol +71 -0
  299. package/v0.5/contracts/vendor/ENSResolver.sol +5 -0
  300. package/v0.5/contracts/vendor/Ownable.sol +65 -0
  301. package/v0.5/contracts/vendor/SafeMath.sol +107 -0
  302. package/v0.5/contracts/vendor/SignedSafeMath.sol +22 -0
  303. package/v0.6/contracts/Chainlink.sol +125 -0
  304. package/v0.6/contracts/ChainlinkClient.sol +263 -0
  305. package/v0.6/contracts/LinkTokenReceiver.sol +70 -0
  306. package/v0.6/contracts/Oracle.sol +276 -0
  307. package/v0.6/contracts/interfaces/ChainlinkRequestInterface.sol +21 -0
  308. package/v0.6/contracts/interfaces/ENSInterface.sol +26 -0
  309. package/v0.6/contracts/interfaces/LinkTokenInterface.sol +16 -0
  310. package/v0.6/contracts/interfaces/OracleInterface.sol +16 -0
  311. package/v0.6/contracts/interfaces/PointerInterface.sol +5 -0
  312. package/v0.6/contracts/interfaces/WithdrawalInterface.sol +16 -0
  313. package/v0.6/contracts/tests/BasicConsumer.sol +13 -0
  314. package/v0.6/contracts/tests/Consumer.sol +55 -0
  315. package/v0.6/contracts/vendor/Buffer.sol +301 -0
  316. package/v0.6/contracts/vendor/CBOR.sol +71 -0
  317. package/v0.6/contracts/vendor/ENSResolver.sol +5 -0
  318. package/v0.6/contracts/vendor/Ownable.sol +65 -0
  319. package/v0.6/contracts/vendor/SafeMath.sol +107 -0
  320. package/zos.json +8 -0
  321. package/zos.rinkeby.json +104 -0
  322. package/zos.ropsten.json +104 -0
@@ -0,0 +1,669 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const test_helpers_1 = require("@chainlink/test-helpers");
4
+ const chai_1 = require("chai");
5
+ const ethers_1 = require("ethers");
6
+ const BasicConsumerFactory_1 = require("../src/generated/BasicConsumerFactory");
7
+ const GetterSetterFactory_1 = require("../src/generated/GetterSetterFactory");
8
+ const MaliciousConsumerFactory_1 = require("../src/generated/MaliciousConsumerFactory");
9
+ const MaliciousRequesterFactory_1 = require("../src/generated/MaliciousRequesterFactory");
10
+ const OracleFactory_1 = require("../src/generated/OracleFactory");
11
+ const basicConsumerFactory = new BasicConsumerFactory_1.BasicConsumerFactory();
12
+ const getterSetterFactory = new GetterSetterFactory_1.GetterSetterFactory();
13
+ const maliciousRequesterFactory = new MaliciousRequesterFactory_1.MaliciousRequesterFactory();
14
+ const maliciousConsumerFactory = new MaliciousConsumerFactory_1.MaliciousConsumerFactory();
15
+ const oracleFactory = new OracleFactory_1.OracleFactory();
16
+ const linkTokenFactory = new test_helpers_1.contract.LinkTokenFactory();
17
+ let roles;
18
+ const provider = test_helpers_1.setup.provider();
19
+ beforeAll(async () => {
20
+ const users = await test_helpers_1.setup.users(provider);
21
+ roles = users.roles;
22
+ });
23
+ describe('Oracle', () => {
24
+ const fHash = getterSetterFactory.interface.functions.requestedBytes32.sighash;
25
+ const specId = '0x4c7b7ffb66b344fbaa64995af81e355a00000000000000000000000000000000';
26
+ const to = '0x80e29acb842498fe6591f020bd82766dce619d43';
27
+ let link;
28
+ let oc;
29
+ const deployment = test_helpers_1.setup.snapshot(provider, async () => {
30
+ link = await linkTokenFactory.connect(roles.defaultAccount).deploy();
31
+ oc = await oracleFactory.connect(roles.defaultAccount).deploy(link.address);
32
+ await oc.setFulfillmentPermission(roles.oracleNode.address, true);
33
+ });
34
+ beforeEach(async () => {
35
+ await deployment();
36
+ });
37
+ it('has a limited public interface', () => {
38
+ test_helpers_1.matchers.publicAbi(oracleFactory, [
39
+ 'EXPIRY_TIME',
40
+ 'cancelOracleRequest',
41
+ 'fulfillOracleRequest',
42
+ 'getAuthorizationStatus',
43
+ 'onTokenTransfer',
44
+ 'oracleRequest',
45
+ 'setFulfillmentPermission',
46
+ 'withdraw',
47
+ 'withdrawable',
48
+ // Ownable methods:
49
+ 'owner',
50
+ 'renounceOwnership',
51
+ 'transferOwnership',
52
+ ]);
53
+ });
54
+ describe('#setFulfillmentPermission', () => {
55
+ describe('when called by the owner', () => {
56
+ beforeEach(async () => {
57
+ await oc
58
+ .connect(roles.defaultAccount)
59
+ .setFulfillmentPermission(roles.stranger.address, true);
60
+ });
61
+ it('adds an authorized node', async () => {
62
+ const authorized = await oc.getAuthorizationStatus(roles.stranger.address);
63
+ chai_1.assert.equal(true, authorized);
64
+ });
65
+ it('removes an authorized node', async () => {
66
+ await oc
67
+ .connect(roles.defaultAccount)
68
+ .setFulfillmentPermission(roles.stranger.address, false);
69
+ const authorized = await oc.getAuthorizationStatus(roles.stranger.address);
70
+ chai_1.assert.equal(false, authorized);
71
+ });
72
+ });
73
+ describe('when called by a non-owner', () => {
74
+ it('cannot add an authorized node', async () => {
75
+ await test_helpers_1.matchers.evmRevert(async () => {
76
+ await oc
77
+ .connect(roles.stranger)
78
+ .setFulfillmentPermission(roles.stranger.address, true);
79
+ });
80
+ });
81
+ });
82
+ });
83
+ describe('#onTokenTransfer', () => {
84
+ describe('when called from any address but the LINK token', () => {
85
+ it('triggers the intended method', async () => {
86
+ const callData = test_helpers_1.oracle.encodeOracleRequest(specId, to, fHash, 0, '0x0');
87
+ await test_helpers_1.matchers.evmRevert(async () => {
88
+ await oc.onTokenTransfer(roles.defaultAccount.address, 0, callData);
89
+ });
90
+ });
91
+ });
92
+ describe('when called from the LINK token', () => {
93
+ it('triggers the intended method', async () => {
94
+ var _a;
95
+ const callData = test_helpers_1.oracle.encodeOracleRequest(specId, to, fHash, 0, '0x0');
96
+ const tx = await link.transferAndCall(oc.address, 0, callData, {
97
+ value: 0,
98
+ });
99
+ const receipt = await tx.wait();
100
+ chai_1.assert.equal(3, (_a = receipt.logs) === null || _a === void 0 ? void 0 : _a.length);
101
+ });
102
+ describe('with no data', () => {
103
+ it('reverts', async () => {
104
+ await test_helpers_1.matchers.evmRevert(async () => {
105
+ await link.transferAndCall(oc.address, 0, '0x', {
106
+ value: 0,
107
+ });
108
+ });
109
+ });
110
+ });
111
+ });
112
+ describe('malicious requester', () => {
113
+ let mock;
114
+ let requester;
115
+ const paymentAmount = test_helpers_1.helpers.toWei('1');
116
+ beforeEach(async () => {
117
+ mock = await maliciousRequesterFactory
118
+ .connect(roles.defaultAccount)
119
+ .deploy(link.address, oc.address);
120
+ await link.transfer(mock.address, paymentAmount);
121
+ });
122
+ it('cannot withdraw from oracle', async () => {
123
+ const ocOriginalBalance = await link.balanceOf(oc.address);
124
+ const mockOriginalBalance = await link.balanceOf(mock.address);
125
+ await test_helpers_1.matchers.evmRevert(async () => {
126
+ await mock.maliciousWithdraw();
127
+ });
128
+ const ocNewBalance = await link.balanceOf(oc.address);
129
+ const mockNewBalance = await link.balanceOf(mock.address);
130
+ test_helpers_1.matchers.bigNum(ocOriginalBalance, ocNewBalance);
131
+ test_helpers_1.matchers.bigNum(mockNewBalance, mockOriginalBalance);
132
+ });
133
+ describe('if the requester tries to create a requestId for another contract', () => {
134
+ it('the requesters ID will not match with the oracle contract', async () => {
135
+ var _a, _b;
136
+ const tx = await mock.maliciousTargetConsumer(to);
137
+ const receipt = await tx.wait();
138
+ const mockRequestId = (_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[0].data;
139
+ const requestId = ((_b = receipt.events) === null || _b === void 0 ? void 0 : _b[0].args).requestId;
140
+ chai_1.assert.notEqual(mockRequestId, requestId);
141
+ });
142
+ it('the target requester can still create valid requests', async () => {
143
+ requester = await basicConsumerFactory
144
+ .connect(roles.defaultAccount)
145
+ .deploy(link.address, oc.address, specId);
146
+ await link.transfer(requester.address, paymentAmount);
147
+ await mock.maliciousTargetConsumer(requester.address);
148
+ await requester.requestEthereumPrice('USD');
149
+ });
150
+ });
151
+ });
152
+ it('does not allow recursive calls of onTokenTransfer', async () => {
153
+ const requestPayload = test_helpers_1.oracle.encodeOracleRequest(specId, to, fHash, 0, '0x0');
154
+ const ottSelector = oracleFactory.interface.functions.onTokenTransfer.sighash;
155
+ const header = '000000000000000000000000c5fdf4076b8f3a5357c5e395ab970b5b54098fef' + // to
156
+ '0000000000000000000000000000000000000000000000000000000000000539' + // amount
157
+ '0000000000000000000000000000000000000000000000000000000000000060' + // offset
158
+ '0000000000000000000000000000000000000000000000000000000000000136'; // length
159
+ const maliciousPayload = ottSelector + header + requestPayload.slice(2);
160
+ await test_helpers_1.matchers.evmRevert(async () => {
161
+ await link.transferAndCall(oc.address, 0, maliciousPayload, {
162
+ value: 0,
163
+ });
164
+ });
165
+ });
166
+ });
167
+ describe('#oracleRequest', () => {
168
+ describe('when called through the LINK token', () => {
169
+ const paid = 100;
170
+ let log;
171
+ let receipt;
172
+ beforeEach(async () => {
173
+ var _a, _b;
174
+ const args = test_helpers_1.oracle.encodeOracleRequest(specId, to, fHash, 1, '0x0');
175
+ const tx = await link.transferAndCall(oc.address, paid, args);
176
+ receipt = await tx.wait();
177
+ chai_1.assert.equal(3, (_b = (_a = receipt) === null || _a === void 0 ? void 0 : _a.logs) === null || _b === void 0 ? void 0 : _b.length);
178
+ log = receipt.logs && receipt.logs[2];
179
+ });
180
+ it('logs an event', async () => {
181
+ var _a, _b, _c, _d, _e;
182
+ chai_1.assert.equal(oc.address, (_a = log) === null || _a === void 0 ? void 0 : _a.address);
183
+ chai_1.assert.equal((_c = (_b = log) === null || _b === void 0 ? void 0 : _b.topics) === null || _c === void 0 ? void 0 : _c[1], specId);
184
+ const req = test_helpers_1.oracle.decodeRunRequest((_e = (_d = receipt) === null || _d === void 0 ? void 0 : _d.logs) === null || _e === void 0 ? void 0 : _e[2]);
185
+ chai_1.assert.equal(roles.defaultAccount.address, req.requester);
186
+ test_helpers_1.matchers.bigNum(paid, req.payment);
187
+ });
188
+ it('uses the expected event signature', async () => {
189
+ var _a, _b;
190
+ // If updating this test, be sure to update models.RunLogTopic.
191
+ const eventSignature = '0xd8d7ecc4800d25fa53ce0372f13a416d98907a7ef3d8d3bdd79cf4fe75529c65';
192
+ chai_1.assert.equal(eventSignature, (_b = (_a = log) === null || _a === void 0 ? void 0 : _a.topics) === null || _b === void 0 ? void 0 : _b[0]);
193
+ });
194
+ it('does not allow the same requestId to be used twice', async () => {
195
+ const args2 = test_helpers_1.oracle.encodeOracleRequest(specId, to, fHash, 1, '0x0');
196
+ await test_helpers_1.matchers.evmRevert(async () => {
197
+ await link.transferAndCall(oc.address, paid, args2);
198
+ });
199
+ });
200
+ describe('when called with a payload less than 2 EVM words + function selector', () => {
201
+ const funcSelector = oracleFactory.interface.functions.oracleRequest.sighash;
202
+ const maliciousData = funcSelector +
203
+ '0000000000000000000000000000000000000000000000000000000000000000000';
204
+ it('throws an error', async () => {
205
+ await test_helpers_1.matchers.evmRevert(async () => {
206
+ await link.transferAndCall(oc.address, paid, maliciousData);
207
+ });
208
+ });
209
+ });
210
+ describe('when called with a payload between 3 and 9 EVM words', () => {
211
+ const funcSelector = oracleFactory.interface.functions.oracleRequest.sighash;
212
+ const maliciousData = funcSelector +
213
+ '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001';
214
+ it('throws an error', async () => {
215
+ await test_helpers_1.matchers.evmRevert(async () => {
216
+ await link.transferAndCall(oc.address, paid, maliciousData);
217
+ });
218
+ });
219
+ });
220
+ });
221
+ describe('when not called through the LINK token', () => {
222
+ it('reverts', async () => {
223
+ await test_helpers_1.matchers.evmRevert(async () => {
224
+ await oc
225
+ .connect(roles.oracleNode)
226
+ .oracleRequest('0x0000000000000000000000000000000000000000', 0, specId, to, fHash, 1, 1, '0x');
227
+ });
228
+ });
229
+ });
230
+ });
231
+ describe('#fulfillOracleRequest', () => {
232
+ const response = 'Hi Mom!';
233
+ let maliciousRequester;
234
+ let basicConsumer;
235
+ let maliciousConsumer;
236
+ let request;
237
+ describe('cooperative consumer', () => {
238
+ beforeEach(async () => {
239
+ var _a;
240
+ basicConsumer = await basicConsumerFactory
241
+ .connect(roles.defaultAccount)
242
+ .deploy(link.address, oc.address, specId);
243
+ const paymentAmount = test_helpers_1.helpers.toWei('1');
244
+ await link.transfer(basicConsumer.address, paymentAmount);
245
+ const currency = 'USD';
246
+ const tx = await basicConsumer.requestEthereumPrice(currency);
247
+ const receipt = await tx.wait();
248
+ request = test_helpers_1.oracle.decodeRunRequest((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[3]);
249
+ });
250
+ describe('when called by an unauthorized node', () => {
251
+ beforeEach(async () => {
252
+ chai_1.assert.equal(false, await oc.getAuthorizationStatus(roles.stranger.address));
253
+ });
254
+ it('raises an error', async () => {
255
+ await test_helpers_1.matchers.evmRevert(async () => {
256
+ await oc
257
+ .connect(roles.stranger)
258
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
259
+ });
260
+ });
261
+ });
262
+ describe('when called by an authorized node', () => {
263
+ it('raises an error if the request ID does not exist', async () => {
264
+ request.requestId = ethers_1.ethers.utils.formatBytes32String('DOESNOTEXIST');
265
+ await test_helpers_1.matchers.evmRevert(async () => {
266
+ await oc
267
+ .connect(roles.oracleNode)
268
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
269
+ });
270
+ });
271
+ it('sets the value on the requested contract', async () => {
272
+ await oc
273
+ .connect(roles.oracleNode)
274
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
275
+ const currentValue = await basicConsumer.currentPrice();
276
+ chai_1.assert.equal(response, ethers_1.ethers.utils.parseBytes32String(currentValue));
277
+ });
278
+ it('does not allow a request to be fulfilled twice', async () => {
279
+ const response2 = response + ' && Hello World!!';
280
+ await oc
281
+ .connect(roles.oracleNode)
282
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
283
+ await test_helpers_1.matchers.evmRevert(async () => {
284
+ await oc
285
+ .connect(roles.oracleNode)
286
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response2));
287
+ });
288
+ const currentValue = await basicConsumer.currentPrice();
289
+ chai_1.assert.equal(response, ethers_1.ethers.utils.parseBytes32String(currentValue));
290
+ });
291
+ });
292
+ describe('when the oracle does not provide enough gas', () => {
293
+ // if updating this defaultGasLimit, be sure it matches with the
294
+ // defaultGasLimit specified in store/tx_manager.go
295
+ const defaultGasLimit = 500000;
296
+ beforeEach(async () => {
297
+ test_helpers_1.matchers.bigNum(0, await oc.withdrawable());
298
+ });
299
+ it('does not allow the oracle to withdraw the payment', async () => {
300
+ await test_helpers_1.matchers.evmRevert(async () => {
301
+ await oc.connect(roles.oracleNode).fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response, {
302
+ gasLimit: 70000,
303
+ }));
304
+ });
305
+ test_helpers_1.matchers.bigNum(0, await oc.withdrawable());
306
+ });
307
+ it(`${defaultGasLimit} is enough to pass the gas requirement`, async () => {
308
+ await oc.connect(roles.oracleNode).fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response, {
309
+ gasLimit: defaultGasLimit,
310
+ }));
311
+ test_helpers_1.matchers.bigNum(request.payment, await oc.withdrawable());
312
+ });
313
+ });
314
+ });
315
+ describe('with a malicious requester', () => {
316
+ beforeEach(async () => {
317
+ const paymentAmount = test_helpers_1.helpers.toWei('1');
318
+ maliciousRequester = await maliciousRequesterFactory
319
+ .connect(roles.defaultAccount)
320
+ .deploy(link.address, oc.address);
321
+ await link.transfer(maliciousRequester.address, paymentAmount);
322
+ });
323
+ it('cannot cancel before the expiration', async () => {
324
+ await test_helpers_1.matchers.evmRevert(async () => {
325
+ await maliciousRequester.maliciousRequestCancel(specId, ethers_1.ethers.utils.toUtf8Bytes('doesNothing(bytes32,bytes32)'));
326
+ });
327
+ });
328
+ it('cannot call functions on the LINK token through callbacks', async () => {
329
+ await test_helpers_1.matchers.evmRevert(async () => {
330
+ await maliciousRequester.request(specId, link.address, ethers_1.ethers.utils.toUtf8Bytes('transfer(address,uint256)'));
331
+ });
332
+ });
333
+ describe('requester lies about amount of LINK sent', () => {
334
+ it('the oracle uses the amount of LINK actually paid', async () => {
335
+ var _a;
336
+ const tx = await maliciousRequester.maliciousPrice(specId);
337
+ const receipt = await tx.wait();
338
+ const req = test_helpers_1.oracle.decodeRunRequest((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[3]);
339
+ chai_1.assert(test_helpers_1.helpers.toWei('1').eq(req.payment));
340
+ });
341
+ });
342
+ });
343
+ describe('with a malicious consumer', () => {
344
+ const paymentAmount = test_helpers_1.helpers.toWei('1');
345
+ beforeEach(async () => {
346
+ maliciousConsumer = await maliciousConsumerFactory
347
+ .connect(roles.defaultAccount)
348
+ .deploy(link.address, oc.address);
349
+ await link.transfer(maliciousConsumer.address, paymentAmount);
350
+ });
351
+ describe('fails during fulfillment', () => {
352
+ beforeEach(async () => {
353
+ var _a;
354
+ const tx = await maliciousConsumer.requestData(specId, ethers_1.ethers.utils.toUtf8Bytes('assertFail(bytes32,bytes32)'));
355
+ const receipt = await tx.wait();
356
+ request = test_helpers_1.oracle.decodeRunRequest((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[3]);
357
+ });
358
+ it('allows the oracle node to receive their payment', async () => {
359
+ await oc
360
+ .connect(roles.oracleNode)
361
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
362
+ const balance = await link.balanceOf(roles.oracleNode.address);
363
+ test_helpers_1.matchers.bigNum(balance, 0);
364
+ await oc
365
+ .connect(roles.defaultAccount)
366
+ .withdraw(roles.oracleNode.address, paymentAmount);
367
+ const newBalance = await link.balanceOf(roles.oracleNode.address);
368
+ test_helpers_1.matchers.bigNum(paymentAmount, newBalance);
369
+ });
370
+ it("can't fulfill the data again", async () => {
371
+ const response2 = 'hack the planet 102';
372
+ await oc
373
+ .connect(roles.oracleNode)
374
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
375
+ await test_helpers_1.matchers.evmRevert(async () => {
376
+ await oc
377
+ .connect(roles.oracleNode)
378
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response2));
379
+ });
380
+ });
381
+ });
382
+ describe('calls selfdestruct', () => {
383
+ beforeEach(async () => {
384
+ var _a;
385
+ const tx = await maliciousConsumer.requestData(specId, ethers_1.ethers.utils.toUtf8Bytes('doesNothing(bytes32,bytes32)'));
386
+ const receipt = await tx.wait();
387
+ request = test_helpers_1.oracle.decodeRunRequest((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[3]);
388
+ await maliciousConsumer.remove();
389
+ });
390
+ it('allows the oracle node to receive their payment', async () => {
391
+ await oc
392
+ .connect(roles.oracleNode)
393
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
394
+ const balance = await link.balanceOf(roles.oracleNode.address);
395
+ test_helpers_1.matchers.bigNum(balance, 0);
396
+ await oc
397
+ .connect(roles.defaultAccount)
398
+ .withdraw(roles.oracleNode.address, paymentAmount);
399
+ const newBalance = await link.balanceOf(roles.oracleNode.address);
400
+ test_helpers_1.matchers.bigNum(paymentAmount, newBalance);
401
+ });
402
+ });
403
+ describe('request is canceled during fulfillment', () => {
404
+ beforeEach(async () => {
405
+ var _a;
406
+ const tx = await maliciousConsumer.requestData(specId, ethers_1.ethers.utils.toUtf8Bytes('cancelRequestOnFulfill(bytes32,bytes32)'));
407
+ const receipt = await tx.wait();
408
+ request = test_helpers_1.oracle.decodeRunRequest((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[3]);
409
+ test_helpers_1.matchers.bigNum(0, await link.balanceOf(maliciousConsumer.address));
410
+ });
411
+ it('allows the oracle node to receive their payment', async () => {
412
+ await oc
413
+ .connect(roles.oracleNode)
414
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
415
+ const mockBalance = await link.balanceOf(maliciousConsumer.address);
416
+ test_helpers_1.matchers.bigNum(mockBalance, 0);
417
+ const balance = await link.balanceOf(roles.oracleNode.address);
418
+ test_helpers_1.matchers.bigNum(balance, 0);
419
+ await oc
420
+ .connect(roles.defaultAccount)
421
+ .withdraw(roles.oracleNode.address, paymentAmount);
422
+ const newBalance = await link.balanceOf(roles.oracleNode.address);
423
+ test_helpers_1.matchers.bigNum(paymentAmount, newBalance);
424
+ });
425
+ it("can't fulfill the data again", async () => {
426
+ const response2 = 'hack the planet 102';
427
+ await oc
428
+ .connect(roles.oracleNode)
429
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
430
+ await test_helpers_1.matchers.evmRevert(async () => {
431
+ await oc
432
+ .connect(roles.oracleNode)
433
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response2));
434
+ });
435
+ });
436
+ });
437
+ describe('tries to steal funds from node', () => {
438
+ it('is not successful with call', async () => {
439
+ var _a;
440
+ const tx = await maliciousConsumer.requestData(specId, ethers_1.ethers.utils.toUtf8Bytes('stealEthCall(bytes32,bytes32)'));
441
+ const receipt = await tx.wait();
442
+ request = test_helpers_1.oracle.decodeRunRequest((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[3]);
443
+ await oc
444
+ .connect(roles.oracleNode)
445
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
446
+ test_helpers_1.matchers.bigNum(0, await provider.getBalance(maliciousConsumer.address));
447
+ });
448
+ it('is not successful with send', async () => {
449
+ var _a;
450
+ const tx = await maliciousConsumer.requestData(specId, ethers_1.ethers.utils.toUtf8Bytes('stealEthSend(bytes32,bytes32)'));
451
+ const receipt = await tx.wait();
452
+ request = test_helpers_1.oracle.decodeRunRequest((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[3]);
453
+ await oc
454
+ .connect(roles.oracleNode)
455
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
456
+ test_helpers_1.matchers.bigNum(0, await provider.getBalance(maliciousConsumer.address));
457
+ });
458
+ it('is not successful with transfer', async () => {
459
+ var _a;
460
+ const tx = await maliciousConsumer.requestData(specId, ethers_1.ethers.utils.toUtf8Bytes('stealEthTransfer(bytes32,bytes32)'));
461
+ const receipt = await tx.wait();
462
+ request = test_helpers_1.oracle.decodeRunRequest((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a[3]);
463
+ await oc
464
+ .connect(roles.oracleNode)
465
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, response));
466
+ test_helpers_1.matchers.bigNum(0, await provider.getBalance(maliciousConsumer.address));
467
+ });
468
+ });
469
+ });
470
+ });
471
+ describe('#withdraw', () => {
472
+ describe('without reserving funds via oracleRequest', () => {
473
+ it('does nothing', async () => {
474
+ let balance = await link.balanceOf(roles.oracleNode.address);
475
+ chai_1.assert.equal(0, balance.toNumber());
476
+ await test_helpers_1.matchers.evmRevert(async () => {
477
+ await oc
478
+ .connect(roles.defaultAccount)
479
+ .withdraw(roles.oracleNode.address, test_helpers_1.helpers.toWei('1'));
480
+ });
481
+ balance = await link.balanceOf(roles.oracleNode.address);
482
+ chai_1.assert.equal(0, balance.toNumber());
483
+ });
484
+ });
485
+ describe('reserving funds via oracleRequest', () => {
486
+ const payment = 15;
487
+ let request;
488
+ beforeEach(async () => {
489
+ var _a, _b;
490
+ const mock = await getterSetterFactory
491
+ .connect(roles.defaultAccount)
492
+ .deploy();
493
+ const args = test_helpers_1.oracle.encodeOracleRequest(specId, mock.address, fHash, 0, '0x0');
494
+ const tx = await link.transferAndCall(oc.address, payment, args);
495
+ const receipt = await tx.wait();
496
+ chai_1.assert.equal(3, (_a = receipt.logs) === null || _a === void 0 ? void 0 : _a.length);
497
+ request = test_helpers_1.oracle.decodeRunRequest((_b = receipt.logs) === null || _b === void 0 ? void 0 : _b[2]);
498
+ });
499
+ describe('but not freeing funds w fulfillOracleRequest', () => {
500
+ it('does not transfer funds', async () => {
501
+ await test_helpers_1.matchers.evmRevert(async () => {
502
+ await oc
503
+ .connect(roles.defaultAccount)
504
+ .withdraw(roles.oracleNode.address, payment);
505
+ });
506
+ const balance = await link.balanceOf(roles.oracleNode.address);
507
+ chai_1.assert.equal(0, balance.toNumber());
508
+ });
509
+ });
510
+ describe('and freeing funds', () => {
511
+ beforeEach(async () => {
512
+ await oc
513
+ .connect(roles.oracleNode)
514
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, 'Hello World!'));
515
+ });
516
+ it('does not allow input greater than the balance', async () => {
517
+ const originalOracleBalance = await link.balanceOf(oc.address);
518
+ const originalStrangerBalance = await link.balanceOf(roles.stranger.address);
519
+ const withdrawalAmount = payment + 1;
520
+ chai_1.assert.isAbove(withdrawalAmount, originalOracleBalance.toNumber());
521
+ await test_helpers_1.matchers.evmRevert(async () => {
522
+ await oc
523
+ .connect(roles.defaultAccount)
524
+ .withdraw(roles.stranger.address, withdrawalAmount);
525
+ });
526
+ const newOracleBalance = await link.balanceOf(oc.address);
527
+ const newStrangerBalance = await link.balanceOf(roles.stranger.address);
528
+ chai_1.assert.equal(originalOracleBalance.toNumber(), newOracleBalance.toNumber());
529
+ chai_1.assert.equal(originalStrangerBalance.toNumber(), newStrangerBalance.toNumber());
530
+ });
531
+ it('allows transfer of partial balance by owner to specified address', async () => {
532
+ const partialAmount = 6;
533
+ const difference = payment - partialAmount;
534
+ await oc
535
+ .connect(roles.defaultAccount)
536
+ .withdraw(roles.stranger.address, partialAmount);
537
+ const strangerBalance = await link.balanceOf(roles.stranger.address);
538
+ const oracleBalance = await link.balanceOf(oc.address);
539
+ chai_1.assert.equal(partialAmount, strangerBalance.toNumber());
540
+ chai_1.assert.equal(difference, oracleBalance.toNumber());
541
+ });
542
+ it('allows transfer of entire balance by owner to specified address', async () => {
543
+ await oc
544
+ .connect(roles.defaultAccount)
545
+ .withdraw(roles.stranger.address, payment);
546
+ const balance = await link.balanceOf(roles.stranger.address);
547
+ chai_1.assert.equal(payment, balance.toNumber());
548
+ });
549
+ it('does not allow a transfer of funds by non-owner', async () => {
550
+ await test_helpers_1.matchers.evmRevert(async () => {
551
+ await oc
552
+ .connect(roles.stranger)
553
+ .withdraw(roles.stranger.address, payment);
554
+ });
555
+ const balance = await link.balanceOf(roles.stranger.address);
556
+ chai_1.assert.isTrue(ethers_1.ethers.constants.Zero.eq(balance));
557
+ });
558
+ });
559
+ });
560
+ });
561
+ describe('#withdrawable', () => {
562
+ let request;
563
+ beforeEach(async () => {
564
+ var _a, _b;
565
+ const amount = test_helpers_1.helpers.toWei('1');
566
+ const mock = await getterSetterFactory
567
+ .connect(roles.defaultAccount)
568
+ .deploy();
569
+ const args = test_helpers_1.oracle.encodeOracleRequest(specId, mock.address, fHash, 0, '0x0');
570
+ const tx = await link.transferAndCall(oc.address, amount, args);
571
+ const receipt = await tx.wait();
572
+ chai_1.assert.equal(3, (_a = receipt.logs) === null || _a === void 0 ? void 0 : _a.length);
573
+ request = test_helpers_1.oracle.decodeRunRequest((_b = receipt.logs) === null || _b === void 0 ? void 0 : _b[2]);
574
+ await oc
575
+ .connect(roles.oracleNode)
576
+ .fulfillOracleRequest(...test_helpers_1.oracle.convertFufillParams(request, 'Hello World!'));
577
+ });
578
+ it('returns the correct value', async () => {
579
+ const withdrawAmount = await oc.withdrawable();
580
+ test_helpers_1.matchers.bigNum(withdrawAmount, request.payment);
581
+ });
582
+ });
583
+ describe('#cancelOracleRequest', () => {
584
+ describe('with no pending requests', () => {
585
+ it('fails', async () => {
586
+ const fakeRequest = {
587
+ requestId: ethers_1.ethers.utils.formatBytes32String('1337'),
588
+ payment: '0',
589
+ callbackFunc: getterSetterFactory.interface.functions.requestedBytes32.sighash,
590
+ expiration: '999999999999',
591
+ callbackAddr: '',
592
+ data: Buffer.from(''),
593
+ dataVersion: 0,
594
+ specId: '',
595
+ requester: '',
596
+ topic: '',
597
+ };
598
+ await test_helpers_1.helpers.increaseTime5Minutes(provider);
599
+ await test_helpers_1.matchers.evmRevert(async () => {
600
+ await oc
601
+ .connect(roles.stranger)
602
+ .cancelOracleRequest(...test_helpers_1.oracle.convertCancelParams(fakeRequest));
603
+ });
604
+ });
605
+ });
606
+ describe('with a pending request', () => {
607
+ const startingBalance = 100;
608
+ let request;
609
+ let receipt;
610
+ beforeEach(async () => {
611
+ var _a, _b;
612
+ const requestAmount = 20;
613
+ await link.transfer(roles.consumer.address, startingBalance);
614
+ const args = test_helpers_1.oracle.encodeOracleRequest(specId, roles.consumer.address, fHash, 1, '0x0');
615
+ const tx = await link
616
+ .connect(roles.consumer)
617
+ .transferAndCall(oc.address, requestAmount, args);
618
+ receipt = await tx.wait();
619
+ chai_1.assert.equal(3, (_a = receipt.logs) === null || _a === void 0 ? void 0 : _a.length);
620
+ request = test_helpers_1.oracle.decodeRunRequest((_b = receipt.logs) === null || _b === void 0 ? void 0 : _b[2]);
621
+ });
622
+ it('has correct initial balances', async () => {
623
+ const oracleBalance = await link.balanceOf(oc.address);
624
+ test_helpers_1.matchers.bigNum(request.payment, oracleBalance);
625
+ const consumerAmount = await link.balanceOf(roles.consumer.address);
626
+ chai_1.assert.equal(startingBalance - Number(request.payment), consumerAmount.toNumber());
627
+ });
628
+ describe('from a stranger', () => {
629
+ it('fails', async () => {
630
+ await test_helpers_1.matchers.evmRevert(async () => {
631
+ await oc
632
+ .connect(roles.consumer)
633
+ .cancelOracleRequest(...test_helpers_1.oracle.convertCancelParams(request));
634
+ });
635
+ });
636
+ });
637
+ describe('from the requester', () => {
638
+ it('refunds the correct amount', async () => {
639
+ await test_helpers_1.helpers.increaseTime5Minutes(provider);
640
+ await oc
641
+ .connect(roles.consumer)
642
+ .cancelOracleRequest(...test_helpers_1.oracle.convertCancelParams(request));
643
+ const balance = await link.balanceOf(roles.consumer.address);
644
+ chai_1.assert.equal(startingBalance, balance.toNumber()); // 100
645
+ });
646
+ it('triggers a cancellation event', async () => {
647
+ var _a, _b;
648
+ await test_helpers_1.helpers.increaseTime5Minutes(provider);
649
+ const tx = await oc
650
+ .connect(roles.consumer)
651
+ .cancelOracleRequest(...test_helpers_1.oracle.convertCancelParams(request));
652
+ const receipt = await tx.wait();
653
+ chai_1.assert.equal((_a = receipt.logs) === null || _a === void 0 ? void 0 : _a.length, 2);
654
+ chai_1.assert.equal(request.requestId, (_b = receipt.logs) === null || _b === void 0 ? void 0 : _b[0].topics[1]);
655
+ });
656
+ it('fails when called twice', async () => {
657
+ await test_helpers_1.helpers.increaseTime5Minutes(provider);
658
+ await oc
659
+ .connect(roles.consumer)
660
+ .cancelOracleRequest(...test_helpers_1.oracle.convertCancelParams(request));
661
+ await test_helpers_1.matchers.evmRevert(oc
662
+ .connect(roles.consumer)
663
+ .cancelOracleRequest(...test_helpers_1.oracle.convertCancelParams(request)));
664
+ });
665
+ });
666
+ });
667
+ });
668
+ });
669
+ //# sourceMappingURL=Oracle.test.js.map