2024-03-01 06:22:37 +00:00
|
|
|
package auction
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"cosmossdk.io/math"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
|
|
addresscodec "github.com/cosmos/cosmos-sdk/codec/address"
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/hd"
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
|
|
|
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
|
|
|
"github.com/cosmos/cosmos-sdk/testutil/network"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2024-03-01 09:51:36 +00:00
|
|
|
|
|
|
|
types "git.vdb.to/cerc-io/laconic2d/x/auction"
|
|
|
|
"git.vdb.to/cerc-io/laconic2d/x/auction/client/cli"
|
2024-03-01 06:22:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ownerAccount = "owner"
|
|
|
|
bidderAccount = "bidder"
|
|
|
|
ownerAddress string
|
|
|
|
bidderAddress string
|
|
|
|
)
|
|
|
|
|
|
|
|
type E2ETestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
cfg network.Config
|
|
|
|
network *network.Network
|
2024-03-01 09:51:36 +00:00
|
|
|
|
|
|
|
defaultAuctionId string
|
2024-03-01 06:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
|
|
|
return &E2ETestSuite{cfg: cfg}
|
|
|
|
}
|
|
|
|
|
2024-03-01 09:51:36 +00:00
|
|
|
func (ets *E2ETestSuite) SetupSuite() { //nolint: all
|
2024-03-02 05:18:27 +00:00
|
|
|
sr := ets.Require()
|
2024-03-01 09:51:36 +00:00
|
|
|
ets.T().Log("setting up e2e test suite")
|
2024-03-01 06:22:37 +00:00
|
|
|
|
|
|
|
var err error
|
|
|
|
|
2024-03-01 09:51:36 +00:00
|
|
|
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
2024-03-02 05:18:27 +00:00
|
|
|
sr.NoError(err)
|
2024-03-01 06:22:37 +00:00
|
|
|
|
2024-03-01 09:51:36 +00:00
|
|
|
_, err = ets.network.WaitForHeight(1)
|
2024-03-02 05:18:27 +00:00
|
|
|
sr.NoError(err)
|
2024-03-01 06:22:37 +00:00
|
|
|
|
|
|
|
// setting up random owner and bidder accounts
|
2024-03-01 09:51:36 +00:00
|
|
|
ets.createAccountWithBalance(ownerAccount, &ownerAddress)
|
|
|
|
ets.createAccountWithBalance(bidderAccount, &bidderAddress)
|
2024-03-01 06:22:37 +00:00
|
|
|
|
2024-03-01 09:51:36 +00:00
|
|
|
ets.defaultAuctionId = ets.createAuctionAndBid(true, false)
|
2024-03-01 06:22:37 +00:00
|
|
|
}
|
|
|
|
|
2024-03-01 09:51:36 +00:00
|
|
|
func (ets *E2ETestSuite) TearDownSuite() {
|
|
|
|
ets.T().Log("tearing down integration test suite")
|
|
|
|
ets.network.Cleanup()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAddress *string) {
|
|
|
|
val := ets.network.Validators[0]
|
|
|
|
sr := ets.Require()
|
2024-03-01 06:22:37 +00:00
|
|
|
|
|
|
|
info, _, err := val.ClientCtx.Keyring.NewMnemonic(accountName, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
|
|
|
|
sr.NoError(err)
|
|
|
|
|
|
|
|
newAddr, _ := info.GetAddress()
|
|
|
|
_, err = clitestutil.MsgSendExec(
|
|
|
|
val.ClientCtx,
|
|
|
|
val.Address,
|
|
|
|
newAddr,
|
2024-03-01 09:51:36 +00:00
|
|
|
sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(200000))),
|
2024-03-01 06:22:37 +00:00
|
|
|
addresscodec.NewBech32Codec("laconic"),
|
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFrom, accountName),
|
|
|
|
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
|
|
|
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
2024-03-02 05:18:27 +00:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
2024-03-01 09:51:36 +00:00
|
|
|
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(10))).String()),
|
2024-03-01 06:22:37 +00:00
|
|
|
)
|
|
|
|
sr.NoError(err)
|
|
|
|
*accountAddress = newAddr.String()
|
2024-03-02 05:18:27 +00:00
|
|
|
|
|
|
|
// wait for tx to take effect
|
|
|
|
err = ets.network.WaitForNextBlock()
|
|
|
|
sr.NoError(err)
|
2024-03-01 06:22:37 +00:00
|
|
|
}
|
2024-03-01 09:51:36 +00:00
|
|
|
|
|
|
|
func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) string {
|
|
|
|
val := ets.network.Validators[0]
|
|
|
|
sr := ets.Require()
|
|
|
|
auctionId := ""
|
|
|
|
|
|
|
|
if createAuction {
|
|
|
|
auctionArgs := []string{
|
|
|
|
sampleCommitTime, sampleRevealTime,
|
|
|
|
fmt.Sprintf("10%s", ets.cfg.BondDenom),
|
|
|
|
fmt.Sprintf("10%s", ets.cfg.BondDenom),
|
|
|
|
fmt.Sprintf("100%s", ets.cfg.BondDenom),
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := ets.executeTx(cli.GetCmdCreateAuction(), auctionArgs, ownerAccount)
|
|
|
|
sr.NoError(err)
|
|
|
|
sr.Zero(resp.Code)
|
|
|
|
out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cli.GetCmdList(), queryJSONFlag)
|
|
|
|
sr.NoError(err)
|
|
|
|
var queryResponse types.QueryAuctionsResponse
|
|
|
|
err = val.ClientCtx.Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
|
|
|
sr.NoError(err)
|
|
|
|
auctionId = queryResponse.Auctions.Auctions[0].Id
|
|
|
|
} else {
|
|
|
|
auctionId = ets.defaultAuctionId
|
|
|
|
}
|
|
|
|
|
|
|
|
if createBid {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
return auctionId
|
|
|
|
}
|