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 all 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
19 changes: 11 additions & 8 deletions contracts/gateway/EIP20CoGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ contract EIP20CoGateway is GatewayBase {

require(
_messageHash != bytes32(0),
"Message hash must not be zero"
"Message hash must not be zero."
);

MessageBus.Message storage message = messages[_messageHash];
Expand All @@ -303,7 +303,7 @@ contract EIP20CoGateway is GatewayBase {
stakeAmount_,
mintedAmount_,
rewardAmount_) =
progressMintInternal(_messageHash, initialGas, true, bytes32(0));
progressMintInternal(_messageHash, initialGas, false, _unlockSecret);
}

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


/* Public functions */

/**
Expand Down Expand Up @@ -1060,6 +1061,7 @@ 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
* It doesn't mint reward if reward is 0.
*
* @param _messageHash Message hash.
* @param _initialGas Initial gas during progress process.
Expand All @@ -1078,7 +1080,6 @@ contract EIP20CoGateway is GatewayBase {
* from the total amount.
* @return rewardAmount_ Reward amount that is transferred to facilitator.
*/

function progressMintInternal(
bytes32 _messageHash,
uint256 _initialGas,
Expand Down Expand Up @@ -1116,11 +1117,13 @@ contract EIP20CoGateway is GatewayBase {
mintedAmount_
);

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

// Delete the mint data.
delete mints[_messageHash];
Expand Down
3 changes: 3 additions & 0 deletions contracts/gateway/EIP20Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,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
13 changes: 13 additions & 0 deletions contracts/gateway/UtilityTokenInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,17 @@ contract UtilityTokenInterface {
*/
function decreaseSupply(uint256 _amount) external returns (bool success_);

/**
* @notice Sets the CoGateway contract address.
*
* @dev Function requires:
* - It is called by whitelisted workers.
* - coGateway address is set only once.
* - coGateway.utilityToken must match this contract.
*
* @param _coGateway CoGateway contract address.
*
*/
function setCoGateway(address _coGateway) external returns (bool);

}
2 changes: 1 addition & 1 deletion contracts/test/TestEIP20CoGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ contract TestEIP20CoGateway is EIP20CoGateway {
/* Public Functions */

/**
* @notice It is used to set the message.
* @notice It is used to set the stake message.
*
* @dev This is used for testing purpose.
*
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/TestEIP20Gateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract TestEIP20Gateway is EIP20Gateway {
StateRootInterface _core,
uint256 _bounty,
IsMemberInterface _membersManager,
address _burner
address payable _burner
)
EIP20Gateway(
_token,
Expand Down
66 changes: 66 additions & 0 deletions contracts/test/gateway/MockUtilityToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
pragma solidity ^0.5.0;

// Copyright 2018 OpenST Ltd.
//
// 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.
//
// ----------------------------------------------------------------------------
//
// http://www.simpletoken.org/
//
// ----------------------------------------------------------------------------

import "../../gateway/UtilityToken.sol";

/**
* @title MockUtilityToken contract.
*
* @notice This contract is used to mock certain functions of UtilityToken
* contract.
*/
contract MockUtilityToken is UtilityToken {

/* Constructor */

/**
* @notice Constructor.
*
* @dev This is used for testing only.
*
* @param _token Address of branded token.
* @param _symbol Symbol of token.
* @param _name Name of token.
* @param _decimals Decimal of token.
* @param _membersManager Address of a contract that manages organization.
*/
constructor(
EIP20Interface _token,
string memory _symbol,
string memory _name,
uint8 _decimals,
IsMemberInterface _membersManager
)
public
UtilityToken(_token, _symbol, _name, _decimals, _membersManager)
{}

/**
* @notice Set the CoGateway address for testing.
*
* @param _coGatewayAddress CoGateway address.
*/
function setCoGatewayAddress(address _coGatewayAddress) external {
coGateway = _coGatewayAddress;
}

}
9 changes: 5 additions & 4 deletions contracts/test/gateway/TestUtilityToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ import "../../gateway/UtilityToken.sol";
* contract.
*/
contract TestUtilityToken is UtilityToken {

/* Constructor */

/**
* @dev This is used for testing by mocking certain variables.
*
* @param _token Address of branded token.
* @param _symbol Symbol of token
* @param _name Name of token
* @param _decimals Decimal of token
* @param _symbol Symbol of token.
* @param _name Name of token.
* @param _decimals Decimal of token.
* @param _membersManager Address of a contract that manages organization.
*/
constructor(
EIP20Interface _token,
Expand Down
Loading