Skip to content

Commit

Permalink
fix test err
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Sep 9, 2024
1 parent d311ff9 commit dcd4ed3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
72 changes: 45 additions & 27 deletions precompiles/avs/avs_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package avs_test

import (
sdkmath "cosmossdk.io/math"
assetstype "github.com/ExocoreNetwork/exocore/x/assets/types"
operatorKeeper "github.com/ExocoreNetwork/exocore/x/operator/keeper"
"math/big"
"time"

"github.com/ExocoreNetwork/exocore/app"
"github.com/ExocoreNetwork/exocore/precompiles/avs"
"github.com/ExocoreNetwork/exocore/x/avs/types"
epochstypes "github.com/ExocoreNetwork/exocore/x/epochs/types"
operatortypes "github.com/ExocoreNetwork/exocore/x/operator/types"
"github.com/cometbft/cometbft/libs/rand"
Expand Down Expand Up @@ -641,33 +644,48 @@ func (suite *AVSManagerPrecompileSuite) TestDeregisterOperatorFromAVS() {
// TestRun tests the precompiles Run method reg avstask.
func (suite *AVSManagerPrecompileSuite) TestRunRegTaskInfo() {
taskAddr := utiltx.GenerateAddress()
registerAVS := func() {
avsName := "avsTest"
avsOwnerAddress := []string{
sdk.AccAddress(suite.Address.Bytes()).String(),
"exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkjr",
"exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkj2",
setUp := func() {
suite.prepare()
// register the new token
usdcAddr := common.HexToAddress("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48")
usdcClientChainAsset := assetstype.AssetInfo{
Name: "USD coin",
Symbol: "USDC",
Address: usdcAddr.String(),
Decimals: 6,
TotalSupply: sdkmath.NewInt(1e18),
LayerZeroChainID: 101,
MetaInfo: "USDC",
}
assetID := []string{"11", "22", "33"}
avsInfo := &types.AVSInfo{
Name: avsName,
AvsAddress: utiltx.GenerateAddress().String(),
SlashAddr: utiltx.GenerateAddress().String(),
AvsOwnerAddress: avsOwnerAddress,
AssetIDs: assetID,
AvsUnbondingPeriod: 7,
MinSelfDelegation: 10,
EpochIdentifier: epochstypes.DayEpochID,
StartingEpoch: 1,
MinOptInOperators: 100,
MinTotalStakeAmount: 1000,
AvsSlash: sdk.MustNewDecFromStr("0.001"),
AvsReward: sdk.MustNewDecFromStr("0.002"),
TaskAddr: taskAddr.String(),
}

err := suite.App.AVSManagerKeeper.SetAVSInfo(suite.Ctx, avsInfo)
err := suite.App.AssetsKeeper.SetStakingAssetInfo(
suite.Ctx,
&assetstype.StakingAssetInfo{
AssetBasicInfo: &usdcClientChainAsset,
StakingTotalAmount: sdkmath.NewInt(0),
},
)
suite.NoError(err)
// register the new AVS
suite.prepareAvs([]string{"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_0x65", "0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"}, taskAddr.String())
// opt in
err = suite.App.OperatorKeeper.OptIn(suite.Ctx, suite.operatorAddr, suite.avsAddr)
suite.NoError(err)
usdtPrice, err := suite.App.OperatorKeeper.OracleInterface().GetSpecifiedAssetsPrice(suite.Ctx, suite.assetID)
suite.NoError(err)
operatorKeeper.CalculateUSDValue(suite.delegationAmount, usdtPrice.Value, suite.assetDecimal, usdtPrice.Decimal)
// deposit and delegate another asset to the operator
suite.NoError(err)
suite.prepareDeposit(usdcAddr, sdkmath.NewInt(1e8))
usdcPrice, err := suite.App.OperatorKeeper.OracleInterface().GetSpecifiedAssetsPrice(suite.Ctx, suite.assetID)
suite.NoError(err)
delegatedAmount := sdkmath.NewIntWithDecimal(8, 7)
suite.prepareDelegation(true, usdcAddr, delegatedAmount)

// updating the new voting power
operatorKeeper.CalculateUSDValue(suite.delegationAmount, usdcPrice.Value, suite.assetDecimal, usdcPrice.Decimal)
suite.CommitAfter(time.Hour*1 + time.Nanosecond)
suite.CommitAfter(time.Hour*1 + time.Nanosecond)
suite.CommitAfter(time.Hour*1 + time.Nanosecond)
}
commonMalleate := func() (common.Address, []byte) {
input, err := suite.precompile.Pack(
Expand Down Expand Up @@ -697,7 +715,7 @@ func (suite *AVSManagerPrecompileSuite) TestRunRegTaskInfo() {
name: "pass - avstask via pre-compiles",
malleate: func() (common.Address, []byte) {
suite.Require().NoError(err)
registerAVS()
setUp()
return commonMalleate()
},
returnBytes: successRet,
Expand Down
5 changes: 3 additions & 2 deletions precompiles/avs/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package avs_test

import (
"fmt"
utiltx "github.com/ExocoreNetwork/exocore/testutil/tx"
"math/big"
"time"

Expand Down Expand Up @@ -161,7 +162,7 @@ func (suite *AVSManagerPrecompileSuite) TestAVSUSDValue() {
)
suite.NoError(err)
// register the new AVS
suite.prepareAvs([]string{"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_0x65", "0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"})
suite.prepareAvs([]string{"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_0x65", "0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"}, utiltx.GenerateAddress().String())
// opt in
err = suite.App.OperatorKeeper.OptIn(suite.Ctx, suite.operatorAddr, suite.avsAddr)
suite.NoError(err)
Expand Down Expand Up @@ -250,7 +251,7 @@ func (suite *AVSManagerPrecompileSuite) TestGetOperatorOptedUSDValue() {
)
suite.NoError(err)
// register the new AVS
suite.prepareAvs([]string{"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_0x65", "0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"})
suite.prepareAvs([]string{"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_0x65", "0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"}, utiltx.GenerateAddress().String())
// opt in
err = suite.App.OperatorKeeper.OptIn(suite.Ctx, suite.operatorAddr, suite.avsAddr)
suite.NoError(err)
Expand Down
16 changes: 12 additions & 4 deletions precompiles/avs/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package avs_test

import (
"fmt"
utiltx "github.com/ExocoreNetwork/exocore/testutil/tx"
"strings"
"time"

Expand Down Expand Up @@ -93,12 +94,19 @@ func (suite *AVSManagerPrecompileSuite) prepare() {
suite.prepareDelegation(true, usdtAddress, delegationAmount)
}

func (suite *AVSManagerPrecompileSuite) prepareAvs(assetIDs []string) {
func (suite *AVSManagerPrecompileSuite) prepareAvs(assetIDs []string, task string) {
avsOwnerAddress := []string{
sdk.AccAddress(suite.Address.Bytes()).String(),
"exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkjr",
"exo13h6xg79g82e2g2vhjwg7j4r2z2hlncelwutkj2",
}
err := suite.App.AVSManagerKeeper.UpdateAVSInfo(suite.Ctx, &avstypes.AVSRegisterOrDeregisterParams{
Action: avskeeper.RegisterAction,
EpochIdentifier: epochstypes.HourEpochID,
AvsAddress: suite.avsAddr,
AssetID: assetIDs,
TaskAddr: task,
AvsOwnerAddress: avsOwnerAddress,
})
suite.NoError(err)
}
Expand Down Expand Up @@ -133,7 +141,7 @@ func (suite *AVSManagerPrecompileSuite) CheckState(expectedState *StateForCheck)

func (suite *AVSManagerPrecompileSuite) TestOptIn() {
suite.prepare()
suite.prepareAvs([]string{"0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"})
suite.prepareAvs([]string{"0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"}, utiltx.GenerateAddress().String())
err := suite.App.OperatorKeeper.OptIn(suite.Ctx, suite.operatorAddr, suite.avsAddr)
suite.NoError(err)
// check if the related state is correct
Expand Down Expand Up @@ -161,7 +169,7 @@ func (suite *AVSManagerPrecompileSuite) TestOptIn() {

func (suite *AVSManagerPrecompileSuite) TestOptInList() {
suite.prepare()
suite.prepareAvs([]string{"0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"})
suite.prepareAvs([]string{"0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"}, utiltx.GenerateAddress().String())
err := suite.App.OperatorKeeper.OptIn(suite.Ctx, suite.operatorAddr, suite.avsAddr)
suite.NoError(err)
// check if the related state is correct
Expand All @@ -177,7 +185,7 @@ func (suite *AVSManagerPrecompileSuite) TestOptInList() {

func (suite *AVSManagerPrecompileSuite) TestOptOut() {
suite.prepare()
suite.prepareAvs([]string{"0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"})
suite.prepareAvs([]string{"0xdac17f958d2ee523a2206206994597c13d831ec7_0x65"}, utiltx.GenerateAddress().String())
err := suite.App.OperatorKeeper.OptOut(suite.Ctx, suite.operatorAddr, suite.avsAddr)
suite.EqualError(err, operatorTypes.ErrNotOptedIn.Error())

Expand Down
2 changes: 1 addition & 1 deletion x/avs/keeper/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (k *Keeper) GetTaskInfo(ctx sdk.Context, taskID, taskContractAddress string
value := store.Get(infoKey)
if value == nil {
return nil, errorsmod.Wrap(types.ErrNoKeyInTheStore,
fmt.Sprintf("GetTaskInfo: key is %s", taskContractAddress))
fmt.Sprintf("GetTaskInfo: key not found for task ID %s at contract address %s", taskID, taskContractAddress))
}

ret := types.TaskInfo{}
Expand Down
2 changes: 1 addition & 1 deletion x/avs/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
)
ErrUnregisterNonExistent = errorsmod.Register(
ModuleName, 4,
"Error: No available avs to DeRegisterAction",
"Error: No available avs ",
)

ErrInvalidAction = errorsmod.Register(
Expand Down

0 comments on commit dcd4ed3

Please sign in to comment.