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

test: refactors cli.network suites with 'Integration' to use common function #1652

Merged
merged 12 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
18 changes: 9 additions & 9 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
paths: ["**.go", "**.proto", "go.mod", "go.sum"]

# Allow concurrent runs on main/release branches but isolates other branches
# Allow concurrent runs on main/release branches but isolates other branches
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
cancel-in-progress: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }}
Expand All @@ -22,17 +22,17 @@ jobs:
cache: true

- name: Run all unit tests.
run: make test-coverage
run: make test-unit
Comment on lines 24 to +25
Copy link
Member Author

@Unique-Divine Unique-Divine Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the unit-test.yml GitHub action, there's no reason to save a coverage.txt since it's not published or visible. We're only using the reports from the integration-test.yml action. We can use make test-unit here to have the CI run faster.


build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19

- name: Build the nibid binary
run: make build
- name: Build the nibid binary
run: make build
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1631](https://github.com/NibiruChain/nibiru/pull/1631) - fix(.goreleaser.yml): Load version for wasmvm dynamically.
* [#1638](https://github.com/NibiruChain/nibiru/pull/1638) - test(tokenfactory): integration test core logic with a real smart contract using `nibiru-std`
* [#1639](https://github.com/NibiruChain/nibiru/pull/1639) - fix(perp): by default, disable new markets until they are toggled on.
* [#1652](https://github.com/NibiruChain/nibiru/pull/1652) - test: refactors cli.network suites with 'Integration' to use common function

### Dependencies
- Bump `github.com/prometheus/client_golang` from 1.16.0 to 1.17.0 ([#1605](https://github.com/NibiruChain/nibiru/pull/1605))
Expand Down Expand Up @@ -779,4 +780,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Testing

* [#695](https://github.com/NibiruChain/nibiru/pull/695) Add `OpenPosition` integration tests.
* [#692](https://github.com/NibiruChain/nibiru/pull/692) Add test coverage for Perp MsgServer methods.
* [#692](https://github.com/NibiruChain/nibiru/pull/692) Add test coverage for Perp MsgServer methods.
10 changes: 6 additions & 4 deletions contrib/make/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# Tests
#########################################################################

PACKAGES_NOSIMULATION = ${shell go list ./... | grep -v simapp}
.PHONY: test-unit
test-unit:
go test ./... -short

.PHONY: test-coverage
test-coverage:
go test ./... $(PACKAGES_NOSIMULATION) -short \
.PHONY: test-coverage-unit
Comment on lines -7 to +9
Copy link
Member Author

@Unique-Divine Unique-Divine Oct 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using $PACKAGES_NOSIMULATION is unnecessary since simulations require a specific flag and we're already using the -short flag, which can filter out simulations

test-coverage-unit:
go test ./... -short \
-coverprofile=coverage.txt \
-covermode=atomic \
-race
Expand Down
47 changes: 35 additions & 12 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,45 @@ import (
"github.com/cosmos/cosmos-sdk/x/simulation"
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/NibiruChain/nibiru/app"
appsim "github.com/NibiruChain/nibiru/app/sim"
"github.com/NibiruChain/nibiru/x/common/testutil"
"github.com/NibiruChain/nibiru/x/common/testutil/testapp"
)

// SimAppChainID hardcoded chainID for simulation
const SimAppChainID = "simulation-app"

func init() {
type SimulationTestSuite struct {
suite.Suite
}

func TestSimulationTestSuite(t *testing.T) {
suite.Run(t, new(SimulationTestSuite))
}

var _ suite.SetupTestSuite = (*SimulationTestSuite)(nil)
var _ suite.SetupAllSuite = (*SimulationTestSuite)(nil)

// SetupSuite: Runs before the entire test suite.
func (s *SimulationTestSuite) SetupSuite() {
// We call GetSimulatorFlags here in order to set the value for
// 'simapp.FlagEnabledValue', which enables simulations
appsim.GetSimulatorFlags()
}

func TestFullAppSimulation(tb *testing.T) {
// SetupTest: Runs before every test in the suite.
func (s *SimulationTestSuite) SetupTest() {
testutil.BeforeIntegrationSuite(s.T())
if !simapp.FlagEnabledValue {
s.T().Skip("skipping application simulation")
}
}

func (s *SimulationTestSuite) TestFullAppSimulation() {
t := s.T()
config := simcli.NewConfigFromFlags()
config.ChainID = SimAppChainID

Expand All @@ -40,15 +65,15 @@ func TestFullAppSimulation(tb *testing.T) {
simcli.FlagVerboseValue, simcli.FlagEnabledValue,
)
if skip {
tb.Skip("skipping application simulation")
t.Skip("skipping application simulation")
}
require.NoError(tb, err, "simulation setup failed")
require.NoError(t, err, "simulation setup failed")

defer func() {
db.Close()
err = os.RemoveAll(dir)
if err != nil {
tb.Fatal(err)
t.Fatal(err)
}
}()

Expand All @@ -57,7 +82,7 @@ func TestFullAppSimulation(tb *testing.T) {

// Run randomized simulation:
_, simParams, simErr := simulation.SimulateFromSeed(
/* tb */ tb,
/* tb */ t,
/* w */ os.Stdout,
/* app */ app.BaseApp,
/* appStateFn */ AppStateFn(app.AppCodec(), app.SimulationManager()),
Expand All @@ -70,22 +95,20 @@ func TestFullAppSimulation(tb *testing.T) {

// export state and simParams before the simulation error is checked
if err = helpers.CheckExportSimulation(app, config, simParams); err != nil {
tb.Fatal(err)
t.Fatal(err)
}

if simErr != nil {
tb.Fatal(simErr)
t.Fatal(simErr)
}

if config.Commit {
simapp.PrintStats(db)
}
}

func TestAppStateDeterminism(t *testing.T) {
if !simapp.FlagEnabledValue {
t.Skip("skipping application simulation")
}
func (s *SimulationTestSuite) TestAppStateDeterminism() {
t := s.T()

encoding := app.MakeEncodingConfig()

Expand Down
7 changes: 2 additions & 5 deletions wasmbinding/test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/NibiruChain/nibiru/x/common"
"github.com/NibiruChain/nibiru/x/common/asset"
"github.com/NibiruChain/nibiru/x/common/denoms"
"github.com/NibiruChain/nibiru/x/common/testutil"
testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli"
"github.com/NibiruChain/nibiru/x/common/testutil/genesis"
epochstypes "github.com/NibiruChain/nibiru/x/epochs/types"
Expand All @@ -39,11 +40,7 @@ type IntegrationTestSuite struct {
}

func (s *IntegrationTestSuite) SetupSuite() {
if testing.Short() {
s.T().Skip("skipping integration test suite")
}

s.T().Log("setting up integration test suite")
testutil.BeforeIntegrationSuite(s.T())

app.SetPrefixes(app.AccountAddressPrefix)

Expand Down
16 changes: 16 additions & 0 deletions x/common/testutil/cases.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@ func RunFunctionTests(t *testing.T, testCases []FunctionTestCase) {
})
}
}

/*
BeforeIntegrationSuite: Skips a test if the `-short` flag is not used:
Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved

All tests: `go test ./...`
Unit tests only: `go test ./... -short`
Integration tests only: `go test ./... -run Integration`

See: https://stackoverflow.com/a/41407042/13305627
*/
func BeforeIntegrationSuite(suiteT *testing.T) {
if testing.Short() {
suiteT.Skip("skipping integration test suite")
}
suiteT.Log("setting up integration test suite")
}
10 changes: 5 additions & 5 deletions x/devgas/v1/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
devgastypes "github.com/NibiruChain/nibiru/x/devgas/v1/types"
)

func (s *IntegrationTestSuite) TestQueryFeeShares() {
func (s *KeeperTestSuite) TestQueryFeeShares() {
s.SetupTest()
_, _, sender := testdata.KeyTestPubAddr()
_ = s.FundAccount(
Expand Down Expand Up @@ -70,7 +70,7 @@ func (s *IntegrationTestSuite) TestQueryFeeShares() {
})
}

func (s *IntegrationTestSuite) TestFeeShare() {
func (s *KeeperTestSuite) TestFeeShare() {
s.SetupTest()
_, _, sender := testdata.KeyTestPubAddr()
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000))))
Expand Down Expand Up @@ -102,7 +102,7 @@ func (s *IntegrationTestSuite) TestFeeShare() {
s.Require().Equal(resp.Feeshare, feeShare)
}

func (s *IntegrationTestSuite) TestFeeSharesByWithdrawer() {
func (s *KeeperTestSuite) TestFeeSharesByWithdrawer() {
s.SetupTest()
_, _, sender := testdata.KeyTestPubAddr()
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000))))
Expand Down Expand Up @@ -141,15 +141,15 @@ func (s *IntegrationTestSuite) TestFeeSharesByWithdrawer() {
})
}

func (s *IntegrationTestSuite) TestQueryParams() {
func (s *KeeperTestSuite) TestQueryParams() {
s.SetupTest()
goCtx := sdk.WrapSDKContext(s.ctx)
resp, err := s.queryClient.Params(goCtx, nil)
s.NoError(err)
s.NotNil(resp)
}

func (s *IntegrationTestSuite) TestNilRequests() {
func (s *KeeperTestSuite) TestNilRequests() {
s.SetupTest()
goCtx := sdk.WrapSDKContext(s.ctx)
querier := devgaskeeper.NewQuerier(s.app.DevGasKeeper)
Expand Down
10 changes: 5 additions & 5 deletions x/devgas/v1/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type BankKeeper interface {
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
}

type IntegrationTestSuite struct {
type KeeperTestSuite struct {
suite.Suite

ctx sdk.Context
Expand All @@ -35,7 +35,7 @@ type IntegrationTestSuite struct {
wasmMsgServer wasmtypes.MsgServer
}

func (s *IntegrationTestSuite) SetupTest() {
func (s *KeeperTestSuite) SetupTest() {
nibiruApp, ctx := testapp.NewNibiruTestAppAndContext()
s.app = nibiruApp
s.ctx = ctx
Expand All @@ -52,16 +52,16 @@ func (s *IntegrationTestSuite) SetupTest() {
s.wasmMsgServer = wasmkeeper.NewMsgServerImpl(&s.app.WasmKeeper)
}

func (s *IntegrationTestSuite) SetupSuite() {
func (s *KeeperTestSuite) SetupSuite() {
s.SetupTest()
}

func (s *IntegrationTestSuite) FundAccount(
func (s *KeeperTestSuite) FundAccount(
ctx sdk.Context, addr sdk.AccAddress, amounts sdk.Coins,
) error {
return testapp.FundAccount(s.app.BankKeeper, ctx, addr, amounts)
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(IntegrationTestSuite))
suite.Run(t, new(KeeperTestSuite))
}
14 changes: 7 additions & 7 deletions x/devgas/v1/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
//go:embed testdata/reflect.wasm
var wasmContract []byte

func (s *IntegrationTestSuite) StoreCode() {
func (s *KeeperTestSuite) StoreCode() {
_, _, sender := testdata.KeyTestPubAddr()
msg := wasmtypes.MsgStoreCodeFixture(func(m *wasmtypes.MsgStoreCode) {
m.WASMByteCode = wasmContract
Expand All @@ -41,7 +41,7 @@ func (s *IntegrationTestSuite) StoreCode() {
s.Require().Equal(wasmtypes.DefaultParams().InstantiateDefaultPermission.With(sender), info.InstantiateConfig)
}

func (s *IntegrationTestSuite) InstantiateContract(sender string, admin string) string {
func (s *KeeperTestSuite) InstantiateContract(sender string, admin string) string {
msgStoreCode := wasmtypes.MsgStoreCodeFixture(func(m *wasmtypes.MsgStoreCode) {
m.WASMByteCode = wasmContract
m.Sender = sender
Expand All @@ -66,7 +66,7 @@ func (s *IntegrationTestSuite) InstantiateContract(sender string, admin string)
return result.Address
}

func (s *IntegrationTestSuite) TestGetContractAdminOrCreatorAddress() {
func (s *KeeperTestSuite) TestGetContractAdminOrCreatorAddress() {
_, _, sender := testdata.KeyTestPubAddr()
_, _, admin := testdata.KeyTestPubAddr()
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000))))
Expand Down Expand Up @@ -117,7 +117,7 @@ func (s *IntegrationTestSuite) TestGetContractAdminOrCreatorAddress() {
}
}

func (s *IntegrationTestSuite) TestRegisterFeeShare() {
func (s *KeeperTestSuite) TestRegisterFeeShare() {
_, _, sender := testdata.KeyTestPubAddr()
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000))))

Expand Down Expand Up @@ -245,7 +245,7 @@ func (s *IntegrationTestSuite) TestRegisterFeeShare() {
}
}

func (s *IntegrationTestSuite) TestUpdateFeeShare() {
func (s *KeeperTestSuite) TestUpdateFeeShare() {
_, _, sender := testdata.KeyTestPubAddr()
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000))))

Expand Down Expand Up @@ -342,7 +342,7 @@ func (s *IntegrationTestSuite) TestUpdateFeeShare() {
}
}

func (s *IntegrationTestSuite) TestCancelFeeShare() {
func (s *KeeperTestSuite) TestCancelFeeShare() {
_, _, sender := testdata.KeyTestPubAddr()
_ = s.FundAccount(s.ctx, sender, sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(1_000_000))))

Expand Down Expand Up @@ -409,7 +409,7 @@ func (s *IntegrationTestSuite) TestCancelFeeShare() {
}
}

func (s *IntegrationTestSuite) TestUpdateParams() {
func (s *KeeperTestSuite) TestUpdateParams() {
govModuleAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String()
goCtx := sdk.WrapSDKContext(s.ctx)

Expand Down
12 changes: 2 additions & 10 deletions x/perp/v2/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/NibiruChain/nibiru/x/common"
"github.com/NibiruChain/nibiru/x/common/asset"
"github.com/NibiruChain/nibiru/x/common/denoms"
"github.com/NibiruChain/nibiru/x/common/testutil"
testutilcli "github.com/NibiruChain/nibiru/x/common/testutil/cli"
"github.com/NibiruChain/nibiru/x/common/testutil/genesis"
oracletypes "github.com/NibiruChain/nibiru/x/oracle/types"
Expand All @@ -32,16 +33,7 @@ type IntegrationTestSuite struct {
}

func (s *IntegrationTestSuite) SetupSuite() {
/* Make test skip if -short is not used:
All tests: `go test ./...`
Unit tests only: `go test ./... -short`
Integration tests only: `go test ./... -run Integration`
https://stackoverflow.com/a/41407042/13305627 */
if testing.Short() {
s.T().Skip("skipping integration test suite")
}

s.T().Log("setting up integration test suite")
testutil.BeforeIntegrationSuite(s.T())

app.SetPrefixes(app.AccountAddressPrefix)

Expand Down
Loading
Loading