diff --git a/precompiles/delegation/tx.go b/precompiles/delegation/tx.go index 0ca524589..e98bc0393 100644 --- a/precompiles/delegation/tx.go +++ b/precompiles/delegation/tx.go @@ -52,7 +52,6 @@ func (p Precompile) Delegate( if err != nil { return nil, err } - err = p.delegationKeeper.DelegateTo(ctx, delegationParams) if err != nil { return nil, err diff --git a/tests/e2e/oracle/create_price.go b/tests/e2e/oracle/create_price.go index 13ce2ae09..37864379d 100644 --- a/tests/e2e/oracle/create_price.go +++ b/tests/e2e/oracle/create_price.go @@ -51,6 +51,67 @@ func (s *E2ETestSuite) TestCreatePrice() { s.testCreatePriceNST() s.testCreatePriceLST() s.testSlashing() + s.testCreatePriceLSTAfterDelegationChangePower() +} + +func (s *E2ETestSuite) testCreatePriceLSTAfterDelegationChangePower() { + s.moveToAndCheck(80) + priceTest1R1 := price2.updateTimestamp() + priceTimeDetID1R1 := priceTest1R1.getPriceTimeDetID("9") + priceSource1R1 := oracletypes.PriceSource{ + SourceID: 1, + Prices: []*oracletypes.PriceTimeDetID{ + &priceTimeDetID1R1, + }, + } + + // send create-price from validator-0 + msg0 := oracletypes.NewMsgCreatePrice(creator0.String(), 1, []*oracletypes.PriceSource{&priceSource1R1}, 80, 1) + err := s.network.SendTxOracleCreateprice([]sdk.Msg{msg0}, "valconskey0", kr0) + s.Require().NoError(err) + + // send create-price from validator-1 + msg1 := oracletypes.NewMsgCreatePrice(creator1.String(), 1, []*oracletypes.PriceSource{&priceSource1R1}, 80, 1) + err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg1}, "valconskey1", kr1) + s.Require().NoError(err) + + s.moveToAndCheck(82) + res, err := s.network.QueryOracle().LatestPrice(ctxWithHeight(81), &oracletypes.QueryGetLatestPriceRequest{TokenId: 1}) + s.NoError(err) + s.Require().Equal(res.Price.Price, price1.Price) + + s.moveToAndCheck(85) + clientChainID := uint32(101) + lzNonce := uint64(0) + assetAddr, _ := hexutil.Decode(network.ETHAssetAddress) + stakerAddr := []byte(s.network.Validators[0].Address) + operatorAddr := []byte(s.network.Validators[0].Address.String()) + opAmount := big.NewInt(90000000) + // deposit 32 NSTETH to staker from beaconchain_validatro_1 + err = s.network.SendPrecompileTx(network.DELEGATION, "delegate", clientChainID, lzNonce, assetAddr, stakerAddr, operatorAddr, opAmount) + s.Require().NoError(err) + + // wait for validator set update + s.moveToAndCheck(120) + + // send create-price from validator-0 + msg0 = oracletypes.NewMsgCreatePrice(creator0.String(), 1, []*oracletypes.PriceSource{&priceSource1R1}, 120, 1) + err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg0}, "valconskey0", kr0) + s.Require().NoError(err) + + // send create-price from validator-1 + msg1 = oracletypes.NewMsgCreatePrice(creator1.String(), 1, []*oracletypes.PriceSource{&priceSource1R1}, 120, 1) + err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg1}, "valconskey1", kr1) + s.Require().NoError(err) + + s.moveToAndCheck(122) + // query final price. query state of 11 on height 12 + res, err = s.network.QueryOracle().LatestPrice(ctxWithHeight(121), &oracletypes.QueryGetLatestPriceRequest{TokenId: 1}) + s.Require().NoError(err) + + ret := priceTest1R1.getPriceTimeRound(12) + ret.Timestamp = res.Price.Timestamp + s.Require().Equal(ret, res.Price) } /* @@ -341,7 +402,8 @@ func (s *E2ETestSuite) testSlashing() { s.Require().NoError(err) s.Require().True(resOperator.Jailed) // wait for validator3 to pass jail duration - time.Sleep(35 * time.Second) + // timeout commit is set to 2 seconds, 10 blocks about 20 seconds + s.moveToAndCheck(75) msgUnjail := slashingtypes.NewMsgUnjail(s.network.Validators[3].ValAddress) // unjail validator3 err = s.network.SendTx([]sdk.Msg{msgUnjail}, "node3", kr3) @@ -374,7 +436,7 @@ func (s *E2ETestSuite) testRegisterTokenThroughPrecompile() { } func (s *E2ETestSuite) moveToAndCheck(height int64) { - _, err := s.network.WaitForStateHeightWithTimeout(height, 30*time.Second) + _, err := s.network.WaitForStateHeightWithTimeout(height, 120*time.Second) s.Require().NoError(err) } diff --git a/tests/e2e/oracle/data.go b/tests/e2e/oracle/data.go index 4d9e40b91..1d7c57cee 100644 --- a/tests/e2e/oracle/data.go +++ b/tests/e2e/oracle/data.go @@ -58,12 +58,12 @@ func generateNSTPriceTime(sc [][]int) priceTime { var ( price1 = priceTime{ - Price: "19", + Price: "1900000000", Decimal: 8, Timestamp: now, } price2 = priceTime{ - Price: "29", + Price: "290000000", Decimal: 8, Timestamp: now, } diff --git a/testutil/network/genesis_data.go b/testutil/network/genesis_data.go index 6fc68971c..fb82968a4 100644 --- a/testutil/network/genesis_data.go +++ b/testutil/network/genesis_data.go @@ -40,8 +40,8 @@ var ( }, }, Tokens: []assetstypes.StakingAssetInfo{ - NewTestToken("ETH", "Ethereum native token", ETHAssetAddress, TestEVMChainID, 5000), - NewTestToken("NST ETH", "native restaking ETH", NativeAssetAddress, TestEVMChainID, 5000), + NewTestToken("ETH", "Ethereum native token", ETHAssetAddress, TestEVMChainID, 0, 5000), + NewTestToken("NST ETH", "native restaking ETH", NativeAssetAddress, TestEVMChainID, 0, 5000), }, } @@ -80,10 +80,10 @@ func init() { // set slashing_miss window to 4 DefaultGenStateOracle.Params.Slashing.ReportedRoundsWindow = 4 // set jailduration of oracle report downtime to 30 seconds for test - DefaultGenStateOracle.Params.Slashing.OracleMissJailDuration = 30 * time.Second + DefaultGenStateOracle.Params.Slashing.OracleMissJailDuration = 15 * time.Second } -func NewTestToken(name, metaInfo, address string, chainID uint64, amount int64) assetstypes.StakingAssetInfo { +func NewTestToken(name, metaInfo, address string, chainID uint64, decimal uint32, amount int64) assetstypes.StakingAssetInfo { if name == "" { panic("token name cannot be empty") } @@ -94,6 +94,7 @@ func NewTestToken(name, metaInfo, address string, chainID uint64, amount int64) AssetBasicInfo: assetstypes.AssetInfo{ Name: name, MetaInfo: metaInfo, + Decimals: decimal, Address: address, LayerZeroChainID: chainID, }, diff --git a/testutil/network/network.go b/testutil/network/network.go index c393f2c50..1a4260c6f 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -118,12 +118,13 @@ func DefaultConfig() Config { NumValidators: 4, NativeDenom: "hua", MinGasPrices: "10hua", - AccountTokens: sdk.TokensFromConsensusPower(1000, evmostypes.PowerReduction), - DepositedTokens: sdk.TokensFromConsensusPower(500, evmostypes.PowerReduction), - StakingTokens: sdk.TokensFromConsensusPower(200, evmostypes.PowerReduction), - PruningStrategy: pruningtypes.PruningOptionNothing, - CleanupDir: true, - SigningAlgo: string(hd.EthSecp256k1Type), + AccountTokens: sdk.NewInt(150000000), + DepositedTokens: sdk.NewInt(110000000), + StakingTokens: sdk.NewInt(20000000), + + PruningStrategy: pruningtypes.PruningOptionNothing, + CleanupDir: true, + SigningAlgo: string(hd.EthSecp256k1Type), // KeyringOptions: []keyring.Option{hd.EthSecp256k1Option()}, KeyringOptions: []keyring.Option{exocorecrypto.Ed25519Option()}, PrintMnemonic: false, diff --git a/testutil/network/util.go b/testutil/network/util.go index 79e45f5f4..36fd6107a 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -36,7 +36,6 @@ import ( cmttime "github.com/cometbft/cometbft/types/time" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/evmos/evmos/v16/server" - evmostypes "github.com/evmos/evmos/v16/types" evmtypes "github.com/evmos/evmos/v16/x/evm/types" feemarkettypes "github.com/evmos/evmos/v16/x/feemarket/types" ) @@ -258,7 +257,9 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance } // generate empty genesis files for each validator and save + // debug-lz gTime := cmttime.Now() + // we use a time 100 minutes before now, to trigger epoch change for each block in the early blocks(more than 100 blocks) for i := 0; i < cfg.NumValidators; i++ { if genDoc.InitialHeight == 0 { genDoc.InitialHeight = 1 @@ -397,7 +398,7 @@ func NewGenStateOperator(operatorAccAddresses []sdk.AccAddress, consPubKeys []st }) // OperatorUSDValues // the price unit of assets is 1 not decimal 18 - stakingValue := sdk.TokensToConsensusPower(stakingAmount, evmostypes.PowerReduction) + stakingValue := stakingAmount.Int64() DefaultGenStateOperator.OperatorUSDValues = append(DefaultGenStateOperator.OperatorUSDValues, operatortypes.OperatorUSDValue{ Key: AVSAddress + "/" + operatorAccAddress.String(), OptedUSDValue: operatortypes.OperatorOptedUSDValue{ @@ -414,7 +415,7 @@ func NewGenStateOperator(operatorAccAddresses []sdk.AccAddress, consPubKeys []st AVSAddr: AVSAddress, Value: operatortypes.DecValueField{ // the price unit of assets is 1 not decimal 18 - Amount: sdkmath.LegacyNewDec(sdk.TokensToConsensusPower(totalStakingAmount, evmostypes.PowerReduction)), + Amount: sdkmath.LegacyNewDec(totalStakingAmount.Int64()), }, }) } @@ -425,7 +426,7 @@ func NewGenStateOperator(operatorAccAddresses []sdk.AccAddress, consPubKeys []st // stakingAmount is the amount each operator have for every single asset defined in assets module, so for a single operator the total stakingAmount they have is stakingAmount*count(assets) // assets genesis state is required as input argument to provide assets information. It should be called with NewGenStateAssets to update default assets genesis state for test func NewGenStateDogfood(consPubKeys []string, stakingAmount sdkmath.Int, genStateAssets assetstypes.GenesisState) (dogfoodtypes.GenesisState, error) { - power := sdk.TokensToConsensusPower(stakingAmount.Mul(sdkmath.NewInt(int64(len(genStateAssets.Tokens)))), evmostypes.PowerReduction) + power := stakingAmount.Mul(sdkmath.NewInt(int64(len(genStateAssets.Tokens)))).Int64() DefaultGenStateDogfood.Params.EpochIdentifier = "minute" DefaultGenStateDogfood.Params.EpochsUntilUnbonded = 5 DefaultGenStateDogfood.Params.MinSelfDelegation = sdkmath.NewInt(100) diff --git a/x/delegation/keeper/delegation.go b/x/delegation/keeper/delegation.go index 4e9240bd8..07f495a4f 100644 --- a/x/delegation/keeper/delegation.go +++ b/x/delegation/keeper/delegation.go @@ -36,7 +36,6 @@ func (k *Keeper) delegateTo( if notGenesis && k.slashKeeper.IsOperatorFrozen(ctx, params.OperatorAddress) { return delegationtype.ErrOperatorIsFrozen } - stakerID, assetID := assetstype.GetStakerIDAndAssetID(params.ClientChainID, params.StakerAddress, params.AssetsAddress) if assetID != assetstype.ExocoreAssetID { // check if the staker asset has been deposited and the canWithdraw amount is bigger than the delegation amount diff --git a/x/oracle/keeper/feedermanagement/feedermanager.go b/x/oracle/keeper/feedermanagement/feedermanager.go index 8b055bba9..251b7a0f8 100644 --- a/x/oracle/keeper/feedermanagement/feedermanager.go +++ b/x/oracle/keeper/feedermanagement/feedermanager.go @@ -89,6 +89,7 @@ func (f *FeederManager) EndBlock(ctx sdk.Context) { f.ResetFlags() f.updateCheckTx() + } func (f *FeederManager) EndBlockInRecovery(ctx sdk.Context, params *oracletypes.Params) { @@ -218,7 +219,7 @@ func (f *FeederManager) updateAndCommitCaches(ctx sdk.Context) (activeValidators // commit caches: msgs is exists, params if updated, validatorPowers is updated _, vUpdated, pUpdated := f.cs.Commit(ctx, false) if vUpdated || pUpdated { - f.k.Logger(ctx).Info("update caches", "validatorUpdates", vUpdated, "paramsUpdated", pUpdated) + f.k.Logger(ctx).Info("update caches", "validatorUpdated", vUpdated, "paramsUpdated", pUpdated) } return activeValidators }