Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d312ba6
feat: add integration env function to update config.yml
May 5, 2022
5dcc276
feat: add integration env function to install Vue boilerplate deps
May 5, 2022
f50ad16
feat: add tstestrunner package to integration tests
May 5, 2022
c148e09
feat: add integration env function to run typescript tests
May 5, 2022
4fa17f5
ci: exclude "testdata" dir from the integration tests run
May 6, 2022
7eab0fb
feat: add fetch API support to TS client tests
May 6, 2022
b15ed6e
chore: rename InstallClientDep to InstallClientVueDeps
May 6, 2022
e997b5c
test: add integration TS client test to perform a transfer
May 6, 2022
012b317
Merge branch 'develop' into feature/tsclient-integration-tests
May 6, 2022
730be0b
fix: change bank client test to serve chain in gopher and wait
May 9, 2022
11f6176
refactor: add tsclient dir to group TS client tests with Go test files
May 9, 2022
424a44b
refactor: remove InstallClientVueDeps to simplify env API
May 9, 2022
df80e20
refactor: move tstestrunner package into tsclient's testdata dir
May 9, 2022
a1c77e1
refactor: move TS bank tests to a separate folder
May 11, 2022
67328ec
refactor: move tsclient bank module test to cosmosgen dir
May 11, 2022
db2a2bc
refactor: move testdata/tstestrunner to integration dir
May 11, 2022
4f38a95
feat: change TS tests to discover user generated module packages
May 12, 2022
de2fc84
refactor: change TS test runner to init global values
May 12, 2022
a04b72d
feat: change test env to allow choosing the TS client test file
May 12, 2022
a7c9ef5
refactor: change bank module test to send accounts to TS tests
May 12, 2022
9b87472
chore: remove ClientTestDir option for the integration tests
May 13, 2022
f6e1164
chore: change names for consistency
May 13, 2022
adf667a
refactor: add "testutil" folder to organize tstestrunner code
May 13, 2022
34fb841
Merge branch 'develop' into feature/tsclient-integration-tests
Jun 24, 2022
0991916
fix: import paths for bank module integration test
Jun 24, 2022
6112d52
Merge branch 'develop' into feature/tsclient-integration-tests
Sep 27, 2022
786e5dc
refactor: moved client integration support to a separate file
Sep 27, 2022
a2197cd
chore: update changelog
Sep 27, 2022
d3858b5
chore: remove unused ts-client generation command flag
Sep 27, 2022
daa7e1c
refactor: change RunClientTests to match latest changes
Sep 27, 2022
19daafb
refactor: change integration TS testrunner for the latest changes
Sep 27, 2022
b3a9043
refactor: change bank TS module test to work with latest changes
Sep 27, 2022
08d5420
Merge branch 'develop' into feature/tsclient-integration-tests
Sep 27, 2022
c5e0925
fix: remove `--proto-all-modules` from TS client integration test
Sep 27, 2022
d733579
chore: changed `global` TS variable to `globalThis`
Sep 28, 2022
af54faa
Merge branch 'develop' into feature/tsclient-integration-tests
Sep 28, 2022
9bd6826
Merge branch 'develop' into feature/tsclient-integration-tests
Oct 3, 2022
407a8c2
Merge branch 'develop' into feature/tsclient-integration-tests
Oct 3, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v2
- name: Finding files and store to output
id: set-matrix
run: echo "::set-output name=matrix::$({ cd integration && find . -type d -maxdepth 1 -print; } | tail -n +2 | cut -c 3- | jq -R . | jq -cs .)"
run: echo "::set-output name=matrix::$({ cd integration && find . -type d ! -name testdata -maxdepth 1 -print; } | tail -n +2 | cut -c 3- | jq -R . | jq -cs .)"

integration:
name: test ${{ matrix.test-path }}
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
- Seal the capability keeper in the `app.go` template
- Change faucet to allow C.O.R.S. preflight requests.

### Features

- Add generated TS client test support to integration tests.

## [`v0.24.0`](https://github.com/ignite/cli/releases/tag/v0.24.0)

### Features
Expand Down
1 change: 0 additions & 1 deletion ignite/cmd/generate_typescript_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func NewGenerateTSClient() *cobra.Command {
RunE: generateTSClientHandler,
}

c.Flags().AddFlagSet(flagSetProto3rdParty(""))
c.Flags().StringP(flagOutput, "o", "", "typescript client output path")

return c
Expand Down
10 changes: 10 additions & 0 deletions integration/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,13 @@ func (a App) EditConfig(apply func(*chainconfig.Config)) {
err = os.WriteFile(a.configPath, bz, 0o644)
require.NoError(a.env.t, err)
}

// GenerateTSClient runs the command to generate the Typescript client code.
func (a App) GenerateTSClient() bool {
return a.env.Exec("generate typescript client", step.NewSteps(
step.New(
step.Exec(IgniteApp, "g", "ts-client", "--yes", "--clear-cache"),
step.Workdir(a.path),
),
))
}
157 changes: 157 additions & 0 deletions integration/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package envtest

import (
"bytes"
"os"
"os/exec"
"path/filepath"
"runtime"

"github.com/stretchr/testify/require"

"github.com/ignite/cli/ignite/chainconfig"
"github.com/ignite/cli/ignite/pkg/cmdrunner"
"github.com/ignite/cli/ignite/pkg/cmdrunner/step"
)

type clientOptions struct {
env map[string]string
testName, testFilePath string
}

// ClientOption defines options for the TS client test runner.
type ClientOption func(*clientOptions)

// ClientEnv option defines environment values for the tests.
func ClientEnv(env map[string]string) ClientOption {
return func(o *clientOptions) {
for k, v := range env {
o.env[k] = v
}
}
}

// ClientTestName option defines a pattern to match the test names that should be run.
func ClientTestName(pattern string) ClientOption {
return func(o *clientOptions) {
o.testName = pattern
}
}

// ClientTestFile option defines the name of the file where to look for tests.
func ClientTestFile(filePath string) ClientOption {
return func(o *clientOptions) {
o.testFilePath = filePath
}
}

// RunClientTests runs the Typescript client tests.
func (a App) RunClientTests(options ...ClientOption) bool {
npm, err := exec.LookPath("npm")
require.NoError(a.env.t, err, "npm binary not found")

// The root dir for the tests must be an absolute path.
// It is used as the start search point to find test files.
rootDir, err := os.Getwd()
require.NoError(a.env.t, err)

// The filename of this module is required to be able to define the location
// of the TS client test runner package to be used as working directory when
// running the tests.
_, filename, _, ok := runtime.Caller(0)
if !ok {
a.env.t.Fatal("failed to read file name")
}

opts := clientOptions{
env: map[string]string{
// Absolute path to the blockchain app directory
"TEST_CHAIN_PATH": a.path,
// Absolute path to the TS client directory
"TEST_TSCLIENT_DIR": filepath.Join(a.path, chainconfig.DefaultTSClientPath),
},
}
for _, o := range options {
o(&opts)
}

var (
output bytes.Buffer
env []string
)

// Install the dependencies needed to run TS client tests
ok = a.env.Exec("install client dependencies", step.NewSteps(
step.New(
step.Workdir(filepath.Join(a.path, chainconfig.DefaultTSClientPath)),
step.Stdout(&output),
step.Exec(npm, "install"),
step.PostExec(func(err error) error {
// Print the npm output when there is an error
if err != nil {
a.env.t.Log("\n", output.String())
}

return err
}),
),
))
if !ok {
return false
}

output.Reset()

args := []string{"run", "test", "--", "--dir", rootDir}
if opts.testName != "" {
args = append(args, "-t", opts.testName)
}

if opts.testFilePath != "" {
args = append(args, opts.testFilePath)
}

for k, v := range opts.env {
env = append(env, cmdrunner.Env(k, v))
}

// The tests are run from the TS client test runner package directory
runnerDir := filepath.Join(filepath.Dir(filename), "testdata/tstestrunner")

// TODO: Ignore stderr ? Errors are already displayed with traceback in the stdout
return a.env.Exec("run client tests", step.NewSteps(
// Make sure the test runner dependencies are installed
step.New(
step.Workdir(runnerDir),
step.Stdout(&output),
step.Exec(npm, "install"),
step.PostExec(func(err error) error {
// Print the npm output when there is an error
if err != nil {
a.env.t.Log("\n", output.String())
}

return err
}),
),
// Run the TS client tests
step.New(
step.Workdir(runnerDir),
step.Stdout(&output),
step.Env(env...),
step.PreExec(func() error {
// Clear the output from the previous step
output.Reset()

return nil
}),
step.Exec(npm, args...),
step.PostExec(func(err error) error {
// Always print tests output to be available on errors or when verbose is enabled
a.env.t.Log("\n", output.String())

return err
}),
),
))
}
87 changes: 87 additions & 0 deletions integration/cosmosgen/bank_module_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package cosmosgen_test

import (
"context"
"encoding/json"
"fmt"
"testing"

"github.com/ignite/cli/ignite/chainconfig"
"github.com/ignite/cli/ignite/pkg/xurl"
envtest "github.com/ignite/cli/integration"
"github.com/stretchr/testify/require"
)

func TestBankModule(t *testing.T) {
var (
env = envtest.New(t)
app = env.Scaffold("chain", "--no-module")
host = app.RandomizeServerPorts()
)

queryAPI, err := xurl.HTTP(host.API)
require.NoError(t, err)

txAPI, err := xurl.TCP(host.RPC)
require.NoError(t, err)

// Accounts to be included in the genesis
accounts := []chainconfig.Account{
{
Name: "account1",
Address: "cosmos1j8hw8283hj80hhq8urxaj40syrzqp77dt8qwhm",
Mnemonic: fmt.Sprint(
"toe mail light plug pact length excess predict real artwork laundry when steel ",
"online adapt clutch debate vehicle dash alter rifle virtual season almost",
),
Coins: []string{"10000token", "10000stake"},
},
{
Name: "account2",
Address: "cosmos19yy9sf00k00cjcwh532haeq8s63uhdy7qs5m2n",
Mnemonic: fmt.Sprint(
"someone major rule wrestle forget want job record coil table enter gold bracket ",
"zone tent music grow shiver width index radio matter asset when",
),
Coins: []string{"100token", "100stake"},
},
{
Name: "account3",
Address: "cosmos10957ee377t2xpwyt4mlpedjldp592h0ylt8uz7",
Mnemonic: fmt.Sprint(
"edit effort own cat chuckle rookie mechanic side tool sausage other fade math ",
"joy midnight cabin act plastic spawn loud chest invest budget rebel",
),
Coins: []string{"100token", "100stake"},
},
}

app.EditConfig(func(cfg *chainconfig.Config) {
cfg.Accounts = append(cfg.Accounts, accounts...)
})

env.Must(app.GenerateTSClient())

ctx, cancel := context.WithTimeout(env.Ctx(), envtest.ServeTimeout)
defer cancel()

go func() {
app.Serve("should serve app", envtest.ExecCtx(ctx))
}()

// Wait for the server to be up before running the client tests
err = env.IsAppServed(ctx, host)
require.NoError(t, err)

testAccounts, err := json.Marshal(accounts)
require.NoError(t, err)

env.Must(app.RunClientTests(
envtest.ClientTestFile("bank_module_test.ts"),
envtest.ClientEnv(map[string]string{
"TEST_QUERY_API": queryAPI,
"TEST_TX_API": txAPI,
"TEST_ACCOUNTS": string(testAccounts),
}),
))
}
61 changes: 61 additions & 0 deletions integration/cosmosgen/bank_module_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { describe, expect, it } from 'vitest'
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing'
import { isDeliverTxSuccess } from '@cosmjs/stargate'

describe('bank module', async () => {
const { Client } = await import('client')

it('should transfer to two different addresses', async () => {
const { account1, account2, account3 } = globalThis.accounts

const mnemonic = account1['Mnemonic']
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic)
const [account] = await wallet.getAccounts();

const denom = 'token'
const env = {
denom,
rpcURL: globalThis.txApi,
apiURL: globalThis.queryApi,
}
const client = new Client(env, wallet)

const toAddresses = [
account2['Address'],
account3['Address'],
]

// Both accounts start with 100token before the transfer
const result = await client.signAndBroadcast([
client.CosmosBankV1Beta1.tx.msgSend({
value: {
fromAddress: account.address,
toAddress: toAddresses[0],
amount: [{ denom, amount: '100' }],
}
}),
client.CosmosBankV1Beta1.tx.msgSend({
value: {
fromAddress: account.address,
toAddress: toAddresses[1],
amount: [{ denom, amount: '200' }],
}
}),
])

expect(isDeliverTxSuccess(result)).toEqual(true)

// Check that the transfers were successful
const cases = [
{ address: toAddresses[0], wantAmount: '200' },
{ address: toAddresses[1], wantAmount: '300' },
]

for (let tc of cases) {
let response = await client.CosmosBankV1Beta1.query.queryBalance(tc.address, { denom })

expect(response.statusText).toEqual('OK')
expect(response.data.balance.amount).toEqual(tc.wantAmount)
}
})
})
Loading