Skip to content

Commit

Permalink
fixed the issue regarding object operation and registration
Browse files Browse the repository at this point in the history
  • Loading branch information
TimmyExogenous committed Dec 1, 2024
1 parent 4f957d8 commit da83bc3
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 27 deletions.
32 changes: 16 additions & 16 deletions testutil/batch/batch_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,20 @@ func (m *Manager) EnqueueDepositWithdrawLSTTxs(msgType string) error {

ethHTTPClient := m.NodeEVMHTTPClients[DefaultNodeIndex]
// construct and push all messages into the queue
stakerOpFunc := func(stakerId uint, _ int64, staker *Staker) error {
stakerOpFunc := func(stakerId uint, _ int64, staker Staker) error {
nonce, err := ethHTTPClient.NonceAt(m.ctx, staker.Address, nil)
if err != nil {
return xerrors.Errorf(
"BatchDeposit: can't get staker's nonce, stakerId:%d, addr:%s,err:%s",
stakerId, staker.Address.String(), err)
}
assetOpFunc := func(assetId uint, _ int64, asset *Asset) error {
assetOpFunc := func(assetId uint, _ int64, asset Asset) error {
data, err := assetsAbi.Pack(msgType, asset.ClientChainID, PaddingAddressTo32(asset.Address), PaddingAddressTo32(staker.Address), opAmount)
if err != nil {
return err
}
// get the total deposit amount before deposit or withdrawal
stakerAssetInfo, err := m.QueryStakerAssetInfo(asset.ClientChainID, staker.EvmAddress().String(), asset.Address.String())
stakerAssetInfo, err := m.QueryStakerAssetInfo(uint64(asset.ClientChainID), staker.EvmAddress().String(), asset.Address.String())
if err != nil {
logger.Error("EnqueueDepositWithdrawLSTTxs, error occurs when querying the staker asset info",
"staker", staker.EvmAddress().String(), "asset", asset.Address.String(), "err", err)
Expand All @@ -129,7 +129,7 @@ func (m *Manager) EnqueueDepositWithdrawLSTTxs(msgType string) error {
}

err = m.enqueueTxAndSaveRecord(&EnqueueTxParams{
staker: staker,
staker: &staker,
nonce: &nonce,
msgType: msgType,
IsCosmosTx: false,
Expand All @@ -143,13 +143,13 @@ func (m *Manager) EnqueueDepositWithdrawLSTTxs(msgType string) error {
}
return nil
}
err = IterateObjects(m, &Asset{}, assetOpFunc)
err = IterateObjects(m, Asset{}, assetOpFunc)
if err != nil {
return err
}
return nil
}
err = IterateObjects(m, &Staker{}, stakerOpFunc)
err = IterateObjects(m, Staker{}, stakerOpFunc)
if err != nil {
return err
}
Expand All @@ -164,7 +164,7 @@ func (m *Manager) EnqueueDelegationTxs(msgType string) error {
if err != nil {
return err
}
operatorNumber, err := ObjectsNumber(m, &Operator{})
operatorNumber, err := ObjectsNumber(m, Operator{})
if err != nil {
return err
}
Expand All @@ -173,17 +173,17 @@ func (m *Manager) EnqueueDelegationTxs(msgType string) error {
opAmount := sdkmath.ZeroInt()
expectedCheckValue := sdkmath.ZeroInt()
// construct and push all messages into the queue
stakerOpFunc := func(stakerId uint, _ int64, staker *Staker) error {
stakerOpFunc := func(stakerId uint, _ int64, staker Staker) error {
nonce, err := ethHTTPClient.NonceAt(m.ctx, staker.Address, nil)
if err != nil {
return xerrors.Errorf(
"BatchDeposit: can't get staker's nonce, stakerId:%d, addr:%s,err:%s",
stakerId, staker.Address.String(), err)
}

assetOpFunc := func(assetId uint, _ int64, asset *Asset) error {
assetOpFunc := func(assetId uint, _ int64, asset Asset) error {
// Each asset needs to perform delegate and undelegate operations on all operators.
stakerAssetInfo, err := m.QueryStakerAssetInfo(asset.ClientChainID, staker.EvmAddress().String(), asset.Address.String())
stakerAssetInfo, err := m.QueryStakerAssetInfo(uint64(asset.ClientChainID), staker.EvmAddress().String(), asset.Address.String())
if err != nil {
logger.Error("EnqueueDelegationTxs, error occurs when querying the staker asset info",
"staker", staker.EvmAddress().String(), "asset", asset.Address.String(), "err", err)
Expand All @@ -197,8 +197,8 @@ func (m *Manager) EnqueueDelegationTxs(msgType string) error {
// delegates half of the withdrawable amount to the operators
opAmount = stakerAssetInfo.WithdrawableAmount.Quo(sdkmath.NewInt(2)).Quo(sdkmath.NewInt(operatorNumber))
}
operatorOpFunc := func(operatorId uint, _ int64, operator *Operator) error {
delegatedAmount, err := m.QueryDelegatedAmount(asset.ClientChainID, staker.EvmAddress().String(), asset.Address.String(), operator.Address)
operatorOpFunc := func(operatorId uint, _ int64, operator Operator) error {
delegatedAmount, err := m.QueryDelegatedAmount(uint64(asset.ClientChainID), staker.EvmAddress().String(), asset.Address.String(), operator.Address)
if err != nil {
return err
}
Expand All @@ -217,7 +217,7 @@ func (m *Manager) EnqueueDelegationTxs(msgType string) error {
return err
}
err = m.enqueueTxAndSaveRecord(&EnqueueTxParams{
staker: staker,
staker: &staker,
nonce: &nonce,
msgType: msgType,
IsCosmosTx: false,
Expand All @@ -232,19 +232,19 @@ func (m *Manager) EnqueueDelegationTxs(msgType string) error {
}
return nil
}
err = IterateObjects(m, &Operator{}, operatorOpFunc)
err = IterateObjects(m, Operator{}, operatorOpFunc)
if err != nil {
return err
}
return nil
}
err = IterateObjects(m, &Asset{}, assetOpFunc)
err = IterateObjects(m, Asset{}, assetOpFunc)
if err != nil {
return err
}
return nil
}
err = IterateObjects(m, &Staker{}, stakerOpFunc)
err = IterateObjects(m, Staker{}, stakerOpFunc)
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions testutil/batch/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ func (m *Manager) Prepare() error {
if err != nil {
return xerrors.Errorf("failed to check assets,err:%s", err)
}
logger.Info("finish registering test assets, next step: operator registration")
// register the operators, EthSigner is the operator sk, tx type is cosmos
if err = m.RegisterOperators(); err != nil {
return xerrors.Errorf("failed to register operators,err:%s", err)
Expand All @@ -443,6 +444,7 @@ func (m *Manager) Prepare() error {
if err != nil {
return xerrors.Errorf("failed to check operators,err:%s", err)
}
logger.Info("finish registering test operators, next step: AVS registration")
// EthSigner is the AVS sk, tx type is evm
if err = m.RegisterAVSs(assets); err != nil {
return xerrors.Errorf("failed to register AVss,err:%s", err)
Expand All @@ -451,6 +453,7 @@ func (m *Manager) Prepare() error {
if err != nil {
return xerrors.Errorf("failed to check AVSs,err:%s", err)
}
logger.Info("finish registering test AVSs, next step: add assets to dogfood")
// add the test assets to the supported list of dogfood AVS, EthSigner is the AVS sk
// tx type is cosmos
if err = m.AddAssetsToDogfoodAVS(assets); err != nil {
Expand All @@ -460,6 +463,7 @@ func (m *Manager) Prepare() error {
if err != nil || isUpdate {
return xerrors.Errorf("failed to check the assets list of dogfood,isUpdate:%v,err:%s", isUpdate, err)
}
logger.Info("finish adding assets to dogfood, next step: opts the operators to AVSs")
// opt all test operators to all test AVSs, EthSigner is the operator sk
// tx type is cosmos
if err = m.OptOperatorsIntoAVSs(); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions testutil/batch/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ package batch

import (
"context"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/common"
"testing"

"github.com/ExocoreNetwork/exocore/app"
Expand Down Expand Up @@ -98,6 +100,18 @@ func Test_ImportPrivKeyHex(t *testing.T) {
assert.Equal(t, exoAddr.String(), keyRecordAddr.String())
}

func Test_queryEvmTx(t *testing.T) {
appManager, err := NewManager(context.Background(), "/home/timmy/tests/test-tool", &DefaultTestToolConfig)
assert.NoError(t, err)
txID := common.HexToHash("0x02530b04f5a645c744bfe98cf91d47c4061a983c1423463c44c6593b5fd9454b")
evmHTTPClient := appManager.NodeEVMHTTPClients[DefaultNodeIndex]
receipt, err := evmHTTPClient.TransactionReceipt(appManager.ctx, txID)
assert.NoError(t, err)
receiptBytes, err := json.MarshalIndent(receipt, " ", " ")
assert.NoError(t, err)
fmt.Println(string(receiptBytes))
}

func Test_Start(t *testing.T) {
appManager, err := NewManager(context.Background(), "/home/timmy/tests/test-tool", &DefaultTestToolConfig)
assert.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions testutil/batch/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (m *Manager) AssetsCheck(opFuncIfCheckFail func(assetID string, asset *Asse
opFunc := func(_ uint, _ int64, asset *Asset) error {
// check if the asset has been registered.
_, assetID := assetstypes.GetStakerIDAndAssetIDFromStr(
asset.ClientChainID, "", asset.Address.String())
uint64(asset.ClientChainID), "", asset.Address.String())
req := &assetstypes.QueryStakingAssetInfo{
AssetID: assetID, // already lowercase
}
Expand Down Expand Up @@ -145,7 +145,7 @@ func (m *Manager) RegisterAssets() ([]string, error) {
allAssetsID := make([]string, 0)
opFuncIfCheckFail := func(assetID string, asset *Asset) error {
// register the asset.
data, err := assetsAbi.Pack(assets.MethodRegisterToken, asset.ClientChainID, asset.Address, asset.Decimal, asset.Name, asset.MetaInfo, asset.OracleInfo)
data, err := assetsAbi.Pack(assets.MethodRegisterToken, asset.ClientChainID, PaddingAddressTo32(asset.Address), asset.Decimal, asset.Name, asset.MetaInfo, asset.OracleInfo)
if err != nil {
return err
}
Expand Down Expand Up @@ -218,7 +218,7 @@ func (m *Manager) RegisterAVSs(allAssetsID []string) error {
avsUnbondingPeriod := uint64(id) % MaxUnbondingDuration
data, err := avsAbi.Pack(
avsprecompile.MethodRegisterAVS,
avs.Address,
avs.EvmAddress(),
name,
minStakeAmount,
tx.GenerateAddress(),
Expand Down
5 changes: 3 additions & 2 deletions testutil/batch/send_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ func (m *Manager) SignSendEvmTxAndWait(txInfo *EvmTxInQueue) error {
return err
}
if receipt.Status != types.ReceiptStatusSuccessful {
logger.Info(" the evm tx has been on chain but the execution is failed", "txHash", txHash)
return xerrors.Errorf("failed evm tx receipt, txID:%s", txHash)
}
logger.Info("the evm tx has been on chain successfully", "txID", txHash)
return nil
}

Expand Down Expand Up @@ -279,10 +281,9 @@ func (m *Manager) WaitForCosmosTxs(responseList []*sdktypes.TxResponse, waitDura

queryRes, err := tx.QueryTx(m.NodeClientCtx[DefaultNodeIndex], res.TxHash)
if err != nil {
logger.Error("can't query the cosmos tx", "txHash", res.TxHash, "err", err)
logger.Error("can't query the cosmos tx, continue waiting", "txHash", res.TxHash, "err", err)
// Wait for the specified duration before retrying
// Log a message indicating the receipt is not yet available
logger.Info("can't get the receipt of EVM transaction, continue waiting", "err", err)
time.Sleep(waitDuration)
continue
}
Expand Down
4 changes: 2 additions & 2 deletions testutil/batch/tx_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (m *Manager) TxOnChainCheck(batchID uint, msgType string) error {
func (m *Manager) DepositWithdrawLSTCheck(batchID uint, msgType string) error {
stakerOpFunc := func(stakerDBID uint, _ int64, staker *Staker) error {
assetOpFunc := func(assetDBID uint, _ int64, asset *Asset) error {
res, err := m.QueryStakerAssetInfo(asset.ClientChainID, staker.EvmAddress().String(), asset.Address.String())
res, err := m.QueryStakerAssetInfo(uint64(asset.ClientChainID), staker.EvmAddress().String(), asset.Address.String())
if err != nil {
logger.Error("DepositWithdrawLSTCheck, error occurs when querying the staker asset info",
"stakerDBID", stakerDBID, "assetDBID", assetDBID, "err", err)
Expand Down Expand Up @@ -209,7 +209,7 @@ func (m *Manager) EvmDelegationCheck(batchID uint, msgType string) error {
stakerOpFunc := func(stakerDBID uint, _ int64, staker *Staker) error {
assetOpFunc := func(assetDBID uint, _ int64, asset *Asset) error {
operatorOpFunc := func(_ uint, _ int64, operator *Operator) error {
delegatedAmount, err := m.QueryDelegatedAmount(asset.ClientChainID, staker.EvmAddress().String(), asset.Address.String(), operator.Address)
delegatedAmount, err := m.QueryDelegatedAmount(uint64(asset.ClientChainID), staker.EvmAddress().String(), asset.Address.String(), operator.Address)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions testutil/batch/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type TestToolConfig struct {
// parameters for the testnet
ChainValidatorNumber int `mapstructure:"chain-validator-number" toml:"chain-validator-number"`
ChainID string `mapstructure:"chain-id" toml:"chain-id"`
DefaultClientChainID uint64 `mapstructure:"default-client-chain-id" toml:"default-client-chain-id"`
DefaultClientChainID uint32 `mapstructure:"default-client-chain-id" toml:"default-client-chain-id"`

// the RPCs of the Exocore chain nodes
NodesRPC []string `mapstructure:"nodes-rpc" toml:"nodes-rpc"`
Expand Down Expand Up @@ -81,7 +81,7 @@ type TestToolConfig struct {
var DefaultTestToolConfig = TestToolConfig{
StakerNumber: 5,
OperatorNumber: 3,
AVSNumber: 1,
AVSNumber: 2,
AsssetNumber: 5,
// this private key is from the local_node.sh
FaucetSk: "D196DCA836F8AC2FFF45B3C9F0113825CCBB33FA1B39737B948503B263ED75AE",
Expand Down Expand Up @@ -112,7 +112,7 @@ type HelperRecord struct {
type Asset struct {
ID uint `gorm:"primaryKey"` // primary key
Address common.Address `gorm:"column:address;type:char(42)"` // eth address
ClientChainID uint64
ClientChainID uint32
Decimal uint8
Name string `gorm:"type:varchar(50)"`
MetaInfo string `gorm:"type:varchar(200)"`
Expand Down
3 changes: 2 additions & 1 deletion testutil/batch/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package batch

import (
"math/big"
"reflect"

sdkmath "cosmossdk.io/math"

Expand Down Expand Up @@ -170,7 +171,7 @@ func FundingObjects[T AddressForFunding](m *Manager, model T, needExo int64) err
}
// check if the object needs to be funded
if len(multiSendMsgs) == 0 {
logger.Info("FundingObjects: no object needs to be funded", "object", model)
logger.Info("FundingObjects: no object needs to be funded", "objectType", reflect.TypeOf(model).Name())
return nil
}
// check if the faucet balance is enough
Expand Down

0 comments on commit da83bc3

Please sign in to comment.