Skip to content

Commit

Permalink
generate
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Aug 29, 2024
1 parent f7aa77e commit d1df9ec
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 21 deletions.
7 changes: 6 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,12 @@ func New(
&app.FeeMarketKeeper,
tracer,
evmSs,
precompiles.StatefulContracts(&app.FungibleKeeper, app.StakingKeeper, appCodec, storetypes.TransientGasConfig()),
precompiles.StatefulContracts(
&app.FungibleKeeper,
app.StakingKeeper,
appCodec,
storetypes.TransientGasConfig(),
),
app.ConsensusParamsKeeper,
aggregateAllKeys(keys, tKeys, memKeys),
)
Expand Down
2 changes: 1 addition & 1 deletion precompiles/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdktypes "github.com/cosmos/cosmos-sdk/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
ethparams "github.com/ethereum/go-ethereum/params"
evmkeeper "github.com/zeta-chain/ethermint/x/evm/keeper"

stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/zeta-chain/zetacore/precompiles/prototype"
"github.com/zeta-chain/zetacore/precompiles/staking"
fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper"
Expand Down
7 changes: 3 additions & 4 deletions precompiles/staking/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import (
"fmt"
"math/big"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"

stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"cosmossdk.io/math"
ptypes "github.com/zeta-chain/zetacore/precompiles/types"
)

Expand Down
97 changes: 82 additions & 15 deletions precompiles/staking/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,14 +578,23 @@ func Test_TransferStake(t *testing.T) {

stakerAddr := common.BytesToAddress(staker.Bytes())

argsStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

// stake to validator src
stakeMethodID := abi.Methods[StakeMethodName]
_, err = contract.Stake(ctx, stakerAddr, &stakeMethodID, argsStake)
require.NoError(t, err)

argsTransferStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, validatorDest.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsTransferStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
validatorDest.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

_, err = contract.TransferStake(ctx, stakerAddr, &methodID, argsTransferStake)
require.Error(t, err)
Expand All @@ -608,14 +617,23 @@ func Test_TransferStake(t *testing.T) {

stakerAddr := common.BytesToAddress(staker.Bytes())

argsStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

// stake to validator src
stakeMethodID := abi.Methods[StakeMethodName]
_, err = contract.Stake(ctx, stakerAddr, &stakeMethodID, argsStake)
require.NoError(t, err)

argsTransferStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, validatorDest.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsTransferStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
validatorDest.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

// transfer stake to validator dest
_, err = contract.TransferStake(ctx, stakerAddr, &methodID, argsTransferStake)
Expand All @@ -639,14 +657,23 @@ func Test_TransferStake(t *testing.T) {

stakerAddr := common.BytesToAddress(staker.Bytes())

argsStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

// stake to validator src
stakeMethodID := abi.Methods[StakeMethodName]
_, err = contract.Stake(ctx, stakerAddr, &stakeMethodID, argsStake)
require.NoError(t, err)

argsTransferStake := []interface{}{42, validatorSrc.OperatorAddress, validatorDest.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsTransferStake := []interface{}{
42,
validatorSrc.OperatorAddress,
validatorDest.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

_, err = contract.TransferStake(ctx, stakerAddr, &methodID, argsTransferStake)
require.Error(t, err)
Expand All @@ -669,14 +696,23 @@ func Test_TransferStake(t *testing.T) {

stakerAddr := common.BytesToAddress(staker.Bytes())

argsStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

// stake to validator src
stakeMethodID := abi.Methods[StakeMethodName]
_, err = contract.Stake(ctx, stakerAddr, &stakeMethodID, argsStake)
require.NoError(t, err)

argsTransferStake := []interface{}{stakerEthAddr, 42, validatorDest.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsTransferStake := []interface{}{
stakerEthAddr,
42,
validatorDest.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

_, err = contract.TransferStake(ctx, stakerAddr, &methodID, argsTransferStake)
require.Error(t, err)
Expand All @@ -699,14 +735,23 @@ func Test_TransferStake(t *testing.T) {

stakerAddr := common.BytesToAddress(staker.Bytes())

argsStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

// stake to validator src
stakeMethodID := abi.Methods[StakeMethodName]
_, err = contract.Stake(ctx, stakerAddr, &stakeMethodID, argsStake)
require.NoError(t, err)

argsTransferStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, validatorDest.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsTransferStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
validatorDest.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

_, err = contract.TransferStake(ctx, stakerAddr, &methodID, argsTransferStake)
require.NoError(t, err)
Expand All @@ -729,14 +774,23 @@ func Test_TransferStake(t *testing.T) {

stakerAddr := common.BytesToAddress(staker.Bytes())

argsStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

// stake to validator src
stakeMethodID := abi.Methods[StakeMethodName]
_, err = contract.Stake(ctx, stakerAddr, &stakeMethodID, argsStake)
require.NoError(t, err)

argsTransferStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, validatorDest.OperatorAddress, coins.AmountOf(config.BaseDenom).Uint64()}
argsTransferStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
validatorDest.OperatorAddress,
coins.AmountOf(config.BaseDenom).Uint64(),
}

_, err = contract.TransferStake(ctx, stakerAddr, &methodID, argsTransferStake)
require.Error(t, err)
Expand All @@ -759,7 +813,11 @@ func Test_TransferStake(t *testing.T) {

stakerAddr := common.BytesToAddress(staker.Bytes())

argsStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

// stake to validator src
stakeMethodID := abi.Methods[StakeMethodName]
Expand Down Expand Up @@ -789,14 +847,23 @@ func Test_TransferStake(t *testing.T) {

stakerAddr := common.BytesToAddress(staker.Bytes())

argsStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

// stake to validator src
stakeMethodID := abi.Methods[StakeMethodName]
_, err = contract.Stake(ctx, stakerAddr, &stakeMethodID, argsStake)
require.NoError(t, err)

argsTransferStake := []interface{}{stakerEthAddr, validatorSrc.OperatorAddress, validatorDest.OperatorAddress, coins.AmountOf(config.BaseDenom).Int64()}
argsTransferStake := []interface{}{
stakerEthAddr,
validatorSrc.OperatorAddress,
validatorDest.OperatorAddress,
coins.AmountOf(config.BaseDenom).Int64(),
}

originEthAddr := common.BytesToAddress(sample.Bech32AccAddress().Bytes())
_, err = contract.TransferStake(ctx, originEthAddr, &methodID, argsTransferStake)
Expand Down

0 comments on commit d1df9ec

Please sign in to comment.