diff --git a/testutil/batch/batch_tx.go b/testutil/batch/batch_tx.go index 4007077ca..00c347995 100644 --- a/testutil/batch/batch_tx.go +++ b/testutil/batch/batch_tx.go @@ -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) @@ -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, @@ -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 } @@ -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 } @@ -173,7 +173,7 @@ 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( @@ -181,9 +181,9 @@ func (m *Manager) EnqueueDelegationTxs(msgType string) error { 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) @@ -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 } @@ -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, @@ -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 } diff --git a/testutil/batch/manager.go b/testutil/batch/manager.go index 74931bef9..b77529a44 100644 --- a/testutil/batch/manager.go +++ b/testutil/batch/manager.go @@ -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) @@ -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) @@ -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 { @@ -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 { diff --git a/testutil/batch/manager_test.go b/testutil/batch/manager_test.go index e75ca9953..ab513b4a8 100644 --- a/testutil/batch/manager_test.go +++ b/testutil/batch/manager_test.go @@ -4,7 +4,9 @@ package batch import ( "context" + "encoding/json" "fmt" + "github.com/ethereum/go-ethereum/common" "testing" "github.com/ExocoreNetwork/exocore/app" @@ -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) diff --git a/testutil/batch/prepare.go b/testutil/batch/prepare.go index 6b3421976..d5cae8613 100644 --- a/testutil/batch/prepare.go +++ b/testutil/batch/prepare.go @@ -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 } @@ -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 } @@ -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(), diff --git a/testutil/batch/send_txs.go b/testutil/batch/send_txs.go index e1266a3c9..82f53343c 100644 --- a/testutil/batch/send_txs.go +++ b/testutil/batch/send_txs.go @@ -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 } @@ -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 } diff --git a/testutil/batch/tx_check.go b/testutil/batch/tx_check.go index 120eff29c..34536cfe4 100644 --- a/testutil/batch/tx_check.go +++ b/testutil/batch/tx_check.go @@ -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) @@ -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 } diff --git a/testutil/batch/type.go b/testutil/batch/type.go index 6d2218b64..0dc2d7be6 100644 --- a/testutil/batch/type.go +++ b/testutil/batch/type.go @@ -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"` @@ -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", @@ -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)"` diff --git a/testutil/batch/utils.go b/testutil/batch/utils.go index cdd495705..5986bd1d3 100644 --- a/testutil/batch/utils.go +++ b/testutil/batch/utils.go @@ -2,6 +2,7 @@ package batch import ( "math/big" + "reflect" sdkmath "cosmossdk.io/math" @@ -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