Skip to content

Commit

Permalink
Merge branch 'mat/make-quote-collection' of github.com:NibiruChain/ni…
Browse files Browse the repository at this point in the history
…biru into mat/make-quote-collection
  • Loading branch information
matthiasmatt committed Nov 2, 2023
2 parents 62fcc8d + 4d5b5fb commit b34931b
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 81 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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 @@ -28,6 +28,26 @@ jobs:
go-version: 1.19
cache: false # the golangci-lint action already caches for us (https://github.com/golangci/golangci-lint-action#performance)

# Use GitHub actions output paramters to get go paths. For more info, see
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
- name: "Set output variables for go cache"
id: go-cache-paths
run: |
echo "go-build-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod-cache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: "Go build cache"
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build-cache }}
key: go-build-cache-${{ hashFiles('**/go.sum') }}

- name: "Go mod cache"
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod-cache }}
key: go-mod-cache-${{ hashFiles('**/go.sum') }}

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
Expand Down
24 changes: 22 additions & 2 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,28 @@ jobs:
go-version: 1.19
cache: true

- name: Run all integration tests.
# Use GitHub actions output paramters to get go paths. For more info, see
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
- name: "Set output variables for go cache"
id: go-cache-paths
run: |
echo "go-build-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod-cache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: "Go build cache"
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build-cache }}
key: go-build-cache-${{ hashFiles('**/go.sum') }}

- name: "Go mod cache"
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod-cache }}
key: go-mod-cache-${{ hashFiles('**/go.sum') }}

- name: "Run all integration tests."
run: make test-coverage-integration

- name: Upload coverage reports to Codecov
- name: "Upload coverage reports to Codecov"
uses: codecov/codecov-action@v3
38 changes: 29 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 @@ -21,18 +21,38 @@ jobs:
go-version: 1.19
cache: true

# Use GitHub actions output paramters to get go paths. For more info, see
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
- name: "Set output variables for go cache"
id: go-cache-paths
run: |
echo "go-build-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod-cache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: "Go build cache"
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build-cache }}
key: go-build-cache-${{ hashFiles('**/go.sum') }}

- name: "Go mod cache"
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-mod-cache }}
key: go-mod-cache-${{ hashFiles('**/go.sum') }}

- name: Run all unit tests.
run: make test-coverage
run: make test-unit

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 @@ -67,6 +67,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 @@ -781,4 +782,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
test-coverage-unit:
go test ./... -short \
-coverprofile=coverage.txt \
-covermode=atomic \
-race
Expand Down
43 changes: 32 additions & 11 deletions simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,43 @@ 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"

type SimulationTestSuite struct {
suite.Suite
}

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

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

func init() {
// 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 +63,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 +80,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 +93,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 used:
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")
}
29 changes: 29 additions & 0 deletions x/common/testutil/cases_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package testutil_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/NibiruChain/nibiru/x/common/testutil"
)

func TestRunFunctionTests(t *testing.T) {
testutil.RunFunctionTests(t, testutil.FunctionTestCases{
{
Name: "test case A",
Test: func() {
},
},
})
}

func TestBeforeIntegrationSuite(t *testing.T) {
testutil.BeforeIntegrationSuite(t)

if testing.Short() {
require.True(t, t.Skipped())
} else {
require.False(t, t.Skipped())
}
}
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
Loading

0 comments on commit b34931b

Please sign in to comment.