feature: inject an optics object into hre

buddies-main-deployment
James Prestwich 4 years ago committed by James Prestwich
parent 3e00a306db
commit fc7f2327f0
No known key found for this signature in database
GPG Key ID: 7CC174C250AD83AD
  1. 18
      solidity/contracts/Queue.sol
  2. 10
      solidity/contracts/test/TestQueue.sol
  3. 2
      solidity/hardhat.config.js
  4. 48
      solidity/lib/index.js
  5. 2
      solidity/package.json
  6. 1
      solidity/scripts/deploy.js

@ -43,8 +43,8 @@ library QueueLib {
returns (uint128 _last)
{
_last = _q.last;
for (uint i = 0; i<_items.length; i+=1) {
_last+= 1;
for (uint256 i = 0; i < _items.length; i += 1) {
_last += 1;
bytes32 _item = _items[i];
if (_item != bytes32(0)) {
_q.queue[_last] = _item;
@ -53,8 +53,10 @@ library QueueLib {
_q.last = _last;
}
function dequeue(Queue storage _q, uint256 _number) internal returns (bytes32[] memory) {
function dequeue(Queue storage _q, uint256 _number)
internal
returns (bytes32[] memory)
{
uint128 _last = _q.last;
uint128 _first = _q.first;
// Cannot underflow unless state is corrupted
@ -62,7 +64,7 @@ library QueueLib {
bytes32[] memory _items = new bytes32[](_number);
for (uint i = 0; i < _number; i++) {
for (uint256 i = 0; i < _number; i++) {
_items[i] = _q.queue[_first];
delete _q.queue[_first];
_first++;
@ -98,7 +100,11 @@ library QueueLib {
return _q.last < _q.first;
}
function _length(uint128 _last, uint128 _first) internal pure returns (uint256) {
function _length(uint128 _last, uint128 _first)
internal
pure
returns (uint256)
{
return uint256(_last + 1 - _first);
}

@ -29,11 +29,17 @@ contract TestQueue is QueueManager {
return queue.dequeue();
}
function enqueueMany(bytes32[] calldata _items) external returns (uint256 _last) {
function enqueueMany(bytes32[] calldata _items)
external
returns (uint256 _last)
{
return queue.enqueue(_items);
}
function dequeueMany(uint256 _number) external returns (bytes32[] memory _items) {
function dequeueMany(uint256 _number)
external
returns (bytes32[] memory _items)
{
return queue.dequeue(_number);
}

@ -1,7 +1,7 @@
require('@nomiclabs/hardhat-waffle');
require('hardhat-gas-reporter');
require('solidity-coverage');
require('./lib');
require('./scripts');
/**

@ -0,0 +1,48 @@
require('@nomiclabs/hardhat-waffle');
const { extendEnvironment } = require('hardhat/config');
const HomeAbi = require('../artifacts/contracts/Home.sol/Home.json').abi;
const ReplicaAbi = require('../artifacts/contracts/Replica.sol/ProcessingReplica.json')
.abi;
extendEnvironment((hre) => {
const { ethers } = hre;
class Common extends ethers.Contract {
constructor(address, abi, providerOrSigner) {
super(address, abi, providerOrSigner);
}
}
class Home extends Common {
constructor(address, providerOrSigner) {
super(address, HomeAbi, providerOrSigner);
}
}
class Replica extends Common {
constructor(address, providerOrSigner) {
super(address, ReplicaAbi, providerOrSigner);
}
}
const getHomeFactory = async () => ethers.getContractFactory('Home');
const getReplicaFactory = async () =>
ethers.getContractFactory('ProcessingReplica');
hre.optics = {
Home,
Replica,
getHomeFactory,
getReplicaFactory,
deployHome: async (...args) => {
let contract = await (await getHomeFactory()).deploy(...args);
await contract.deployed();
return new Home(contract.address, contract.signer);
},
deployReplica: async (...args) => {
let contract = await (await getReplicaFactory()).deploy(...args);
await contract.deployed();
return new Replica(contract.address, contract.signer);
},
};
});

@ -22,7 +22,7 @@
},
"dependencies": {},
"scripts": {
"prettier": "prettier --write 'contracts/**/*.sol' ./test ./scripts",
"prettier": "prettier --write 'contracts/**/*.sol' ./test ./scripts ./lib",
"compile": "hardhat compile && ./scripts/update_abis.sh",
"coverage": "hardhat coverage",
"test": "hardhat test"

@ -1,3 +1,4 @@
// const { hre } = require('hardhat');
const { types } = require('hardhat/config');
task('deploy-home')

Loading…
Cancel
Save