Skip to content

Commit 16be26f

Browse files
committedDec 9, 2020
lint-staged on contracts

14 files changed

+82
-115
lines changed
 

‎.lintstagedrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
'*.{js,ts,vue}': 'eslint --cache --fix',
3-
'*.{js,ts,css,md}': 'prettier --write',
3+
'*.{js,ts,css,md,sol}': 'prettier --write',
44
};

‎contracts/.eslintrc.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ module.exports = {
1717
},
1818

1919
// Rules order is important,
20-
extends: [
21-
'airbnb-base',
22-
'plugin:chai-friendly/recommended',
23-
],
20+
extends: ['airbnb-base', 'plugin:chai-friendly/recommended'],
2421

25-
plugins: [
26-
],
22+
plugins: [],
2723

2824
// add your custom rules here
2925
rules: {
@@ -44,8 +40,14 @@ module.exports = {
4440
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
4541

4642
// Max line length of 100 characters, except for lines with comments or strings
47-
'max-len': ['error', {
48-
code: 100, ignoreComments: true, ignoreTrailingComments: true, ignoreStrings: true,
49-
}],
43+
'max-len': [
44+
'error',
45+
{
46+
code: 100,
47+
ignoreComments: true,
48+
ignoreTrailingComments: true,
49+
ignoreStrings: true,
50+
},
51+
],
5052
},
5153
};

‎contracts/.lintstagedrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
...require('../.lintstagedrc'),
3+
};

‎contracts/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ On chain components of the [Umbra protocol](../README.md).
88

99
Contract development uses the OpenZeppelin tools and test framework. All are installed and exercised via `npm`. Development has been tested with:
1010

11-
* node.js v12.16.1 or later
12-
* yarn 1.22.0 or later
11+
- node.js v12.16.1 or later
12+
- yarn 1.22.0 or later
1313

1414
### Usage
1515

1616
From the current working directory, run `yarn install`. Afterwards run:
1717

18-
* `yarn compile` — To compile all contracts
19-
* `yarn test` — To run all tests
18+
- `yarn compile` — To compile all contracts
19+
- `yarn test` — To run all tests
2020

2121
To deploy to Ropsten, you'll need to create a `.env` file with the following:
2222

@@ -25,4 +25,4 @@ INFURA_ID="Your Infura API Key"
2525
ROPSTEN_MNEMONIC="Your Ropsten address mnemonic"
2626
```
2727

28-
Then run `npx oz deploy` and follow the prompts.
28+
Then run `npx oz deploy` and follow the prompts.

‎contracts/contracts/TestToken.sol

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@ pragma solidity ^0.6.12;
44

55
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
66

7-
87
contract TestToken is ERC20 {
9-
10-
constructor (string memory name, string memory symbol)
11-
ERC20(name, symbol)
12-
public {}
8+
constructor(string memory name, string memory symbol) public ERC20(name, symbol) {}
139

1410
function mint(address account, uint256 amount) public {
1511
_mint(account, amount);

‎contracts/contracts/Umbra.sol

+5-16
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ contract Umbra is BaseRelayRecipient, IKnowForwarderAddress, Ownable {
6868
trustedForwarder = _forwarder;
6969
}
7070

71-
function getTrustedForwarder() external override view returns(address) {
71+
function getTrustedForwarder() external view override returns (address) {
7272
return trustedForwarder;
7373
}
7474

75-
function versionRecipient() external override view returns (string memory) {
75+
function versionRecipient() external view override returns (string memory) {
7676
return "1.0.0";
7777
}
7878

@@ -84,13 +84,7 @@ contract Umbra is BaseRelayRecipient, IKnowForwarderAddress, Ownable {
8484
require(msg.value > toll, "Umbra: Must pay more than the toll");
8585

8686
uint256 amount = msg.value.sub(toll);
87-
emit Announcement(
88-
_receiver,
89-
amount,
90-
ETH_TOKEN_PLACHOLDER,
91-
_pkx,
92-
_ciphertext
93-
);
87+
emit Announcement(_receiver, amount, ETH_TOKEN_PLACHOLDER, _pkx, _ciphertext);
9488

9589
_receiver.transfer(amount);
9690
}
@@ -109,12 +103,7 @@ contract Umbra is BaseRelayRecipient, IKnowForwarderAddress, Ownable {
109103
);
110104

111105
tokenPayments[_receiver] = TokenPayment({token: _tokenAddr, amount: _amount});
112-
emit Announcement(
113-
_receiver,
114-
_amount,
115-
_tokenAddr,
116-
_pkx,
117-
_ciphertext);
106+
emit Announcement(_receiver, _amount, _tokenAddr, _pkx, _ciphertext);
118107

119108
SafeERC20.safeTransferFrom(IERC20(_tokenAddr), _msgSender(), address(this), _amount);
120109
}
@@ -133,8 +122,8 @@ contract Umbra is BaseRelayRecipient, IKnowForwarderAddress, Ownable {
133122

134123
function _msgSender()
135124
internal
136-
override(Context, BaseRelayRecipient)
137125
view
126+
override(Context, BaseRelayRecipient)
138127
returns (address payable)
139128
{
140129
return BaseRelayRecipient._msgSender();

‎contracts/contracts/UmbraPaymaster.sol

+12-18
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,28 @@ contract UmbraPaymaster is BasePaymaster {
1313
umbraAddr = _umbraAddr;
1414
}
1515

16-
function versionPaymaster() external override view returns (string memory) {
16+
function versionPaymaster() external view override returns (string memory) {
1717
return "1.0.0";
1818
}
1919

2020
function preRelayedCall(
21-
GsnTypes.RelayRequest calldata relayRequest,
22-
bytes calldata signature,
23-
bytes calldata approvalData,
24-
uint256 maxPossibleGas
25-
)
26-
external
27-
override
28-
returns (bytes memory context, bool rejectOnRecipientRevert) {
29-
(signature, approvalData, maxPossibleGas); // to silence compiler warnings
30-
31-
require(relayRequest.request.to == umbraAddr, "UmbraPaymaster: Not Target");
32-
return (abi.encode(0x0), true);
33-
}
21+
GsnTypes.RelayRequest calldata relayRequest,
22+
bytes calldata signature,
23+
bytes calldata approvalData,
24+
uint256 maxPossibleGas
25+
) external override returns (bytes memory context, bool rejectOnRecipientRevert) {
26+
(signature, approvalData, maxPossibleGas); // to silence compiler warnings
27+
28+
require(relayRequest.request.to == umbraAddr, "UmbraPaymaster: Not Target");
29+
return (abi.encode(0x0), true);
30+
}
3431

3532
function postRelayedCall(
3633
bytes calldata context,
3734
bool success,
3835
uint256 gasUseWithoutPost,
3936
GsnTypes.RelayData calldata relayData
40-
)
41-
external
42-
override
43-
relayHubOnly {
37+
) external override relayHubOnly {
4438
(context, success, gasUseWithoutPost, relayData); // to silence compiler warnings
4539
}
4640
}

‎contracts/networks.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ const HDWalletProvider = require('@truffle/hdwallet-provider');
44
const projectId = process.env.INFURA_ID;
55
const mnemonic = process.env.ROPSTEN_MNEMONIC;
66

7-
module.exports = {
8-
networks: {
9-
7+
module.exports = {
8+
networks: {
109
ropsten: {
11-
provider: () => new HDWalletProvider(
12-
mnemonic, `https://ropsten.infura.io/v3/${projectId}`
13-
),
10+
provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/${projectId}`),
1411
networkId: 3,
1512
gasPrice: 10e9,
1613
gas: 5e6,
17-
}
18-
},
19-
};
14+
},
15+
},
16+
};

‎contracts/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"clean": "rimraf build",
99
"test": "oz compile && mocha --exit --timeout 0 test/*-test.js",
1010
"gas": "oz compile && mocha --exit --timeout 0 test/gastests.js",
11-
"gas-optimized": "oz compile --optimizer on --optimizer-runs 1 && mocha --exit --timeout 0 test/gastests.js"
11+
"gas-optimized": "oz compile --optimizer on --optimizer-runs 1 && mocha --exit --timeout 0 test/gastests.js",
12+
"precommit": "lint-staged"
1213
},
1314
"dependencies": {
1415
"@opengsn/gsn": "^2.0.0-beta.1.3",

‎contracts/test-environment.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = { };
1+
module.exports = {};

‎contracts/test/sample-data.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
0x04a8ca477cb9ec0f45dd9aac5775487f224c4e40b08a60199a7789ed2a158cbee7e0ceb9d9f6bcf76d8221268f130d2218064a605f1cb670b4741ed4713baa5595
2-
0x15feb82777f1fe95dc9f13368e2d376a87fbad0354672b2aa983590d492a46a4
1+
/* eslint-disable */
2+
0x04a8ca477cb9ec0f45dd9aac5775487f224c4e40b08a60199a7789ed2a158cbee7e0ceb9d9f6bcf76d8221268f130d2218064a605f1cb670b4741ed4713baa5595;
3+
0x15feb82777f1fe95dc9f13368e2d376a87fbad0354672b2aa983590d492a46a4;
4+
/* eslint-enable */
5+
36
const rawData = {
4-
ephemeralPublicKey: '0x04a8ca477cb9ec0f45dd9aac5775487f224c4e40b08a60199a7789ed2a158cbee7e0ceb9d9f6bcf76d8221268f130d2218064a605f1cb670b4741ed4713baa5595',
7+
ephemeralPublicKey:
8+
'0x04a8ca477cb9ec0f45dd9aac5775487f224c4e40b08a60199a7789ed2a158cbee7e0ceb9d9f6bcf76d8221268f130d2218064a605f1cb670b4741ed4713baa5595',
59
ciphertext: '0x15feb82777f1fe95dc9f13368e2d376a87fbad0354672b2aa983590d492a46a4',
610
};
711

‎contracts/test/umbra-gsn-test.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@ const origProvider = web3.currentProvider;
1818
const tokenAmount = toWei('100', 'ether');
1919

2020
describe('Umbra GSN', () => {
21-
const [
22-
owner,
23-
tollCollector,
24-
tollReceiver,
25-
payer,
26-
receiver,
27-
acceptor,
28-
other,
29-
] = accounts;
21+
const [owner, tollCollector, tollReceiver, payer, receiver, acceptor, other] = accounts;
3022

3123
const deployedToll = toWei('0.001', 'ether');
3224

@@ -42,7 +34,9 @@ describe('Umbra GSN', () => {
4234
// Start the GSN Test environment— this includes deployment of a relay hub, a forwarder, and
4335
// a stake manager, as well as starting a relay server. It also deploys a naive Paymaster, but we
4436
// will use our own
45-
const gsnInstance = await GsnTestEnvironment.startGsn(Umbra.web3.currentProvider.wrappedProvider.host);
37+
const gsnInstance = await GsnTestEnvironment.startGsn(
38+
Umbra.web3.currentProvider.wrappedProvider.host,
39+
);
4640

4741
// Save the forwader, as we'll need it when sending contract calls via our RelayProvider
4842
this.forwarder = gsnInstance.deploymentResult.forwarderAddress;
@@ -85,7 +79,7 @@ describe('Umbra GSN', () => {
8579

8680
// Drain the receiver's balance to ensure later that it is able to withdraw the
8781
// tokens sent to it without having to pay anything for gas.
88-
it('should drain the receiver\'s balance', async () => {
82+
it("should drain the receiver's balance", async () => {
8983
const receiverBalance = await web3.eth.getBalance(receiver);
9084
await web3.eth.sendTransaction({
9185
from: receiver,

‎contracts/test/umbra-test.js

+22-35
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('Umbra', () => {
8383
it('should not allow someone other than the owner to update the toll', async () => {
8484
await expectRevert(
8585
this.umbra.setToll(deployedToll, { from: other }),
86-
'Ownable: caller is not the owner',
86+
'Ownable: caller is not the owner'
8787
);
8888
});
8989

@@ -93,7 +93,7 @@ describe('Umbra', () => {
9393

9494
await expectRevert(
9595
this.umbra.sendEth(receiver1, ...argumentBytes, { from: payer1, value: paymentAmount }),
96-
'Umbra: Must pay more than the toll',
96+
'Umbra: Must pay more than the toll'
9797
);
9898
});
9999

@@ -102,7 +102,7 @@ describe('Umbra', () => {
102102

103103
await expectRevert(
104104
this.umbra.sendEth(receiver1, ...argumentBytes, { from: payer1, value: toll }),
105-
'Umbra: Must pay more than the toll',
105+
'Umbra: Must pay more than the toll'
106106
);
107107
});
108108

@@ -161,20 +161,16 @@ describe('Umbra', () => {
161161
it('should not let the eth receiver withdraw tokens', async () => {
162162
await expectRevert(
163163
this.umbra.withdrawToken(acceptor, { from: receiver1 }),
164-
'Umbra: No tokens available for withdrawal',
164+
'Umbra: No tokens available for withdrawal'
165165
);
166166
});
167167

168168
it('should not allow someone to pay with a token without sending the toll', async () => {
169169
await expectRevert(
170-
this.umbra.sendToken(
171-
receiver2,
172-
this.token.address,
173-
tokenAmount,
174-
...argumentBytes,
175-
{ from: payer2 },
176-
),
177-
'Umbra: Must pay the exact toll',
170+
this.umbra.sendToken(receiver2, this.token.address, tokenAmount, ...argumentBytes, {
171+
from: payer2,
172+
}),
173+
'Umbra: Must pay the exact toll'
178174
);
179175
});
180176

@@ -183,14 +179,11 @@ describe('Umbra', () => {
183179
const lessToll = toll.sub(new BN('1'));
184180

185181
await expectRevert(
186-
this.umbra.sendToken(
187-
receiver2,
188-
this.token.address,
189-
tokenAmount,
190-
...argumentBytes,
191-
{ from: payer2, value: lessToll },
192-
),
193-
'Umbra: Must pay the exact toll',
182+
this.umbra.sendToken(receiver2, this.token.address, tokenAmount, ...argumentBytes, {
183+
from: payer2,
184+
value: lessToll,
185+
}),
186+
'Umbra: Must pay the exact toll'
194187
);
195188
});
196189

@@ -199,14 +192,11 @@ describe('Umbra', () => {
199192
const moreToll = toll.add(new BN('1'));
200193

201194
await expectRevert(
202-
this.umbra.sendToken(
203-
receiver2,
204-
this.token.address,
205-
tokenAmount,
206-
...argumentBytes,
207-
{ from: payer2, value: moreToll },
208-
),
209-
'Umbra: Must pay the exact toll',
195+
this.umbra.sendToken(receiver2, this.token.address, tokenAmount, ...argumentBytes, {
196+
from: payer2,
197+
value: moreToll,
198+
}),
199+
'Umbra: Must pay the exact toll'
210200
);
211201
});
212202

@@ -218,7 +208,7 @@ describe('Umbra', () => {
218208
this.token.address,
219209
tokenAmount,
220210
...argumentBytes,
221-
{ from: payer2, value: toll },
211+
{ from: payer2, value: toll }
222212
);
223213

224214
const contractBalance = await this.token.balanceOf(this.umbra.address);
@@ -303,7 +293,7 @@ describe('Umbra', () => {
303293
it('should not allow a non-receiver to withdraw tokens', async () => {
304294
await expectRevert(
305295
this.umbra.withdrawToken(acceptor, { from: other }),
306-
'Umbra: No tokens available for withdrawal',
296+
'Umbra: No tokens available for withdrawal'
307297
);
308298
});
309299

@@ -325,7 +315,7 @@ describe('Umbra', () => {
325315
it('should not allow a receiver to withdraw their tokens twice', async () => {
326316
await expectRevert(
327317
this.umbra.withdrawToken(acceptor, { from: receiver2 }),
328-
'Umbra: No tokens available for withdraw',
318+
'Umbra: No tokens available for withdraw'
329319
);
330320
});
331321

@@ -355,10 +345,7 @@ describe('Umbra', () => {
355345
});
356346

357347
it('should not allow someone else to move tolls to toll receiver', async () => {
358-
await expectRevert(
359-
this.umbra.collectTolls({ from: other }),
360-
'Umbra: Not Toll Collector',
361-
);
348+
await expectRevert(this.umbra.collectTolls({ from: other }), 'Umbra: Not Toll Collector');
362349
});
363350

364351
it('should allow the toll collector to move tolls to toll receiver', async () => {

‎tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"files": [],
33
"references": [{ "path": "frontend" }, { "path": "umbra-js" }],
44
"exclude": ["node_modules"]
5-
}
5+
}

0 commit comments

Comments
 (0)
Please sign in to comment.