Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI tests for simd, distribution #6095

Merged
merged 88 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
014caf8
Added cli integration base setup
sahith-narahari Apr 14, 2020
a42c097
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 14, 2020
df53367
Added cmd to simapp
sahith-narahari Apr 15, 2020
c2e22b9
Fixed ci-lint issues
sahith-narahari Apr 15, 2020
13b5531
Fixed ci-lint issues
sahith-narahari Apr 15, 2020
858e744
Addressed changes in Makefile
sahith-narahari Apr 16, 2020
0755f09
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 16, 2020
0ae1966
Updated simd to latest
sahith-narahari Apr 16, 2020
6f362fd
Removed testnet and replay commands
sahith-narahari Apr 17, 2020
5136a91
Modified tx command for simcli
sahith-narahari Apr 17, 2020
295b023
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 17, 2020
df2424a
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 17, 2020
da5b8e3
Did code cleanup
sahith-narahari Apr 17, 2020
6e82b44
Merge branch 'sahith/add-cli-tests' of github.com:regen-network/cosmo…
sahith-narahari Apr 18, 2020
0ef94f2
Removed duplication in Makefile
sahith-narahari Apr 18, 2020
6670f90
Refactored cli_test
sahith-narahari Apr 20, 2020
e130c40
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 20, 2020
bc88c76
Added build-sim to Makefile
sahith-narahari Apr 20, 2020
baa4b60
Added test-cli to circleci
sahith-narahari Apr 20, 2020
828092c
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 20, 2020
85fae47
Added tests for staking txns
Apr 21, 2020
5d33cbd
Addressed format issues
sahith-narahari Apr 21, 2020
349e09d
Merge branch 'sahith/add-staking-tests' of github.com:regen-network/c…
sahith-narahari Apr 21, 2020
61b6692
refctored tests code
Apr 21, 2020
0258675
Added tests for send, staking
sahith-narahari Apr 21, 2020
8815250
Merge remote-tracking branch 'origin/atheesh/cli-test-send' into athe…
sahith-narahari Apr 21, 2020
1b9c2ec
Removed test_hepers file
sahith-narahari Apr 21, 2020
3101ed3
Moved test_cover to contrib
sahith-narahari Apr 21, 2020
09efc33
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 21, 2020
93f1b09
Added codec in fixtures
Apr 22, 2020
cf27dff
Merge pull request #32 from vitwit/atheesh/cli-test-send
kaustubhkapatral Apr 22, 2020
d31c20d
Migrated tests to respective modules
sahith-narahari Apr 22, 2020
c083a83
Exported helper methods
sahith-narahari Apr 23, 2020
4f03138
Merge branch 'sahith/add-base-setup' of github.com:regen-network/cosm…
sahith-narahari Apr 23, 2020
82c0abc
Moved helpers to bank
sahith-narahari Apr 23, 2020
e67c965
Added codec to fixtures
sahith-narahari Apr 23, 2020
71365b7
Migrated tests to modules
sahith-narahari Apr 23, 2020
878bf70
Removed auth helpers from staking
sahith-narahari Apr 23, 2020
b272b89
Did minor code cleanup
sahith-narahari Apr 23, 2020
c94c654
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 23, 2020
b3335b4
Added test-cli to Makefile
sahith-narahari Apr 23, 2020
6f79058
Merge pull request #33 from regen-network/sahith/add-staking-tests
sahith-narahari Apr 24, 2020
2fb801c
Updated github actions
sahith-narahari Apr 24, 2020
b867814
Merge branch 'sahith/add-base-setup' of github.com:regen-network/cosm…
sahith-narahari Apr 24, 2020
f41876b
Did code refactor
sahith-narahari Apr 24, 2020
8237441
Fixed github actions for cli-test
sahith-narahari Apr 24, 2020
7197e7d
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 24, 2020
2600b5d
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 27, 2020
107091e
Added tests for recover keys and fee deduction
sahith-narahari Apr 27, 2020
044d318
Did minor code cleanup
sahith-narahari Apr 27, 2020
6e90919
Added build flag to cli_tests
sahith-narahari Apr 27, 2020
5fc398c
Moved cli_test to tests
sahith-narahari Apr 27, 2020
f351b47
Merge branch 'master' into sahith/add-base-setup
aaronc Apr 28, 2020
e400f11
Modified path in Makefile
sahith-narahari Apr 28, 2020
53e8e9c
Merge branch 'sahith/add-base-setup' of github.com:regen-network/cosm…
sahith-narahari Apr 28, 2020
e3913ae
Updated codec std in fixtures
sahith-narahari Apr 28, 2020
8454ecc
Added doc for cli tests
sahith-narahari Apr 28, 2020
0b167c6
Remove ibc genesis validation
anilcse Apr 28, 2020
55b8d0d
Fix issue number
anilcse Apr 28, 2020
446b283
Merge branch 'sahith/add-base-setup' of github.com:regen-network/cosm…
sahith-narahari Apr 29, 2020
01c14f7
Added missing imports
sahith-narahari Apr 29, 2020
664ed28
Add tests for distribution and simd
sahith-narahari Apr 29, 2020
4899346
Modified naming for test functions
sahith-narahari Apr 29, 2020
cb1afad
Merge branch 'sahith/add-fee-tests' of github.com:regen-network/cosmo…
sahith-narahari Apr 29, 2020
d61687f
Added test for withdraw rewards
sahith-narahari Apr 29, 2020
7c3d6f5
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 29, 2020
2c6bdde
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 29, 2020
fe17591
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 29, 2020
1a15454
Modified test function names
sahith-narahari Apr 29, 2020
b3427f7
Fixed import format
sahith-narahari Apr 29, 2020
a659395
Migrated helpers to package cli
sahith-narahari Apr 30, 2020
51d7db3
Fixed github test actions
sahith-narahari Apr 30, 2020
dde5ddf
Fixed test coverage in actions
sahith-narahari Apr 30, 2020
c805470
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari Apr 30, 2020
119a097
Added build sim to actions
sahith-narahari Apr 30, 2020
97fc16d
Apply Alessio patch for tests
sahith-narahari May 1, 2020
4cf393a
Merge branch 'master' of github.com:cosmos/cosmos-sdk into sahith/add…
sahith-narahari May 1, 2020
6ba5c0d
Removed unused imports
sahith-narahari May 1, 2020
c0d95b5
Added init for go tests
sahith-narahari May 1, 2020
018443a
try fix tests
May 1, 2020
e019301
goimports what wasn't goimports'd
May 1, 2020
bc35ac4
Merge branch 'master' into pr-6095
May 1, 2020
9815dc3
try fix ci
May 1, 2020
ae6b442
add relevant tags to integration tests
May 1, 2020
2076931
run integration tests separately
May 1, 2020
99a454e
use go build -o flag and let compiler gemerate the binary with the
May 1, 2020
3774f86
update ci
May 1, 2020
1671cbd
rename
May 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ jobs:
file: ./coverage.txt # optional
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"
cli-test:
integration-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: build-sim
run: |
make build-sim
if: "env.GIT_DIFF != ''"
- name: cli-test
run: |
make cli-test
make test-integration
21 changes: 8 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ HTTPS_GIT := https://github.com/cosmos/cosmos-sdk.git
DOCKER_BUF := docker run -v $(shell pwd):/workspace --workdir /workspace bufbuild/buf

export GO111MODULE = on
export BUILDDIR

# The below include contains the tools and runsim targets.
include contrib/devtools/Makefile
Expand All @@ -28,13 +27,9 @@ build: go.sum
@go build -mod=readonly ./...

build-sim: go.sum
ifeq ($(OS),Windows_NT)
go build -mod=readonly $(BUILD_FLAGS) -o build/simd.exe ./simapp/cmd/simd
go build -mod=readonly $(BUILD_FLAGS) -o build/simcli.exe ./simapp/cmd/simcli
else
go build -mod=readonly $(BUILD_FLAGS) -o build/simd ./simapp/cmd/simd
go build -mod=readonly $(BUILD_FLAGS) -o build/simcli ./simapp/cmd/simcli
endif
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/cmd/simd
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/cmd/simcli

.PHONY: \
build \
Expand Down Expand Up @@ -128,6 +123,10 @@ test-unit:
test-race:
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)

test-integration: build-sim
BUILDDIR=$(BUILDDIR) go test -mod=readonly -p 4 `go list ./tests/cli/...` -tags=-tags='ledger test_ledger_mock cli_test'
BUILDDIR=$(BUILDDIR) go test -mod=readonly -p 4 `go list ./x/.../client/cli_test/...` -tags=-tags='ledger test_ledger_mock cli_test'

.PHONY: test test-all test-ledger-mock test-ledger test-unit test-race

test-sim-nondeterminism:
Expand Down Expand Up @@ -168,10 +167,6 @@ test-sim-benchmark-invariants:
-Enabled=true -NumBlocks=1000 -BlockSize=200 \
-Period=1 -Commit=true -Seed=57 -v -timeout 24h

cli-test: build-sim
@go test -mod=readonly -p 4 `go list ./tests/cli/tests/...` -tags=cli_test -v
@go test -mod=readonly -p 4 `go list ./x/.../client/cli_test/...` -tags=cli_test -v

.PHONY: \
test-sim-nondeterminism \
test-sim-custom-genesis-fast \
Expand All @@ -181,7 +176,7 @@ test-sim-custom-genesis-multi-seed \
test-sim-multi-seed-short \
test-sim-multi-seed-long \
test-sim-benchmark-invariants \
cli-test
test-integration

SIM_NUM_BLOCKS ?= 500
SIM_BLOCK_SIZE ?= 200
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/helpers/constants.go → tests/cli/constants.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers
package cli

const (
Denom = "stake"
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/tests/doc.go → tests/cli/doc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package tests
package cli

// package tests runs integration tests which make use of CLI commands.
2 changes: 1 addition & 1 deletion tests/cli/helpers/executors.go → tests/cli/executors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers
package cli

import (
"fmt"
Expand Down
10 changes: 7 additions & 3 deletions tests/cli/helpers/fixtures.go → tests/cli/fixtures.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers
package cli

import (
"io/ioutil"
Expand All @@ -16,7 +16,9 @@ import (
"github.com/cosmos/cosmos-sdk/simapp"
)

var cdc = std.MakeCodec(simapp.ModuleBasics)
var (
cdc = std.MakeCodec(simapp.ModuleBasics)
)

// Fixtures is used to setup the testing environment
type Fixtures struct {
Expand Down Expand Up @@ -46,7 +48,9 @@ func NewFixtures(t *testing.T) *Fixtures {
require.NoError(t, err)

buildDir := os.Getenv("BUILDDIR")
require.NotNil(t, buildDir)
if buildDir == "" {
t.Skip("builddir is empty, skipping")
}

return &Fixtures{
T: t,
Expand Down
8 changes: 4 additions & 4 deletions tests/cli/helpers/helpers.go → tests/cli/helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers
package cli

import (
"encoding/json"
Expand All @@ -19,21 +19,21 @@ import (
)

var (
totalCoins = sdk.NewCoins(
TotalCoins = sdk.NewCoins(
sdk.NewCoin(Fee2Denom, sdk.TokensFromConsensusPower(2000000)),
sdk.NewCoin(FeeDenom, sdk.TokensFromConsensusPower(2000000)),
sdk.NewCoin(FooDenom, sdk.TokensFromConsensusPower(2000)),
sdk.NewCoin(Denom, sdk.TokensFromConsensusPower(300).Add(sdk.NewInt(12))), // add coins from inflation
)

startCoins = sdk.NewCoins(
StartCoins = sdk.NewCoins(
sdk.NewCoin(Fee2Denom, sdk.TokensFromConsensusPower(1000000)),
sdk.NewCoin(FeeDenom, sdk.TokensFromConsensusPower(1000000)),
sdk.NewCoin(FooDenom, sdk.TokensFromConsensusPower(1000)),
sdk.NewCoin(Denom, sdk.TokensFromConsensusPower(150)),
)

vestingCoins = sdk.NewCoins(
VestingCoins = sdk.NewCoins(
sdk.NewCoin(FeeDenom, sdk.TokensFromConsensusPower(500000)),
)
)
Expand Down
8 changes: 4 additions & 4 deletions tests/cli/helpers/init.go → tests/cli/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package helpers
package cli

import (
"fmt"
Expand Down Expand Up @@ -42,10 +42,10 @@ func InitFixtures(t *testing.T) (f *Fixtures) {
f.CLIConfig("trust-node", "true")

// start an account with tokens
f.AddGenesisAccount(f.KeyAddress(KeyFoo), startCoins)
f.AddGenesisAccount(f.KeyAddress(KeyFoo), StartCoins)
f.AddGenesisAccount(
f.KeyAddress(KeyVesting), startCoins,
fmt.Sprintf("--vesting-amount=%s", vestingCoins),
f.KeyAddress(KeyVesting), StartCoins,
fmt.Sprintf("--vesting-amount=%s", VestingCoins),
fmt.Sprintf("--vesting-start-time=%d", time.Now().UTC().UnixNano()),
fmt.Sprintf("--vesting-end-time=%d", time.Now().Add(60*time.Second).UTC().UnixNano()),
)
Expand Down
19 changes: 9 additions & 10 deletions tests/cli/tests/keys_test.go → tests/cli/keys_test.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
// +build cli_test

package tests
package cli_test

import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/tests/cli"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/tests/cli/helpers"
)

func TestCLIKeysAddMultisig(t *testing.T) {
t.Parallel()
f := helpers.InitFixtures(t)
f := cli.InitFixtures(t)

// key names order does not matter
f.KeysAdd("msig1", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", helpers.KeyBar, helpers.KeyBaz))
fmt.Sprintf("--multisig=%s,%s", cli.KeyBar, cli.KeyBaz))
ke1Address1 := f.KeysShow("msig1").Address
f.KeysDelete("msig1")

f.KeysAdd("msig2", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", helpers.KeyBaz, helpers.KeyBar))
fmt.Sprintf("--multisig=%s,%s", cli.KeyBaz, cli.KeyBar))
require.Equal(t, ke1Address1, f.KeysShow("msig2").Address)
f.KeysDelete("msig2")

f.KeysAdd("msig3", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", helpers.KeyBar, helpers.KeyBaz),
fmt.Sprintf("--multisig=%s,%s", cli.KeyBar, cli.KeyBaz),
"--nosort")
f.KeysAdd("msig4", "--multisig-threshold=2",
fmt.Sprintf("--multisig=%s,%s", helpers.KeyBaz, helpers.KeyBar),
fmt.Sprintf("--multisig=%s,%s", cli.KeyBaz, cli.KeyBar),
"--nosort")
require.NotEqual(t, f.KeysShow("msig3").Address, f.KeysShow("msig4").Address)

Expand All @@ -40,7 +39,7 @@ func TestCLIKeysAddMultisig(t *testing.T) {

func TestCLIKeysAddRecover(t *testing.T) {
t.Parallel()
f := helpers.InitFixtures(t)
f := cli.InitFixtures(t)

exitSuccess, _, _ := f.KeysAddRecover("empty-mnemonic", "")
require.False(t, exitSuccess)
Expand All @@ -55,7 +54,7 @@ func TestCLIKeysAddRecover(t *testing.T) {

func TestCLIKeysAddRecoverHDPath(t *testing.T) {
t.Parallel()
f := helpers.InitFixtures(t)
f := cli.InitFixtures(t)

f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
require.Equal(t, "cosmos1qcfdf69js922qrdr4yaww3ax7gjml6pdds46f4", f.KeyAddress("test-recoverHD1").String())
Expand Down
128 changes: 128 additions & 0 deletions tests/cli/simd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
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()
}
Loading