Skip to content

Commit

Permalink
Add test for transfer reward ownership, and redeem shares
Browse files Browse the repository at this point in the history
  • Loading branch information
jstr1121 committed Jul 14, 2023
1 parent e0deb2f commit ef4ed7d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
26 changes: 26 additions & 0 deletions tests/e2e/e2e_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 773 in tests/e2e/e2e_exec_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: method parameter recordId should be recordID (revive)

Check failure on line 773 in tests/e2e/e2e_exec_test.go

View workflow job for this annotation

GitHub Actions / Analyze

var-naming: method parameter recordId should be recordID (revive)
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)
}
42 changes: 38 additions & 4 deletions tests/e2e/e2e_lsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Check failure on line 85 in tests/e2e/e2e_lsm_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: var recordId should be recordID (revive)

Check failure on line 85 in tests/e2e/e2e_lsm_test.go

View workflow job for this annotation

GitHub Actions / Analyze

var-naming: var recordId should be recordID (revive)
shareDenom := fmt.Sprintf("%s/%s", strings.ToLower(validatorAddressA), strconv.Itoa(recordId))
s.Require().Eventually(
func() bool {
res, err := getSpecificBalance(chainEndpoint, delegatorAddress, shareDenom)
Expand Down Expand Up @@ -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,
)
}
14 changes: 14 additions & 0 deletions tests/e2e/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,17 @@ func queryAllEvidence(endpoint string) (evidencetypes.QueryAllEvidenceResponse,
}
return res, nil
}

func queryTokenizeShareRecordById(endpoint string, recordId int) (stakingtypes.TokenizeShareRecord, error) {

Check failure on line 291 in tests/e2e/query.go

View workflow job for this annotation

GitHub Actions / golangci-lint

var-naming: func queryTokenizeShareRecordById should be queryTokenizeShareRecordByID (revive)

Check failure on line 291 in tests/e2e/query.go

View workflow job for this annotation

GitHub Actions / Analyze

var-naming: func queryTokenizeShareRecordById should be queryTokenizeShareRecordByID (revive)
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
}

0 comments on commit ef4ed7d

Please sign in to comment.