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

Reward calculation clean up for zero gas. #527

Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c019299
Reward is not transferred to facilitator if reward is 0.
gulshanvasnani Dec 6, 2018
3fb87c4
Merge branch 'develop' into gulshan/gh_495_reward_calculation_cleanup…
Dec 6, 2018
ad2723d
Added getter to calculate penalty amount
gulshanvasnani Dec 7, 2018
d5d8cb3
Merge branch 'gulshan/gh_495_reward_calculation_cleanup_zero_gas' of …
gulshanvasnani Dec 7, 2018
c8609cf
Merge branch 'develop' into gulshan/gh_495_reward_calculation_cleanup…
0xsarvesh Dec 10, 2018
a2eff7f
Added unit test cases to verify that mint was called only for non-zer…
gulshanvasnani Dec 10, 2018
b71ac3a
Merge branch 'gulshan/gh_495_reward_calculation_cleanup_zero_gas' of …
gulshanvasnani Dec 10, 2018
251451d
Added test to verify the reward amount for facilitator
gulshanvasnani Dec 10, 2018
f889087
Merge branch 'develop' into gulshan/gh_495_reward_calculation_cleanup…
0xsarvesh Dec 10, 2018
5043148
Removed getPenalty method
gulshanvasnani Dec 10, 2018
95a21f5
Merge branch 'gulshan/gh_495_reward_calculation_cleanup_zero_gas' of …
gulshanvasnani Dec 10, 2018
7913fd3
Removed getPenalty method
gulshanvasnani Dec 10, 2018
1caf80a
Merge remote-tracking branch 'remotes/upstream/develop' into gulshan/…
gulshanvasnani Dec 11, 2018
12513e8
Merge branch 'develop' into gulshan/gh_495_reward_calculation_cleanup…
Dec 11, 2018
03c98d0
PR feedback changes
gulshanvasnani Dec 11, 2018
e102ebf
Merge branch 'gulshan/gh_495_reward_calculation_cleanup_zero_gas' of …
gulshanvasnani Dec 11, 2018
f6d379f
Changed parameter type to StateRootInterface
gulshanvasnani Dec 11, 2018
b579027
Added documentation for zero reward.
gulshanvasnani Dec 11, 2018
660c7c9
Merge branch 'develop' into gulshan/gh_495_reward_calculation_cleanup…
gulshanvasnani Dec 11, 2018
1b22697
Changes done to incorporate MockSafeCore
gulshanvasnani Dec 11, 2018
0bca4d2
Indentation changes
gulshanvasnani Dec 12, 2018
b49953c
Merge branch 'develop' into gulshan/gh_495_reward_calculation_cleanup…
Dec 12, 2018
e64bac5
Mocking for mint method is removed and correct unlockSecret value is …
gulshanvasnani Dec 13, 2018
8ef75ae
Merge branch 'gulshan/gh_495_reward_calculation_cleanup_zero_gas' of …
gulshanvasnani Dec 13, 2018
5091ba2
Merge remote-tracking branch 'upstream/develop' into gulshan/gh_495_r…
gulshanvasnani Dec 13, 2018
7bb84d1
Merge branch 'develop' into gulshan/gh_495_reward_calculation_cleanup…
0xsarvesh Dec 13, 2018
c06ddd9
Added test case when message hash is zero
gulshanvasnani Dec 13, 2018
8786e41
Merge branch 'gulshan/gh_495_reward_calculation_cleanup_zero_gas' of …
gulshanvasnani Dec 13, 2018
e246e8b
Merge branch 'develop' into gulshan/gh_495_reward_calculation_cleanup…
schemar Dec 13, 2018
983eb23
Merge branch 'develop' into gulshan/gh_495_reward_calculation_cleanup…
Dec 13, 2018
c4a442f
Merge remote-tracking branch 'upstream/develop' into gulshan/gh_495_r…
gulshanvasnani Dec 13, 2018
b6f7184
Merge remote-tracking branch 'upstream/develop' into gulshan/gh_495_r…
gulshanvasnani Dec 13, 2018
53189b2
Merge branch 'gulshan/gh_495_reward_calculation_cleanup_zero_gas' of …
gulshanvasnani Dec 13, 2018
695b646
Added test-cases
gulshanvasnani Dec 13, 2018
15c32c6
Renamed the MockUtilityToken to TestUtilityToken,added documentation …
gulshanvasnani Dec 14, 2018
6336a6c
Code cleanup and updated the documentation
gulshanvasnani Dec 17, 2018
8c6232f
Updated test-case statements
gulshanvasnani Dec 17, 2018
5b0af8f
Merge remote-tracking branch 'upstream/develop' into gulshan/gh_495_r…
gulshanvasnani Dec 17, 2018
0d15dd3
Removed TestUtilityToken under test directory, updated unit test-case…
gulshanvasnani Dec 17, 2018
4729b01
Merge branch 'develop' into gulshan/gh_495_reward_calculation_cleanup…
gulshanvasnani Dec 18, 2018
b495fbd
Used MockUtilityToken instead of TestUtilityToken
gulshanvasnani Dec 18, 2018
4cd0600
Merge branch 'gulshan/gh_495_reward_calculation_cleanup_zero_gas' of …
gulshanvasnani Dec 18, 2018
12e43c7
Merge remote-tracking branch 'upstream/develop' into gulshan/gh_495_r…
gulshanvasnani Dec 18, 2018
71e4534
Added MockUtilityToken instead of TestUtilityToken
gulshanvasnani Dec 18, 2018
514dd56
Corrected indentation of constructor
gulshanvasnani Dec 18, 2018
b167ec9
Updated documentation of MockUtilityToken
gulshanvasnani Dec 18, 2018
e7a0f12
Indentation fixes of constructor
gulshanvasnani Dec 19, 2018
cfa941c
Removed setCoGateway and getNonce method from helper
gulshanvasnani Dec 19, 2018
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
25 changes: 14 additions & 11 deletions contracts/gateway/EIP20CoGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ contract EIP20CoGateway is GatewayBase {
);
}


/* Public functions */

/**
Expand Down Expand Up @@ -979,6 +980,7 @@ contract EIP20CoGateway is GatewayBase {
);
}


/* Private functions */

/**
Expand Down Expand Up @@ -1063,12 +1065,12 @@ contract EIP20CoGateway is GatewayBase {
* @notice This is internal method for process minting contains common logic.
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
*
* @param _messageHash Message hash.
* @param _initialGas initial gas during progress process.
* @param _initialGas Initial gas during progress process.
*
* @param _proofProgress true if progress with proof, false if progress
* @param _proofProgress True if progress with proof, false if progress
* with hashlock.
* @param _unlockSecret unlock secret to progress, zero in case of progress
* with proof
* @param _unlockSecret Unlock secret to progress, zero in case of progress
* with proof.
*
* @return beneficiary_ Address to which the utility tokens will be
* transferred after minting.
Expand All @@ -1077,9 +1079,8 @@ contract EIP20CoGateway is GatewayBase {
* is given to the facilitator.
* @return mintedAmount_ Actual minted amount, after deducting the reward
* from the total amount.
* @return rewardAmount_ Reward amount that is transferred to facilitator
* @return rewardAmount_ Reward amount that is transferred to facilitator.
*/

function progressMintInternal(
bytes32 _messageHash,
uint256 _initialGas,
Expand Down Expand Up @@ -1111,16 +1112,18 @@ contract EIP20CoGateway is GatewayBase {

mintedAmount_ = stakeAmount_.sub(rewardAmount_);

//Mint token after subtracting reward amount
// Mint token after subtracting reward amount.
UtilityTokenInterface(utilityToken).mint(beneficiary_, mintedAmount_);

//reward beneficiary with the reward amount
UtilityTokenInterface(utilityToken).mint(msg.sender, rewardAmount_);
if(rewardAmount_ > 0) {
// Reward beneficiary with the reward amount.
UtilityTokenInterface(utilityToken).mint(msg.sender, rewardAmount_);
}

// delete the mint data
// Delete the mint data.
delete mints[_messageHash];

// Emit MintProgressed event
// Emit MintProgressed event.
emit MintProgressed(
_messageHash,
message.sender,
Expand Down
3 changes: 3 additions & 0 deletions contracts/gateway/EIP20Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,9 @@ contract EIP20Gateway is GatewayBase {
progressUnstakeInternal(_messageHash, initialGas, bytes32(0), true);
}


/** External methods */
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved

/**
* @notice Declare redeem revert intent.
* This will set message status to revoked. This method will also
Expand Down
61 changes: 61 additions & 0 deletions contracts/test/MockUtilityToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
pragma solidity ^0.5.0;

// Copyright 2017 OpenST Ltd.
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ----------------------------------------------------------------------------
// Auxiliary chain: MockUtilityToken
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
//
// http://www.simpletoken.org/
//
// ----------------------------------------------------------------------------

contract MockUtilityToken {
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved

/* Storage */
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved

/**
* Address to which the utility tokens will be transferred after minting.
*/
address public beneficiary;

/* Amount received by beneficiary. */
uint256 public amount;


/* External functions */

/**
* @notice Mints the utility token
*
* @dev Adds _amount tokens to beneficiary balance and increases the
* totalTokenSupply. Can be called only by CoGateway.
*
* @param _beneficiary Address of tokens beneficiary.
* @param _amount Amount of tokens to mint.
*
* @return True if mint is successful, false otherwise.
*/
function mint(
address _beneficiary,
uint256 _amount
)
external
returns (bool /* success */)
{
beneficiary = _beneficiary;
amount = _amount;
return true;
}
}
138 changes: 138 additions & 0 deletions contracts/test/TestEIP20CoGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
pragma solidity ^0.5.0;
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved

import "../gateway/EIP20CoGateway.sol";

/**
* @title TestEIP20CoGateway contract.
*
* @notice Used for test only.
*/
contract TestEIP20CoGateway is EIP20CoGateway {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we currently differentiate between Test... and Mock...?

/cc @deepesh-kn @sarvesh-ost

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mock... is to completely mock a contract.
Test.. is to test existing contract function, and has some functions to set data (for testing)


/* Constructor */

/**
* @notice Initialise the contract by providing the Gateway contract
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
* address for which the CoGateway will enable facilitation of
* minting and redeeming.
*
* @param _valueToken The value token contract address.
* @param _utilityToken The utility token address that will be used for
* minting the utility token.
* @param _core Core contract address.
* @param _bounty The amount that facilitator will stakes to initiate the
* staking process.
* @param _membersManager Organisation address.
* @param _gateway Gateway contract address.
*/
constructor(
address _valueToken,
address _utilityToken,
CoreInterface _core,
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
uint256 _bounty,
IsMemberInterface _membersManager,
address _gateway
)
EIP20CoGateway(
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
_valueToken,
_utilityToken,
_core,
_bounty,
_membersManager,
_gateway
)
public
{
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved

}


/* Public Functions */

/**
* @notice It is used to set the messagehash.
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
*
* @dev It is for test purposes only.
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
*
* @param _intentHash Intent hash.
* @param _stakerNonce Nonce of the staker address.
* @param _gasPrice Gas price that staker is ready to pay to get the stake
* and mint process done.
* @param _gasLimit Gas limit that staker is ready to pay.
* @param _hashLock Hash Lock provided by the facilitator.
* @param _staker Staker address.
*
* @return messageHash_ Hash unique for every request.
*/
function setMessage(
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
bytes32 _intentHash,
uint256 _stakerNonce,
uint256 _gasPrice,
uint256 _gasLimit,
bytes32 _hashLock,
address _staker
)
public
returns (bytes32 messageHash_)
{

messageHash_ = MessageBus.messageDigest(
STAKE_TYPEHASH,
_intentHash,
_stakerNonce,
_gasPrice,
_gasLimit
);

messages[messageHash_] = getMessage(
_staker,
_stakerNonce,
_gasPrice,
_gasLimit,
_intentHash,
_hashLock
);

return messageHash_;

}

/**
* @notice It sets the mints mapping with respect to the messageHash.
*
* @dev It is for test purposes only.
*
* @param _messageHash Hash for which mints mapping is updated.
* @param _beneficiary Beneficiary Address to which the utility tokens
* will be transferred after minting.
* @param _amount Total amount for which the stake was initiated. The
* reward amount is deducted from the total amount and
* is given to the facilitator.
*/
function setMints(
bytes32 _messageHash,
address _beneficiary,
uint256 _amount
)
public
{
mints[_messageHash] = Mint({
amount : _amount,
beneficiary : _beneficiary
});
}

/**
* @notice It sets the status of inbox to Declared.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @notice It sets the status of inbox to Declared.
* @notice It sets the status of the inbox to declared status.

*
* @dev It is for test purposes only.
*
* @param _messageHash Hash for which status is set to Declared.
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
*/
function setInboxStatus(bytes32 _messageHash) public {

messageBox.inbox[_messageHash] = MessageBus.MessageStatus.Declared;
gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved

gulshanvasnani marked this conversation as resolved.
Show resolved Hide resolved
}

}
5 changes: 3 additions & 2 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const MetaBlock = artifacts.require("../contracts/lib/MetaBlock.sol");
const BlockStore = artifacts.require("../contracts/BlockStore.sol");
const TestEIP20Gateway = artifacts.require("TestEIP20Gateway");
const EIP20CoGateway = artifacts.require("EIP20CoGateway");
const TestEIP20CoGateway = artifacts.require("TestEIP20CoGateway");
const AuxiliaryBlockStore = artifacts.require(
"../contracts/AuxiliaryBlockStore.sol"
);
Expand Down Expand Up @@ -35,8 +36,8 @@ module.exports = function (deployer) {
deployer.deploy(GatewayLib);
deployer.deploy(MockGatewayLib);
deployer.deploy(MetaBlock);
deployer.link(GatewayLib, [GatewayBase, EIP20Gateway, TestEIP20Gateway, EIP20CoGateway]);
deployer.link(MessageBus, [EIP20CoGateway,TestEIP20Gateway, EIP20Gateway]);
deployer.link(GatewayLib, [GatewayBase, EIP20Gateway, TestEIP20Gateway, EIP20CoGateway, TestEIP20CoGateway]);
deployer.link(MessageBus, [EIP20CoGateway, TestEIP20CoGateway, TestEIP20Gateway, EIP20Gateway]);
deployer.link(MockGatewayLib, [MockGatewayBase, TestEIP20Gateway]);
deployer.link(MetaBlock, [BlockStore, AuxiliaryBlockStore]);

Expand Down
Loading