-
Notifications
You must be signed in to change notification settings - Fork 25
dxdaoTimeLock #754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
orenyodfat
wants to merge
2
commits into
arc-factory
Choose a base branch
from
DxDAOTimeLock
base: arc-factory
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+79
−0
Draft
dxdaoTimeLock #754
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pragma solidity ^0.5.17; | ||
|
||
|
||
contract TimeLock { | ||
|
||
address public owner; | ||
uint256 public releaseTime; | ||
|
||
constructor(address _owner, uint256 _releaseTime) public { | ||
owner = _owner; | ||
releaseTime = _releaseTime; | ||
} | ||
|
||
function () external payable { | ||
} | ||
|
||
function withdraw() external { | ||
require(msg.sender == owner, "only owner can withdraw"); | ||
// solhint-disable-next-line not-rely-on-time | ||
require(releaseTime < now, "cannot withdraw before releaseTime"); | ||
// solhint-disable-next-line avoid-call-value | ||
(bool success, ) = owner.call.value(address(this).balance)(""); | ||
require(success, "sendEther failed."); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const helpers = require('./helpers'); | ||
|
||
const Wallet = artifacts.require("./Wallet.sol"); | ||
const TimeLock = artifacts.require("./TimeLock.sol"); | ||
contract('TimeLock', accounts => { | ||
|
||
it("sendEther", async () => { | ||
var wallet = await Wallet.new(); | ||
await wallet.initialize(accounts[0]); | ||
var owner = wallet.address; | ||
var block = await web3.eth.getBlock("latest"); | ||
var releaseTime = block.timestamp + (30*60*60*24); | ||
var timeLock = await TimeLock.new(owner,releaseTime); | ||
assert.equal(await timeLock.owner(), owner); | ||
assert.equal(await timeLock.releaseTime(), releaseTime); | ||
|
||
//send funds to wallet | ||
await web3.eth.sendTransaction({from:accounts[0],to:owner, value: web3.utils.toWei('10', "ether")}); | ||
assert.equal(await web3.eth.getBalance(owner), web3.utils.toWei('10', "ether")); | ||
await wallet.pay(timeLock.address); | ||
await wallet.pay(timeLock.address); | ||
assert.equal(await web3.eth.getBalance(timeLock.address), web3.utils.toWei('10', "ether")); | ||
|
||
var encodedABI = await new web3.eth.Contract(timeLock.abi) | ||
.methods | ||
.withdraw() | ||
.encodeABI(); | ||
|
||
try { | ||
await wallet.genericCall(timeLock.address, encodedABI); | ||
throw 'cannot withdraw before time'; | ||
} catch (error) { | ||
helpers.assertVMException(error); | ||
} | ||
await helpers.increaseTime((30*60*60*24)+1); | ||
try { | ||
await timeLock.withdraw(); | ||
throw 'only Owner can withdraw'; | ||
} catch (error) { | ||
helpers.assertVMException(error); | ||
} | ||
await wallet.genericCall(timeLock.address, encodedABI); | ||
assert.equal(await web3.eth.getBalance(owner), web3.utils.toWei('10', "ether")); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why instead of sending the _encodeABI we execute the withdraw function with the signature that we already know it will have?
Doing this we make sure that the ONLY function that can be executed is the
withdraw()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a public generic function which can call any contract specific Abis.
this is just a test helper contract and is not part of any dao.