Verify write transactions in E2E tests #22
@ -15,6 +15,7 @@ import (
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
laconictestcli "git.vdb.to/cerc-io/laconic2d/testutil/cli"
|
||||
"git.vdb.to/cerc-io/laconic2d/testutil/network"
|
||||
types "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
|
||||
@ -74,7 +75,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
|
||||
sr.NoError(err)
|
||||
|
||||
newAddr, _ := info.GetAddress()
|
||||
_, err = clitestutil.MsgSendExec(
|
||||
out, err := clitestutil.MsgSendExec(
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
newAddr,
|
||||
@ -87,11 +88,12 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
)
|
||||
sr.NoError(err)
|
||||
*accountAddress = newAddr.String()
|
||||
|
||||
// wait for tx to take effect
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
var response sdk.TxResponse
|
||||
sr.NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, response.TxHash, 0))
|
||||
|
||||
*accountAddress = newAddr.String()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) string {
|
||||
@ -109,9 +111,7 @@ func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) stri
|
||||
|
||||
resp, err := ets.executeTx(cli.GetCmdCreateAuction(), auctionArgs, ownerAccount)
|
||||
sr.NoError(err)
|
||||
sr.Zero(resp.Code)
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, resp.TxHash, 0))
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.GetCmdList(), queryJSONFlag)
|
||||
sr.NoError(err)
|
||||
@ -127,7 +127,7 @@ func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) stri
|
||||
bidArgs := []string{auctionId, fmt.Sprintf("200%s", ets.cfg.BondDenom)}
|
||||
resp, err := ets.executeTx(cli.GetCmdCommitBid(), bidArgs, bidderAccount)
|
||||
sr.NoError(err)
|
||||
sr.Zero(resp.Code)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, resp.TxHash, 0))
|
||||
}
|
||||
|
||||
return auctionId
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
laconictestcli "git.vdb.to/cerc-io/laconic2d/testutil/cli"
|
||||
auctiontypes "git.vdb.to/cerc-io/laconic2d/x/auction"
|
||||
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
|
||||
)
|
||||
@ -51,8 +52,9 @@ func (ets *E2ETestSuite) TestTxCommitBid() {
|
||||
fmt.Sprintf("100%s", ets.cfg.BondDenom),
|
||||
}
|
||||
|
||||
_, err := ets.executeTx(cli.GetCmdCreateAuction(), auctionArgs, ownerAccount)
|
||||
resp, err := ets.executeTx(cli.GetCmdCreateAuction(), auctionArgs, ownerAccount)
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, resp.TxHash, 0))
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.GetCmdList(),
|
||||
[]string{fmt.Sprintf("--%s=json", flags.FlagOutput)})
|
||||
@ -67,7 +69,7 @@ func (ets *E2ETestSuite) TestTxCommitBid() {
|
||||
resp, err := ets.executeTx(cli.GetCmdCommitBid(), test.args, bidderAccount)
|
||||
if test.createAuction {
|
||||
sr.NoError(err)
|
||||
sr.Zero(resp.Code)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, resp.TxHash, 0))
|
||||
} else {
|
||||
sr.Error(err)
|
||||
}
|
||||
@ -96,10 +98,5 @@ func (ets *E2ETestSuite) executeTx(cmd *cobra.Command, args []string, caller str
|
||||
return sdk.TxResponse{}, err
|
||||
}
|
||||
|
||||
err = ets.network.WaitForNextBlock()
|
||||
if err != nil {
|
||||
return sdk.TxResponse{}, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
laconictestcli "git.vdb.to/cerc-io/laconic2d/testutil/cli"
|
||||
"git.vdb.to/cerc-io/laconic2d/testutil/network"
|
||||
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||
"git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
|
||||
@ -62,7 +63,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
|
||||
sr.NoError(err)
|
||||
|
||||
newAddr, _ := info.GetAddress()
|
||||
_, err = clitestutil.MsgSendExec(
|
||||
out, err := clitestutil.MsgSendExec(
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
newAddr,
|
||||
@ -75,11 +76,12 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
)
|
||||
sr.NoError(err)
|
||||
*accountAddress = newAddr.String()
|
||||
|
||||
// wait for tx to take effect
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
var response sdk.TxResponse
|
||||
sr.NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, response.TxHash, 0))
|
||||
|
||||
*accountAddress = newAddr.String()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createBond() string {
|
||||
@ -96,14 +98,12 @@ func (ets *E2ETestSuite) createBond() string {
|
||||
}
|
||||
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, createBondCmd, args)
|
||||
sr.NoError(err)
|
||||
|
||||
var d sdk.TxResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.Zero(d.Code)
|
||||
|
||||
// wait for tx to take effect
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, d.TxHash, 0))
|
||||
|
||||
// getting the bonds list and returning the bond-id
|
||||
clientCtx := val.ClientCtx
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
"github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
|
||||
laconicApp "git.vdb.to/cerc-io/laconic2d/app"
|
||||
@ -58,6 +59,7 @@ func NewTestNetworkFixture() network.TestFixture {
|
||||
GenesisState: app.DefaultGenesis(),
|
||||
EncodingConfig: testutil.MakeTestEncodingConfig(
|
||||
auth.AppModuleBasic{},
|
||||
bank.AppModuleBasic{},
|
||||
staking.AppModuleBasic{},
|
||||
auctionmodule.AppModule{},
|
||||
bondmodule.AppModule{},
|
||||
|
@ -15,6 +15,7 @@ import (
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
laconictestcli "git.vdb.to/cerc-io/laconic2d/testutil/cli"
|
||||
"git.vdb.to/cerc-io/laconic2d/testutil/network"
|
||||
bondtypes "git.vdb.to/cerc-io/laconic2d/x/bond"
|
||||
bondcli "git.vdb.to/cerc-io/laconic2d/x/bond/client/cli"
|
||||
@ -81,7 +82,7 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
|
||||
sr.NoError(err)
|
||||
|
||||
newAddr, _ := info.GetAddress()
|
||||
_, err = clitestutil.MsgSendExec(
|
||||
out, err := clitestutil.MsgSendExec(
|
||||
val.ClientCtx,
|
||||
val.Address,
|
||||
newAddr,
|
||||
@ -94,11 +95,12 @@ func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAdd
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(10))).String()),
|
||||
)
|
||||
sr.NoError(err)
|
||||
*accountAddress = newAddr.String()
|
||||
|
||||
// wait for tx to take effect
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
var response sdk.TxResponse
|
||||
sr.NoError(val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, response.TxHash, 0))
|
||||
|
||||
*accountAddress = newAddr.String()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createBond() string {
|
||||
@ -118,11 +120,7 @@ func (ets *E2ETestSuite) createBond() string {
|
||||
var d sdk.TxResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.Zero(d.Code)
|
||||
|
||||
// wait for tx to take effect
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, d.TxHash, 0))
|
||||
|
||||
// getting the bonds list and returning the bond-id
|
||||
clientCtx := val.ClientCtx
|
||||
@ -162,10 +160,7 @@ func (ets *E2ETestSuite) reserveName(authorityName string) {
|
||||
var d sdk.TxResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.Zero(d.Code)
|
||||
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, d.TxHash, 0))
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createNameRecord(authorityName string) {
|
||||
@ -189,10 +184,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) {
|
||||
var d sdk.TxResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.Zero(d.Code)
|
||||
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, d.TxHash, 0))
|
||||
|
||||
// Get the bond-id
|
||||
bondId := ets.bondId
|
||||
@ -212,10 +204,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) {
|
||||
sr.NoError(err)
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.Zero(d.Code)
|
||||
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, d.TxHash, 0))
|
||||
|
||||
args = []string{
|
||||
fmt.Sprintf("lrn://%s/", authorityName),
|
||||
@ -233,10 +222,7 @@ func (ets *E2ETestSuite) createNameRecord(authorityName string) {
|
||||
sr.NoError(err)
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.Zero(d.Code)
|
||||
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, d.TxHash, 0))
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createRecord(bondId string) {
|
||||
@ -263,10 +249,7 @@ func (ets *E2ETestSuite) createRecord(bondId string) {
|
||||
var d sdk.TxResponse
|
||||
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.Zero(d.Code, d.RawLog)
|
||||
|
||||
err = ets.network.WaitForNextBlock()
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.ClientCtx, d.TxHash, 0))
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) updateParams(params *registrytypes.Params) {
|
||||
|
43
testutil/cli/tx.go
Normal file
43
testutil/cli/tx.go
Normal file
@ -0,0 +1,43 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||
|
||||
"git.vdb.to/cerc-io/laconic2d/testutil/network"
|
||||
)
|
||||
|
||||
// Reference: https://github.com/cosmos/cosmos-sdk/blob/v0.50.3/testutil/cli/tx.go#L15
|
||||
|
||||
// CheckTxCode verifies that the transaction result returns a specific code
|
||||
// Takes a network, wait for two blocks and fetch the transaction from its hash
|
||||
func CheckTxCode(network *network.Network, clientCtx client.Context, txHash string, expectedCode uint32) error {
|
||||
// wait for 2 blocks
|
||||
for i := 0; i < 2; i++ {
|
||||
if err := network.WaitForNextBlock(); err != nil {
|
||||
return fmt.Errorf("failed to wait for next block: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
cmd := authcli.QueryTxCmd()
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, []string{txHash, fmt.Sprintf("--%s=json", flags.FlagOutput)})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var response sdk.TxResponse
|
||||
if err := clientCtx.Codec.UnmarshalJSON(out.Bytes(), &response); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if response.Code != expectedCode {
|
||||
return fmt.Errorf("expected code %d, got %d", expectedCode, response.Code)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -68,5 +68,7 @@ package network
|
||||
/*
|
||||
NOTE:
|
||||
Copied over from https://github.com/cosmos/cosmos-sdk/tree/v0.50.3/testutil/network
|
||||
Patch: Skipped network.LatestHeight() call at the end of New()
|
||||
Patch:
|
||||
- Skipped network.LatestHeight() call at the end of New()
|
||||
- Removed block timeouts
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user