Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
add unused code
add test cases for recovery check in e2e tets, including force seal
add test cases to elaborate all quoting cases in uint-test
keep at least one history recent params when update
  • Loading branch information
leonz789 committed Jan 22, 2025
1 parent b2ba303 commit 73d247a
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 240 deletions.
16 changes: 0 additions & 16 deletions tests/e2e/bank/bank_test.go

This file was deleted.

18 changes: 0 additions & 18 deletions tests/e2e/bank/query.go

This file was deleted.

26 changes: 0 additions & 26 deletions tests/e2e/bank/suite.go

This file was deleted.

Empty file removed tests/e2e/bank/test.result
Empty file.
52 changes: 0 additions & 52 deletions tests/e2e/bank/tx.go

This file was deleted.

26 changes: 0 additions & 26 deletions tests/e2e/basesuite.go

This file was deleted.

31 changes: 21 additions & 10 deletions tests/e2e/oracle/create_price.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,22 @@ func (s *E2ETestSuite) TestCreatePrice() {
creator3 = sdk.AccAddress(s.network.Validators[3].PubKey.Address())

// we combine all test cases into one big case to avoid reset the network multiple times, the order can't be changed
s.testRegisterTokenThroughPrecompile()
s.testCreatePriceNST()
s.testCreatePriceLST()
s.testSlashing()
s.testCreatePriceLSTAfterDelegationChangePower()

option := os.Getenv("TEST_OPTION")
if option == "local" {
s.testRecoveryCases(130)
s.testRecoveryCases(10)
} else {
s.testRegisterTokenThroughPrecompile()
s.testCreatePriceNST()
s.testCreatePriceLST()
s.testSlashing()
s.testCreatePriceLSTAfterDelegationChangePower()
}
// option := os.Getenv("TEST_OPTION")
//
// if option == "local" {
// s.testRecoveryCases(130)
// }
}

func (s *E2ETestSuite) testCreatePriceLSTAfterDelegationChangePower() {
Expand Down Expand Up @@ -258,18 +265,22 @@ func (s *E2ETestSuite) testCreatePriceLST() {
s.Require().NoError(err)
err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg2}, "valconskey2", kr2)
s.Require().NoError(err)

s.moveToAndCheck(41)
// send create-price from validator3 to avoid being slashed for downtime
msg3 = oracletypes.NewMsgCreatePrice(creator3.String(), 1, []*oracletypes.PriceSource{&priceSource1R4}, 40, 1)
err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg3}, "valconskey3", kr3)
s.Require().NoError(err)

s.moveToAndCheck(42)

res, err = s.network.QueryOracle().LatestPrice(ctxWithHeight(41), &oracletypes.QueryGetLatestPriceRequest{TokenId: 1})
s.Require().NoError(err)
// price updated, round 4 has price{p1}
// NOTE: update timestamp manually to ignore
ret = priceTest1R4.getPriceTimeRound(4)
ret.Timestamp = res.Price.Timestamp
s.Require().Equal(ret, res.Price)
// send create-price from validator3 to avoid being slashed for downtime
msg3 = oracletypes.NewMsgCreatePrice(creator3.String(), 1, []*oracletypes.PriceSource{&priceSource1R4}, 40, 1)
err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg3}, "valconskey3", kr3)
s.Require().NoError(err)
}

func (s *E2ETestSuite) testCreatePriceNST() {
Expand Down
76 changes: 74 additions & 2 deletions tests/e2e/oracle/recovery.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package oracle

import (
"math/big"

"github.com/ExocoreNetwork/exocore/testutil/network"
oracletypes "github.com/ExocoreNetwork/exocore/x/oracle/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common/hexutil"
)

// the test cases run with 'devmode' flag, we try to elaborate all cases to check the recovery logic works fine in each scenario
Expand Down Expand Up @@ -452,7 +456,75 @@ func (s *E2ETestSuite) testRecoveryCases(start int64) {
s.Require().Equal(res.Price.Price, priceRecovery3.Prices[0].Price)

// 2.3 failed for forceSeal by paramsUpdate
// TODO: implement me
// TODO: for now all paramsUpdate related forceSeal are not supported (the related fields are not allowed to be updated by msgUpdateParms)
// we comment out this case for now
// start += 10
// startUint = uint64(start)
// msg0.BasedBlock = startUint
// msg1.BasedBlock = startUint
// msg2.BasedBlock = startUint
// msgUpdateParams := oracletypes.NewMsgUpdateParams("creator", `{"max_nonce":5}`)
// s.moveNAndCheck(start)
//
// err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg0}, "valconsKey0", kr0)
// s.Require().NoError(err)
//
// err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg1}, "valconsKey1", kr1)
// s.Require().NoError(err)
//
// // send updateParams msg to forceSeal current round
// err = s.network.SendTx([]sdk.Msg{msgUpdateParams}, s.network.Validators[0].ClientCtx.FromName, kr0)
// s.Require().NoError(err)
// s.moveToAndCheck(start + 1)
//
// err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg2}, "valconsKey2", kr2)
// s.Require().NoError(err)
//
// s.moveToAndCheck(start + 3)
//
// res, err = s.network.QueryOracle().LatestPrice(ctxWithHeight(start+2), &oracletypes.QueryGetLatestPriceRequest{TokenId: 1})
// s.Require().NoError(err)
// // price failed to update
// s.Require().Equal(res.Price.Price, priceRecovery3.Prices[0].Price)

// 2.4 failed for forceSeal by validatorSetUpdate: we use an old timestamp in genesisfile to setup the network so that the epoch end will be triggered on each block
// TODO: implement me
start += 10
startUint = uint64(start)

msg0.BasedBlock = startUint
msg1.BasedBlock = startUint
msg2.BasedBlock = startUint
// msgUpdateParams := oracletypes.NewMsgUpdateParams(s.network.Validators[0].Address.String(), `{"max_nonce":5}`)
s.moveToAndCheck(start)

err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg0}, "valconsKey0", kr0)
s.Require().NoError(err)

err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg1}, "valconsKey1", kr1)
s.Require().NoError(err)

// delegate to change validator set, we set genesis time to a history time so that the validator set update will be triggered every block
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)

// power will be updated at endBlock of start+2, it would force seal this round
s.moveToAndCheck(start + 2)

err = s.network.SendTxOracleCreateprice([]sdk.Msg{msg2}, "valconsKey2", kr2)
s.Require().NotNil(err)

s.moveToAndCheck(start + 3)

res, err = s.network.QueryOracle().LatestPrice(ctxWithHeight(start+2), &oracletypes.QueryGetLatestPriceRequest{TokenId: 1})
s.NoError(err)
s.Require().Equal(res.Price.Price, priceRecovery3.Prices[0].Price)

s.moveToAndCheck(start + 20)
}
37 changes: 0 additions & 37 deletions tests/e2e/util.go

This file was deleted.

6 changes: 4 additions & 2 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package network
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"

Expand Down Expand Up @@ -258,8 +259,9 @@ func initGenFiles(cfg Config, genAccounts []authtypes.GenesisAccount, genBalance

// generate empty genesis files for each validator and save
gTime := cmttime.Now()
// debug-lz, set time to a history time so that we can trigger epoch end on every block
// gTime = gTime.Add(-300 * time.Minute)
if os.Getenv("TEST_OPTION") == "local" {
gTime = gTime.Add(-300 * time.Minute)
}
// 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 {
Expand Down
Empty file.
Loading

0 comments on commit 73d247a

Please sign in to comment.