Skip to content
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

Fix: set snapshot block in the past #25

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/EasyTrack.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ contract EasyTrack is Pausable, AccessControl, MotionSettings, EVMScriptFactorie
newMotion.id = _newMotionId;
newMotion.creator = msg.sender;
newMotion.startDate = block.timestamp;
newMotion.snapshotBlock = block.number;
newMotion.snapshotBlock = block.number - 1;
newMotion.duration = motionDuration;
newMotion.objectionsThreshold = objectionsThreshold;
newMotion.evmScriptFactory = _evmScriptFactory;
Expand Down
43 changes: 43 additions & 0 deletions contracts/test/MotionStarter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: 2022 Lido <[email protected]>
// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.4;

import "../EasyTrack.sol";

interface IMiniMeTokenERC20 is IMiniMeToken {
function transfer(address _recipient, uint256 _amount) external;

function balanceOf(address _holder) external view returns (uint256);
}

contract MotionStarter {
EasyTrack immutable easyTrack;

constructor(address _easyTrack) {
easyTrack = EasyTrack(_easyTrack);
}

function startMotionTransferringLDO(
address _evmScriptFactory,
bytes memory _evmScriptCallData,
address _ldoRecipient
) public {
IMiniMeTokenERC20 govToken = IMiniMeTokenERC20(address(easyTrack.governanceToken()));

uint256 prevBlock = block.number - 1;

uint256 myBalanceAtPrevBlock = govToken.balanceOfAt(address(this), prevBlock);
assert(myBalanceAtPrevBlock == govToken.balanceOf(address(this)));

assert(govToken.balanceOfAt(_ldoRecipient, prevBlock) == 0);
assert(govToken.balanceOf(_ldoRecipient) == 0);

govToken.transfer(_ldoRecipient, myBalanceAtPrevBlock);

assert(govToken.balanceOf(_ldoRecipient) == myBalanceAtPrevBlock);
assert(govToken.balanceOf(address(this)) == 0);

easyTrack.createMotion(_evmScriptFactory, _evmScriptCallData);
}
}
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,8 @@ def vote_id_from_env() -> Optional[int]:
@pytest.fixture(scope="module")
def bokkyPooBahsDateTimeContract():
return "0x23d23d8f243e57d0b924bff3a3191078af325101"


@pytest.fixture(scope="module")
def motion_starter(owner, MotionStarter, easy_track):
return owner.deploy(MotionStarter, easy_track)
61 changes: 60 additions & 1 deletion tests/test_easy_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_create_motion(
assert new_motion[2] == owner # creator
assert new_motion[3] == constants.MIN_MOTION_DURATION # duration
assert new_motion[4] == chain[-1].timestamp # startDate
assert new_motion[5] == chain[-1].number # snapshotBlock
assert new_motion[5] == chain[-1].number - 1 # snapshotBlock
assert (
new_motion[6] == constants.DEFAULT_OBJECTIONS_THRESHOLD
) # objectionsThreshold
Expand Down Expand Up @@ -786,3 +786,62 @@ def test_can_object_to_motion(
assert easy_track.canObjectToMotion(1, ldo_holders[0])
easy_track.objectToMotion(1, {"from": ldo_holders[0]})
assert not easy_track.canObjectToMotion(1, ldo_holders[0])


def test_snapshot_block(
owner,
voting,
stranger,
ldo_holders,
ldo,
easy_track,
evm_script_factory_stub,
distribute_holder_balance,
motion_starter,
):
"Must return False if caller had no governance tokens one block before the motion start."
"Returns True in other cases"

# add evm script factory to create motions§
permissions = (
evm_script_factory_stub.address
+ evm_script_factory_stub.setEVMScript.signature[2:]
)
easy_track.addEVMScriptFactory(
evm_script_factory_stub, permissions, {"from": voting}
)
evm_script = encode_call_script(
[
(
evm_script_factory_stub.address,
evm_script_factory_stub.setEVMScript.encode_input(b""),
)
]
)
evm_script_factory_stub.setEVMScript(evm_script)

assert easy_track.isEVMScriptFactory(evm_script_factory_stub)

ldo.transfer(
motion_starter, ldo.balanceOf(ldo_holders[0]), {"from": ldo_holders[0]}
)

chain = Chain()
chain.mine(1)

assert ldo.balanceOf(stranger) == 0
assert ldo.balanceOf(motion_starter) > 0

motion_starter.startMotionTransferringLDO(
evm_script_factory_stub, b"", stranger, {"from": owner}
)

chain.mine(1)

assert ldo.balanceOf(stranger) > 0
assert ldo.balanceOf(motion_starter) == 0

assert not easy_track.canObjectToMotion(1, stranger)
assert easy_track.canObjectToMotion(1, motion_starter)
easy_track.objectToMotion(1, {"from": motion_starter})
assert not easy_track.canObjectToMotion(1, motion_starter)