Skip to content

Commit

Permalink
updated for best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAlphaC committed Dec 18, 2020
2 parents 8429560 + 4219f8f commit f83bf96
Show file tree
Hide file tree
Showing 11 changed files with 2,464 additions and 633 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ There are 3 helper scripts provided with this box in the scripts directory:
- `request-data.js`
- `read-contract.js`

In addition, for working with Chainlink Price Feeds and ChainlinkVRF there are folders respectivly.
In addition, for working with Chainlink Price Feeds and ChainlinkVRF there are folders respectively.

They can be used by calling them from `npx truffle exec`, for example:

Expand Down Expand Up @@ -111,3 +111,6 @@ Node v10.16.3

- Add tests for ChainlinkVRF
- Add tests for Chainlink Price Feeds
- Refactor tests to use this instead of defining contracts with let
- Use the Chainlink-published mocks for [MockV3Aggregator](https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/tests/MockV3Aggregator.sol) and [VRFCoordinatorMock](https://github.com/smartcontractkit/chainlink/blob/develop/evm-contracts/src/v0.6/tests/VRFCoordinatorMock.sol)
- Upgrade to Solidity 0.6.12 (to show that you don't have to use 0.6.6)
2 changes: 1 addition & 1 deletion contracts/MyContract.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.6.6;
pragma solidity 0.6.12;

import "@chainlink/contracts/src/v0.6/ChainlinkClient.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/PriceConsumerV3.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

pragma solidity ^0.6.6;
pragma solidity ^0.6.12;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";

Expand Down Expand Up @@ -28,4 +28,4 @@ contract PriceConsumerV3 {
) = priceFeed.latestRoundData();
return price;
}
}
}
6 changes: 2 additions & 4 deletions contracts/RandomNumberConsumer.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

pragma solidity 0.6.6;
pragma solidity 0.6.12;

import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";

Expand All @@ -8,7 +8,6 @@ contract RandomNumberConsumer is VRFConsumerBase {
bytes32 internal keyHash;
uint256 internal fee;
address public linkTokenAddress;

uint256 public randomResult;

/**
Expand All @@ -34,7 +33,6 @@ contract RandomNumberConsumer is VRFConsumerBase {
* Requests randomness from a user-provided seed
*/
function getRandomNumber(uint256 userProvidedSeed) public returns (bytes32 requestId) {
require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet");
return requestRandomness(keyHash, fee, userProvidedSeed);
}

Expand All @@ -51,4 +49,4 @@ contract RandomNumberConsumer is VRFConsumerBase {
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
randomResult = randomness;
}
}
}
14 changes: 4 additions & 10 deletions migrations/3_price_consumer_v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ const PriceConsumerV3 = artifacts.require('PriceConsumerV3')
module.exports = async (deployer, network, [defaultAccount]) => {
// Local (development) networks need their own deployment of the LINK
// token and the Oracle contract
if (!network.startsWith('live')) {
try {
await deployer.deploy(PriceConsumerV3, { from: defaultAccount })
} catch (err) {
console.error(err)
}
} else {
// For live networks, use the 0 address to allow the ChainlinkRegistry
// contract automatically retrieve the correct address for you
deployer.deploy(PriceConsumerV3, { from: defaultAccount })
try {
await deployer.deploy(PriceConsumerV3, { from: defaultAccount })
} catch (err) {
console.error(err)
}
}
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
},
"license": "MIT",
"dependencies": {
"@chainlink/contracts": "^0.0.8",
"@chainlink/contracts": "^0.0.11",
"@openzeppelin/contracts": "^3.1.0",
"@truffle/hdwallet-provider": "^1.0.40",
"mathjs": "^8.1.0"
"@truffle/hdwallet-provider": "^1.2.0"
},
"devDependencies": {
"@chainlink/belt": "^0.0.1",
"@chainlink/belt": "^0.0.3",
"@chainlink/test-helpers": "0.0.5",
"@openzeppelin/test-helpers": "^0.5.6",
"chai": "^4.2.0",
"depcheck": "^0.9.1",
"jest": "^26.6.3",
"solhint": "^2.1.0",
"truffle": "^5.1.5"
"depcheck": "^1.3.1",
"solhint": "^3.3.2",
"truffle": "^5.1.57"
}
}
43 changes: 43 additions & 0 deletions package.json.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@chainlink/box",
"version": "0.6.0",
"description": "A Chainlink example in a Truffle box",
"scripts": {
"compile": "npx truffle compile",
"console:dev": "npx truffle console --network cldev",
"console:live": "npx truffle console --network live",
"depcheck": "echo '@chainlink/box' && depcheck --ignore-dirs=build/contracts || true",
"solhint": "solhint ./contracts/**/*.sol",
"lint": "yarn solhint",
"migrate:dev": "npx truffle migrate --reset --network cldev",
"migrate:live": "npx truffle migrate --network live",
"test": "npx truffle test"
},
"license": "MIT",
"dependencies": {
"@chainlink/contracts": "^0.0.11",
"@openzeppelin/contracts": "^3.1.0",
<<<<<<< HEAD
"@truffle/hdwallet-provider": "^1.0.40",
"mathjs": "^8.1.0"
=======
"@truffle/hdwallet-provider": "^1.2.0"
>>>>>>> 4219f8f21da822083b100dff85eb3b4b5c3c5e3f
},
"devDependencies": {
"@chainlink/belt": "^0.0.3",
"@chainlink/test-helpers": "0.0.5",
"@openzeppelin/test-helpers": "^0.5.6",
"chai": "^4.2.0",
<<<<<<< HEAD
"depcheck": "^0.9.1",
"jest": "^26.6.3",
"solhint": "^2.1.0",
"truffle": "^5.1.5"
=======
"depcheck": "^1.3.1",
"solhint": "^3.3.2",
"truffle": "^5.1.57"
>>>>>>> 4219f8f21da822083b100dff85eb3b4b5c3c5e3f
}
}
11 changes: 5 additions & 6 deletions scripts/random-number-consumer-scripts/request-randomness.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const RandomNumberConsumer = artifacts.require('RandomNumberConsumer')
const math = require("mathjs")

/*
This script allows for a Chainlink request for a
Expand All @@ -9,9 +8,9 @@ const math = require("mathjs")


module.exports = async callback => {
const USER_PROVIDED_SEED = process.env.RANDOM_SEED || 1
const randomNumberConsumer = await RandomNumberConsumer.deployed()
console.log('Creating getting a random number from: ', randomNumberConsumer.address)
const tx = await randomNumberConsumer.getRandomNumber(USER_PROVIDED_SEED)
callback(tx.tx)
const USER_PROVIDED_SEED = process.env.RANDOM_SEED || 1
const randomNumberConsumer = await RandomNumberConsumer.deployed()
console.log('Requesting a random number from: ', randomNumberConsumer.address)
const tx = await randomNumberConsumer.getRandomNumber(USER_PROVIDED_SEED)
callback(tx.tx)
}
6 changes: 2 additions & 4 deletions test/MyContract_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ contract('MyContract', accounts => {
// These parameters are used to validate the data was received
// on the deployed oracle contract. The Job ID only represents
// the type of data, but will not work on a public testnet.
// For the latest JobIDs, visit our docs here:
// https://docs.chain.link/docs/testnet-oracles
// Alternativly, visti a node listing service and choose your
// own nodes: https://market.link/
// For the latest JobIDs, visit a node listing service like:
// https://market.link/
const jobId = web3.utils.toHex('4c7b7ffb66b344fbaa64995af81e355a')
const url =
'https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD,EUR,JPY'
Expand Down
17 changes: 1 addition & 16 deletions truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,10 @@ module.exports = {
// Necessary due to https://github.com/trufflesuite/truffle/issues/3008
skipDryRun: true,
},
// TODO
// Setup a local ganache chain through the CLI
// so we can fork mainnet for testing
// test: {
// // provider: () => {
// // return new HDWalletProvider(process.env.MNEMONIC,
// // "http://127.0.0.1:8545")
// // },
// // host: "127.0.0.1",
// // port: 8545,
// // skipDryRun: true,
// skipDryRun: true,
// network_id: '*',
// fork: process.env.RPC_URL
// }
},
compilers: {
solc: {
version: '0.6.6',
version: '0.6.12',
},
},
}
Loading

0 comments on commit f83bf96

Please sign in to comment.