cosmos-sdk/x/distribution/client/testutil/helpers.go

104 lines
4.8 KiB
Go
Raw Normal View History

package testutil
Add CLI tests for simd, distribution (#6095) * Added cli integration base setup * Added cmd to simapp * Fixed ci-lint issues * Fixed ci-lint issues * Addressed changes in Makefile * Updated simd to latest * Removed testnet and replay commands * Modified tx command for simcli * Did code cleanup * Removed duplication in Makefile * Refactored cli_test * Added build-sim to Makefile * Added test-cli to circleci * Added tests for staking txns * Addressed format issues * refctored tests code * Added tests for send, staking * Removed test_hepers file * Moved test_cover to contrib * Added codec in fixtures * Migrated tests to respective modules * Exported helper methods * Moved helpers to bank * Added codec to fixtures * Migrated tests to modules * Removed auth helpers from staking * Did minor code cleanup * Added test-cli to Makefile * Updated github actions * Did code refactor * Fixed github actions for cli-test * Added tests for recover keys and fee deduction * Did minor code cleanup * Added build flag to cli_tests * Moved cli_test to tests * Modified path in Makefile * Updated codec std in fixtures * Added doc for cli tests * Remove ibc genesis validation * Fix issue number * Added missing imports * Add tests for distribution and simd * Modified naming for test functions * Added test for withdraw rewards * Modified test function names * Fixed import format * Migrated helpers to package cli * Fixed github test actions * Fixed test coverage in actions * Added build sim to actions * Apply Alessio patch for tests * Removed unused imports * Added init for go tests * try fix tests * goimports what wasn't goimports'd * try fix ci * add relevant tags to integration tests * run integration tests separately * use go build -o flag and let compiler gemerate the binary with the right extension for the HOST platform rename cli-test to test-integration * update ci * rename Co-authored-by: atheesh <atheesh1> Co-authored-by: kaustubhkapatral <54210167+kaustubhkapatral@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2020-05-01 13:16:17 -07:00
import (
"fmt"
"github.com/stretchr/testify/require"
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/tests"
"github.com/cosmos/cosmos-sdk/tests/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
Add CLI tests for simd, distribution (#6095) * Added cli integration base setup * Added cmd to simapp * Fixed ci-lint issues * Fixed ci-lint issues * Addressed changes in Makefile * Updated simd to latest * Removed testnet and replay commands * Modified tx command for simcli * Did code cleanup * Removed duplication in Makefile * Refactored cli_test * Added build-sim to Makefile * Added test-cli to circleci * Added tests for staking txns * Addressed format issues * refctored tests code * Added tests for send, staking * Removed test_hepers file * Moved test_cover to contrib * Added codec in fixtures * Migrated tests to respective modules * Exported helper methods * Moved helpers to bank * Added codec to fixtures * Migrated tests to modules * Removed auth helpers from staking * Did minor code cleanup * Added test-cli to Makefile * Updated github actions * Did code refactor * Fixed github actions for cli-test * Added tests for recover keys and fee deduction * Did minor code cleanup * Added build flag to cli_tests * Moved cli_test to tests * Modified path in Makefile * Updated codec std in fixtures * Added doc for cli tests * Remove ibc genesis validation * Fix issue number * Added missing imports * Add tests for distribution and simd * Modified naming for test functions * Added test for withdraw rewards * Modified test function names * Fixed import format * Migrated helpers to package cli * Fixed github test actions * Fixed test coverage in actions * Added build sim to actions * Apply Alessio patch for tests * Removed unused imports * Added init for go tests * try fix tests * goimports what wasn't goimports'd * try fix ci * add relevant tags to integration tests * run integration tests separately * use go build -o flag and let compiler gemerate the binary with the right extension for the HOST platform rename cli-test to test-integration * update ci * rename Co-authored-by: atheesh <atheesh1> Co-authored-by: kaustubhkapatral <54210167+kaustubhkapatral@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2020-05-01 13:16:17 -07:00
)
// TxWithdrawRewards raises a txn to withdraw rewards
Add CLI tests for simd, distribution (#6095) * Added cli integration base setup * Added cmd to simapp * Fixed ci-lint issues * Fixed ci-lint issues * Addressed changes in Makefile * Updated simd to latest * Removed testnet and replay commands * Modified tx command for simcli * Did code cleanup * Removed duplication in Makefile * Refactored cli_test * Added build-sim to Makefile * Added test-cli to circleci * Added tests for staking txns * Addressed format issues * refctored tests code * Added tests for send, staking * Removed test_hepers file * Moved test_cover to contrib * Added codec in fixtures * Migrated tests to respective modules * Exported helper methods * Moved helpers to bank * Added codec to fixtures * Migrated tests to modules * Removed auth helpers from staking * Did minor code cleanup * Added test-cli to Makefile * Updated github actions * Did code refactor * Fixed github actions for cli-test * Added tests for recover keys and fee deduction * Did minor code cleanup * Added build flag to cli_tests * Moved cli_test to tests * Modified path in Makefile * Updated codec std in fixtures * Added doc for cli tests * Remove ibc genesis validation * Fix issue number * Added missing imports * Add tests for distribution and simd * Modified naming for test functions * Added test for withdraw rewards * Modified test function names * Fixed import format * Migrated helpers to package cli * Fixed github test actions * Fixed test coverage in actions * Added build sim to actions * Apply Alessio patch for tests * Removed unused imports * Added init for go tests * try fix tests * goimports what wasn't goimports'd * try fix ci * add relevant tags to integration tests * run integration tests separately * use go build -o flag and let compiler gemerate the binary with the right extension for the HOST platform rename cli-test to test-integration * update ci * rename Co-authored-by: atheesh <atheesh1> Co-authored-by: kaustubhkapatral <54210167+kaustubhkapatral@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2020-05-01 13:16:17 -07:00
func TxWithdrawRewards(f *cli.Fixtures, valAddr sdk.ValAddress, from string, flags ...string) bool {
cmd := fmt.Sprintf("%s tx distribution withdraw-rewards %s %v --keyring-backend=test --from=%s", f.SimdBinary, valAddr, f.Flags(), from)
Add CLI tests for simd, distribution (#6095) * Added cli integration base setup * Added cmd to simapp * Fixed ci-lint issues * Fixed ci-lint issues * Addressed changes in Makefile * Updated simd to latest * Removed testnet and replay commands * Modified tx command for simcli * Did code cleanup * Removed duplication in Makefile * Refactored cli_test * Added build-sim to Makefile * Added test-cli to circleci * Added tests for staking txns * Addressed format issues * refctored tests code * Added tests for send, staking * Removed test_hepers file * Moved test_cover to contrib * Added codec in fixtures * Migrated tests to respective modules * Exported helper methods * Moved helpers to bank * Added codec to fixtures * Migrated tests to modules * Removed auth helpers from staking * Did minor code cleanup * Added test-cli to Makefile * Updated github actions * Did code refactor * Fixed github actions for cli-test * Added tests for recover keys and fee deduction * Did minor code cleanup * Added build flag to cli_tests * Moved cli_test to tests * Modified path in Makefile * Updated codec std in fixtures * Added doc for cli tests * Remove ibc genesis validation * Fix issue number * Added missing imports * Add tests for distribution and simd * Modified naming for test functions * Added test for withdraw rewards * Modified test function names * Fixed import format * Migrated helpers to package cli * Fixed github test actions * Fixed test coverage in actions * Added build sim to actions * Apply Alessio patch for tests * Removed unused imports * Added init for go tests * try fix tests * goimports what wasn't goimports'd * try fix ci * add relevant tags to integration tests * run integration tests separately * use go build -o flag and let compiler gemerate the binary with the right extension for the HOST platform rename cli-test to test-integration * update ci * rename Co-authored-by: atheesh <atheesh1> Co-authored-by: kaustubhkapatral <54210167+kaustubhkapatral@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2020-05-01 13:16:17 -07:00
return cli.ExecuteWrite(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxSetWithdrawAddress helps to set the withdraw address for rewards associated with a delegator address
func TxSetWithdrawAddress(f *cli.Fixtures, from, withDrawAddr string, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx distribution set-withdraw-addr %s --from %s %v --keyring-backend=test", f.SimdBinary, withDrawAddr, from, f.Flags())
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxWithdrawAllRewards raises a txn to withdraw all rewards of a delegator address
func TxWithdrawAllRewards(f *cli.Fixtures, from string, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx distribution withdraw-all-rewards %v --keyring-backend=test --from=%s", f.SimdBinary, f.Flags(), from)
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
// TxFundCommunityPool Funds the community pool with the specified amount
func TxFundCommunityPool(f *cli.Fixtures, from string, amount sdk.Coin, flags ...string) (bool, string, string) {
cmd := fmt.Sprintf("%s tx distribution fund-community-pool %v %v --keyring-backend=test --from=%s", f.SimdBinary, amount, f.Flags(), from)
return cli.ExecuteWriteRetStdStreams(f.T, cli.AddFlags(cmd, flags), clientkeys.DefaultKeyPass)
}
Add CLI tests for simd, distribution (#6095) * Added cli integration base setup * Added cmd to simapp * Fixed ci-lint issues * Fixed ci-lint issues * Addressed changes in Makefile * Updated simd to latest * Removed testnet and replay commands * Modified tx command for simcli * Did code cleanup * Removed duplication in Makefile * Refactored cli_test * Added build-sim to Makefile * Added test-cli to circleci * Added tests for staking txns * Addressed format issues * refctored tests code * Added tests for send, staking * Removed test_hepers file * Moved test_cover to contrib * Added codec in fixtures * Migrated tests to respective modules * Exported helper methods * Moved helpers to bank * Added codec to fixtures * Migrated tests to modules * Removed auth helpers from staking * Did minor code cleanup * Added test-cli to Makefile * Updated github actions * Did code refactor * Fixed github actions for cli-test * Added tests for recover keys and fee deduction * Did minor code cleanup * Added build flag to cli_tests * Moved cli_test to tests * Modified path in Makefile * Updated codec std in fixtures * Added doc for cli tests * Remove ibc genesis validation * Fix issue number * Added missing imports * Add tests for distribution and simd * Modified naming for test functions * Added test for withdraw rewards * Modified test function names * Fixed import format * Migrated helpers to package cli * Fixed github test actions * Fixed test coverage in actions * Added build sim to actions * Apply Alessio patch for tests * Removed unused imports * Added init for go tests * try fix tests * goimports what wasn't goimports'd * try fix ci * add relevant tags to integration tests * run integration tests separately * use go build -o flag and let compiler gemerate the binary with the right extension for the HOST platform rename cli-test to test-integration * update ci * rename Co-authored-by: atheesh <atheesh1> Co-authored-by: kaustubhkapatral <54210167+kaustubhkapatral@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2020-05-01 13:16:17 -07:00
// QueryRewards returns the rewards of a delegator
func QueryRewards(f *cli.Fixtures, delAddr sdk.AccAddress, flags ...string) types.QueryDelegatorTotalRewardsResponse {
cmd := fmt.Sprintf("%s query distribution rewards %s %s", f.SimdBinary, delAddr, f.Flags())
Add CLI tests for simd, distribution (#6095) * Added cli integration base setup * Added cmd to simapp * Fixed ci-lint issues * Fixed ci-lint issues * Addressed changes in Makefile * Updated simd to latest * Removed testnet and replay commands * Modified tx command for simcli * Did code cleanup * Removed duplication in Makefile * Refactored cli_test * Added build-sim to Makefile * Added test-cli to circleci * Added tests for staking txns * Addressed format issues * refctored tests code * Added tests for send, staking * Removed test_hepers file * Moved test_cover to contrib * Added codec in fixtures * Migrated tests to respective modules * Exported helper methods * Moved helpers to bank * Added codec to fixtures * Migrated tests to modules * Removed auth helpers from staking * Did minor code cleanup * Added test-cli to Makefile * Updated github actions * Did code refactor * Fixed github actions for cli-test * Added tests for recover keys and fee deduction * Did minor code cleanup * Added build flag to cli_tests * Moved cli_test to tests * Modified path in Makefile * Updated codec std in fixtures * Added doc for cli tests * Remove ibc genesis validation * Fix issue number * Added missing imports * Add tests for distribution and simd * Modified naming for test functions * Added test for withdraw rewards * Modified test function names * Fixed import format * Migrated helpers to package cli * Fixed github test actions * Fixed test coverage in actions * Added build sim to actions * Apply Alessio patch for tests * Removed unused imports * Added init for go tests * try fix tests * goimports what wasn't goimports'd * try fix ci * add relevant tags to integration tests * run integration tests separately * use go build -o flag and let compiler gemerate the binary with the right extension for the HOST platform rename cli-test to test-integration * update ci * rename Co-authored-by: atheesh <atheesh1> Co-authored-by: kaustubhkapatral <54210167+kaustubhkapatral@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2020-05-01 13:16:17 -07:00
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)
var rewards types.QueryDelegatorTotalRewardsResponse
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(res), &rewards))
Add CLI tests for simd, distribution (#6095) * Added cli integration base setup * Added cmd to simapp * Fixed ci-lint issues * Fixed ci-lint issues * Addressed changes in Makefile * Updated simd to latest * Removed testnet and replay commands * Modified tx command for simcli * Did code cleanup * Removed duplication in Makefile * Refactored cli_test * Added build-sim to Makefile * Added test-cli to circleci * Added tests for staking txns * Addressed format issues * refctored tests code * Added tests for send, staking * Removed test_hepers file * Moved test_cover to contrib * Added codec in fixtures * Migrated tests to respective modules * Exported helper methods * Moved helpers to bank * Added codec to fixtures * Migrated tests to modules * Removed auth helpers from staking * Did minor code cleanup * Added test-cli to Makefile * Updated github actions * Did code refactor * Fixed github actions for cli-test * Added tests for recover keys and fee deduction * Did minor code cleanup * Added build flag to cli_tests * Moved cli_test to tests * Modified path in Makefile * Updated codec std in fixtures * Added doc for cli tests * Remove ibc genesis validation * Fix issue number * Added missing imports * Add tests for distribution and simd * Modified naming for test functions * Added test for withdraw rewards * Modified test function names * Fixed import format * Migrated helpers to package cli * Fixed github test actions * Fixed test coverage in actions * Added build sim to actions * Apply Alessio patch for tests * Removed unused imports * Added init for go tests * try fix tests * goimports what wasn't goimports'd * try fix ci * add relevant tags to integration tests * run integration tests separately * use go build -o flag and let compiler gemerate the binary with the right extension for the HOST platform rename cli-test to test-integration * update ci * rename Co-authored-by: atheesh <atheesh1> Co-authored-by: kaustubhkapatral <54210167+kaustubhkapatral@users.noreply.github.com> Co-authored-by: Aaron Craelius <aaron@regen.network> Co-authored-by: anilCSE <anil@vitwit.com> Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2020-05-01 13:16:17 -07:00
return rewards
}
// QueryValidatorOutstandingRewards distribution outstanding (un-withdrawn) rewards
func QueryValidatorOutstandingRewards(f *cli.Fixtures, valAddr string) types.ValidatorOutstandingRewards {
cmd := fmt.Sprintf("%s query distribution validator-outstanding-rewards %s %v", f.SimdBinary, valAddr, f.Flags())
res, errStr := tests.ExecuteT(f.T, cmd, "")
require.Empty(f.T, errStr)
var outstandingRewards types.ValidatorOutstandingRewards
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(res), &outstandingRewards))
return outstandingRewards
}
// QueryParameters is simcli query distribution parameters
func QueryParameters(f *cli.Fixtures, flags ...string) types.Params {
cmd := fmt.Sprintf("%s query distribution params %v", f.SimdBinary, f.Flags())
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
require.Empty(f.T, errStr)
var params types.Params
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &params))
return params
}
// QueryCommission returns validator commission rewards from delegators to that validator.
func QueryCommission(f *cli.Fixtures, valAddr string, flags ...string) types.ValidatorAccumulatedCommission {
cmd := fmt.Sprintf("%s query distribution commission %s %v", f.SimdBinary, valAddr, f.Flags())
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
require.Empty(f.T, errStr)
var commission types.ValidatorAccumulatedCommission
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &commission))
return commission
}
// QuerySlashes returns all slashes of a validator for a given block range.
func QuerySlashes(f *cli.Fixtures, valAddr string, flags ...string) []types.ValidatorSlashEvent {
cmd := fmt.Sprintf("%s query distribution slashes %s 0 5 %v ", f.SimdBinary, valAddr, f.Flags())
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
require.Empty(f.T, errStr)
var slashes []types.ValidatorSlashEvent
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &slashes))
return slashes
}
// QueryCommunityPool returns the amount of coins in the community pool
func QueryCommunityPool(f *cli.Fixtures, flags ...string) sdk.DecCoins {
cmd := fmt.Sprintf("%s query distribution community-pool %v ", f.SimdBinary, f.Flags())
out, errStr := tests.ExecuteT(f.T, cli.AddFlags(cmd, flags), "")
require.Empty(f.T, errStr)
var amount sdk.DecCoins
require.NoError(f.T, f.Cdc.UnmarshalJSON([]byte(out), &amount))
return amount
}