Skip to content

Commit beecc04

Browse files
committed
test(contracts): update tests to handle direct deposit
ack @thomas-waite for helping with bug fixing.
1 parent 9eb4611 commit beecc04

25 files changed

Lines changed: 1680 additions & 304 deletions

packages/contracts/contracts/NoteStream.sol

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
pragma solidity ^0.5.11;
22

3-
import "@openzeppelin/contracts/lifecycle/Pausable.sol";
4-
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
3+
import '@openzeppelin/contracts/lifecycle/Pausable.sol';
4+
import '@openzeppelin/contracts/utils/ReentrancyGuard.sol';
55

6-
import "./StreamUtilities.sol";
6+
import './StreamUtilities.sol';
77

8-
import "./Types.sol";
8+
import './Types.sol';
99

1010

1111
/**
@@ -65,7 +65,7 @@ contract NoteStream is Pausable, ReentrancyGuard {
6565
require(
6666
msg.sender == streams[streamId].sender ||
6767
msg.sender == streams[streamId].recipient,
68-
"caller is not the sender or the recipient of the stream"
68+
'caller is not the sender or the recipient of the stream'
6969
);
7070
_;
7171
}
@@ -76,7 +76,7 @@ contract NoteStream is Pausable, ReentrancyGuard {
7676
modifier onlyRecipient(uint256 streamId) {
7777
require(
7878
msg.sender == streams[streamId].recipient,
79-
"caller is not the recipient of the stream"
79+
'caller is not the recipient of the stream'
8080
);
8181
_;
8282
}
@@ -85,7 +85,7 @@ contract NoteStream is Pausable, ReentrancyGuard {
8585
* @dev Throws if the provided id does not point to a valid stream.
8686
*/
8787
modifier streamExists(uint256 streamId) {
88-
require(streams[streamId].isEntity, "stream does not exist");
88+
require(streams[streamId].isEntity, 'stream does not exist');
8989
_;
9090
}
9191

@@ -94,7 +94,7 @@ contract NoteStream is Pausable, ReentrancyGuard {
9494
constructor(address _aceContractAddress) public {
9595
require(
9696
_aceContractAddress != address(0x00),
97-
"ACE contract is the zero address"
97+
'ACE contract is the zero address'
9898
);
9999
aceContractAddress = _aceContractAddress;
100100
nextStreamId = 1;
@@ -158,14 +158,14 @@ contract NoteStream is Pausable, ReentrancyGuard {
158158
uint256 startTime,
159159
uint256 stopTime
160160
) public whenNotPaused returns (uint256) {
161-
require(recipient != address(0x00), "stream to the zero address");
162-
require(recipient != address(this), "stream to the contract itself");
163-
require(recipient != msg.sender, "stream to the caller");
161+
require(recipient != address(0x00), 'stream to the zero address');
162+
require(recipient != address(this), 'stream to the contract itself');
163+
require(recipient != msg.sender, 'stream to the caller');
164164
require(
165165
startTime >= block.timestamp, // solium-disable-line security/no-block-members
166-
"start time before block.timestamp"
166+
'start time before block.timestamp'
167167
);
168-
require(stopTime > startTime, "Stream duration not greater than zero");
168+
require(stopTime > startTime, 'Stream duration not greater than zero');
169169

170170
// Transfer the ZkAsset to the streaming contract
171171
bytes32 streamNoteHash = StreamUtilities._processDeposit(
@@ -211,27 +211,21 @@ contract NoteStream is Pausable, ReentrancyGuard {
211211
bytes memory _proof1, // Dividend Proof
212212
bytes memory _proof2, // Join-Split Proof
213213
uint256 _streamDurationToWithdraw
214-
)
215-
public
216-
nonReentrant
217-
streamExists(streamId)
218-
onlyRecipient(streamId)
219-
{
214+
) public nonReentrant streamExists(streamId) onlyRecipient(streamId) {
220215
Types.AztecStream storage stream = streams[streamId];
221216

222217
// First check that this isn't a zero value withdrawal
223-
require(_streamDurationToWithdraw > 0, "zero value withdrawal");
218+
require(_streamDurationToWithdraw > 0, 'zero value withdrawal');
224219

225220
// Check that fraction to withdraw isn't greater than fraction of time passed
226221
require(
227222
stream.lastWithdrawTime.add(_streamDurationToWithdraw) <
228223
block.timestamp, // solium-disable-line security/no-block-members
229-
"withdraw is greater than allowed"
224+
'withdraw is greater than allowed'
230225
);
231226

232227
// Check that value of withdrawal matches the fraction given by the above timestamp
233-
(, bytes memory _proof1OutputNotes) = StreamUtilities
234-
._validateRatioProof(
228+
bytes32 withdrawalNoteHash = StreamUtilities._validateRatioProof(
235229
aceContractAddress,
236230
_proof1,
237231
_streamDurationToWithdraw,
@@ -243,7 +237,7 @@ contract NoteStream is Pausable, ReentrancyGuard {
243237
bytes32 newNoteHash = StreamUtilities._processWithdrawal(
244238
aceContractAddress,
245239
_proof2,
246-
_proof1OutputNotes,
240+
withdrawalNoteHash,
247241
stream
248242
);
249243

@@ -294,7 +288,7 @@ contract NoteStream is Pausable, ReentrancyGuard {
294288
}
295289

296290
// We require the denominator of ratio proof to be nonzero
297-
require(_unclaimedTime > 0, "cancellation with zero unclaimed time");
291+
require(_unclaimedTime > 0, 'cancellation with zero unclaimed time');
298292

299293
// Otherwise check that cancelling party isn't trying to scam the other
300294
// Each party can only cancel from a timestamp favourable to the other party.
@@ -307,20 +301,19 @@ contract NoteStream is Pausable, ReentrancyGuard {
307301
stream.lastWithdrawTime.add(_unclaimedTime) > block.timestamp ||
308302
stream.lastWithdrawTime.add(_unclaimedTime) ==
309303
stream.stopTime,
310-
"sender receives too much from cancellation"
304+
'sender receives too much from cancellation'
311305
);
312306
} else if (msg.sender == stream.recipient) {
313307
// Recipient can only cancel from a timestamp which has already passed
314308
require(
315309
// solium-disable-next-line security/no-block-members
316310
stream.lastWithdrawTime.add(_unclaimedTime) < block.timestamp,
317-
"recipient receives too much from cancellation"
311+
'recipient receives too much from cancellation'
318312
);
319313
}
320314

321315
// Check that value of withdrawal matches the fraction given by the above timestamp
322-
(, bytes memory _proof1OutputNotes) = StreamUtilities
323-
._validateRatioProof(
316+
bytes32 withdrawalNoteHash = StreamUtilities._validateRatioProof(
324317
aceContractAddress,
325318
_proof1,
326319
_unclaimedTime,
@@ -332,7 +325,7 @@ contract NoteStream is Pausable, ReentrancyGuard {
332325
StreamUtilities._processCancelation(
333326
aceContractAddress,
334327
_proof2,
335-
_proof1OutputNotes,
328+
withdrawalNoteHash,
336329
stream
337330
);
338331

0 commit comments

Comments
 (0)