Skip to content

Commit

Permalink
test: tx
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniFrenchBread committed Nov 4, 2024
1 parent 1602c96 commit 605a71e
Show file tree
Hide file tree
Showing 8 changed files with 395 additions and 31 deletions.
3 changes: 1 addition & 2 deletions precompiles/interfaces/contracts/IStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ struct CommissionRates {
uint maxChangeRate; // 18 decimals
}


/**
* @dev Commission defines the commission parameters.
*/
Expand Down Expand Up @@ -207,7 +206,7 @@ interface IStaking {
function delegate(
string memory validatorAddress,
uint amount // in bond denom
) external returns (bool success);
) external;

/**
* @dev BeginRedelegate defines a method for performing a redelegationA
Expand Down
8 changes: 1 addition & 7 deletions precompiles/staking/IStaking.abi
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,7 @@
}
],
"name": "delegate",
"outputs": [
{
"internalType": "bool",
"name": "success",
"type": "bool"
}
],
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
Expand Down
8 changes: 4 additions & 4 deletions precompiles/staking/contract.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions precompiles/staking/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func (suite *StakingTestSuite) setupValidator(signer *testutil.TestSigner) {
suite.Assert().NoError(err)
_, err = suite.runTx(input, signer, 10000000)
suite.Assert().NoError(err)
_, err = suite.stakingKeeper.ApplyAndReturnValidatorSetUpdates(suite.Ctx)
suite.Assert().NoError(err)
}

func (suite *StakingTestSuite) firstBondedValidator() (sdk.ValAddress, error) {
Expand Down
9 changes: 5 additions & 4 deletions precompiles/staking/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package staking

import (
"fmt"
"math/big"

precopmiles_common "github.com/0glabs/0g-chain/precompiles/common"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -103,12 +104,12 @@ func (s *StakingPrecompile) BeginRedelegate(
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin)
}
// execute
_, err = stakingkeeper.NewMsgServerImpl(s.stakingKeeper).BeginRedelegate(ctx, msg)
response, err := stakingkeeper.NewMsgServerImpl(s.stakingKeeper).BeginRedelegate(ctx, msg)
if err != nil {
return nil, err
}
// emit events
return method.Outputs.Pack()
return method.Outputs.Pack(big.NewInt(response.CompletionTime.UTC().Unix()))
}

func (s *StakingPrecompile) Undelegate(
Expand All @@ -128,12 +129,12 @@ func (s *StakingPrecompile) Undelegate(
return nil, fmt.Errorf(precopmiles_common.ErrSenderNotOrigin)
}
// execute
_, err = stakingkeeper.NewMsgServerImpl(s.stakingKeeper).Undelegate(ctx, msg)
response, err := stakingkeeper.NewMsgServerImpl(s.stakingKeeper).Undelegate(ctx, msg)
if err != nil {
return nil, err
}
// emit events
return method.Outputs.Pack()
return method.Outputs.Pack(big.NewInt(response.CompletionTime.UTC().Unix()))
}

func (s *StakingPrecompile) CancelUnbondingDelegation(
Expand Down
Loading

0 comments on commit 605a71e

Please sign in to comment.