Hitesh_jadhav

stackoverflow_test_of_getLatestPrice()

Jun 21st, 2022 (edited)
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. what should be the problem over here?
  2.  
  3. test.js =>
  4.  
  5. const { expect } = require("chai");
  6.  
  7. describe("test for price feed", async function ()
  8. {
  9. let Token;
  10. let hahrdhatToken;
  11. let owner;
  12. let add1;
  13. let add2;
  14. let add3;
  15. beforeEach(async function ()
  16. {
  17. [owner, add1, add2, add3, ...addrs] = await ethers.getSigners();
  18. PriceConsumerV3 = await ethers.getContractFactory("PriceConsumerV3");
  19. hardhatToken = await PriceConsumerV3.deploy();
  20. });
  21. it("lets see it gives the error or not after transfer", async function ()
  22. {
  23. const pricefromcontract = await hardhatToken.getLatestPrice();
  24. expect(pricefromcontract).to.equal(116415000000);
  25. console.log(pricefromcontract);
  26. })
  27. })
  28.  
  29. PriceaConsumerv3 =>
  30.  
  31. // SPDX-License-Identifier: MIT
  32. pragma solidity ^0.8.7;
  33.  
  34. import "./AggregatorV3Interface.sol";
  35.  
  36. contract PriceConsumerV3 {
  37.  
  38. AggregatorV3Interface internal priceFeed;
  39.  
  40. /**
  41. * Network: Kovan
  42. * Aggregator: ETH/USD
  43. * Address: 0x9326BFA02ADD2366b30bacB125260Af641031331
  44. */
  45. constructor() {
  46. priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);
  47. }
  48.  
  49. /**
  50. * Returns the latest price
  51. */
  52. function getLatestPrice() public view returns (int) {
  53. (
  54. /*uint80 roundID*/,
  55. int price,
  56. /*uint startedAt*/,
  57. /*uint timeStamp*/,
  58. /*uint80 answeredInRound*/
  59. ) = priceFeed.latestRoundData();
  60. return price;
  61. }
  62. }
  63.  
  64.  
Add Comment
Please, Sign In to add comment