Skip to content

Commit

Permalink
strategy update (#148)
Browse files Browse the repository at this point in the history
* Enable voting for specific validator group (#88)

* deposit + withdraw + partly transfer

* Possibly working

* StCelo token transfer

* Some tests + bug fixes

* Manager tests

* Working and tests running

* Comments

* yml update

* removal of HH console

* Comment updates

* Version update

* Minor changes

* added test when specific group does not have enough stCelo

* Withdraw dust from specific group

* deprecate specific group

* part of e2e test

* PR comments

* Rebalancing

* Rebalance tests

* Update contracts/Account.sol

Co-authored-by: Martin <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: Martin <[email protected]>

* Some PR comments

* Default to default strategy

* Allow groups

* rename to allowed

* almost working :-)

* Tests working

* Rebalancing script working

* Activate and vote working

* simple e2e with rebalance

* e2e with transfer/rebalance working

* e2e done and working

* e2e comments updated

* Manager contract split to not to exceed allowed smart contract size

* Update contracts/Account.sol

Co-authored-by: Martin <[email protected]>

* PR comments

* Tests

* versions

* Method ordering

* Some of PR comments

* separation of default strategy from manager

* comment

* Update contracts/Account.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/SpecificGroupStrategy.sol

Co-authored-by: soloseng <[email protected]>

* Some PR comments

* extend e2e test

* Minor comment fix

* Default strategy accounting

* Group health update

* PR comments

* rebalance back to manager

* PR comments 2

* e2e cleanup

* AddressSortedLinkedList added and simple tests are working

* All tests working

* Finalize Revoke Task (#106)

* distributeWithdrawals during transfer

* Pr comments

* PR comments

* Pr comments

* Group health refactor

* Update contracts/Manager.sol

Co-authored-by: Martin <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: Martin <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: Martin <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: Martin <[email protected]>

* Pr comments

* updateGroupHealth added

* blacklisting of specific group strategies

* Update of depositing to unhealthy specific strategy

* Introduce round robin to Default strategy (#109)

* Manager deposit tests working

* e2e working

* sort tests

* all tests working

* tests working

* added tests

* lint

* removal of console

* test split + block unhealthy validator group

* sorting limit 1

* Max number of groups limitation for specific group

* lint

* PR comments 2

* PR comments 3

* Update contracts/DefaultStrategy.sol

Co-authored-by: Martin <[email protected]>

* Update contracts/DefaultStrategy.sol

Co-authored-by: Martin <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/DefaultStrategy.sol

Co-authored-by: Martin <[email protected]>

* Update contracts/DefaultStrategy.sol

Co-authored-by: Martin <[email protected]>

* Update contracts/DefaultStrategy.sol

Co-authored-by: Martin <[email protected]>

* Update contracts/DefaultStrategy.sol

Co-authored-by: Martin <[email protected]>

* Pr comments

* PR comments 2

* sort helper

* PR comments

* Simplification of lesser and greater

* removal of comments

* PR comments

* PR comments

* Update contracts/DefaultStrategy.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/SpecificGroupStrategy.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* PR comments

* Handle overflow of validator groups (#112)

* mostly working

* V1 -> V2 test

* Rename activeGroups in default strategy

* overflow e2e test

* PR comments

* overflow refactoring

* overflow specific group when group limit reached

* rebalanceOverflow tests

* Update contracts/SpecificGroupStrategy.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/SpecificGroupStrategy.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* PR comments

* Update contracts/DefaultStrategy.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/DefaultStrategy.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Manager.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/SpecificGroupStrategy.sol

Co-authored-by: soloseng <[email protected]>

* CELO vs stCELO tests

* healthy -> unhealthy -> healthy group e2e test

* compiler warning fix

* Update group health deploy script

* PR comments

* utils fixes

* Fork somehow working

* Revert "Fork somehow working"

This reverts commit d5ac488.

* Deployment fix

* PR comments

* Unhealthy group deployment fix

---------

Co-authored-by: soloseng <[email protected]>

---------

Co-authored-by: Martin <[email protected]>
Co-authored-by: soloseng <[email protected]>

* Update lib/account-tasks/helpers/revokeHelper.ts

Co-authored-by: soloseng <[email protected]>

* Update contracts/Account.sol

Co-authored-by: soloseng <[email protected]>

* PR comments

* test util fix

* Refactor + test optimizations

* Before removal of mock default strategy

* Minor comments fixes

* Group health optimizations 1

* Group health test fixes

* Proxy tests

* Fix for unhealthy specific group

* rebalanceWhenHealthChanged tests

* stCelo to Celo ratios tests

* Block strategy update

* PR comments

* PR comments + version update

* removal of unused methods + added tests

* split of methods because compiler complains

---------

Co-authored-by: Martin <[email protected]>
Co-authored-by: soloseng <[email protected]>

* Make sure that Vote.updateHistoryAndReturnLockedStCeloInVoting will n… (#120)

* Make sure that Vote.updateHistoryAndReturnLockedStCeloInVoting will not run out of gas

* version update

* Update contracts/Vote.sol

Co-authored-by: soloseng <[email protected]>

* Update contracts/Vote.sol

Co-authored-by: soloseng <[email protected]>

* PR comments

* PR comments 2

* lint

* lint v2

---------

Co-authored-by: soloseng <[email protected]>

* Audit - Info fixes (#122)

* Audit fixes

* #31

* Audit comment (#119)

* V1 to V2 deployment scripts (#116) (#126)

* deposit + withdraw + partly transfer

* Possibly working

* StCelo token transfer

* Some tests + bug fixes

* Manager tests

* Working and tests running

* Comments

* yml update

* removal of HH console

* Comment updates

* Version update

* Minor changes

* added test when specific group does not have enough stCelo

* Withdraw dust from specific group

* deprecate specific group

* part of e2e test

* PR comments

* Rebalancing

* Rebalance tests

* Update contracts/Account.sol



* Update contracts/Manager.sol



* Some PR comments

* Default to default strategy

* Allow groups

* rename to allowed

* almost working :-)

* Tests working

* Rebalancing script working

* Activate and vote working

* simple e2e with rebalance

* e2e with transfer/rebalance working

* e2e done and working

* e2e comments updated

* Manager contract split to not to exceed allowed smart contract size

* Update contracts/Account.sol



* PR comments

* Tests

* versions

* Method ordering

* Some of PR comments

* separation of default strategy from manager

* comment

* Update contracts/Account.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* Update contracts/SpecificGroupStrategy.sol



* Some PR comments

* extend e2e test

* Minor comment fix

* Default strategy accounting

* Group health update

* PR comments

* rebalance back to manager

* PR comments 2

* e2e cleanup

* AddressSortedLinkedList added and simple tests are working

* All tests working

* Manager deposit tests working

* Finalize Revoke Task (#106)

* e2e working

* distributeWithdrawals during transfer

* sort tests

* all tests working

* tests working

* added tests

* lint

* removal of console

* test split + block unhealthy validator group

* Pr comments

* PR comments

* Pr comments

* sorting limit 1

* Max number of groups limitation for specific group

* Group health refactor

* lint

* mostly working

* V1 -> V2 test

* Rename activeGroups in default strategy

* overflow e2e test

* Update contracts/Manager.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* Pr comments

* updateGroupHealth added

* blacklisting of specific group strategies

* PR comments 2

* PR comments 3

* PR comments

* overflow refactoring

* overflow specific group when group limit reached

* rebalanceOverflow tests

* Update contracts/DefaultStrategy.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/Manager.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/DefaultStrategy.sol



* Pr comments

* Update contracts/SpecificGroupStrategy.sol



* Update contracts/SpecificGroupStrategy.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* PR comments 2

* sort helper

* PR comments

* Simplification of lesser and greater

* removal of comments

* PR comments

* PR comments

* PR comments

* Update contracts/DefaultStrategy.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* Update contracts/SpecificGroupStrategy.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/Manager.sol



* Update contracts/SpecificGroupStrategy.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* PR comments

* CELO vs stCELO tests

* healthy -> unhealthy -> healthy group e2e test

* Update of depositing to unhealthy specific strategy

* compiler warning fix

* Update group health deploy script

* PR comments

* utils fixes

* Fork somehow working

* Revert "Fork somehow working"

This reverts commit d5ac488.

* devchain working

* Deployment fix

* PR comments

* Unhealthy group deployment fix

* deployment script fixes

* multisig update

* update of scripts

* Introduce round robin to Default strategy (#109)

* Manager deposit tests working

* e2e working

* sort tests

* all tests working

* tests working

* added tests

* lint

* removal of console

* test split + block unhealthy validator group

* sorting limit 1

* Max number of groups limitation for specific group

* lint

* PR comments 2

* PR comments 3

* Update contracts/DefaultStrategy.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/Manager.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/DefaultStrategy.sol



* Pr comments

* PR comments 2

* sort helper

* PR comments

* Simplification of lesser and greater

* removal of comments

* PR comments

* PR comments

* Update contracts/DefaultStrategy.sol



* Update contracts/Manager.sol



* Update contracts/SpecificGroupStrategy.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* PR comments

* Handle overflow of validator groups (#112)

* mostly working

* V1 -> V2 test

* Rename activeGroups in default strategy

* overflow e2e test

* PR comments

* overflow refactoring

* overflow specific group when group limit reached

* rebalanceOverflow tests

* Update contracts/SpecificGroupStrategy.sol



* Update contracts/SpecificGroupStrategy.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* PR comments

* Update contracts/DefaultStrategy.sol



* Update contracts/DefaultStrategy.sol



* Update contracts/Manager.sol



* Update contracts/Manager.sol



* Update contracts/SpecificGroupStrategy.sol



* CELO vs stCELO tests

* healthy -> unhealthy -> healthy group e2e test

* compiler warning fix

* Update group health deploy script

* PR comments

* utils fixes

* Fork somehow working

* Revert "Fork somehow working"

This reverts commit d5ac488.

* Deployment fix

* PR comments

* Unhealthy group deployment fix

---------



---------




* PR comments

* removal of deployments

* removal of deployments 2

* bump the CI pipeline

---------

Co-authored-by: Martin <[email protected]>
Co-authored-by: soloseng <[email protected]>

* Alfajores release (#127)

* Alfajores release

* Vote proposal task

* PR comments

* Enable allow to vote over max number of tasks (#133)

* Enable allow to vote over max number of tasks

* alfajores vote update

* activation added to upgrade proposal

* Update of update script

* Fix + tests (#135)

* Fix + tests

* PR comments

* V2 mainnet deployment (#141)

* underflow fix

* Revokable when not enough of balance in group

* Activate only what account has

* Dont transfer during changeStrategy

* do not schedule transfers when deactivating group

* version update

* Revert "version update"

This reverts commit 9d708ea.

* fixes

* comment removal

* PR comments

---------

Co-authored-by: Martin <[email protected]>
Co-authored-by: soloseng <[email protected]>
  • Loading branch information
3 people authored Feb 29, 2024
1 parent 8140310 commit fabd7b2
Show file tree
Hide file tree
Showing 11 changed files with 583 additions and 534 deletions.
49 changes: 34 additions & 15 deletions contracts/Account.sol
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,6 @@ contract Account is UUPSOwnableUpgradeable, UsingRegistryUpgradeable, Managed, I
// The amount of unlocked CELO for group that we want to lock and vote with.
(uint256 celoToVoteForGroup, ) = getAndUpdateToVoteAndToRevoke(group, 0, 0);

// Reset the unlocked CELO amount for group.
scheduledVotes[group].toVote = 0;

// If there are activatable pending votes from this contract for group, activate them.
if (election.hasActivatablePendingVotes(address(this), group)) {
// Revert if the activation fails.
Expand All @@ -472,14 +469,21 @@ contract Account is UUPSOwnableUpgradeable, UsingRegistryUpgradeable, Managed, I
? 0
: celoToVoteForGroup - accountLockedNonvotingCelo;

// There might not be enough of balance to lock because of unbalanced groups
uint256 availableToLock = Math.min(address(this).balance, toLock);

// Lock up the unlockedCeloForGroup in LockedGold, which increments the
// non-voting LockedGold balance for this contract.
if (toLock > 0) {
getLockedGold().lock{value: toLock}();
if (availableToLock > 0) {
getLockedGold().lock{value: availableToLock}();
}

// Vote for group using the newly locked CELO, reverting if it fails.
if (!election.vote(group, celoToVoteForGroup, voteLesser, voteGreater)) {
uint256 finalVoteAmount = celoToVoteForGroup - (toLock - availableToLock);

// Update the CELO amount for group.
scheduledVotes[group].toVote -= finalVoteAmount;

if (!election.vote(group, finalVoteAmount, voteLesser, voteGreater)) {
revert VoteFailed(group, celoToVoteForGroup);
}
}
Expand Down Expand Up @@ -641,11 +645,15 @@ contract Account is UUPSOwnableUpgradeable, UsingRegistryUpgradeable, Managed, I
* @return The total amount of CELO directed towards `group`.
*/
function getCeloForGroup(address group) external view returns (uint256) {
return
getElection().getTotalVotesForGroupByAccount(group, address(this)) +
scheduledVotes[group].toVote -
scheduledVotes[group].toRevoke -
scheduledVotes[group].toWithdraw;
uint256 combinedVotes = getElection().getTotalVotesForGroupByAccount(group, address(this)) +
scheduledVotes[group].toVote;
uint256 toBeRemoved = scheduledVotes[group].toRevoke + scheduledVotes[group].toWithdraw;

if (combinedVotes > toBeRemoved) {
return combinedVotes - toBeRemoved;
}

return 0;
}

/**
Expand Down Expand Up @@ -707,7 +715,7 @@ contract Account is UUPSOwnableUpgradeable, UsingRegistryUpgradeable, Managed, I
uint256
)
{
return (1, 2, 1, 0);
return (1, 2, 2, 0);
}

/**
Expand Down Expand Up @@ -745,17 +753,28 @@ contract Account is UUPSOwnableUpgradeable, UsingRegistryUpgradeable, Managed, I
return;
}

uint256 revokable = Math.min(votesForGroup(group), revokeAmount);

_revokeVotes(
group,
revokeAmount,
revokable,
lesserAfterPendingRevoke,
greaterAfterPendingRevoke,
lesserAfterActiveRevoke,
greaterAfterActiveRevoke,
index
);

scheduledVotes[group].toRevoke -= revokeAmount;
scheduledVotes[group].toRevoke -= revokable;
}

/**
* @notice Returns the total amount of CELO that's voted with for a group.
* @param group The address of the validator group.
* @return The total amount of CELO voted with for `group`.
*/
function votesForGroup(address group) public view returns (uint256) {
return getElection().getTotalVotesForGroupByAccount(group, address(this));
}

/**
Expand Down
21 changes: 4 additions & 17 deletions contracts/DefaultStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ contract DefaultStrategy is Errors, UUPSOwnableUpgradeable, Managed, Pausable {
uint256
)
{
return (1, 1, 2, 0);
return (1, 1, 2, 1);
}

/**
Expand Down Expand Up @@ -678,22 +678,9 @@ contract DefaultStrategy is Errors, UUPSOwnableUpgradeable, Managed, Pausable {

if (groupTotalStCeloVotes > 0) {
updateGroupStCelo(group, groupTotalStCeloVotes, false);
address[] memory fromGroups = new address[](1);
uint256[] memory fromVotes = new uint256[](1);
fromGroups[0] = group;
fromVotes[0] = IManager(manager).toCelo(groupTotalStCeloVotes);
(
address[] memory toGroups,
uint256[] memory toVotes
) = _generateDepositVoteDistribution(
IManager(manager).toCelo(groupTotalStCeloVotes),
address(0)
);
IManager(manager).scheduleTransferWithinStrategy(
fromGroups,
toGroups,
fromVotes,
toVotes
_generateDepositVoteDistribution(
IManager(manager).toCelo(groupTotalStCeloVotes),
address(0)
);
}

Expand Down
29 changes: 15 additions & 14 deletions contracts/Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ contract Manager is Errors, UUPSOwnableUpgradeable, UsingRegistryUpgradeable, Pa
uint256
)
{
return (1, 3, 1, 0);
return (1, 3, 1, 1);
}

/**
Expand Down Expand Up @@ -523,7 +523,15 @@ contract Manager is Errors, UUPSOwnableUpgradeable, UsingRegistryUpgradeable, Pa
view
returns (uint256 expectedCelo, uint256 actualCelo)
{
actualCelo = account.getCeloForGroup(group);
uint256 celoScheduled = account.votesForGroup(group) +
account.scheduledVotesForGroup(group);
uint256 celoToRemove = account.scheduledRevokeForGroup(group) +
account.scheduledWithdrawalsForGroup(group);
if (celoToRemove > celoScheduled) {
return (celoToRemove - celoScheduled, 0);
}

actualCelo = celoScheduled - celoToRemove;

bool isSpecificGroupStrategy = !specificGroupStrategy.isBlockedGroup(group);
bool isActiveGroup = defaultStrategy.isActive(group);
Expand All @@ -537,13 +545,13 @@ contract Manager is Errors, UUPSOwnableUpgradeable, UsingRegistryUpgradeable, Pa
(stCeloFromSpecificStrategy, overflow, unhealthy) = specificGroupStrategy
.getStCeloInGroup(group);

stCeloFromSpecificStrategy -= overflow + unhealthy;
uint256 toSubtract = overflow + unhealthy;
stCeloFromSpecificStrategy -= Math.min(stCeloFromSpecificStrategy, toSubtract);
}

if (isActiveGroup) {
stCeloFromDefaultStrategy = defaultStrategy.stCeloInGroup(group);
}

expectedCelo = toCelo(stCeloFromSpecificStrategy + stCeloFromDefaultStrategy);
}

Expand Down Expand Up @@ -684,7 +692,7 @@ contract Manager is Errors, UUPSOwnableUpgradeable, UsingRegistryUpgradeable, Pa
}

/**
* @notice Schedules transfer of CELO between strategies.
* @notice Updates accounting of CELO between strategies.
* @param fromStrategy The from validator group.
* @param toStrategy The to validator group.
* @param stCeloAmount The stCELO amount.
Expand All @@ -694,15 +702,8 @@ contract Manager is Errors, UUPSOwnableUpgradeable, UsingRegistryUpgradeable, Pa
address toStrategy,
uint256 stCeloAmount
) private {
address[] memory fromGroups;
uint256[] memory fromVotes;
(fromGroups, fromVotes) = distributeWithdrawals(stCeloAmount, fromStrategy, true);

address[] memory toGroups;
uint256[] memory toVotes;
(toGroups, toVotes) = distributeVotes(toCelo(stCeloAmount), stCeloAmount, toStrategy);

account.scheduleTransfer(fromGroups, fromVotes, toGroups, toVotes);
distributeWithdrawals(stCeloAmount, fromStrategy, true);
distributeVotes(toCelo(stCeloAmount), stCeloAmount, toStrategy);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions contracts/SpecificGroupStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,11 @@ contract SpecificGroupStrategy is Errors, UUPSOwnableUpgradeable, Managed, Pausa
// overflow
(address[] memory groups, uint256[] memory votesForGroups) = defaultStrategy
.generateDepositVoteDistribution(celoAmount, group);
updateOverflowGroup(group, IManager(manager).toStakedCelo(celoAmount), true);
updateOverflowGroup(
group,
Math.min(IManager(manager).toStakedCelo(celoAmount), stCeloAmount),
true
);
finalGroups = new address[](groups.length + 1);
finalVotes = new uint256[](groups.length + 1);
for (uint256 i = 0; i < groups.length; i++) {
Expand Down Expand Up @@ -460,7 +464,7 @@ contract SpecificGroupStrategy is Errors, UUPSOwnableUpgradeable, Managed, Pausa
uint256
)
{
return (1, 1, 1, 0);
return (1, 1, 1, 1);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ interface IAccount {
function scheduledRevokeForGroup(address group) external view returns (uint256);

function scheduledWithdrawalsForGroup(address group) external view returns (uint256);

function votesForGroup(address group) external view returns (uint256);
}
5 changes: 5 additions & 0 deletions contracts/mock/MockAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract MockAccount {
mapping(address => uint256) public scheduledVotesForGroup;
mapping(address => uint256) public scheduledRevokeForGroup;
mapping(address => uint256) public scheduledWithdrawalsForGroup;
mapping(address => uint256) public votesForGroup;

uint256 public proposalIdVoted;
uint256 public indexVoted;
Expand Down Expand Up @@ -72,6 +73,10 @@ contract MockAccount {
scheduledWithdrawalsForGroup[group] = amount;
}

function setVotesForGroup(address group, uint256 amount) external {
votesForGroup[group] = amount;
}

function scheduleTransfer(
address[] calldata fromGroups,
uint256[] calldata fromVotes,
Expand Down
116 changes: 116 additions & 0 deletions test-ts/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,60 @@ describe("Account", () => {
expect(votes.pending).to.eq(40);
});
});

describe("When group doesnt have enough of Celo", () => {
beforeEach(async () => {
await account
.connect(manager)
.scheduleVotes(groupAddresses, [100, 30, 70], { value: "200" });
await account
.connect(manager)
.scheduleVotes(groupAddresses, [40, 50, 20], { value: "110" });

await account
.connect(manager)
.activateAndVote(groupAddresses[0], groupAddresses[1], ADDRESS_ZERO);
await account
.connect(manager)
.activateAndVote(groupAddresses[1], ADDRESS_ZERO, groupAddresses[0]);
await account
.connect(manager)
.activateAndVote(groupAddresses[2], groupAddresses[1], groupAddresses[0]);
await mineToNextEpoch(hre.web3);
await account
.connect(manager)
.activateAndVote(groupAddresses[0], groupAddresses[1], ADDRESS_ZERO);
await account
.connect(manager)
.activateAndVote(groupAddresses[1], ADDRESS_ZERO, groupAddresses[0]);
await account
.connect(manager)
.activateAndVote(groupAddresses[2], groupAddresses[1], groupAddresses[0]);
});

it("should activate when not enough of Celo in account", async () => {
await account
.connect(manager)
.scheduleTransfer([groupAddresses[0]], [100], [groupAddresses[1]], [100]);
await account.connect(manager).scheduleVotes([groupAddresses[1]], [5], { value: 5 });

expect(await account.scheduledVotesForGroup(groupAddresses[1])).to.eq(105);
expect(await account.scheduledRevokeForGroup(groupAddresses[1])).to.eq(0);
expect(await account.scheduledWithdrawalsForGroup(groupAddresses[1])).to.eq(0);
expect(await account.votesForGroup(groupAddresses[1])).to.eq(80);
expect(await hre.ethers.provider.getBalance(account.address)).to.eq(5);

await account
.connect(manager)
.activateAndVote(groupAddresses[1], ADDRESS_ZERO, groupAddresses[2]);

expect(await account.scheduledVotesForGroup(groupAddresses[1])).to.eq(100);
expect(await account.scheduledRevokeForGroup(groupAddresses[1])).to.eq(0);
expect(await account.scheduledWithdrawalsForGroup(groupAddresses[1])).to.eq(0);
expect(await account.votesForGroup(groupAddresses[1])).to.eq(85);
expect(await hre.ethers.provider.getBalance(account.address)).to.eq(0);
});
});
});

describe("#scheduleWithdrawals()", () => {
Expand Down Expand Up @@ -1023,6 +1077,36 @@ describe("Account", () => {
expect(scheduled).to.eq(originalAmount);
});

describe("When transferred more then current group has", () => {
beforeEach(async () => {
await account
.connect(manager)
.scheduleTransfer(
[groupAddresses[0]],
[originalAmount * 2],
[groupAddresses[1]],
[originalAmount * 2]
);

await account.revokeVotes(
groupAddresses[0],
groupAddresses[1],
ADDRESS_ZERO,
groupAddresses[1],
ADDRESS_ZERO,
0
);
});

it("should return still pending revoke for first group", async () => {
expect(await account.scheduledRevokeForGroup(groupAddresses[0])).to.eq(originalAmount);
});

it("should return votes in second group", async () => {
expect(await account.scheduledVotesForGroup(groupAddresses[1])).to.eq(originalAmount * 2);
});
});

describe("When there is transfer to new group", () => {
beforeEach(async () => {
await account
Expand Down Expand Up @@ -1693,6 +1777,38 @@ describe("Account", () => {
});
});
});

describe("When there is not enough stCelo locked from previous transfers", () => {
beforeEach(async () => {
await account
.connect(manager)
.scheduleTransfer([groupAddresses[0]], [30], [groupAddresses[1]], [30]);
});

it("reports correctly", async () => {
const votesGroupFrom = await account.getCeloForGroup(groupAddresses[0]);
expect(votesGroupFrom).to.eq(0);

const votesGroupTo = await account.getCeloForGroup(groupAddresses[1]);
expect(votesGroupTo).to.eq(30);
});

describe("When scheduled new votes", () => {
beforeEach(async () => {
await account
.connect(manager)
.scheduleVotes([groupAddresses[0]], [31], { value: "31" });
});

it("reports correctly", async () => {
const votesGroupFrom = await account.getCeloForGroup(groupAddresses[0]);
expect(votesGroupFrom).to.eq(1);

const votesGroupTo = await account.getCeloForGroup(groupAddresses[1]);
expect(votesGroupTo).to.eq(30);
});
});
});
});

describe("when there are active votes", () => {
Expand Down
Loading

0 comments on commit fabd7b2

Please sign in to comment.