-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
613 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ jobs: | |
# timeout-minutes: 5 | ||
# steps: | ||
# - uses: actions/checkout@v4 | ||
# - uses: bufbuild/[email protected].0 | ||
# - uses: bufbuild/[email protected].1 | ||
# - uses: bufbuild/buf-lint-action@v1 | ||
# with: | ||
# input: "proto" | ||
|
@@ -31,7 +31,7 @@ jobs: | |
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: bufbuild/[email protected].0 | ||
- uses: bufbuild/[email protected].1 | ||
with: | ||
github_token: ${{ github.token }} | ||
- uses: bufbuild/buf-breaking-action@v1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package testutil_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/NibiruChain/nibiru/x/common/denoms" | ||
"github.com/NibiruChain/nibiru/x/common/testutil" | ||
"github.com/NibiruChain/nibiru/x/common/testutil/testapp" | ||
) | ||
|
||
func (s *TestSuite) TestEventsUtils() { | ||
bapp, ctx := testapp.NewNibiruTestAppAndContext() | ||
|
||
// Events on the ctx before we broadcast any txs | ||
var beforeEvents sdk.Events = ctx.EventManager().Events() | ||
|
||
newCoins := func(coinsStr string) sdk.Coins { | ||
out, err := sdk.ParseCoinsNormalized(coinsStr) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return out | ||
} | ||
|
||
funds := sdk.NewCoins(sdk.NewInt64Coin(denoms.NIBI, 5_000_000)) | ||
_, addrs := testutil.PrivKeyAddressPairs(2) | ||
senderAddr, otherAddr := addrs[0], addrs[1] | ||
err := testapp.FundAccount(bapp.BankKeeper, ctx, senderAddr, funds) | ||
s.NoError(err) | ||
|
||
s.NoError( | ||
bapp.BankKeeper.SendCoins(ctx, senderAddr, otherAddr, newCoins("12unibi")), | ||
) | ||
|
||
// Events on the ctx after broadcasting tx | ||
var sdkEvents sdk.Events = ctx.EventManager().Events() | ||
|
||
s.Run("AssertEventsPresent", func() { | ||
err = testutil.AssertEventsPresent(sdkEvents, | ||
[]string{"transfer", "coin_received", "message", "coin_spent"}, | ||
) | ||
s.NoError(err) | ||
s.Error( | ||
testutil.AssertEventsPresent(sdkEvents, []string{"foobar"}), | ||
) | ||
}) | ||
|
||
s.Run("EventHasAttributeValue", func() { | ||
var transferEvent sdk.Event | ||
for _, abciEvent := range sdkEvents { | ||
if abciEvent.Type == "transfer" { | ||
transferEvent = abciEvent | ||
} | ||
} | ||
for _, err := range []error{ | ||
testutil.EventHasAttributeValue(transferEvent, "sender", senderAddr.String()), | ||
testutil.EventHasAttributeValue(transferEvent, "recipient", otherAddr.String()), | ||
testutil.EventHasAttributeValue(transferEvent, "amount", "12unibi"), | ||
} { | ||
s.NoError(err) | ||
} | ||
}) | ||
|
||
s.Run("FilterNewEvents", func() { | ||
newEvents := testutil.FilterNewEvents(beforeEvents, sdkEvents) | ||
lenBefore := len(beforeEvents) | ||
lenAfter := len(sdkEvents) | ||
lenNew := len(newEvents) | ||
s.Equal(lenAfter-lenNew, lenBefore) | ||
|
||
expectedNewEvents := sdkEvents[lenBefore:lenAfter] | ||
s.Len(expectedNewEvents, lenNew) | ||
s.ElementsMatch(newEvents, expectedNewEvents) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package testutil | ||
|
||
import ( | ||
"path" | ||
"path/filepath" | ||
"runtime" | ||
) | ||
|
||
// GetPackageDir: Returns the absolute path of the Golang package that | ||
// calls this function. | ||
func GetPackageDir() (string, error) { | ||
// Get the import path of the current package | ||
_, filename, _, _ := runtime.Caller(0) | ||
pkgDir := path.Dir(filename) | ||
pkgPath := path.Join(path.Base(pkgDir), "..") | ||
|
||
// Get the directory path of the package | ||
return filepath.Abs(pkgPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package testutil_test | ||
|
||
import ( | ||
"context" | ||
"os/exec" | ||
"path" | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/suite" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/NibiruChain/nibiru/x/common/set" | ||
"github.com/NibiruChain/nibiru/x/common/testutil" | ||
) | ||
|
||
type TestSuite struct { | ||
suite.Suite | ||
} | ||
|
||
func TestTestSuite(t *testing.T) { | ||
suite.Run(t, new(TestSuite)) | ||
} | ||
|
||
func (s *TestSuite) TestGetPackageDir() { | ||
pkgDir, err := testutil.GetPackageDir() | ||
s.NoError(err) | ||
s.Equal("testutil", path.Base(pkgDir)) | ||
s.Equal("common", path.Base(path.Dir(pkgDir))) | ||
} | ||
|
||
// TestSampleFns: Tests functions that generate test data from sample.go | ||
func (s *TestSuite) TestSampleFns() { | ||
s.T().Log("consecutive calls give different addrs") | ||
addrs := set.New[string]() | ||
for times := 0; times < 16; times++ { | ||
newAddr := testutil.AccAddress().String() | ||
s.False(addrs.Has(newAddr)) | ||
addrs.Add(newAddr) | ||
} | ||
} | ||
|
||
func (s *TestSuite) TestPrivKeyAddressPairs() { | ||
s.T().Log("calls should be deterministic") | ||
keysA, addrsA := testutil.PrivKeyAddressPairs(4) | ||
keysB, addrsB := testutil.PrivKeyAddressPairs(4) | ||
s.Equal(keysA, keysB) | ||
s.Equal(addrsA, addrsB) | ||
} | ||
|
||
func (s *TestSuite) TestBlankContext() { | ||
ctx := testutil.BlankContext("new-kv-store-key") | ||
goCtx := sdk.WrapSDKContext(ctx) | ||
|
||
freshGoCtx := context.Background() | ||
s.Require().Panics(func() { sdk.UnwrapSDKContext(freshGoCtx) }) | ||
|
||
s.Require().NotPanics(func() { sdk.UnwrapSDKContext(goCtx) }) | ||
} | ||
|
||
func (s *TestSuite) TestNullifyFill() { | ||
for _, tc := range []struct { | ||
name string | ||
input any | ||
want any | ||
}{ | ||
{ | ||
name: "nullify fill slice", | ||
input: []string{}, | ||
want: make([]string, 0), | ||
}, | ||
{ | ||
name: "nullify fill struct with coins", | ||
input: struct { | ||
Coins sdk.Coins | ||
Strings []string | ||
}{}, | ||
want: struct { | ||
Coins sdk.Coins | ||
Strings []string | ||
}{ | ||
Coins: sdk.Coins(nil), | ||
Strings: []string(nil), | ||
}, | ||
}, | ||
{ | ||
name: "nullify fill sdk.Coin struct", | ||
input: struct { | ||
Coin sdk.Coin | ||
Ints []int | ||
}{}, | ||
want: struct { | ||
Coin sdk.Coin | ||
Ints []int | ||
}{ | ||
Coin: sdk.Coin{}, | ||
Ints: []int(nil), | ||
}, | ||
}, | ||
{ | ||
name: "nullify fill pointer to null concrete", | ||
input: new(sdk.Coin), | ||
want: sdk.Coin{}, | ||
}, | ||
} { | ||
s.Run(tc.name, func() { | ||
got := testutil.Fill(tc.input) | ||
s.EqualValues(tc.want, got) | ||
}) | ||
} | ||
} | ||
|
||
func (s *TestSuite) TestSetupClientCtx() { | ||
goCtx := testutil.SetupClientCtx(s.T()) | ||
trivialCobraCommand := &cobra.Command{ | ||
Use: "run-true", | ||
Short: "Runs the Unix command, 'true'", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return exec.Command("true").Run() | ||
}, | ||
} | ||
|
||
err := trivialCobraCommand.ExecuteContext(goCtx) | ||
s.NoError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package fixture | ||
|
||
const ( | ||
// WASM_NIBI_STARGATE is a compiled version of: https://github.com/NibiruChain/cw-nibiru/blob/main/contracts/nibi-stargate/src/contract.rs | ||
WASM_NIBI_STARGATE = "nibi_stargate.wasm" | ||
) |
Binary file not shown.
Oops, something went wrong.