cosmos-sdk/tests/cli/simd_test.go
SaReN f92f6c9dd1
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 20:16:17 +00:00

129 lines
3.2 KiB
Go

package cli_test
import (
"fmt"
"github.com/cosmos/cosmos-sdk/std"
"github.com/cosmos/cosmos-sdk/tests/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/stretchr/testify/require"
tmtypes "github.com/tendermint/tendermint/types"
"io/ioutil"
"path/filepath"
"testing"
)
func TestSimdCollectGentxs(t *testing.T) {
t.Parallel()
var customMaxBytes, customMaxGas int64 = 99999999, 1234567
f := cli.NewFixtures(t)
// Initialise temporary directories
gentxDir, err := ioutil.TempDir("", "")
gentxDoc := filepath.Join(gentxDir, "gentx.json")
require.NoError(t, err)
// Reset testing path
f.UnsafeResetAll()
// Initialize keys
f.KeysAdd(cli.KeyFoo)
// Configure json output
f.CLIConfig("output", "json")
// Run init
f.SDInit(cli.KeyFoo)
// Customise genesis.json
genFile := f.GenesisFile()
genDoc, err := tmtypes.GenesisDocFromFile(genFile)
require.NoError(t, err)
genDoc.ConsensusParams.Block.MaxBytes = customMaxBytes
genDoc.ConsensusParams.Block.MaxGas = customMaxGas
genDoc.SaveAs(genFile)
// Add account to genesis.json
f.AddGenesisAccount(f.KeyAddress(cli.KeyFoo), cli.StartCoins)
// Write gentx file
f.GenTx(cli.KeyFoo, fmt.Sprintf("--output-document=%s", gentxDoc))
// Collect gentxs from a custom directory
f.CollectGenTxs(fmt.Sprintf("--gentx-dir=%s", gentxDir))
genDoc, err = tmtypes.GenesisDocFromFile(genFile)
require.NoError(t, err)
require.Equal(t, genDoc.ConsensusParams.Block.MaxBytes, customMaxBytes)
require.Equal(t, genDoc.ConsensusParams.Block.MaxGas, customMaxGas)
f.Cleanup(gentxDir)
}
func TestSimdAddGenesisAccount(t *testing.T) {
t.Parallel()
f := cli.NewFixtures(t)
// Reset testing path
f.UnsafeResetAll()
// Initialize keys
f.KeysDelete(cli.KeyFoo)
f.KeysDelete(cli.KeyBar)
f.KeysDelete(cli.KeyBaz)
f.KeysAdd(cli.KeyFoo)
f.KeysAdd(cli.KeyBar)
f.KeysAdd(cli.KeyBaz)
// Configure json output
f.CLIConfig("output", "json")
// Run init
f.SDInit(cli.KeyFoo)
// Add account to genesis.json
bazCoins := sdk.Coins{
sdk.NewInt64Coin("acoin", 1000000),
sdk.NewInt64Coin("bcoin", 1000000),
}
f.AddGenesisAccount(f.KeyAddress(cli.KeyFoo), cli.StartCoins)
f.AddGenesisAccount(f.KeyAddress(cli.KeyBar), bazCoins)
genesisState := f.GenesisState()
appCodec := std.NewAppCodec(f.Cdc)
accounts := auth.GetGenesisStateFromAppState(appCodec, genesisState).Accounts
balances := bank.GetGenesisStateFromAppState(f.Cdc, genesisState).Balances
balancesSet := make(map[string]sdk.Coins)
for _, b := range balances {
balancesSet[b.GetAddress().String()] = b.Coins
}
require.Equal(t, accounts[0].GetAddress(), f.KeyAddress(cli.KeyFoo))
require.Equal(t, accounts[1].GetAddress(), f.KeyAddress(cli.KeyBar))
require.True(t, balancesSet[accounts[0].GetAddress().String()].IsEqual(cli.StartCoins))
require.True(t, balancesSet[accounts[1].GetAddress().String()].IsEqual(bazCoins))
// Cleanup testing directories
f.Cleanup()
}
func TestValidateGenesis(t *testing.T) {
t.Parallel()
f := cli.InitFixtures(t)
// start simd server
proc := f.SDStart()
defer proc.Stop(false)
f.ValidateGenesis()
// Cleanup testing directories
f.Cleanup()
}