Skip to content

Commit

Permalink
Merged v1 into v1.3.0-aplha with hotfixes (#966)
Browse files Browse the repository at this point in the history
* Hotfix-proposed data (#913)

* Updated propose data global variables correctly

* Fixed tests

* Returned correct waitForBlockCompletion error

* coverage increase

* GetLocalData returns type types.ProposeFileData

* fixed benchmark

* Fetched Last proposed from contracts (#917)

* fetched getLastProposedEpoch from contracts and tests for it

* typo fix

* V1 propose hotfix (#918)

* Change propose.go to get sorted proposed block ids.
* Fix sorted proposed block issue.

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* allow stakers to addStake < minSafeRazor (#928)

* Call claimStakerReward only if there reward to claim (#926)

* Make contract call only if there is commission to claim

* Add tests for claimCommission file

* update check

* Hotfix-giveSorted (#921)

* ResetDispute only done after FinalizeDispute

* Fixed tests

* Update README (#931)

* Update README

* Update logs path

* Fix home dir path

* Add logs to vote.go and commit.go

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* Add logs for dispute and propose.

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* Fix tests.

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* Suppress unneccessary error logs. (#935)

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* changed http timeout to 30 sec (#943)

* saving commit data only after successfull commit (#947)

* Added password flag (#946)

* added password flag

* README updated

* Hotfix-giveSorted (new implementation) (#953)

* GiveSorted linear recursion

* Added backupNode flag

* Compilation success for tests

* Fixed tests

* removed recusrsion, called giveSorted linearly

* fixed tests

* Added leafId to giveSortedLeafIds[] on successful giveSorted

* Hotfix-sortedProposedBlocks (#957)

* Shuffled copied slice instead of original slice

* returned error from giveSorted when len(sortedValues)=0

* Fixed dispute tests

* Changed pending nonce at to nonce at. (#948)

* Changed pending nonce at to nonce at.
* Update mockery

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* Hotfix -RPCTimeout (#955)

* Added a generic function with timeout for contract calls

* Moved generic function to utils and implemented to all contract getter calls

* Implemented timeout for contract setter functions

* rpc timeout custom error

* type asserting structs from contract mappings

* Shifted timeout to constants

* passed timeout in int in constants.go

* Added rpcTimeout as config

* Removed errorIndex paramter from CheckIfAnyError()

* Function renamed

* Fixed tests

* Unrequired change

* Added backup node info in readme (#963)

* Passed a initialized varible instead of nil value as a parameter

Signed-off-by: Ashish Kumar Mishra <[email protected]>
Co-authored-by: Shekhar Gaur <[email protected]>
Co-authored-by: Ashish Kumar Mishra <[email protected]>
Co-authored-by: Shyam Patel <[email protected]>
Co-authored-by: Raj Kharvar <[email protected]>
Co-authored-by: Skanda Bhat <[email protected]>
  • Loading branch information
6 people authored Oct 7, 2022
1 parent ba96f0e commit 709908d
Show file tree
Hide file tree
Showing 75 changed files with 2,093 additions and 988 deletions.
176 changes: 141 additions & 35 deletions README.md

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions cmd/addStake.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) {
logger.SetLoggerParameters(client, address)
razorUtils.AssignLogFile(flagSet)

password := razorUtils.AssignPassword()
password := razorUtils.AssignPassword(flagSet)

balance, err := razorUtils.FetchBalance(client, address)
utils.CheckError("Error in fetching razor balance for account: "+address, err)
Expand All @@ -57,7 +57,10 @@ func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) {
minSafeRazor, err := utils.UtilsInterface.GetMinSafeRazor(client)
utils.CheckError("Error in getting minimum safe razor amount: ", err)

if valueInWei.Cmp(minSafeRazor) < 0 {
stakerId, err := razorUtils.GetStakerId(client, address)
utils.CheckError("Error in getting stakerId: ", err)

if valueInWei.Cmp(minSafeRazor) < 0 && stakerId == 0 {
log.Fatal("The amount of razors entered is below min safe value.")
}

Expand Down Expand Up @@ -111,11 +114,13 @@ func init() {
var (
Amount string
Address string
Password string
WeiRazor bool
)

stakeCmd.Flags().StringVarP(&Amount, "value", "v", "0", "amount of Razors to stake")
stakeCmd.Flags().StringVarP(&Address, "address", "a", "", "address of the staker")
stakeCmd.Flags().StringVarP(&Password, "password", "", "", "password path of staker to protect the keystore")
stakeCmd.Flags().BoolVarP(&WeiRazor, "weiRazor", "", false, "value can be passed in wei")

amountErr := stakeCmd.MarkFlagRequired("value")
Expand Down
29 changes: 27 additions & 2 deletions cmd/addStake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ func TestExecuteStake(t *testing.T) {
approveErr error
minSafeRazor *big.Int
minSafeRazorErr error
stakerId uint32
stakerIdErr error
stakeTxn common.Hash
stakeErr error
}
Expand All @@ -164,6 +166,7 @@ func TestExecuteStake(t *testing.T) {
amount: big.NewInt(2000),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
approveTxn: common.BigToHash(big.NewInt(1)),
stakeTxn: common.BigToHash(big.NewInt(2)),
},
Expand All @@ -179,6 +182,7 @@ func TestExecuteStake(t *testing.T) {
amount: big.NewInt(2000),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
approveTxn: common.BigToHash(big.NewInt(1)),
stakeTxn: common.BigToHash(big.NewInt(2)),
},
Expand All @@ -194,6 +198,7 @@ func TestExecuteStake(t *testing.T) {
amount: big.NewInt(2000),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
approveTxn: common.BigToHash(big.NewInt(1)),
stakeTxn: common.BigToHash(big.NewInt(2)),
},
Expand Down Expand Up @@ -222,6 +227,7 @@ func TestExecuteStake(t *testing.T) {
amount: big.NewInt(2000),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
approveTxn: core.NilHash,
approveErr: errors.New("approve error"),
stakeTxn: common.BigToHash(big.NewInt(2)),
Expand All @@ -237,6 +243,7 @@ func TestExecuteStake(t *testing.T) {
amount: big.NewInt(2000),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
approveTxn: common.BigToHash(big.NewInt(1)),
stakeTxn: core.NilHash,
stakeErr: errors.New("stake error"),
Expand All @@ -251,6 +258,7 @@ func TestExecuteStake(t *testing.T) {
address: "0x000000000000000000000000000000000000dead",
amount: big.NewInt(2000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
balance: nil,
balanceErr: errors.New("balance error"),
approveTxn: common.BigToHash(big.NewInt(1)),
Expand All @@ -259,17 +267,33 @@ func TestExecuteStake(t *testing.T) {
expectedFatal: true,
},
{
name: "Test 8: When stake value is less than minSafeRazor",
name: "Test 8: When stake value is less than minSafeRazor and staker has never staked",
args: args{
config: config,
password: "test",
address: "0x000000000000000000000000000000000000dead",
amount: big.NewInt(20),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(100),
stakerId: 0,
},
expectedFatal: true,
},
{
name: "Test 9: When stake value is less than minSafeRazor and staker's stake is more than the minSafeRazor already",
args: args{
config: config,
password: "test",
address: "0x000000000000000000000000000000000000dead",
amount: big.NewInt(20),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(100),
stakerId: 1,
approveTxn: common.BigToHash(big.NewInt(1)),
stakeTxn: common.BigToHash(big.NewInt(2)),
},
expectedFatal: false,
},
}

defer func() { log.ExitFunc = nil }()
Expand All @@ -290,7 +314,7 @@ func TestExecuteStake(t *testing.T) {

utilsMock.On("AssignLogFile", mock.AnythingOfType("*pflag.FlagSet"))
cmdUtilsMock.On("GetConfigData").Return(tt.args.config, tt.args.configErr)
utilsMock.On("AssignPassword").Return(tt.args.password)
utilsMock.On("AssignPassword", mock.AnythingOfType("*pflag.FlagSet")).Return(tt.args.password)
flagSetUtilsMock.On("GetStringAddress", mock.AnythingOfType("*pflag.FlagSet")).Return(tt.args.address, tt.args.addressErr)
utilsMock.On("ConnectToClient", mock.AnythingOfType("string")).Return(client)
utilsMock.On("WaitForBlockCompletion", mock.AnythingOfType("*ethclient.Client"), mock.AnythingOfType("string")).Return(nil)
Expand All @@ -299,6 +323,7 @@ func TestExecuteStake(t *testing.T) {
utilsMock.On("CheckAmountAndBalance", mock.AnythingOfType("*big.Int"), mock.AnythingOfType("*big.Int")).Return(tt.args.amount)
utilsMock.On("CheckEthBalanceIsZero", mock.AnythingOfType("*ethclient.Client"), mock.AnythingOfType("string")).Return()
utilsPkgMock.On("GetMinSafeRazor", mock.AnythingOfType("*ethclient.Client")).Return(tt.args.minSafeRazor, tt.args.minSafeRazorErr)
utilsMock.On("GetStakerId", mock.Anything, mock.Anything).Return(tt.args.stakerId, tt.args.stakerIdErr)
cmdUtilsMock.On("Approve", mock.Anything).Return(tt.args.approveTxn, tt.args.approveErr)
cmdUtilsMock.On("StakeCoins", mock.Anything).Return(tt.args.stakeTxn, tt.args.stakeErr)

Expand Down
4 changes: 3 additions & 1 deletion cmd/claimBounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (*UtilsStruct) ExecuteClaimBounty(flagSet *pflag.FlagSet) {
logger.SetLoggerParameters(client, address)
razorUtils.AssignLogFile(flagSet)

password := razorUtils.AssignPassword()
password := razorUtils.AssignPassword(flagSet)

if utilsInterface.IsFlagPassed("bountyId") {
bountyId, err := flagSetUtils.GetUint32BountyId(flagSet)
Expand Down Expand Up @@ -183,10 +183,12 @@ func init() {
rootCmd.AddCommand(claimBountyCmd)
var (
Address string
Password string
BountyId uint32
)

claimBountyCmd.Flags().StringVarP(&Address, "address", "a", "", "address of the staker")
claimBountyCmd.Flags().StringVarP(&Password, "password", "", "", "password path of staker to protect the keystore")
claimBountyCmd.Flags().Uint32VarP(&BountyId, "bountyId", "", 0, "bountyId of the bounty hunter")

addrErr := claimBountyCmd.MarkFlagRequired("address")
Expand Down
2 changes: 1 addition & 1 deletion cmd/claimBounty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestExecuteClaimBounty(t *testing.T) {

utilsMock.On("AssignLogFile", mock.AnythingOfType("*pflag.FlagSet"))
cmdUtilsMock.On("GetConfigData").Return(tt.args.config, tt.args.configErr)
utilsMock.On("AssignPassword").Return(tt.args.password)
utilsMock.On("AssignPassword", mock.AnythingOfType("*pflag.FlagSet")).Return(tt.args.password)
flagSetUtilsMock.On("GetStringAddress", mock.AnythingOfType("*pflag.FlagSet")).Return(tt.args.address, tt.args.addressErr)
flagSetUtilsMock.On("GetUint32BountyId", mock.AnythingOfType("*pflag.FlagSet")).Return(tt.args.bountyId, tt.args.bountyIdErr)
utilsMock.On("ConnectToClient", mock.AnythingOfType("string")).Return(client)
Expand Down
61 changes: 37 additions & 24 deletions cmd/claimCommission.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
package cmd

import (
"github.com/spf13/pflag"
"math/big"
"razor/core"
"razor/core/types"
"razor/logger"
"razor/pkg/bindings"
"razor/utils"

"github.com/spf13/pflag"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -36,42 +38,53 @@ func (*UtilsStruct) ClaimCommission(flagSet *pflag.FlagSet) {
logger.SetLoggerParameters(client, address)
razorUtils.AssignLogFile(flagSet)

password := razorUtils.AssignPassword()
password := razorUtils.AssignPassword(flagSet)

razorUtils.CheckEthBalanceIsZero(client, address)

txnOpts := razorUtils.GetTxnOpts(types.TransactionOptions{
Client: client,
AccountAddress: address,
Password: password,
ChainId: core.ChainId,
Config: config,
ContractAddress: core.StakeManagerAddress,
MethodName: "claimStakerReward",
Parameters: []interface{}{},
ABI: bindings.StakeManagerABI,
})

log.Info("Claiming commission")

txn, err := stakeManagerUtils.ClaimStakeReward(client, txnOpts)
if err != nil {
log.Fatal("Error in claiming stake reward: ", err)
stakerId, err := razorUtils.GetStakerId(client, address)
utils.CheckError("Error in getting stakerId: ", err)
callOpts := razorUtils.GetOptions()

stakerInfo, err := stakeManagerUtils.StakerInfo(client, &callOpts, stakerId)
utils.CheckError("Error in getting stakerInfo: ", err)

if stakerInfo.StakerReward.Cmp(big.NewInt(0)) > 0 {
txnOpts := razorUtils.GetTxnOpts(types.TransactionOptions{
Client: client,
AccountAddress: address,
Password: password,
ChainId: core.ChainId,
Config: config,
ContractAddress: core.StakeManagerAddress,
MethodName: "claimStakerReward",
Parameters: []interface{}{},
ABI: bindings.StakeManagerABI,
})

log.Info("Claiming commission")

txn, err := stakeManagerUtils.ClaimStakeReward(client, txnOpts)
utils.CheckError("Error in claiming stake reward: ", err)

err = razorUtils.WaitForBlockCompletion(client, transactionUtils.Hash(txn).String())
utils.CheckError("Error in WaitForBlockCompletion for claimCommission: ", err)
} else {
log.Error("no commission to claim")
return
}

err = razorUtils.WaitForBlockCompletion(client, transactionUtils.Hash(txn).String())
utils.CheckError("Error in WaitForBlockCompletion for claimCommission: ", err)

}

func init() {
rootCmd.AddCommand(claimCommissionCmd)

var (
Address string
Address string
Password string
)

claimCommissionCmd.Flags().StringVarP(&Address, "address", "a", "", "address of the staker")
claimCommissionCmd.Flags().StringVarP(&Password, "password", "", "", "password path of staker to protect the keystore")

addrErr := claimCommissionCmd.MarkFlagRequired("address")
utils.CheckError("Address error: ", addrErr)
Expand Down
Loading

0 comments on commit 709908d

Please sign in to comment.