Created
April 17, 2022 07:33
-
-
Save ashish173/dbb8e551ee34100ce3814c4d7facd852 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.4.22 <0.9.0; | |
library TestsAccounts { | |
function getAccount(uint index) pure public returns (address) { | |
address[15] memory accounts; | |
accounts[0] = 0x5B38Da6a701c568545dCfcB03FcB875f56beddC4; | |
accounts[1] = 0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2; | |
accounts[2] = 0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db; | |
accounts[3] = 0x78731D3Ca6b7E34aC0F824c42a7cC18A495cabaB; | |
accounts[4] = 0x617F2E2fD72FD9D5503197092aC168c91465E7f2; | |
accounts[5] = 0x17F6AD8Ef982297579C203069C1DbfFE4348c372; | |
accounts[6] = 0x5c6B0f7Bf3E7ce046039Bd8FABdfD3f9F5021678; | |
accounts[7] = 0x03C6FcED478cBbC9a4FAB34eF9f40767739D1Ff7; | |
accounts[8] = 0x1aE0EA34a72D944a8C7603FfB3eC30a6669E454C; | |
accounts[9] = 0x0A098Eda01Ce92ff4A4CCb7A4fFFb5A43EBC70DC; | |
accounts[10] = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c; | |
accounts[11] = 0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C; | |
accounts[12] = 0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB; | |
accounts[13] = 0x583031D1113aD414F02576BD6afaBfb302140225; | |
accounts[14] = 0xdD870fA1b7C4700F2BD7f44238821C26f7392148; | |
return accounts[index]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.4.22 <0.9.0; | |
library Assert { | |
event AssertionEvent( | |
bool passed, | |
string message, | |
string methodName | |
); | |
event AssertionEventUint( | |
bool passed, | |
string message, | |
string methodName, | |
uint256 returned, | |
uint256 expected | |
); | |
event AssertionEventInt( | |
bool passed, | |
string message, | |
string methodName, | |
int256 returned, | |
int256 expected | |
); | |
event AssertionEventBool( | |
bool passed, | |
string message, | |
string methodName, | |
bool returned, | |
bool expected | |
); | |
event AssertionEventAddress( | |
bool passed, | |
string message, | |
string methodName, | |
address returned, | |
address expected | |
); | |
event AssertionEventBytes32( | |
bool passed, | |
string message, | |
string methodName, | |
bytes32 returned, | |
bytes32 expected | |
); | |
event AssertionEventString( | |
bool passed, | |
string message, | |
string methodName, | |
string returned, | |
string expected | |
); | |
event AssertionEventUintInt( | |
bool passed, | |
string message, | |
string methodName, | |
uint256 returned, | |
int256 expected | |
); | |
event AssertionEventIntUint( | |
bool passed, | |
string message, | |
string methodName, | |
int256 returned, | |
uint256 expected | |
); | |
function ok(bool a, string memory message) public returns (bool result) { | |
result = a; | |
emit AssertionEvent(result, message, "ok"); | |
} | |
function equal(uint256 a, uint256 b, string memory message) public returns (bool result) { | |
result = (a == b); | |
emit AssertionEventUint(result, message, "equal", a, b); | |
} | |
function equal(int256 a, int256 b, string memory message) public returns (bool result) { | |
result = (a == b); | |
emit AssertionEventInt(result, message, "equal", a, b); | |
} | |
function equal(bool a, bool b, string memory message) public returns (bool result) { | |
result = (a == b); | |
emit AssertionEventBool(result, message, "equal", a, b); | |
} | |
// TODO: only for certain versions of solc | |
//function equal(fixed a, fixed b, string message) public returns (bool result) { | |
// result = (a == b); | |
// emit AssertionEvent(result, message); | |
//} | |
// TODO: only for certain versions of solc | |
//function equal(ufixed a, ufixed b, string message) public returns (bool result) { | |
// result = (a == b); | |
// emit AssertionEvent(result, message); | |
//} | |
function equal(address a, address b, string memory message) public returns (bool result) { | |
result = (a == b); | |
emit AssertionEventAddress(result, message, "equal", a, b); | |
} | |
function equal(bytes32 a, bytes32 b, string memory message) public returns (bool result) { | |
result = (a == b); | |
emit AssertionEventBytes32(result, message, "equal", a, b); | |
} | |
function equal(string memory a, string memory b, string memory message) public returns (bool result) { | |
result = (keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b))); | |
emit AssertionEventString(result, message, "equal", a, b); | |
} | |
function notEqual(uint256 a, uint256 b, string memory message) public returns (bool result) { | |
result = (a != b); | |
emit AssertionEventUint(result, message, "notEqual", a, b); | |
} | |
function notEqual(int256 a, int256 b, string memory message) public returns (bool result) { | |
result = (a != b); | |
emit AssertionEventInt(result, message, "notEqual", a, b); | |
} | |
function notEqual(bool a, bool b, string memory message) public returns (bool result) { | |
result = (a != b); | |
emit AssertionEventBool(result, message, "notEqual", a, b); | |
} | |
// TODO: only for certain versions of solc | |
//function notEqual(fixed a, fixed b, string message) public returns (bool result) { | |
// result = (a != b); | |
// emit AssertionEvent(result, message); | |
//} | |
// TODO: only for certain versions of solc | |
//function notEqual(ufixed a, ufixed b, string message) public returns (bool result) { | |
// result = (a != b); | |
// emit AssertionEvent(result, message); | |
//} | |
function notEqual(address a, address b, string memory message) public returns (bool result) { | |
result = (a != b); | |
emit AssertionEventAddress(result, message, "notEqual", a, b); | |
} | |
function notEqual(bytes32 a, bytes32 b, string memory message) public returns (bool result) { | |
result = (a != b); | |
emit AssertionEventBytes32(result, message, "notEqual", a, b); | |
} | |
function notEqual(string memory a, string memory b, string memory message) public returns (bool result) { | |
result = (keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b))); | |
emit AssertionEventString(result, message, "notEqual", a, b); | |
} | |
/*----------------- Greater than --------------------*/ | |
function greaterThan(uint256 a, uint256 b, string memory message) public returns (bool result) { | |
result = (a > b); | |
emit AssertionEventUint(result, message, "greaterThan", a, b); | |
} | |
function greaterThan(int256 a, int256 b, string memory message) public returns (bool result) { | |
result = (a > b); | |
emit AssertionEventInt(result, message, "greaterThan", a, b); | |
} | |
// TODO: safely compare between uint and int | |
function greaterThan(uint256 a, int256 b, string memory message) public returns (bool result) { | |
if(b < int(0)) { | |
// int is negative uint "a" always greater | |
result = true; | |
} else { | |
result = (a > uint(b)); | |
} | |
emit AssertionEventUintInt(result, message, "greaterThan", a, b); | |
} | |
function greaterThan(int256 a, uint256 b, string memory message) public returns (bool result) { | |
if(a < int(0)) { | |
// int is negative uint "b" always greater | |
result = false; | |
} else { | |
result = (uint(a) > b); | |
} | |
emit AssertionEventIntUint(result, message, "greaterThan", a, b); | |
} | |
/*----------------- Lesser than --------------------*/ | |
function lesserThan(uint256 a, uint256 b, string memory message) public returns (bool result) { | |
result = (a < b); | |
emit AssertionEventUint(result, message, "lesserThan", a, b); | |
} | |
function lesserThan(int256 a, int256 b, string memory message) public returns (bool result) { | |
result = (a < b); | |
emit AssertionEventInt(result, message, "lesserThan", a, b); | |
} | |
// TODO: safely compare between uint and int | |
function lesserThan(uint256 a, int256 b, string memory message) public returns (bool result) { | |
if(b < int(0)) { | |
// int is negative int "b" always lesser | |
result = false; | |
} else { | |
result = (a < uint(b)); | |
} | |
emit AssertionEventUintInt(result, message, "lesserThan", a, b); | |
} | |
function lesserThan(int256 a, uint256 b, string memory message) public returns (bool result) { | |
if(a < int(0)) { | |
// int is negative int "a" always lesser | |
result = true; | |
} else { | |
result = (uint(a) < b); | |
} | |
emit AssertionEventIntUint(result, message, "lesserThan", a, b); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.7; | |
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; | |
contract PriceConsumerV3 { | |
AggregatorV3Interface internal priceFeed; | |
/** | |
* Network: Kovan | |
* Aggregator: ETH/USD | |
* Address: 0x9326BFA02ADD2366b30bacB125260Af641031331 | |
*/ | |
constructor() { | |
priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331); | |
} | |
/** | |
* Returns the latest price | |
*/ | |
function getLatestPrice() public view returns (int) { | |
( | |
/*uint80 roundID*/, | |
int price, | |
/*uint startedAt*/, | |
/*uint timeStamp*/, | |
/*uint80 answeredInRound*/ | |
) = priceFeed.latestRoundData(); | |
return price; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment