Skip to content

Commit 800123b

Browse files
authored
Merge pull request th4s#1 from PumpkinSeed/I7-development-env
Setup development environment
2 parents ebbbd2a + d3c7ca3 commit 800123b

File tree

17 files changed

+670
-240
lines changed

17 files changed

+670
-240
lines changed

.github/workflows/main.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
on: [push, pull_request]
2+
3+
name: Ethane Rust
4+
5+
jobs:
6+
check:
7+
name: Check
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions-rs/toolchain@v1
12+
with:
13+
# profile: minimal
14+
toolchain: stable
15+
override: true
16+
- uses: actions-rs/cargo@v1
17+
with:
18+
command: check
19+
20+
test:
21+
runs-on: ubuntu-latest
22+
services:
23+
ganache:
24+
image: pumpkinseed/ganache-fix
25+
ports:
26+
- 8545:8545
27+
env:
28+
WEB3_FORK_URL: ${{ secrets.INFURA_LINK }}
29+
steps:
30+
- name: Check out code
31+
uses: actions/checkout@v2
32+
- name: Setup Dependencies
33+
run: |
34+
sudo add-apt-repository ppa:ethereum/ethereum
35+
sudo apt-get update
36+
sudo apt-get install -y solc
37+
- uses: actions-rs/toolchain@v1
38+
with:
39+
profile: minimal
40+
toolchain: stable
41+
override: true
42+
- uses: actions-rs/cargo@v1
43+
with:
44+
command: test
45+

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
Cargo.lock
33
.idea/
44
/test-helper/target
5-
/test-helper/Cargo.lock
5+
/test-helper/Cargo.lock
6+
.env

src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! # Examples
1818
//!
1919
//! ## Request over http
20-
//! ```
20+
//! ```no_run
2121
//! use ethane::Connector;
2222
//! use ethane::rpc::eth_get_balance;
2323
//! use ethane::types::H160;
@@ -34,7 +34,7 @@
3434
//! ```
3535
//!
3636
//! ## Starting a subscription over websocket
37-
//! ```
37+
//! ```no_run
3838
//! use ethane::Connector;
3939
//! use ethane::rpc::sub::eth_subscribe_new_pending_transactions;
4040
//! # use test_helper::NodeProcess;

src/rpc/personal.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ pub fn personal_list_accounts() -> Rpc<Vec<H160>> {
1515
pub fn personal_unlock_account(
1616
address: H160,
1717
password: String,
18-
duration: Option<u32>,
18+
wrapped_duration: Option<u32>,
1919
) -> Rpc<bool> {
2020
let mut rpc = Rpc::new("personal_unlockAccount");
2121
rpc.add_param(address);
2222
rpc.add_param(password);
23-
if let Some(duration) = duration {
24-
rpc.add_param(duration);
25-
}
23+
let duration = match wrapped_duration {
24+
Some(duration) => duration,
25+
None => 0,
26+
};
27+
rpc.add_param(duration);
2628
rpc
2729
}
2830

test-helper/infrastructure/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
### Start ganache instance
2+
3+
Create `.env` file and add this (replace the URL section with the infure url):
4+
5+
```
6+
WEB3_FORK_URL=<YOUR URL HERE>
7+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
3+
services:
4+
explorer:
5+
image: alethio/ethereum-lite-explorer
6+
environment:
7+
- APP_NODE_URL=http://localhost:8545
8+
ports:
9+
- 8080:80
10+
ganache:
11+
build:
12+
context: ./ganache-cli
13+
environment:
14+
- WEB3_FORK_URL=${WEB3_FORK_URL}
15+
ports:
16+
- "8545:8545"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# node:alpine will be our base image to create this image
2+
FROM node:alpine
3+
4+
ARG WEB3_FORK_URL
5+
ENV WEB3_FORK_URL ${WEB3_FORK_URL}
6+
7+
# Set the /app directory as working directory
8+
WORKDIR /app
9+
10+
# Install ganache-cli globally
11+
RUN npm install -g ganache-cli
12+
13+
EXPOSE 8545
14+
15+
# Set the default command for the image
16+
# Add a fix private key and 1000 ETH on it.
17+
CMD ganache-cli -h 0.0.0.0 --fork ${WEB3_FORK_URL} \
18+
--account "0x31c354f57fc542eba2c56699286723e94f7bd02a4891a0a7f68566c2a2df6795,100000000000000000000000" \
19+
--account "0x31c354f57fc342eba2c56699286723e94f7bd12a4891a0a7f68566c2a2df6795,100000000000000000000000" \
20+
--account "0x31c354f57fc342eba2c56699286723e94f7bd12a4891a0a7f68566c2a2d56795,100000000000000000000000"
+211
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
//SPDX-License-Identifier: UNLICENSED
2+
3+
pragma solidity ^0.8.1;
4+
5+
contract Ownable {
6+
address private _owner;
7+
8+
constructor() {
9+
_owner = msg.sender;
10+
}
11+
12+
modifier onlyOwner() {
13+
require(isOwner(), "Ownable: caller is not the owner");
14+
_;
15+
}
16+
17+
function owner() public view returns (address) {
18+
return _owner;
19+
}
20+
21+
function isOwner() public view returns (bool) {
22+
return msg.sender == _owner;
23+
}
24+
}
25+
26+
library SafeMath {
27+
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
28+
if (a == 0) {
29+
return 0;
30+
}
31+
32+
uint256 c = a * b;
33+
assert(c / a == b);
34+
return c;
35+
}
36+
37+
function div(uint256 a, uint256 b) internal pure returns (uint256) {
38+
uint256 c = a / b;
39+
return c;
40+
}
41+
42+
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
43+
assert(b <= a);
44+
return a - b;
45+
}
46+
47+
function add(uint256 a, uint256 b) internal pure returns (uint256) {
48+
uint256 c = a + b;
49+
assert(c >= a);
50+
return c;
51+
}
52+
}
53+
54+
contract Pausable is Ownable {
55+
event Paused(address account);
56+
event Unpaused(address account);
57+
58+
bool private _paused;
59+
60+
modifier whenNotPaused() {
61+
require(!_paused, "Pausable: paused");
62+
_;
63+
}
64+
65+
modifier whenPaused() {
66+
require(_paused, "Pausable: not paused");
67+
_;
68+
}
69+
70+
function paused() public view returns (bool)
71+
{
72+
return _paused;
73+
}
74+
75+
function pause() public onlyOwner whenNotPaused {
76+
_paused = true;
77+
emit Paused(msg.sender);
78+
}
79+
80+
function unpause() public onlyOwner whenPaused {
81+
_paused = false;
82+
emit Unpaused(msg.sender);
83+
}
84+
}
85+
86+
contract ERC20 is Ownable, Pausable {
87+
using SafeMath for uint;
88+
89+
string internal _name;
90+
string internal _symbol;
91+
uint8 internal _decimals;
92+
uint256 internal _totalSupply;
93+
94+
mapping (address => uint256) internal _balances;
95+
mapping (address => mapping (address => uint256)) internal _allowed;
96+
97+
event Mint(address indexed minter, address indexed account, uint256 amount);
98+
event Burn(address indexed burner, address indexed account, uint256 amount);
99+
100+
constructor (string memory nameC, string memory symbolC, uint8 decimalsC, uint256 totalSupplyC) {
101+
_symbol = symbolC;
102+
_name = nameC;
103+
_decimals = decimalsC;
104+
_totalSupply = totalSupplyC;
105+
_balances[msg.sender] = totalSupplyC;
106+
}
107+
108+
function name() public view returns (string memory) {
109+
return _name;
110+
}
111+
112+
function symbol() public view returns (string memory) {
113+
return _symbol;
114+
}
115+
116+
function decimals() public view returns (uint8) {
117+
return _decimals;
118+
}
119+
120+
function totalSupply() public view returns (uint256) {
121+
return _totalSupply;
122+
}
123+
124+
function transfer(address _to, uint256 _value) public whenNotPaused returns (bool) {
125+
require(_to != address(0), 'ERC20: to address is not valid');
126+
require(_value <= _balances[msg.sender], 'ERC20: insufficient balance');
127+
128+
_balances[msg.sender] = SafeMath.sub(_balances[msg.sender], _value);
129+
_balances[_to] = SafeMath.add(_balances[_to], _value);
130+
131+
emit Transfer(msg.sender, _to, _value);
132+
133+
return true;
134+
}
135+
136+
function balanceOf(address _owner) public view returns (uint256 balance) {
137+
return _balances[_owner];
138+
}
139+
140+
function approve(address _spender, uint256 _value) public whenNotPaused returns (bool) {
141+
_allowed[msg.sender][_spender] = _value;
142+
143+
emit Approval(msg.sender, _spender, _value);
144+
145+
return true;
146+
}
147+
148+
function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool) {
149+
require(_from != address(0), 'ERC20: from address is not valid');
150+
require(_to != address(0), 'ERC20: to address is not valid');
151+
require(_value <= _balances[_from], 'ERC20: insufficient balance');
152+
require(_value <= _allowed[_from][msg.sender], 'ERC20: from not allowed');
153+
154+
_balances[_from] = SafeMath.sub(_balances[_from], _value);
155+
_balances[_to] = SafeMath.add(_balances[_to], _value);
156+
_allowed[_from][msg.sender] = SafeMath.sub(_allowed[_from][msg.sender], _value);
157+
158+
emit Transfer(_from, _to, _value);
159+
160+
return true;
161+
}
162+
163+
function allowance(address _owner, address _spender) public view whenNotPaused returns (uint256) {
164+
return _allowed[_owner][_spender];
165+
}
166+
167+
function increaseApproval(address _spender, uint _addedValue) public whenNotPaused returns (bool) {
168+
_allowed[msg.sender][_spender] = SafeMath.add(_allowed[msg.sender][_spender], _addedValue);
169+
170+
emit Approval(msg.sender, _spender, _allowed[msg.sender][_spender]);
171+
172+
return true;
173+
}
174+
175+
function decreaseApproval(address _spender, uint _subtractedValue) public whenNotPaused returns (bool) {
176+
uint oldValue = _allowed[msg.sender][_spender];
177+
178+
if (_subtractedValue > oldValue) {
179+
_allowed[msg.sender][_spender] = 0;
180+
} else {
181+
_allowed[msg.sender][_spender] = SafeMath.sub(oldValue, _subtractedValue);
182+
}
183+
184+
emit Approval(msg.sender, _spender, _allowed[msg.sender][_spender]);
185+
186+
return true;
187+
}
188+
189+
function mintTo(address _to, uint _amount) public whenNotPaused onlyOwner {
190+
require(_to != address(0), 'ERC20: to address is not valid');
191+
require(_amount > 0, 'ERC20: amount is not valid');
192+
193+
_totalSupply = _totalSupply.add(_amount);
194+
_balances[_to] = _balances[_to].add(_amount);
195+
196+
emit Mint(msg.sender, _to, _amount);
197+
}
198+
199+
function burnFrom(address _from, uint _amount) public whenNotPaused onlyOwner {
200+
require(_from != address(0), 'ERC20: from address is not valid');
201+
require(_balances[_from] >= _amount, 'ERC20: insufficient balance');
202+
203+
_balances[_from] = _balances[_from].sub(_amount);
204+
_totalSupply = _totalSupply.sub(_amount);
205+
206+
emit Burn(msg.sender, _from, _amount);
207+
}
208+
209+
event Transfer(address indexed from, address indexed to, uint256 value);
210+
event Approval(address indexed owner, address indexed spender, uint256 value);
211+
}

test-helper/src/fixtures/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
pub const TEST_CONTRACT_PATH: &str = "./test-helper/src/fixtures/TestContract.sol";
22
pub const TEST_CONTRACT_NAME: &str = "TestContract";
3+
pub const TEST_ERC20_PATH: &str = "./test-helper/src/fixtures/TestERC20.sol";
4+
pub const TEST_ERC20_NAME: &str = "ERC20";
35
pub const ACCOUNTS_PASSWORD: &str = "12345678";
46
pub const FIX_SECRET: &str = "fdc861959d1768d936bf17eec56260d4de3a7473e58c349e31beba539e5fc88d";
57
pub const FIX_ADDRESS: &str = "0xDc677f7C5060B0b441d30F361D0c8529Ac04E099";

0 commit comments

Comments
 (0)