diff --git a/tests/e2e/e2e_exec_test.go b/tests/e2e/e2e_exec_test.go index 327164b478e..8ef684c1c02 100644 --- a/tests/e2e/e2e_exec_test.go +++ b/tests/e2e/e2e_exec_test.go @@ -769,3 +769,29 @@ func (s *IntegrationTestSuite) executeRedeemShares(c *chain, valIdx int, amount, s.executeGaiaTxCommand(ctx, c, gaiaCommand, valIdx, s.defaultExecValidation(c, valIdx)) s.T().Logf("%s successfully executed redeem share tx for %s", delegatorAddr, amount) } + +func (s *IntegrationTestSuite) executeTransferTokenizeShareRecord(c *chain, valIdx int, recordId, owner, newOwner, home, txFees string) { //nolint:unparam + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + s.T().Logf("Executing gaiad tx staking transfer-tokenize-share-record %s", c.id) + + gaiaCommand := []string{ + gaiadBinary, + txCommand, + stakingtypes.ModuleName, + "transfer-tokenize-share-record", + recordId, + newOwner, + fmt.Sprintf("--%s=%s", flags.FlagFrom, owner), + fmt.Sprintf("--%s=%s", flags.FlagChainID, c.id), + fmt.Sprintf("--%s=%s", flags.FlagGasPrices, txFees), + "--keyring-backend=test", + fmt.Sprintf("--%s=%s", flags.FlagHome, home), + "--output=json", + "-y", + } + + s.executeGaiaTxCommand(ctx, c, gaiaCommand, valIdx, s.defaultExecValidation(c, valIdx)) + s.T().Logf("%s successfully executed transfer tokenize share record for %s", owner, recordId) +} diff --git a/tests/e2e/e2e_lsm_test.go b/tests/e2e/e2e_lsm_test.go index 2edb9f1d58c..790eb5f1279 100644 --- a/tests/e2e/e2e_lsm_test.go +++ b/tests/e2e/e2e_lsm_test.go @@ -29,10 +29,13 @@ func (s *IntegrationTestSuite) testLSM() { s.executeValidatorBond(s.chainA, 0, validatorAddressA, validatorAAddr.String(), gaiaHomePath, fees.String()) // Validate validator bond successful + selfBondedShares := sdk.ZeroDec() s.Require().Eventually( func() bool { res, err := queryDelegation(chainEndpoint, validatorAddressA, validatorAAddr.String()) - isValidatorBond := res.GetDelegationResponse().GetDelegation().ValidatorBond + delegation := res.GetDelegationResponse().GetDelegation() + selfBondedShares = delegation.Shares + isValidatorBond := delegation.ValidatorBond s.Require().NoError(err) return isValidatorBond == true @@ -79,7 +82,8 @@ func (s *IntegrationTestSuite) testLSM() { ) // Validate balance increased - shareDenom := fmt.Sprintf("%s/%s", strings.ToLower(validatorAddressA), strconv.Itoa(1)) + recordId := int(1) + shareDenom := fmt.Sprintf("%s/%s", strings.ToLower(validatorAddressA), strconv.Itoa(recordId)) s.Require().Eventually( func() bool { res, err := getSpecificBalance(chainEndpoint, delegatorAddress, shareDenom) @@ -112,7 +116,37 @@ func (s *IntegrationTestSuite) testLSM() { 5*time.Second, ) - // TODO: TransferTokenizeShareRecord (transfer reward ownership) + // transfer reward ownership + s.executeTransferTokenizeShareRecord(s.chainA, 0, strconv.Itoa(recordId), delegatorAddress, validatorAAddr.String(), gaiaHomePath, standardFees.String()) + + // Validate ownership transferred correctly + s.Require().Eventually( + func() bool { + record, err := queryTokenizeShareRecordById(chainEndpoint, recordId) + s.Require().NoError(err) + return record.Owner == validatorAAddr.String() + }, + time.Minute, + 5*time.Second, + ) + // TODO: IBC transfer LSM token - // TODO: Redeem tokens for shares + + // Redeem tokens for shares + s.executeRedeemShares(s.chainA, 0, sendAmount.String(), validatorAAddr.String(), gaiaHomePath, fees.String()) + + // check redeem success + s.Require().Eventually( + func() bool { + delegationRes, err := queryDelegation(chainEndpoint, validatorAddressA, validatorAAddr.String()) + delegation := delegationRes.GetDelegationResponse().GetDelegation() + s.Require().NoError(err) + + balanceRes, err := getSpecificBalance(chainEndpoint, delegatorAddress, shareDenom) + s.Require().NoError(err) + return balanceRes.Amount.IsZero() && delegation.Shares.GT(selfBondedShares) + }, + 20*time.Second, + 5*time.Second, + ) } diff --git a/tests/e2e/query.go b/tests/e2e/query.go index ccd30a96c81..71fa198c5f8 100644 --- a/tests/e2e/query.go +++ b/tests/e2e/query.go @@ -287,3 +287,17 @@ func queryAllEvidence(endpoint string) (evidencetypes.QueryAllEvidenceResponse, } return res, nil } + +func queryTokenizeShareRecordById(endpoint string, recordId int) (stakingtypes.TokenizeShareRecord, error) { + var res stakingtypes.QueryTokenizeShareRecordByIdResponse + + body, err := httpGet(fmt.Sprintf("%s/cosmos/staking/v1beta1/tokenize-share-record-by-id/%d", endpoint, recordId)) + if err != nil { + return stakingtypes.TokenizeShareRecord{}, fmt.Errorf("failed to execute HTTP request: %w", err) + } + + if err := cdc.UnmarshalJSON(body, &res); err != nil { + return stakingtypes.TokenizeShareRecord{}, err + } + return res.Record, nil +}