-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add:system tests * add: go.mod * update: rename send_test * update: own go mod * block tests * add: accounts, mempool and network tests * some construction endpoints * add: system-test workflow * fix: lint * update: workflows * fix: lint * fix: system tests * fix: makefile rosetta-cli * update: echo sdk version in test-system * rabbit suggestions * update: nosec annotation
- Loading branch information
1 parent
c370232
commit 9b56e7a
Showing
20 changed files
with
2,016 additions
and
11 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
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 |
---|---|---|
|
@@ -37,4 +37,31 @@ jobs: | |
- name: tests | ||
if: env.GIT_DIFF | ||
run: | | ||
make plugin && make test | ||
make plugin && make test | ||
test-system: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 30 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: "1.23" | ||
check-latest: true | ||
cache: true | ||
cache-dependency-path: tests/systemtests/go.sum | ||
- uses: technote-space/[email protected] | ||
id: git_diff | ||
with: | ||
PATTERNS: | | ||
**/*.go | ||
go.mod | ||
go.sum | ||
**/go.mod | ||
**/go.sum | ||
**/Makefile | ||
Makefile | ||
- name: system tests | ||
if: env.GIT_DIFF | ||
run: | | ||
make test-system |
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
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 |
---|---|---|
@@ -1,18 +1,50 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu -o pipefail | ||
set -e | ||
|
||
REPO_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )" | ||
export REPO_ROOT | ||
|
||
LINT_TAGS="system_test" | ||
lint_module() { | ||
local root="$1" | ||
shift | ||
cd "$(dirname "$root")" && | ||
echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" && | ||
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" | ||
if [ -f $root ]; then | ||
cd "$(dirname "$root")" | ||
else | ||
cd "$REPO_ROOT/$root" | ||
fi | ||
echo "linting $(grep "^module" go.mod) [$(date -Iseconds -u)]" | ||
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=${LINT_TAGS} | ||
} | ||
export -f lint_module | ||
|
||
find "${REPO_ROOT}" -type f -name go.mod -print0 | | ||
xargs -0 -I{} bash -c 'lint_module "$@"' _ {} "$@" # Prepend go.mod file before command-line args. | ||
if [[ -z "${LINT_DIFF:-}" ]]; then | ||
find "${REPO_ROOT}" -type f -name go.mod -print0 | xargs -0 -I{} bash -c 'lint_module "$@"' _ {} "$@" --build-tags=${LINT_TAGS} | ||
else | ||
if [[ -z $GIT_DIFF ]]; then | ||
GIT_DIFF=$(git diff --name-only) || true | ||
fi | ||
|
||
if [[ -z "$GIT_DIFF" ]]; then | ||
echo "no files to lint" | ||
exit 0 | ||
fi | ||
|
||
GIT_DIFF=$(echo $GIT_DIFF | tr -d "'" | tr ' ' '\n' | grep '\.go$' | grep -v '\.pb\.go$' | grep -Eo '^[^/]+\/[^/]+' | uniq) | ||
|
||
lint_sdk=false | ||
for dir in ${GIT_DIFF[@]}; do | ||
if [[ ! -f "$REPO_ROOT/$dir/go.mod" ]]; then | ||
lint_sdk=true | ||
else | ||
lint_module $dir "$@" | ||
fi | ||
done | ||
|
||
if [[ $lint_sdk ]]; then | ||
cd "$REPO_ROOT" | ||
echo "linting github.com/cosmos/rosetta [$(date -Iseconds -u)]" | ||
golangci-lint run ./... -c "${REPO_ROOT}/.golangci.yml" "$@" --build-tags=${LINT_TAGS} | ||
fi | ||
fi |
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 @@ | ||
#!/usr/bin/make -f | ||
|
||
WAIT_TIME ?= 45s | ||
|
||
test: | ||
go test -mod=readonly -failfast -timeout=15m -tags='system_test' ./... --wait-time=$(WAIT_TIME) --verbose |
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,45 @@ | ||
//go:build system_test | ||
|
||
package systemtests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tidwall/gjson" | ||
|
||
"cosmossdk.io/systemtests" | ||
) | ||
|
||
func TestAccounts(t *testing.T) { | ||
sut.ResetChain(t) | ||
cli := systemtests.NewCLIWrapper(t, sut, verbose) | ||
// add genesis account with some tokens | ||
fromAddr := cli.AddKey("account1") | ||
sut.ModifyGenesisCLI(t, | ||
[]string{"genesis", "add-genesis-account", fromAddr, "10000000stake"}, | ||
) | ||
toAddr := cli.AddKey("account2") | ||
sut.StartChain(t) | ||
|
||
rsp := cli.RunAndWait("tx", "bank", "send", fromAddr, toAddr, "1000000stake") | ||
systemtests.RequireTxSuccess(t, rsp) | ||
|
||
rosetta.restart(t) | ||
rosettaRest := newRestClient(rosetta) | ||
|
||
// check balance after spent | ||
res, err := rosettaRest.accountBalance(fromAddr) | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(8999999), gjson.GetBytes(res, "balances.0.value").Int()) | ||
|
||
// check recipient's balance after receiving tokens | ||
res, err = rosettaRest.accountBalance(toAddr) | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(1000000), gjson.GetBytes(res, "balances.0.value").Int()) | ||
|
||
// check balance at genesis, before spent | ||
res, err = rosettaRest.accountBalance(fromAddr, withBlockIdentifier("1")) | ||
assert.NoError(t, err) | ||
assert.Equal(t, int64(10000000), gjson.GetBytes(res, "balances.0.value").Int()) | ||
} |
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,45 @@ | ||
//go:build system_test | ||
|
||
package systemtests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tidwall/gjson" | ||
|
||
"cosmossdk.io/systemtests" | ||
) | ||
|
||
func TestBlockAndBlockTransaction(t *testing.T) { | ||
sut.ResetChain(t) | ||
cli := systemtests.NewCLIWrapper(t, sut, verbose) | ||
// add genesis account with some tokens | ||
fromAddr := cli.AddKey("account1") | ||
sut.ModifyGenesisCLI(t, | ||
[]string{"genesis", "add-genesis-account", fromAddr, "10000000stake"}, | ||
) | ||
toAddr := cli.AddKey("account2") | ||
sut.StartChain(t) | ||
|
||
rosetta.restart(t) | ||
|
||
// stake tokens | ||
rsp := cli.RunAndWait("tx", "bank", "send", fromAddr, toAddr, "10stake") | ||
systemtests.RequireTxSuccess(t, rsp) | ||
|
||
rosettaRest := newRestClient(rosetta) | ||
|
||
// test /block endpoint | ||
height := gjson.Get(rsp, "height").String() | ||
res, err := rosettaRest.block(height) | ||
assert.NoError(t, err) | ||
assert.Equal(t, gjson.GetBytes(res, "block.block_identifier.index").String(), height) | ||
|
||
// test block/transaction endpoint | ||
blockHash := gjson.GetBytes(res, "block.block_identifier.hash").String() | ||
hash := gjson.GetBytes(res, "block.transactions.0.transaction_identifier.hash").String() | ||
res, err = rosettaRest.blockTransaction(height, blockHash, hash) | ||
assert.NoError(t, err) | ||
assert.Equal(t, gjson.GetBytes(res, "transaction.operations.0.metadata.from_address").String(), fromAddr) | ||
} |
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,84 @@ | ||
//go:build system_test | ||
|
||
package systemtests | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/hex" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/tidwall/gjson" | ||
|
||
"cosmossdk.io/systemtests" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec/address" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
) | ||
|
||
func TestDerive(t *testing.T) { | ||
sut.ResetChain(t) | ||
sut.StartChain(t) | ||
|
||
rosetta.restart(t) | ||
rosettaRest := newRestClient(rosetta) | ||
|
||
pubKey := secp256k1.GenPrivKey().PubKey() | ||
addr, err := address.NewBech32Codec("cosmos").BytesToString(pubKey.Address().Bytes()) | ||
assert.NoError(t, err) | ||
|
||
hexPk := strings.Split(pubKey.String(), "{")[1] | ||
res, err := rosettaRest.constructionDerive(hexPk[:len(hexPk)-1]) | ||
assert.NoError(t, err) | ||
assert.Equal(t, addr, gjson.GetBytes(res, "address").String()) | ||
} | ||
|
||
func TestHash(t *testing.T) { | ||
sut.ResetChain(t) | ||
sut.StartChain(t) | ||
|
||
cli := systemtests.NewCLIWrapper(t, sut, verbose) | ||
fromAddr := cli.AddKey("account1") | ||
sut.ModifyGenesisCLI(t, | ||
[]string{"genesis", "add-genesis-account", fromAddr, "10000000stake"}, | ||
) | ||
toAddr := cli.AddKey("account2") | ||
|
||
rosetta.restart(t) | ||
rosettaRest := newRestClient(rosetta) | ||
|
||
rsp := cli.RunCommandWithArgs(cli.WithTXFlags("tx", "bank", "send", fromAddr, toAddr, "10stake", "--generate-only")...) | ||
tempFile := systemtests.StoreTempFile(t, []byte(rsp)) | ||
rsp = cli.RunCommandWithArgs(cli.WithTXFlags("tx", "sign", tempFile.Name(), "--from", fromAddr)...) | ||
tempFile = systemtests.StoreTempFile(t, []byte(rsp)) | ||
rsp = cli.RunCommandWithArgs("tx", "encode", tempFile.Name()) | ||
|
||
txBytes, err := base64.StdEncoding.DecodeString(rsp) | ||
assert.NoError(t, err) | ||
hexTx := hex.EncodeToString(txBytes) | ||
|
||
res, err := rosettaRest.constructionHash(hexTx) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, gjson.GetBytes(res, "transaction_identifier.hash")) | ||
} | ||
|
||
func TestMetadata(t *testing.T) { | ||
sut.ResetChain(t) | ||
sut.StartChain(t) | ||
|
||
rosetta.restart(t) | ||
rosettaRest := newRestClient(rosetta) | ||
|
||
pubKey := secp256k1.GenPrivKey().PubKey() | ||
hexPk := strings.Split(pubKey.String(), "{")[1] | ||
|
||
metadata := make(map[string]interface{}) | ||
metadata["gas_price"] = `"123uatom"` | ||
metadata["gas_limit"] = 423 | ||
|
||
res, err := rosettaRest.constructionMetadata(hexPk, metadata) | ||
assert.NoError(t, err) | ||
assert.Equal(t, gjson.GetBytes(res, "metadata.gas_price").String(), "123uatom") | ||
assert.Greater(t, gjson.GetBytes(res, "suggested_fee.0.value").Int(), int64(0)) | ||
} |
Oops, something went wrong.