cosmos-sdk/tests/cli/fixtures.go

84 lines
2.0 KiB
Go
Raw Normal View History

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
package cli
2020-04-29 08:52:30 -07:00
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/std"
2020-04-29 08:52:30 -07:00
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/simapp"
)
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
var (
cdc = std.MakeCodec(simapp.ModuleBasics)
)
2020-04-29 08:52:30 -07:00
// Fixtures is used to setup the testing environment
type Fixtures struct {
BuildDir string
RootDir string
SimdBinary string
SimcliBinary string
ChainID string
RPCAddr string
Port string
SimdHome string
SimcliHome string
P2PAddr string
Cdc *codec.Codec
T *testing.T
}
// NewFixtures creates a new instance of Fixtures with many vars set
func NewFixtures(t *testing.T) *Fixtures {
tmpDir, err := ioutil.TempDir("", "sdk_integration_"+t.Name()+"_")
require.NoError(t, err)
servAddr, port, err := server.FreeTCPAddr()
require.NoError(t, err)
p2pAddr, _, err := server.FreeTCPAddr()
require.NoError(t, err)
buildDir := os.Getenv("BUILDDIR")
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
if buildDir == "" {
t.Skip("builddir is empty, skipping")
}
2020-04-29 08:52:30 -07:00
return &Fixtures{
T: t,
BuildDir: buildDir,
RootDir: tmpDir,
SimdBinary: filepath.Join(buildDir, "simd"),
SimcliBinary: filepath.Join(buildDir, "simcli"),
SimdHome: filepath.Join(tmpDir, ".simd"),
SimcliHome: filepath.Join(tmpDir, ".simcli"),
RPCAddr: servAddr,
P2PAddr: p2pAddr,
Cdc: cdc,
Port: port,
}
}
// GenesisFile returns the path of the genesis file
func (f Fixtures) GenesisFile() string {
return filepath.Join(f.SimdHome, "config", "genesis.json")
}
// GenesisFile returns the application's genesis state
func (f Fixtures) GenesisState() simapp.GenesisState {
genDoc, err := tmtypes.GenesisDocFromFile(f.GenesisFile())
require.NoError(f.T, err)
var appState simapp.GenesisState
require.NoError(f.T, f.Cdc.UnmarshalJSON(genDoc.AppState, &appState))
return appState
}