Skip to content

Commit

Permalink
Merge pull request #235 from DistributedCollective/refactor
Browse files Browse the repository at this point in the history
Refactor #1
  • Loading branch information
Franklin Richards committed May 17, 2021
2 parents a8c02c0 + 161644f commit b2bd3e1
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 51 deletions.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
First install all the npm packages:

```
npm i
npm ci
```

And then install all the python packages using pip3:
Expand Down Expand Up @@ -63,6 +63,7 @@ To check the test coverage of JS:
```
npm run coverage
```

Note: Sometimes it might show an error "JavaScript heap out of memory", then please increase the memory allocation using:

```
Expand All @@ -74,19 +75,33 @@ If still the error persists, make sure that you closed the shell and opened anot
## Deployment on RSK testnet

1. Add account with RBTC balance to brownie

```bash
brownie accounts new rskdeployer
```

2. Add network Rsk-testnet

```bash
brownie networks add rsk testnet host=https://testnet.sovryn.app/rpc chainid=31
```

OR

```bash
brownie networks add rsk testnet host=https://public-node.testnet.rsk.co chainid=31
```

Note: If you want to work with mainnet, please use host as `wss://mainnet.sovryn.app/ws` and chainid as `30`

3. Deploy contracts locally

```bash
brownie run deploy_everything.py
```

or use an absolute path to the script

```bash
brownie run ~/Code/Sovryn-smart-contracts/scripts/deployment/deploy_everything.py
```
Expand All @@ -98,25 +113,31 @@ brownie run deploy_everything.py --network testnet
```

or use an absolute path to the script

```bash
brownie run ~/Code/Sovryn-smart-contracts/scripts/deployment/deploy_everything.py --network testnet
```

## Sovryn Swap joint testing for RSK (local)

1. Start `ganache` with

```bash
ganache-cli --gasLimit 6800000 --port 8545
```

Overriding default `brownie` port will make it connect to our local chain and keep it open.

If you changed the port in the brownie config, use that port instead.

2. Deploy contracts

```bash
brownie run deploy_everything.py
```

or use an absolute path to the script

```bash
brownie run ~/Code/Sovryn-smart-contracts/scripts/deployment/deploy_everything.py
```
Expand All @@ -130,11 +151,13 @@ brownie run ~/Code/Sovryn-smart-contracts/scripts/deployment/deploy_everything.p
6. After deployment, copy the address of the deployed `ContractRegistry` and update the `scripts/swap_test.json` accordingly.

7. Run the `swap_test.py` script to set the SovrynSwap ContractRegistry address

```bash
brownie run swap_test.py
```

or use an absolute path to the script

```bash
brownie run ~/Code/Sovryn-smart-contracts/scripts/swapTest/swap_test.py
```
Expand Down Expand Up @@ -566,6 +589,12 @@ The function which pays the reward is `PayFeeReward` from `FeesHelper.sol`.
#### 9.3 Withdraw
The protocol can withdraw SOV tokens using `sovryn.withdrawProtocolToken()` from `ProtocolSettings.sol`. This function is executable only by the owner.

## Contributing

<a href="https://github.com/DistributedCollective/Sovryn-smart-contracts/graphs/contributors">
<img src="https://contrib.rocks/image?repo=DistributedCollective/Sovryn-smart-contracts" />
</a>

## License

This project is licensed under the [Apache License, Version 2.0](LICENSE).
2 changes: 1 addition & 1 deletion contracts/mixins/EnumerableBytes32Set.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ library EnumerableBytes32Set {
*
* WARNING: This function may run out of gas on large sets: use {length} and
* {get} instead in these cases.
*/
*/
function enumerate(
Bytes32Set storage set,
uint256 start,
Expand Down
4 changes: 2 additions & 2 deletions contracts/multisig/MultiSigWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ contract MultiSigWallet {
/*
* Public functions
*/

/**
* @notice Contract constructor sets initial owners and required number
* of confirmations.
Expand Down Expand Up @@ -302,7 +302,7 @@ contract MultiSigWallet {
/*
* Internal functions
*/

/**
* @notice Adds a new transaction to the transaction mapping,
* if transaction does not exist yet.
Expand Down
4 changes: 2 additions & 2 deletions docs/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests-js/EscrowReward/multisig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ contract("Escrow Rewards (Multisig Functions)", (accounts) => {
});

it("Multisig should be approved before depositing reward tokens using depositRewardByMultisig.", async () => {
await expectRevert(escrowReward.depositRewardByMultisig(randomValue(), { from: multisig }), "invalid transfer");
await expectRevert(escrowReward.depositRewardByMultisig(randomValue() + 1, { from: multisig }), "invalid transfer");
});

it("Multisig should not be able to deposit reward tokens using depositRewardByMultisig during Withdraw State.", async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests-js/Governance/GovernorAlpha/anyone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ contract("GovernorAlpha (Any User Functions)", (accounts) => {
});

it("All actions mentioned in the queue of a proposal should be executed correctly.", async () => {
let value = randomValue();
let value = randomValue() + 1;
// Proposal Parameters
targets = [setGet.address];
values = [new BN("0")];
Expand Down
10 changes: 0 additions & 10 deletions tests-js/Locked/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ let zeroAddress = constants.ZERO_ADDRESS;
let cliff = 1; // This is in 4 weeks. i.e. 1 * 4 weeks.
let duration = 11; // This is in 4 weeks. i.e. 11 * 4 weeks.

/**
* Function to create a random value.
* It expects no parameter.
*
* @return {number} Random Value.
*/
function randomValue() {
return Math.floor(Math.random() * 10000);
}

contract("Locked SOV (Admin Functions)", (accounts) => {
let sov, lockedSOV, newLockedSOV, vestingRegistry, vestingLogic, stakingLogic;
let creator, admin, newAdmin, userOne, userTwo, userThree, userFour, userFive;
Expand Down
20 changes: 0 additions & 20 deletions tests-js/Locked/creator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,6 @@ let zeroAddress = constants.ZERO_ADDRESS;
let cliff = 1; // This is in 4 weeks. i.e. 1 * 4 weeks.
let duration = 11; // This is in 4 weeks. i.e. 11 * 4 weeks.

/**
* Function to create a random value.
* It expects no parameter.
*
* @return {number} Random Value.
*/
function randomValue() {
return Math.floor(Math.random() * 10000);
}

/**
* Function to get the current timestamp.
* It expects no parameter.
*
* @return {number} Current Timestamp.
*/
function currentTimestamp() {
return Math.floor(Date.now() / 1000);
}

contract("Locked SOV (Creator Functions)", (accounts) => {
let sov, lockedSOV, newLockedSOV, vestingRegistry, vestingLogic, stakingLogic;
let creator, admin, newAdmin, userOne, userTwo, userThree, userFour, userFive;
Expand Down
2 changes: 1 addition & 1 deletion tests-js/vesting/DevelopmentFund/event.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ contract("DevelopmentFund (Events)", (accounts) => {
});

it("Depositing Token should emit the TokenDeposit event.", async () => {
let value = randomValue();
let value = randomValue() + 1;
await testToken.mint(userOne, value);
await testToken.approve(developmentFund.address, value, { from: userOne });
let txReceipt = await developmentFund.depositTokens(value, { from: userOne });
Expand Down
4 changes: 2 additions & 2 deletions tests-js/vesting/DevelopmentFund/multisig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ contract("DevelopmentFund (Multisig Functions)", (accounts) => {
});

it("Unlocked Token Owner should be able to transfer all tokens to safeVault.", async () => {
let value = randomValue();
let value = randomValue() + 1;
await testToken.mint(userOne, value);
await testToken.approve(developmentFund.address, value, { from: userOne });
await developmentFund.depositTokens(value, { from: userOne });
Expand Down Expand Up @@ -225,7 +225,7 @@ contract("DevelopmentFund (Multisig Functions)", (accounts) => {
await testToken.mint(governance, totalReleaseTokenAmount);
await testToken.approve(developmentFund.address, totalReleaseTokenAmount, { from: governance });
await developmentFund.changeTokenReleaseSchedule(zero, releaseDuration, releaseTokenAmount, { from: governance });
let value = randomValue();
let value = randomValue() + 1;
await expectRevert(developmentFund.withdrawTokensByUnlockedTokenOwner(value, { from: multisig }), "No release schedule reached.");
});

Expand Down
20 changes: 10 additions & 10 deletions tests-js/vesting/DevelopmentFund/state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ contract("DevelopmentFund (State)", (accounts) => {
});

it("Adding new Deposit should update the remaining token and contract token balance.", async () => {
let value = randomValue();
let value = randomValue() + 1;
await testToken.mint(userOne, value);
await testToken.approve(developmentFund.address, value, { from: userOne });
await developmentFund.depositTokens(value, { from: userOne });
Expand All @@ -259,7 +259,7 @@ contract("DevelopmentFund (State)", (accounts) => {
});

it("The contract should be approved to make token transfer for deposit.", async () => {
let value = randomValue();
let value = randomValue() + 1;
await expectRevert(developmentFund.depositTokens(value, { from: userOne }), "invalid transfer");
});

Expand All @@ -268,7 +268,7 @@ contract("DevelopmentFund (State)", (accounts) => {
});

it("Updating the release schedule should update the lastReleaseTime, releaseDuration and releaseTokenAmount.", async () => {
let newReleaseTime = randomValue();
let newReleaseTime = randomValue() + 1;
releaseTokenAmount = createReleaseTokenAmount();
totalReleaseTokenAmount = calculateTotalTokenAmount(releaseTokenAmount);
await testToken.mint(governance, totalReleaseTokenAmount);
Expand All @@ -291,7 +291,7 @@ contract("DevelopmentFund (State)", (accounts) => {

it("Updating the release schedule twice should update the lastReleaseTime, releaseDuration and releaseTokenAmount accordingly.", async () => {
// First Time
let newReleaseTime = randomValue();
let newReleaseTime = randomValue() + 1;
releaseTokenAmount = createReleaseTokenAmount();
totalReleaseTokenAmount = calculateTotalTokenAmount(releaseTokenAmount);
await testToken.mint(governance, totalReleaseTokenAmount);
Expand All @@ -312,7 +312,7 @@ contract("DevelopmentFund (State)", (accounts) => {
assert.equal(tokenBalance.toNumber(), totalReleaseTokenAmount, "Token Balance in contract does not match the correct amount.");

// Second Time
newReleaseTime = randomValue();
newReleaseTime = randomValue() + 1;
releaseTokenAmount = createReleaseTokenAmount();
totalReleaseTokenAmount = calculateTotalTokenAmount(releaseTokenAmount);
await testToken.mint(governance, totalReleaseTokenAmount);
Expand All @@ -335,7 +335,7 @@ contract("DevelopmentFund (State)", (accounts) => {

it("While updating release schedule, extra tokens should be sent back.", async () => {
let previousReleaseTokenAmount = totalReleaseTokenAmount;
let newReleaseTime = randomValue();
let newReleaseTime = randomValue() + 1;
releaseTokenAmount = createReleaseTokenAmount();
totalReleaseTokenAmount = calculateTotalTokenAmount(releaseTokenAmount);

Expand Down Expand Up @@ -372,7 +372,7 @@ contract("DevelopmentFund (State)", (accounts) => {
});

it("While updating release schedule, deficient tokens should be sent to contract.", async () => {
let newReleaseTime = randomValue();
let newReleaseTime = randomValue() + 1;
releaseTokenAmount = createReleaseTokenAmount();
let newTotalReleaseTokenAmount = calculateTotalTokenAmount(releaseTokenAmount);
if (newTotalReleaseTokenAmount <= totalReleaseTokenAmount) {
Expand Down Expand Up @@ -410,7 +410,7 @@ contract("DevelopmentFund (State)", (accounts) => {
});

it("Unequal array for duration and tokens should not be accepted for token release schedule.", async () => {
let newReleaseTime = randomValue();
let newReleaseTime = randomValue() + 1;
releaseTokenAmount = createReleaseTokenAmount();
releaseTokenAmount.pop();
await expectRevert(
Expand All @@ -420,7 +420,7 @@ contract("DevelopmentFund (State)", (accounts) => {
});

it("Transferring all tokens to a safeVault by Unlocked Token Owner should update the remainingToken.", async () => {
let value = randomValue();
let value = randomValue() + 1;
await testToken.mint(userOne, value);
await testToken.approve(developmentFund.address, value, { from: userOne });
await developmentFund.depositTokens(value, { from: userOne });
Expand Down Expand Up @@ -535,7 +535,7 @@ contract("DevelopmentFund (State)", (accounts) => {
});

it("Transferring all tokens to a receiver by Locked Token should update the remainingToken.", async () => {
let value = randomValue();
let value = randomValue() + 1;
await testToken.mint(userOne, value);
await testToken.approve(developmentFund.address, value, { from: userOne });
await developmentFund.depositTokens(value, { from: userOne });
Expand Down

0 comments on commit b2bd3e1

Please sign in to comment.