-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add boilerplate for staking precompile with empty delegate method * add simple undelegate and redelegate methods * add new methods to run * add simple tests * add delegator caller checks * fix del addr origin check * add unit tests for delegate method * changelog * add undelegate tests * add redelegate unit tests * renamings * generate * pr comments * codecov * renaming * e2e test and fixes * generate * fix tests * fix view methods required gas * add queries unit tests * add more unit tests and refactor a bit * fmt * fixes after merge * cleanup * PR comments * add todo with issue * PR comment and bug fix with validators append
- Loading branch information
Showing
21 changed files
with
2,341 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package e2etests | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/node/e2e/runner" | ||
"github.com/zeta-chain/node/e2e/utils" | ||
"github.com/zeta-chain/node/precompiles/staking" | ||
) | ||
|
||
func TestPrecompilesStaking(r *runner.E2ERunner, args []string) { | ||
require.Len(r, args, 0, "No arguments expected") | ||
|
||
stakingContract, err := staking.NewIStaking(staking.ContractAddress, r.ZEVMClient) | ||
require.NoError(r, err, "Failed to create staking contract caller") | ||
|
||
previousGasLimit := r.ZEVMAuth.GasLimit | ||
r.ZEVMAuth.GasLimit = 10000000 | ||
defer func() { | ||
r.ZEVMAuth.GasLimit = previousGasLimit | ||
}() | ||
|
||
validators, err := stakingContract.GetAllValidators(&bind.CallOpts{}) | ||
require.NoError(r, err) | ||
require.GreaterOrEqual(r, len(validators), 2) | ||
|
||
// shares are 0 for both validators at the start | ||
sharesBeforeVal1, err := stakingContract.GetShares(&bind.CallOpts{}, r.ZEVMAuth.From, validators[0].OperatorAddress) | ||
require.NoError(r, err) | ||
require.Equal(r, int64(0), sharesBeforeVal1.Int64()) | ||
|
||
sharesBeforeVal2, err := stakingContract.GetShares(&bind.CallOpts{}, r.ZEVMAuth.From, validators[1].OperatorAddress) | ||
require.NoError(r, err) | ||
require.Equal(r, int64(0), sharesBeforeVal2.Int64()) | ||
|
||
// stake 3 to validator1 | ||
tx, err := stakingContract.Stake(r.ZEVMAuth, r.ZEVMAuth.From, validators[0].OperatorAddress, big.NewInt(3)) | ||
require.NoError(r, err) | ||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
|
||
// check shares are set to 3 | ||
sharesAfterVal1, err := stakingContract.GetShares(&bind.CallOpts{}, r.ZEVMAuth.From, validators[0].OperatorAddress) | ||
require.NoError(r, err) | ||
require.Equal(r, big.NewInt(3e18).String(), sharesAfterVal1.String()) | ||
|
||
// unstake 1 from validator1 | ||
tx, err = stakingContract.Unstake(r.ZEVMAuth, r.ZEVMAuth.From, validators[0].OperatorAddress, big.NewInt(1)) | ||
require.NoError(r, err) | ||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
|
||
// check shares are set to 2 | ||
sharesAfterVal1, err = stakingContract.GetShares(&bind.CallOpts{}, r.ZEVMAuth.From, validators[0].OperatorAddress) | ||
require.NoError(r, err) | ||
require.Equal(r, big.NewInt(2e18).String(), sharesAfterVal1.String()) | ||
|
||
// move 1 stake from validator1 to validator2 | ||
tx, err = stakingContract.MoveStake( | ||
r.ZEVMAuth, | ||
r.ZEVMAuth.From, | ||
validators[0].OperatorAddress, | ||
validators[1].OperatorAddress, | ||
big.NewInt(1), | ||
) | ||
require.NoError(r, err) | ||
|
||
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout) | ||
|
||
// check shares for both validator1 and validator2 are 1 | ||
sharesAfterVal1, err = stakingContract.GetShares(&bind.CallOpts{}, r.ZEVMAuth.From, validators[0].OperatorAddress) | ||
require.NoError(r, err) | ||
require.Equal(r, big.NewInt(1e18).String(), sharesAfterVal1.String()) | ||
|
||
sharesAfterVal2, err := stakingContract.GetShares(&bind.CallOpts{}, r.ZEVMAuth.From, validators[1].OperatorAddress) | ||
require.NoError(r, err) | ||
require.Equal(r, big.NewInt(1e18).String(), sharesAfterVal2.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.