[wip: convert to system test] remove tests/e2e
fix integration test
This commit is contained in:
parent
b55e05e4ec
commit
78da408563
@ -1,18 +0,0 @@
|
||||
package auction
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/tests/e2e"
|
||||
)
|
||||
|
||||
func TestAuctionE2ETestSuite(t *testing.T) {
|
||||
// e2e.RunTestSuite(t)
|
||||
cfg := network.DefaultConfig(e2e.NewTestNetworkFixture)
|
||||
cfg.NumValidators = 1
|
||||
|
||||
suite.Run(t, NewE2ETestSuite(cfg))
|
||||
}
|
@ -1,263 +0,0 @@
|
||||
package auction
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
|
||||
auctiontypes "git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
)
|
||||
|
||||
const (
|
||||
randomAuctionId = "randomAuctionId"
|
||||
randomBidderAddress = "randomBidderAddress"
|
||||
randomOwnerAddress = "randomOwnerAddress"
|
||||
)
|
||||
|
||||
func (ets *E2ETestSuite) TestQueryParamsGrpc() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := fmt.Sprintf("%s/cerc/auction/v1/params", val.GetAPIAddress())
|
||||
|
||||
ets.Run("valid request to get auction params", func() {
|
||||
resp, err := testutil.GetRequest(reqURL)
|
||||
ets.Require().NoError(err)
|
||||
|
||||
var params auctiontypes.QueryParamsResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, ¶ms)
|
||||
|
||||
sr.NoError(err)
|
||||
sr.Equal(*params.GetParams(), auctiontypes.DefaultParams())
|
||||
})
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGetAllAuctionsGrpc() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := fmt.Sprintf("%s/cerc/auction/v1/auctions", val.GetAPIAddress())
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
url string
|
||||
errorMsg string
|
||||
isErrorExpected bool
|
||||
}{
|
||||
{
|
||||
"invalid request to get all auctions",
|
||||
reqURL + randomAuctionId,
|
||||
"",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"valid request to get all auctions",
|
||||
reqURL,
|
||||
"",
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.msg, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
if tc.isErrorExpected {
|
||||
sr.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
var auctions auctiontypes.QueryAuctionsResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &auctions)
|
||||
sr.NoError(err)
|
||||
sr.NotZero(len(auctions.Auctions.Auctions))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGetAuctionGrpc() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := fmt.Sprintf("%s/cerc/auction/v1/auctions/", val.GetAPIAddress())
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
url string
|
||||
errorMsg string
|
||||
isErrorExpected bool
|
||||
preRun func() string
|
||||
}{
|
||||
{
|
||||
"invalid request to get an auction",
|
||||
reqURL + randomAuctionId,
|
||||
"",
|
||||
true,
|
||||
func() string { return "" },
|
||||
},
|
||||
{
|
||||
"valid request to get an auction",
|
||||
reqURL,
|
||||
"",
|
||||
false,
|
||||
func() string { return ets.defaultAuctionId },
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.msg, func() {
|
||||
auctionId := tc.preRun()
|
||||
resp, err := testutil.GetRequest(tc.url + auctionId)
|
||||
if tc.isErrorExpected {
|
||||
sr.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
var auction auctiontypes.QueryGetAuctionResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &auction)
|
||||
sr.NoError(err)
|
||||
sr.Equal(auctionId, auction.Auction.Id)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGetBidsGrpc() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := fmt.Sprintf("%s/cerc/auction/v1/bids/", val.GetAPIAddress())
|
||||
testCases := []struct {
|
||||
msg string
|
||||
url string
|
||||
errorMsg string
|
||||
isErrorExpected bool
|
||||
preRun func() string
|
||||
}{
|
||||
{
|
||||
"invalid request to get all bids",
|
||||
reqURL,
|
||||
"",
|
||||
true,
|
||||
func() string { return "" },
|
||||
},
|
||||
{
|
||||
"valid request to get all bids",
|
||||
reqURL,
|
||||
"",
|
||||
false,
|
||||
func() string { return ets.createAuctionAndBid(false, true) },
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.msg, func() {
|
||||
auctionId := tc.preRun()
|
||||
tc.url += auctionId
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
if tc.isErrorExpected {
|
||||
sr.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
var bids auctiontypes.QueryGetBidsResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &bids)
|
||||
sr.NoError(err)
|
||||
sr.Equal(auctionId, bids.Bids[0].AuctionId)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGetBidGrpc() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := fmt.Sprintf("%s/cerc/auction/v1/bids/", val.GetAPIAddress())
|
||||
testCases := []struct {
|
||||
msg string
|
||||
url string
|
||||
errorMsg string
|
||||
isErrorExpected bool
|
||||
preRun func() string
|
||||
}{
|
||||
{
|
||||
"invalid request to get bid",
|
||||
reqURL,
|
||||
"",
|
||||
true,
|
||||
func() string { return randomAuctionId },
|
||||
},
|
||||
{
|
||||
"valid request to get bid",
|
||||
reqURL,
|
||||
"",
|
||||
false,
|
||||
func() string { return ets.createAuctionAndBid(false, true) },
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.msg, func() {
|
||||
auctionId := tc.preRun()
|
||||
tc.url += auctionId + "/" + bidderAddress
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
|
||||
if tc.isErrorExpected {
|
||||
sr.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
var bid auctiontypes.QueryGetBidResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &bid)
|
||||
sr.NoError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGetAuctionsByOwnerGrpc() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := fmt.Sprintf("%s/cerc/auction/v1/by-owner/", val.GetAPIAddress())
|
||||
testCases := []struct {
|
||||
msg string
|
||||
url string
|
||||
errorMsg string
|
||||
isErrorExpected bool
|
||||
}{
|
||||
{
|
||||
"invalid request to get auctions by owner",
|
||||
reqURL,
|
||||
"",
|
||||
true,
|
||||
},
|
||||
{
|
||||
"valid request to get auctions by owner",
|
||||
fmt.Sprintf("%s/%s", reqURL, ownerAddress),
|
||||
"",
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.msg, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
if tc.isErrorExpected {
|
||||
sr.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
var auctions auctiontypes.QueryAuctionsResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &auctions)
|
||||
sr.NoError(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestQueryBalanceGrpc() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := fmt.Sprintf("%s/cerc/auction/v1/balance", val.GetAPIAddress())
|
||||
msg := "valid request to get the auction module balance"
|
||||
|
||||
ets.createAuctionAndBid(false, true)
|
||||
|
||||
ets.Run(msg, func() {
|
||||
resp, err := testutil.GetRequest(reqURL)
|
||||
sr.NoError(err)
|
||||
|
||||
var response auctiontypes.QueryGetAuctionModuleBalanceResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
|
||||
sr.NoError(err)
|
||||
sr.NotZero(len(response.GetBalance()))
|
||||
})
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package auction
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
|
||||
types "git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
"git.vdb.to/cerc-io/laconicd/x/auction/client/cli"
|
||||
)
|
||||
|
||||
var queryJSONFlag = []string{fmt.Sprintf("--%s=json", flags.FlagOutput)}
|
||||
|
||||
func (ets *E2ETestSuite) TestGetCmdList() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
|
||||
testCases := []struct {
|
||||
msg string
|
||||
createAuction bool
|
||||
}{
|
||||
{
|
||||
"list auctions when no auctions exist",
|
||||
false,
|
||||
},
|
||||
{
|
||||
"list auctions after creating an auction",
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
ets.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||
out, err := clitestutil.ExecTestCLICmd(val.GetClientCtx(), cli.GetCmdList(), queryJSONFlag)
|
||||
sr.NoError(err)
|
||||
var auctions types.QueryAuctionsResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &auctions)
|
||||
sr.NoError(err)
|
||||
if test.createAuction {
|
||||
sr.NotZero(len(auctions.Auctions.Auctions))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
package auction
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
banktypes "cosmossdk.io/x/bank/types"
|
||||
"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"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
laconictestcli "git.vdb.to/cerc-io/laconicd/testutil/cli"
|
||||
types "git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
"git.vdb.to/cerc-io/laconicd/x/auction/client/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
ownerAccount = "owner"
|
||||
bidderAccount = "bidder"
|
||||
ownerAddress string
|
||||
bidderAddress string
|
||||
)
|
||||
|
||||
type E2ETestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cfg network.Config
|
||||
network network.NetworkI
|
||||
|
||||
defaultAuctionId string
|
||||
}
|
||||
|
||||
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
return &E2ETestSuite{cfg: cfg}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) SetupSuite() { //nolint: all
|
||||
sr := ets.Require()
|
||||
ets.T().Log("setting up e2e test suite")
|
||||
|
||||
var err error
|
||||
|
||||
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
||||
sr.NoError(err)
|
||||
|
||||
_, err = ets.network.WaitForHeight(1)
|
||||
sr.NoError(err)
|
||||
|
||||
// setting up random owner and bidder accounts
|
||||
ets.createAccountWithBalance(ownerAccount, &ownerAddress)
|
||||
ets.createAccountWithBalance(bidderAccount, &bidderAddress)
|
||||
|
||||
ets.defaultAuctionId = ets.createAuctionAndBid(true, false)
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TearDownSuite() {
|
||||
ets.T().Log("tearing down integration test suite")
|
||||
ets.network.Cleanup()
|
||||
|
||||
ets.cleanupBidFiles()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAddress *string) {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
|
||||
info, _, err := val.GetClientCtx().Keyring.NewMnemonic(accountName, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
|
||||
sr.NoError(err)
|
||||
|
||||
newAddr, _ := info.GetAddress()
|
||||
msgSend := &banktypes.MsgSend{
|
||||
FromAddress: newAddr.String(),
|
||||
ToAddress: val.GetAddress().String(),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(200000))),
|
||||
}
|
||||
out, err := clitestutil.SubmitTestTx(
|
||||
val.GetClientCtx(),
|
||||
msgSend,
|
||||
newAddr,
|
||||
clitestutil.TestTxConfig{
|
||||
Fee: sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(10))),
|
||||
},
|
||||
)
|
||||
sr.NoError(err)
|
||||
|
||||
var response sdk.TxResponse
|
||||
sr.NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.GetClientCtx(), response.TxHash, 0))
|
||||
|
||||
*accountAddress = newAddr.String()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createAuctionAndBid(createAuction, createBid bool) string {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
auctionId := ""
|
||||
|
||||
if createAuction {
|
||||
auctionArgs := []string{
|
||||
types.AuctionKindVickrey,
|
||||
sampleCommitTime, sampleRevealTime,
|
||||
fmt.Sprintf("10%s", ets.cfg.BondDenom),
|
||||
fmt.Sprintf("10%s", ets.cfg.BondDenom),
|
||||
fmt.Sprintf("100%s", ets.cfg.BondDenom),
|
||||
fmt.Sprintf("0%s", ets.cfg.BondDenom),
|
||||
"0",
|
||||
}
|
||||
|
||||
resp, err := ets.executeTx(cli.GetCmdCreateAuction(), auctionArgs, ownerAccount)
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.GetClientCtx(), resp.TxHash, 0))
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(val.GetClientCtx(), cli.GetCmdList(), queryJSONFlag)
|
||||
sr.NoError(err)
|
||||
var queryResponse types.QueryAuctionsResponse
|
||||
err = val.GetClientCtx().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.NoError(laconictestcli.CheckTxCode(ets.network, val.GetClientCtx(), resp.TxHash, 0))
|
||||
}
|
||||
|
||||
return auctionId
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) cleanupBidFiles() {
|
||||
matches, err := filepath.Glob(fmt.Sprintf("%s-*.json", bidderAccount))
|
||||
if err != nil {
|
||||
ets.T().Errorf("Error matching bidder files: %v\n", err)
|
||||
}
|
||||
|
||||
for _, match := range matches {
|
||||
err := os.Remove(match)
|
||||
if err != nil {
|
||||
ets.T().Errorf("Error removing bidder file: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
package auction
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
laconictestcli "git.vdb.to/cerc-io/laconicd/testutil/cli"
|
||||
auctiontypes "git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
"git.vdb.to/cerc-io/laconicd/x/auction/client/cli"
|
||||
)
|
||||
|
||||
const (
|
||||
sampleCommitTime = "90s"
|
||||
sampleRevealTime = "5s"
|
||||
placeholderAuctionId = "placeholder_auction_id"
|
||||
)
|
||||
|
||||
func (ets *E2ETestSuite) TestTxCommitBid() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
testCases := []struct {
|
||||
msg string
|
||||
args []string
|
||||
createAuction bool
|
||||
}{
|
||||
{
|
||||
"commit bid with missing args",
|
||||
[]string{fmt.Sprintf("200%s", ets.cfg.BondDenom)},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"commit bid with valid args",
|
||||
[]string{
|
||||
placeholderAuctionId,
|
||||
fmt.Sprintf("200%s", ets.cfg.BondDenom),
|
||||
},
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
ets.Run(fmt.Sprintf("Case %s", test.msg), func() {
|
||||
if test.createAuction {
|
||||
auctionArgs := []string{
|
||||
auctiontypes.AuctionKindVickrey,
|
||||
sampleCommitTime, sampleRevealTime,
|
||||
fmt.Sprintf("10%s", ets.cfg.BondDenom),
|
||||
fmt.Sprintf("10%s", ets.cfg.BondDenom),
|
||||
fmt.Sprintf("100%s", ets.cfg.BondDenom),
|
||||
fmt.Sprintf("0%s", ets.cfg.BondDenom),
|
||||
"0",
|
||||
}
|
||||
|
||||
resp, err := ets.executeTx(cli.GetCmdCreateAuction(), auctionArgs, ownerAccount)
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.GetClientCtx(), resp.TxHash, 0))
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(val.GetClientCtx(), cli.GetCmdList(),
|
||||
[]string{fmt.Sprintf("--%s=json", flags.FlagOutput)})
|
||||
sr.NoError(err)
|
||||
var queryResponse auctiontypes.QueryAuctionsResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
||||
sr.NoError(err)
|
||||
sr.NotNil(queryResponse.GetAuctions())
|
||||
test.args[0] = queryResponse.GetAuctions().Auctions[0].Id
|
||||
}
|
||||
|
||||
resp, err := ets.executeTx(cli.GetCmdCommitBid(), test.args, bidderAccount)
|
||||
if test.createAuction {
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.GetClientCtx(), resp.TxHash, 0))
|
||||
} else {
|
||||
sr.Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) executeTx(cmd *cobra.Command, args []string, caller string) (sdk.TxResponse, error) {
|
||||
val := ets.network.GetValidators()[0]
|
||||
additionalArgs := []string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, caller),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
|
||||
}
|
||||
args = append(args, additionalArgs...)
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(val.GetClientCtx(), cmd, args)
|
||||
if err != nil {
|
||||
return sdk.TxResponse{}, err
|
||||
}
|
||||
|
||||
var resp sdk.TxResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &resp)
|
||||
if err != nil {
|
||||
return sdk.TxResponse{}, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package bond
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/tests/e2e"
|
||||
)
|
||||
|
||||
func TestBondE2ETestSuite(t *testing.T) {
|
||||
// e2e.RunTestSuite(t)
|
||||
cfg := network.DefaultConfig(e2e.NewTestNetworkFixture)
|
||||
cfg.NumValidators = 1
|
||||
|
||||
suite.Run(t, NewE2ETestSuite(cfg))
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
package bond
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
|
||||
bondtypes "git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
)
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCGetParams() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := fmt.Sprintf("%s/cerc/bond/v1/params", val.GetAPIAddress())
|
||||
|
||||
resp, err := testutil.GetRequest(reqURL)
|
||||
ets.Require().NoError(err)
|
||||
|
||||
var params bondtypes.QueryParamsResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, ¶ms)
|
||||
|
||||
sr.NoError(err)
|
||||
sr.Equal(params.GetParams().MaxBondAmount, bondtypes.DefaultParams().MaxBondAmount)
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCGetBonds() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := fmt.Sprintf("%s/cerc/bond/v1/bonds", val.GetAPIAddress())
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
errorMsg string
|
||||
preRun func() string
|
||||
}{
|
||||
{
|
||||
"invalid request with headers",
|
||||
reqURL + "asdasdas",
|
||||
true,
|
||||
"",
|
||||
func() string { return "" },
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
reqURL,
|
||||
false,
|
||||
"",
|
||||
func() string { return ets.createBond() },
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
tc.preRun()
|
||||
|
||||
resp, _ := testutil.GetRequest(tc.url)
|
||||
if tc.expErr {
|
||||
sr.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
var response bondtypes.QueryBondsResponse
|
||||
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
sr.NoError(err)
|
||||
sr.NotZero(len(response.GetBonds()))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCGetBondsByOwner() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := val.GetAPIAddress() + "/cerc/bond/v1/by-owner/%s"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
preRun func() string
|
||||
}{
|
||||
{
|
||||
"empty list",
|
||||
fmt.Sprintf(reqURL, "asdasd"),
|
||||
true,
|
||||
func() string { return "" },
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
fmt.Sprintf(reqURL, ets.accountAddress),
|
||||
false,
|
||||
func() string { return ets.createBond() },
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
tc.preRun()
|
||||
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.Require().NoError(err)
|
||||
|
||||
var bonds bondtypes.QueryGetBondsByOwnerResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &bonds)
|
||||
sr.NoError(err)
|
||||
if tc.expErr {
|
||||
sr.Empty(bonds.GetBonds())
|
||||
} else {
|
||||
bondsList := bonds.GetBonds()
|
||||
sr.NotZero(len(bondsList))
|
||||
sr.Equal(ets.accountAddress, bondsList[0].GetOwner())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCGetBondById() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := val.GetAPIAddress() + "/cerc/bond/v1/bonds/%s"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expErr bool
|
||||
preRun func() string
|
||||
}{
|
||||
{
|
||||
"invalid request",
|
||||
fmt.Sprintf(reqURL, "asdadad"),
|
||||
true,
|
||||
func() string { return "" },
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
reqURL,
|
||||
false,
|
||||
func() string { return ets.createBond() },
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
var bondId string
|
||||
if !tc.expErr {
|
||||
bondId = tc.preRun()
|
||||
tc.url = fmt.Sprintf(reqURL, bondId)
|
||||
}
|
||||
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.Require().NoError(err)
|
||||
|
||||
var bonds bondtypes.QueryGetBondByIdResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &bonds)
|
||||
|
||||
if tc.expErr {
|
||||
sr.Empty(bonds.GetBond().GetId())
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
sr.NotZero(bonds.GetBond().GetId())
|
||||
sr.Equal(bonds.GetBond().GetId(), bondId)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCGetBondModuleBalance() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := fmt.Sprintf("%s/cerc/bond/v1/balance", val.GetAPIAddress())
|
||||
|
||||
// creating the bond
|
||||
ets.createBond()
|
||||
|
||||
ets.Run("valid request", func() {
|
||||
resp, err := testutil.GetRequest(reqURL)
|
||||
sr.NoError(err)
|
||||
|
||||
var response bondtypes.QueryGetBondModuleBalanceResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
|
||||
sr.NoError(err)
|
||||
sr.False(response.GetBalance().IsZero())
|
||||
})
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package bond
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
|
||||
bondtypes "git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
"git.vdb.to/cerc-io/laconicd/x/bond/client/cli"
|
||||
)
|
||||
|
||||
func (ets *E2ETestSuite) TestGetQueryBondList() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
createBond bool
|
||||
preRun func()
|
||||
}{
|
||||
{
|
||||
"create and get bond lists",
|
||||
[]string{fmt.Sprintf("--%s=json", flags.FlagOutput)},
|
||||
true,
|
||||
func() {
|
||||
ets.createBond()
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(fmt.Sprintf("Case %s", tc.name), func() {
|
||||
clientCtx := val.GetClientCtx()
|
||||
if tc.createBond {
|
||||
tc.preRun()
|
||||
}
|
||||
|
||||
cmd := cli.GetQueryBondList()
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
sr.NoError(err)
|
||||
var queryResponse bondtypes.QueryBondsResponse
|
||||
err = clientCtx.Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
||||
sr.NoError(err)
|
||||
sr.NotZero(len(queryResponse.GetBonds()))
|
||||
})
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
package bond
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
banktypes "cosmossdk.io/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"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"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
laconictestcli "git.vdb.to/cerc-io/laconicd/testutil/cli"
|
||||
bondtypes "git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
"git.vdb.to/cerc-io/laconicd/x/bond/client/cli"
|
||||
)
|
||||
|
||||
type E2ETestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
cfg network.Config
|
||||
network network.NetworkI
|
||||
|
||||
accountName string
|
||||
accountAddress string
|
||||
}
|
||||
|
||||
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
return &E2ETestSuite{cfg: cfg}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) SetupSuite() { //nolint: all
|
||||
sr := ets.Require()
|
||||
ets.T().Log("setting up e2e test suite")
|
||||
|
||||
var err error
|
||||
|
||||
ets.network, err = network.New(ets.T(), ets.T().TempDir(), ets.cfg)
|
||||
sr.NoError(err)
|
||||
|
||||
_, err = ets.network.WaitForHeight(1)
|
||||
sr.NoError(err)
|
||||
|
||||
// setting up random account
|
||||
ets.accountName = "accountName"
|
||||
ets.createAccountWithBalance(ets.accountName, &ets.accountAddress)
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TearDownSuite() {
|
||||
ets.T().Log("tearing down e2e test suite")
|
||||
ets.network.Cleanup()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAddress *string) {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
|
||||
info, _, err := val.GetClientCtx().Keyring.NewMnemonic(accountName, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
|
||||
sr.NoError(err)
|
||||
|
||||
newAddr, _ := info.GetAddress()
|
||||
msgSend := &banktypes.MsgSend{
|
||||
FromAddress: newAddr.String(),
|
||||
ToAddress: val.GetAddress().String(),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(200000))),
|
||||
}
|
||||
out, err := clitestutil.SubmitTestTx(
|
||||
val.GetClientCtx(),
|
||||
msgSend,
|
||||
newAddr,
|
||||
clitestutil.TestTxConfig{
|
||||
Fee: sdk.NewCoins(sdk.NewCoin(ets.cfg.BondDenom, math.NewInt(10))),
|
||||
},
|
||||
)
|
||||
sr.NoError(err)
|
||||
|
||||
var response sdk.TxResponse
|
||||
sr.NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.GetClientCtx(), response.TxHash, 0))
|
||||
|
||||
*accountAddress = newAddr.String()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createBond() string {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
createBondCmd := cli.NewCreateBondCmd()
|
||||
args := []string{
|
||||
fmt.Sprintf("10%s", ets.cfg.BondDenom),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
|
||||
}
|
||||
out, err := clitestutil.ExecTestCLICmd(val.GetClientCtx(), createBondCmd, args)
|
||||
sr.NoError(err)
|
||||
|
||||
var d sdk.TxResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.Zero(d.Code)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.network, val.GetClientCtx(), d.TxHash, 0))
|
||||
|
||||
// getting the bonds list and returning the bond-id
|
||||
clientCtx := val.GetClientCtx()
|
||||
cmd := cli.GetQueryBondList()
|
||||
args = []string{
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
}
|
||||
out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
sr.NoError(err)
|
||||
var queryResponse bondtypes.QueryBondsResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
||||
sr.NoError(err)
|
||||
|
||||
// extract bond id from bonds list
|
||||
bonds := queryResponse.GetBonds()
|
||||
sr.NotEmpty(bonds)
|
||||
|
||||
return queryResponse.GetBonds()[0].GetId()
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package bond
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/x/bond/client/cli"
|
||||
)
|
||||
|
||||
func (ets *E2ETestSuite) TestTxCreateBond() {
|
||||
val := ets.network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
"without deposit",
|
||||
[]string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"create bond",
|
||||
[]string{
|
||||
fmt.Sprintf("10%s", ets.cfg.BondDenom),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.cfg.BondDenom)),
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(fmt.Sprintf("Case %s", tc.name), func() {
|
||||
clientCtx := val.GetClientCtx()
|
||||
cmd := cli.NewCreateBondCmd()
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.err {
|
||||
sr.Error(err)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
var d sdk.TxResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.Nil(err)
|
||||
sr.NoError(err)
|
||||
sr.Zero(d.Code)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
serverv2 "cosmossdk.io/server/v2"
|
||||
"cosmossdk.io/server/v2/cometbft/mempool"
|
||||
"cosmossdk.io/x/bank"
|
||||
"cosmossdk.io/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
|
||||
serverv1types "github.com/cosmos/cosmos-sdk/server/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil/network"
|
||||
"github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/app"
|
||||
laconicApp "git.vdb.to/cerc-io/laconicd/app"
|
||||
auctionmodule "git.vdb.to/cerc-io/laconicd/x/auction/module"
|
||||
bondmodule "git.vdb.to/cerc-io/laconicd/x/bond/module"
|
||||
registrymodule "git.vdb.to/cerc-io/laconicd/x/registry/module"
|
||||
|
||||
_ "cosmossdk.io/runtime/v2" // import for side-effects
|
||||
_ "git.vdb.to/cerc-io/laconicd/app/params" // import for side-effects (see init)
|
||||
"git.vdb.to/cerc-io/laconicd/cmd/laconicd/cmd"
|
||||
)
|
||||
|
||||
// NewTestNetworkFixture returns a new LaconicApp AppConstructor for network simulation tests
|
||||
func NewTestNetworkFixture() network.TestFixture {
|
||||
dir, err := os.MkdirTemp("", "laconic")
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed creating temporary directory: %v", err))
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
// logfile := "/Users/roy/vulcanize/dump/laconic-debug/e2e_depinject.log"
|
||||
// var genapp *app.AppBuilder
|
||||
// if err := depinject.InjectDebug(
|
||||
// depinject.DebugOptions(
|
||||
// depinject.FileLogger(logfile),
|
||||
// ),
|
||||
// depinject.Configs(
|
||||
// app.AppConfig(),
|
||||
// depinject.Supply(
|
||||
// log.NewNopLogger(),
|
||||
// ),
|
||||
// ),
|
||||
// &genapp); err != nil {
|
||||
// panic(fmt.Errorf("failed to initialize app builder: %w", err))
|
||||
// }
|
||||
|
||||
vp := viper.New()
|
||||
vp.Set(flags.FlagHome, dir)
|
||||
genapp, err := laconicApp.NewLaconicApp(log.NewNopLogger(), vp, true)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create laconic app: %v", err))
|
||||
}
|
||||
|
||||
appConstructor := func(val network.ValidatorI) serverv1types.Application {
|
||||
vp := val.GetViper()
|
||||
vp.Set(flags.FlagHome, dir)
|
||||
|
||||
// viper.SetString(flags.FlagHome, ?)
|
||||
vp.Set(serverv2.FlagMinGasPrices, val.GetAppConfig().MinGasPrices)
|
||||
// bam.SetChainID(val.GetClientCtx().Viper.GetString(flags.FlagChainID)),
|
||||
app, err := laconicApp.NewLaconicApp(
|
||||
val.GetLogger(), val.GetViper(), true,
|
||||
// simtestutil.NewAppOptionsWithFlagHome(val.GetViper().GetString(flags.FlagHome)),
|
||||
// bam.SetPruning(pruningtypes.NewPruningOptionsFromString(val.GetAppConfig().Pruning)),
|
||||
// bam.SetMinGasPrices(val.GetAppConfig().MinGasPrices),
|
||||
// bam.SetChainID(val.GetClientCtx().Viper.GetString(flags.FlagChainID)),
|
||||
)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed creating temporary directory: %v", err))
|
||||
}
|
||||
|
||||
abci, err := setUpConsensus(
|
||||
val.GetLogger(), 100_000, mempool.NoOpMempool[laconicApp.Tx]{},
|
||||
dir, val.GetClientCtx().TxConfig)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to build ABCI app: %w", err))
|
||||
}
|
||||
return &serverAppV1{App: app, ABCI: abci}
|
||||
}
|
||||
|
||||
return network.TestFixture{
|
||||
AppConstructor: appConstructor,
|
||||
GenesisState: genapp.DefaultGenesis(),
|
||||
EncodingConfig: testutil.MakeTestEncodingConfig(
|
||||
codectestutil.CodecOptions{},
|
||||
auth.AppModule{},
|
||||
bank.AppModule{},
|
||||
staking.AppModule{},
|
||||
auctionmodule.AppModule{},
|
||||
bondmodule.AppModule{},
|
||||
registrymodule.AppModule{},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// type BaseE2ETestSuite struct {
|
||||
// suite.Suite
|
||||
|
||||
// Config network.Config
|
||||
// Network network.NetworkI
|
||||
// }
|
||||
|
||||
func MakeNetworkConfig() network.Config {
|
||||
logfile := "/Users/roy/vulcanize/dump/laconic-debug/e2e_depinject.log"
|
||||
var clientCtx client.Context
|
||||
if err := depinject.InjectDebug(
|
||||
depinject.DebugOptions(
|
||||
depinject.FileLogger(logfile),
|
||||
),
|
||||
depinject.Configs(
|
||||
app.AppConfig(),
|
||||
depinject.Supply(
|
||||
log.NewNopLogger(),
|
||||
),
|
||||
depinject.Provide(
|
||||
cmd.ProvideClientContext,
|
||||
cmd.ProvideKeyring,
|
||||
),
|
||||
),
|
||||
&clientCtx); err != nil {
|
||||
panic(fmt.Errorf("failed to initialize app builder: %w", err))
|
||||
}
|
||||
|
||||
cfg := network.DefaultConfig(NewTestNetworkFixture)
|
||||
cfg.NumValidators = 1
|
||||
|
||||
// cfg.Codec = clientCtx.Codec
|
||||
cfg.InterfaceRegistry = clientCtx.InterfaceRegistry
|
||||
cfg.TxConfig = clientCtx.TxConfig
|
||||
cfg.AccountRetriever = clientCtx.AccountRetriever
|
||||
cfg.KeyringOptions = clientCtx.KeyringOptions
|
||||
// cfg.MinGasPrices =
|
||||
cfg.AddressCodec = clientCtx.AddressCodec
|
||||
cfg.ValidatorAddressCodec = clientCtx.ValidatorAddressCodec
|
||||
cfg.ConsensusAddressCodec = clientCtx.ConsensusAddressCodec
|
||||
|
||||
return cfg
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/tests/e2e"
|
||||
)
|
||||
|
||||
func TestRegistryE2ETestSuite(t *testing.T) {
|
||||
// cfg := network.DefaultConfig(e2e.NewTestNetworkFixture)
|
||||
// cfg.NumValidators = 1
|
||||
|
||||
suite.Run(t, NewE2ETestSuite(e2e.MakeNetworkConfig()))
|
||||
// e2e.RunTestSuite(t)
|
||||
}
|
@ -1,429 +0,0 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
|
||||
registrytypes "git.vdb.to/cerc-io/laconicd/x/registry"
|
||||
"git.vdb.to/cerc-io/laconicd/x/registry/client/cli"
|
||||
)
|
||||
|
||||
const badPath = "/asdasd"
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCQueryParams() {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := val.GetAPIAddress() + "/cerc/registry/v1/params"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
}{
|
||||
{
|
||||
"invalid request",
|
||||
reqURL + badPath,
|
||||
true,
|
||||
"",
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
reqURL,
|
||||
false,
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.NoError(err)
|
||||
require := ets.Require()
|
||||
if tc.expectErr {
|
||||
require.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
var response registrytypes.QueryParamsResponse
|
||||
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
sr.NoError(err)
|
||||
|
||||
params := registrytypes.DefaultParams()
|
||||
ets.updateParams(¶ms)
|
||||
sr.Equal(params.String(), response.GetParams().String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCQueryWhoIs() {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqUrl := val.GetAPIAddress() + "/cerc/registry/v1/whois/%s"
|
||||
authorityName := "QueryWhoIS"
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
preRun func(authorityName string)
|
||||
}{
|
||||
{
|
||||
"invalid url",
|
||||
reqUrl + badPath,
|
||||
true,
|
||||
"",
|
||||
func(authorityName string) {
|
||||
},
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
reqUrl,
|
||||
false,
|
||||
"",
|
||||
func(authorityName string) { ets.reserveName(authorityName) },
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
tc.preRun(authorityName)
|
||||
tc.url = fmt.Sprintf(tc.url, authorityName)
|
||||
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.NoError(err)
|
||||
require := ets.Require()
|
||||
if tc.expectErr {
|
||||
require.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
var response registrytypes.QueryWhoisResponse
|
||||
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
sr.NoError(err)
|
||||
sr.Equal(registrytypes.AuthorityActive, response.GetNameAuthority().Status)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCQueryLookup() {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := val.GetAPIAddress() + "/cerc/registry/v1/lookup"
|
||||
authorityName := "QueryLookUp"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
preRun func(authorityName string)
|
||||
}{
|
||||
{
|
||||
"invalid url",
|
||||
reqURL + badPath,
|
||||
true,
|
||||
"",
|
||||
func(authorityName string) {
|
||||
},
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
fmt.Sprintf(reqURL+"?lrn=lrn://%s/", authorityName),
|
||||
false,
|
||||
"",
|
||||
func(authorityName string) {
|
||||
// create name record
|
||||
ets.createNameRecord(authorityName)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
tc.preRun(authorityName)
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.NoError(err)
|
||||
if tc.expectErr {
|
||||
sr.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
var response registrytypes.QueryLookupLrnResponse
|
||||
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
sr.NoError(err)
|
||||
sr.NotZero(len(response.Name.Latest.Id))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCQueryListRecords() {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqUrl := val.GetAPIAddress() + "/cerc/registry/v1/records"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
preRun func(bondId string)
|
||||
}{
|
||||
{
|
||||
"invalid url",
|
||||
reqUrl + badPath,
|
||||
true,
|
||||
"",
|
||||
func(bondId string) {
|
||||
},
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
reqUrl,
|
||||
false,
|
||||
"",
|
||||
func(bondId string) { ets.createRecord(bondId) },
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
tc.preRun(ets.bondId)
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.NoError(err)
|
||||
require := ets.Require()
|
||||
if tc.expectErr {
|
||||
require.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
var response registrytypes.QueryRecordsResponse
|
||||
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
sr.NoError(err)
|
||||
sr.NotZero(len(response.GetRecords()))
|
||||
sr.Equal(ets.bondId, response.GetRecords()[0].GetBondId())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCQueryGetRecordById() {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := val.GetAPIAddress() + "/cerc/registry/v1/records/%s"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
preRun func(bondId string) string
|
||||
}{
|
||||
{
|
||||
"invalid url",
|
||||
reqURL + badPath,
|
||||
true,
|
||||
"",
|
||||
func(bondId string) string {
|
||||
return ""
|
||||
},
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
reqURL,
|
||||
false,
|
||||
"",
|
||||
func(bondId string) string {
|
||||
// creating the record
|
||||
ets.createRecord(bondId)
|
||||
|
||||
// list the records
|
||||
clientCtx := val.GetClientCtx()
|
||||
cmd := cli.GetCmdList()
|
||||
args := []string{
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
}
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
sr.NoError(err)
|
||||
var records []registrytypes.ReadableRecord
|
||||
err = json.Unmarshal(out.Bytes(), &records)
|
||||
sr.NoError(err)
|
||||
return records[0].Id
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
recordId := tc.preRun(ets.bondId)
|
||||
tc.url = fmt.Sprintf(reqURL, recordId)
|
||||
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.NoError(err)
|
||||
require := ets.Require()
|
||||
if tc.expectErr {
|
||||
require.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
var response registrytypes.QueryGetRecordResponse
|
||||
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
sr.NoError(err)
|
||||
record := response.GetRecord()
|
||||
sr.NotZero(len(record.GetId()))
|
||||
sr.Equal(record.GetId(), recordId)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCQueryGetRecordByBondId() {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := val.GetAPIAddress() + "/cerc/registry/v1/records-by-bond-id/%s"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
preRun func(bondId string)
|
||||
}{
|
||||
{
|
||||
"invalid url",
|
||||
reqURL + badPath,
|
||||
true,
|
||||
"",
|
||||
func(bondId string) {
|
||||
},
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
reqURL,
|
||||
false,
|
||||
"",
|
||||
func(bondId string) {
|
||||
// creating the record
|
||||
ets.createRecord(bondId)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
tc.preRun(ets.bondId)
|
||||
tc.url = fmt.Sprintf(reqURL, ets.bondId)
|
||||
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.NoError(err)
|
||||
require := ets.Require()
|
||||
if tc.expectErr {
|
||||
require.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
var response registrytypes.QueryGetRecordsByBondIdResponse
|
||||
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
sr.NoError(err)
|
||||
records := response.GetRecords()
|
||||
sr.NotZero(len(records))
|
||||
sr.Equal(records[0].GetBondId(), ets.bondId)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCQueryGetRegistryModuleBalance() {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := val.GetAPIAddress() + "/cerc/registry/v1/balance"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
preRun func(bondId string)
|
||||
}{
|
||||
{
|
||||
"invalid url",
|
||||
reqURL + badPath,
|
||||
true,
|
||||
"",
|
||||
func(bondId string) {
|
||||
},
|
||||
},
|
||||
{
|
||||
"Success",
|
||||
reqURL,
|
||||
false,
|
||||
"",
|
||||
func(bondId string) {
|
||||
// creating the record
|
||||
ets.createRecord(bondId)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
tc.preRun(ets.bondId)
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.NoError(err)
|
||||
require := ets.Require()
|
||||
if tc.expectErr {
|
||||
require.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
var response registrytypes.QueryGetRegistryModuleBalanceResponse
|
||||
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
sr.NoError(err)
|
||||
sr.NotZero(len(response.GetBalances()))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TestGRPCQueryNamesList() {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
reqURL := val.GetAPIAddress() + "/cerc/registry/v1/names"
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
url string
|
||||
expectErr bool
|
||||
errorMsg string
|
||||
preRun func(authorityName string)
|
||||
}{
|
||||
{
|
||||
"invalid url",
|
||||
reqURL + badPath,
|
||||
true,
|
||||
"",
|
||||
func(authorityName string) {
|
||||
},
|
||||
},
|
||||
{
|
||||
"valid request",
|
||||
reqURL,
|
||||
false,
|
||||
"",
|
||||
func(authorityName string) {
|
||||
// create name record
|
||||
ets.createNameRecord(authorityName)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(tc.name, func() {
|
||||
tc.preRun("ListNameRecords")
|
||||
resp, err := testutil.GetRequest(tc.url)
|
||||
ets.NoError(err)
|
||||
require := ets.Require()
|
||||
if tc.expectErr {
|
||||
require.Contains(string(resp), tc.errorMsg)
|
||||
} else {
|
||||
var response registrytypes.QueryNameRecordsResponse
|
||||
err := val.GetClientCtx().Codec.UnmarshalJSON(resp, &response)
|
||||
sr.NoError(err)
|
||||
sr.NotZero(len(response.GetNames()))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,266 +0,0 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
banktypes "cosmossdk.io/x/bank/types"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"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"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
laconictestcli "git.vdb.to/cerc-io/laconicd/testutil/cli"
|
||||
bondtypes "git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
bondcli "git.vdb.to/cerc-io/laconicd/x/bond/client/cli"
|
||||
registrytypes "git.vdb.to/cerc-io/laconicd/x/registry"
|
||||
"git.vdb.to/cerc-io/laconicd/x/registry/client/cli"
|
||||
)
|
||||
|
||||
type E2ETestSuite struct {
|
||||
// e2e.E2ETestSuite
|
||||
suite.Suite
|
||||
|
||||
Config network.Config
|
||||
Network network.NetworkI
|
||||
|
||||
accountName string
|
||||
accountAddress string
|
||||
|
||||
bondId string
|
||||
}
|
||||
|
||||
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
return &E2ETestSuite{Config: cfg}
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) SetupSuite() {
|
||||
sr := ets.Require()
|
||||
ets.T().Log("setting up e2e test suite")
|
||||
|
||||
var err error
|
||||
|
||||
genesisState := ets.Config.GenesisState
|
||||
var registryGenesis registrytypes.GenesisState
|
||||
ets.Require().NoError(ets.Config.Codec.UnmarshalJSON(genesisState[registrytypes.ModuleName], ®istryGenesis))
|
||||
|
||||
ets.updateParams(®istryGenesis.Params)
|
||||
|
||||
registryGenesisBz, err := ets.Config.Codec.MarshalJSON(®istryGenesis)
|
||||
ets.Require().NoError(err)
|
||||
genesisState[registrytypes.ModuleName] = registryGenesisBz
|
||||
ets.Config.GenesisState = genesisState
|
||||
|
||||
ets.Network, err = network.New(ets.T(), ets.T().TempDir(), ets.Config)
|
||||
sr.NoError(err)
|
||||
|
||||
_, err = ets.Network.WaitForHeight(2)
|
||||
sr.NoError(err)
|
||||
|
||||
// setting up random account
|
||||
ets.accountName = "accountName"
|
||||
ets.createAccountWithBalance(ets.accountName, &ets.accountAddress)
|
||||
|
||||
ets.bondId = ets.createBond()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) TearDownSuite() {
|
||||
ets.T().Log("tearing down e2e test suite")
|
||||
ets.Network.Cleanup()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createAccountWithBalance(accountName string, accountAddress *string) {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
|
||||
info, _, err := val.GetClientCtx().Keyring.NewMnemonic(accountName, keyring.English, sdk.FullFundraiserPath, keyring.DefaultBIP39Passphrase, hd.Secp256k1)
|
||||
sr.NoError(err)
|
||||
|
||||
newAddr, _ := info.GetAddress()
|
||||
msgSend := &banktypes.MsgSend{
|
||||
FromAddress: newAddr.String(),
|
||||
ToAddress: val.GetAddress().String(),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(ets.Config.BondDenom, math.NewInt(100000000))),
|
||||
}
|
||||
out, err := clitestutil.SubmitTestTx(
|
||||
val.GetClientCtx(),
|
||||
msgSend,
|
||||
newAddr,
|
||||
clitestutil.TestTxConfig{
|
||||
Fee: sdk.NewCoins(sdk.NewCoin(ets.Config.BondDenom, math.NewInt(10))),
|
||||
},
|
||||
)
|
||||
sr.NoError(err)
|
||||
|
||||
var response sdk.TxResponse
|
||||
sr.NoError(val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &response), out.String())
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.Network, val.GetClientCtx(), response.TxHash, 0))
|
||||
|
||||
*accountAddress = newAddr.String()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createBond() string {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
createBondCmd := bondcli.NewCreateBondCmd()
|
||||
args := []string{
|
||||
fmt.Sprintf("1000000%s", ets.Config.BondDenom),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.Config.BondDenom)),
|
||||
}
|
||||
out, err := clitestutil.ExecTestCLICmd(val.GetClientCtx(), createBondCmd, args)
|
||||
sr.NoError(err)
|
||||
var d sdk.TxResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.Network, val.GetClientCtx(), d.TxHash, 0))
|
||||
|
||||
// getting the bonds list and returning the bond-id
|
||||
clientCtx := val.GetClientCtx()
|
||||
cmd := bondcli.GetQueryBondList()
|
||||
args = []string{
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
}
|
||||
out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
sr.NoError(err)
|
||||
var queryResponse bondtypes.QueryBondsResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &queryResponse)
|
||||
sr.NoError(err)
|
||||
|
||||
// extract bond id from bonds list
|
||||
bond := queryResponse.GetBonds()[0]
|
||||
return bond.GetId()
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) reserveName(authorityName string) {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
|
||||
clientCtx := val.GetClientCtx()
|
||||
cmd := cli.GetCmdReserveAuthority()
|
||||
args := []string{
|
||||
authorityName,
|
||||
ets.accountAddress,
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.Config.BondDenom)),
|
||||
}
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
sr.NoError(err)
|
||||
|
||||
var d sdk.TxResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.Network, val.GetClientCtx(), d.TxHash, 0))
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createNameRecord(authorityName string) {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
|
||||
// reserving the name
|
||||
clientCtx := val.GetClientCtx()
|
||||
cmd := cli.GetCmdReserveAuthority()
|
||||
args := []string{
|
||||
authorityName,
|
||||
ets.accountAddress,
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.Config.BondDenom)),
|
||||
}
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
sr.NoError(err)
|
||||
var d sdk.TxResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.Network, val.GetClientCtx(), d.TxHash, 0))
|
||||
|
||||
// Get the bond-id
|
||||
bondId := ets.bondId
|
||||
|
||||
// adding bond-id to name authority
|
||||
args = []string{
|
||||
authorityName, bondId,
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.Config.BondDenom)),
|
||||
}
|
||||
cmd = cli.GetCmdSetAuthorityBond()
|
||||
|
||||
out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
sr.NoError(err)
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.Network, val.GetClientCtx(), d.TxHash, 0))
|
||||
|
||||
args = []string{
|
||||
fmt.Sprintf("lrn://%s/", authorityName),
|
||||
"test_hello_cid",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.Config.BondDenom)),
|
||||
}
|
||||
|
||||
cmd = cli.GetCmdSetName()
|
||||
|
||||
out, err = clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
sr.NoError(err)
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.Network, val.GetClientCtx(), d.TxHash, 0))
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) createRecord(bondId string) {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
|
||||
payloadPath := "../../data/examples/service_provider_example.yml"
|
||||
payloadFilePath, err := filepath.Abs(payloadPath)
|
||||
sr.NoError(err)
|
||||
|
||||
args := []string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.Config.BondDenom)),
|
||||
}
|
||||
args = append([]string{payloadFilePath, bondId}, args...)
|
||||
clientCtx := val.GetClientCtx()
|
||||
cmd := cli.GetCmdSetRecord()
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, args)
|
||||
sr.NoError(err)
|
||||
var d sdk.TxResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.NoError(laconictestcli.CheckTxCode(ets.Network, val.GetClientCtx(), d.TxHash, 0))
|
||||
}
|
||||
|
||||
func (ets *E2ETestSuite) updateParams(params *registrytypes.Params) {
|
||||
params.RecordRent = sdk.NewCoin(ets.Config.BondDenom, math.NewInt(1000))
|
||||
params.RecordRentDuration = 10 * time.Second
|
||||
|
||||
params.AuthorityRent = sdk.NewCoin(ets.Config.BondDenom, math.NewInt(1000))
|
||||
params.AuthorityGracePeriod = 10 * time.Second
|
||||
|
||||
params.AuthorityAuctionCommitFee = sdk.NewCoin(ets.Config.BondDenom, math.NewInt(100))
|
||||
params.AuthorityAuctionRevealFee = sdk.NewCoin(ets.Config.BondDenom, math.NewInt(100))
|
||||
params.AuthorityAuctionMinimumBid = sdk.NewCoin(ets.Config.BondDenom, math.NewInt(500))
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/x/registry/client/cli"
|
||||
)
|
||||
|
||||
func (ets *E2ETestSuite) TestGetCmdSetRecord() {
|
||||
val := ets.Network.GetValidators()[0]
|
||||
sr := ets.Require()
|
||||
|
||||
bondId := ets.bondId
|
||||
payloadPath := "../../data/examples/service_provider_example.yml"
|
||||
payloadFilePath, err := filepath.Abs(payloadPath)
|
||||
sr.NoError(err)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
err bool
|
||||
}{
|
||||
{
|
||||
"invalid request without bond id/without payload",
|
||||
[]string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.Config.BondDenom)),
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"success",
|
||||
[]string{
|
||||
payloadFilePath, bondId,
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, ets.accountName),
|
||||
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
|
||||
fmt.Sprintf("--%s=json", flags.FlagOutput),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, fmt.Sprintf("3%s", ets.Config.BondDenom)),
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ets.Run(fmt.Sprintf("Case %s", tc.name), func() {
|
||||
clientCtx := val.GetClientCtx()
|
||||
cmd := cli.GetCmdSetRecord()
|
||||
|
||||
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)
|
||||
if tc.err {
|
||||
sr.Error(err)
|
||||
} else {
|
||||
sr.NoError(err)
|
||||
var d sdk.TxResponse
|
||||
err = val.GetClientCtx().Codec.UnmarshalJSON(out.Bytes(), &d)
|
||||
sr.NoError(err)
|
||||
sr.Zero(d.Code)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -1,162 +0,0 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/store/snapshots"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
cmtcrypto "github.com/cometbft/cometbft/crypto"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/server/api"
|
||||
"github.com/cosmos/cosmos-sdk/server/config"
|
||||
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
||||
"github.com/cosmos/gogoproto/grpc"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/app"
|
||||
)
|
||||
|
||||
// wrap a server/v2 implementation so it satisfies v1 server/types.Application
|
||||
// type Application interface {
|
||||
// Info(*abci.InfoRequest) (*abci.InfoResponse, error)
|
||||
// Query(context.Context, *abci.QueryRequest) (*abci.QueryResponse, error)
|
||||
// CheckTx(*abci.CheckTxRequest) (*abci.CheckTxResponse, error)
|
||||
// InitChain(*abci.InitChainRequest) (*abci.InitChainResponse, error)
|
||||
// PrepareProposal(*abci.PrepareProposalRequest) (*abci.PrepareProposalResponse, error)
|
||||
// ProcessProposal(*abci.ProcessProposalRequest) (*abci.ProcessProposalResponse, error)
|
||||
// FinalizeBlock(*abci.FinalizeBlockRequest) (*abci.FinalizeBlockResponse, error)
|
||||
// ExtendVote(context.Context, *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error)
|
||||
// VerifyVoteExtension(*abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error)
|
||||
// Commit() (*abci.CommitResponse, error)
|
||||
|
||||
// ListSnapshots(*abci.ListSnapshotsRequest) (*abci.ListSnapshotsResponse, error)
|
||||
// OfferSnapshot(*abci.OfferSnapshotRequest) (*abci.OfferSnapshotResponse, error)
|
||||
// LoadSnapshotChunk(*abci.LoadSnapshotChunkRequest) (*abci.LoadSnapshotChunkResponse, error)
|
||||
// ApplySnapshotChunk(*abci.ApplySnapshotChunkRequest) (*abci.ApplySnapshotChunkResponse, error)
|
||||
|
||||
// RegisterAPIRoutes(*api.Server, config.APIConfig)
|
||||
// RegisterGRPCServer(grpc.Server)
|
||||
// RegisterTxService(client.Context)
|
||||
// RegisterTendermintService(client.Context)
|
||||
// RegisterNodeService(client.Context, config.Config)
|
||||
|
||||
// CommitMultiStore() storetypes.CommitMultiStore
|
||||
// SnapshotManager() *snapshots.Manager
|
||||
// ValidatorKeyProvider() func() (cmtcrypto.PrivKey, error)
|
||||
|
||||
// Close() error
|
||||
// }
|
||||
|
||||
var _ servertypes.Application = (*serverAppV1)(nil)
|
||||
|
||||
type serverAppV1 struct {
|
||||
// serverv2.AppI[transaction.Tx]
|
||||
App *app.LaconicApp
|
||||
ABCI abci.Application
|
||||
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (s *serverAppV1) Info(req *abci.InfoRequest) (*abci.InfoResponse, error) {
|
||||
return s.ABCI.Info(s.ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) Query(ctx context.Context, req *abci.QueryRequest) (*abci.QueryResponse, error) {
|
||||
return s.ABCI.Query(ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) CheckTx(req *abci.CheckTxRequest) (*abci.CheckTxResponse, error) {
|
||||
return s.ABCI.CheckTx(s.ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) InitChain(req *abci.InitChainRequest) (*abci.InitChainResponse, error) {
|
||||
return s.ABCI.InitChain(s.ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) PrepareProposal(req *abci.PrepareProposalRequest) (*abci.PrepareProposalResponse, error) {
|
||||
return s.ABCI.PrepareProposal(s.ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) ProcessProposal(req *abci.ProcessProposalRequest) (*abci.ProcessProposalResponse, error) {
|
||||
return s.ABCI.ProcessProposal(s.ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) FinalizeBlock(req *abci.FinalizeBlockRequest) (*abci.FinalizeBlockResponse, error) {
|
||||
return s.ABCI.FinalizeBlock(s.ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) ExtendVote(ctx context.Context, req *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error) {
|
||||
return s.ABCI.ExtendVote(ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) VerifyVoteExtension(req *abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error) {
|
||||
return s.ABCI.VerifyVoteExtension(s.ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) Commit() (*abci.CommitResponse, error) {
|
||||
return s.ABCI.Commit(s.ctx, nil)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) ListSnapshots(req *abci.ListSnapshotsRequest) (*abci.ListSnapshotsResponse, error) {
|
||||
return s.ABCI.ListSnapshots(s.ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) OfferSnapshot(req *abci.OfferSnapshotRequest) (*abci.OfferSnapshotResponse, error) {
|
||||
return s.ABCI.OfferSnapshot(s.ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) LoadSnapshotChunk(req *abci.LoadSnapshotChunkRequest) (*abci.LoadSnapshotChunkResponse, error) {
|
||||
return s.ABCI.LoadSnapshotChunk(s.ctx, req)
|
||||
}
|
||||
|
||||
func (s *serverAppV1) ApplySnapshotChunk(req *abci.ApplySnapshotChunkRequest) (*abci.ApplySnapshotChunkResponse, error) {
|
||||
return s.ABCI.ApplySnapshotChunk(s.ctx, req)
|
||||
}
|
||||
|
||||
// Placeholder implementations for the API, gRPC, and services registration
|
||||
func (s *serverAppV1) RegisterAPIRoutes(apiServer *api.Server, apiConfig config.APIConfig) {
|
||||
// Implement API route registration
|
||||
}
|
||||
|
||||
func (s *serverAppV1) RegisterGRPCServer(grpcServer grpc.Server) {
|
||||
// Implement gRPC server registration
|
||||
}
|
||||
|
||||
func (s *serverAppV1) RegisterTxService(clientCtx client.Context) {
|
||||
// Implement Tx service registration
|
||||
}
|
||||
|
||||
func (s *serverAppV1) RegisterTendermintService(clientCtx client.Context) {
|
||||
// Implement Tendermint service registration
|
||||
}
|
||||
|
||||
func (s *serverAppV1) RegisterNodeService(clientCtx client.Context, cfg config.Config) {
|
||||
// Implement Node service registration
|
||||
}
|
||||
|
||||
type unsupportedMethod struct {
|
||||
method string
|
||||
}
|
||||
|
||||
func (u unsupportedMethod) Error() string {
|
||||
return "unsupported method: " + u.method
|
||||
}
|
||||
|
||||
func (s *serverAppV1) CommitMultiStore() storetypes.CommitMultiStore {
|
||||
panic(unsupportedMethod{"CommitMultiStore"})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *serverAppV1) SnapshotManager() *snapshots.Manager {
|
||||
panic(unsupportedMethod{"SnapshotManager"})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *serverAppV1) ValidatorKeyProvider() func() (cmtcrypto.PrivKey, error) {
|
||||
panic(unsupportedMethod{"ValidatorKeyProvider"})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *serverAppV1) Close() error {
|
||||
return s.App.Close()
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
// client "cosmossdk.io/client/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/store"
|
||||
"cosmossdk.io/core/transaction"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/server/v2/appmanager"
|
||||
"cosmossdk.io/server/v2/cometbft"
|
||||
"cosmossdk.io/server/v2/cometbft/mempool"
|
||||
"cosmossdk.io/server/v2/stf"
|
||||
"cosmossdk.io/server/v2/stf/branch"
|
||||
consensustypes "cosmossdk.io/x/consensus/types"
|
||||
v1 "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
gogotypes "github.com/cosmos/gogoproto/types"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/app"
|
||||
cometmock "git.vdb.to/cerc-io/laconicd/testutil/cometbft/mock"
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
)
|
||||
|
||||
var actorName = []byte("cookies")
|
||||
|
||||
func getQueryRouterBuilder[T any, PT interface {
|
||||
*T
|
||||
proto.Message
|
||||
},
|
||||
U any, UT interface {
|
||||
*U
|
||||
proto.Message
|
||||
}](
|
||||
// t *testing.T,
|
||||
handler func(ctx context.Context, msg PT) (UT, error),
|
||||
) (*stf.MsgRouterBuilder, error) {
|
||||
// t.Helper()
|
||||
queryRouterBuilder := stf.NewMsgRouterBuilder()
|
||||
err := queryRouterBuilder.RegisterHandler(
|
||||
proto.MessageName(PT(new(T))),
|
||||
func(ctx context.Context, msg transaction.Msg) (msgResp transaction.Msg, err error) {
|
||||
typedReq := msg.(PT)
|
||||
typedResp, err := handler(ctx, typedReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return typedResp, nil
|
||||
},
|
||||
)
|
||||
return queryRouterBuilder, err
|
||||
}
|
||||
|
||||
func getMsgRouterBuilder[T any, PT interface {
|
||||
*T
|
||||
transaction.Msg
|
||||
},
|
||||
U any, UT interface {
|
||||
*U
|
||||
transaction.Msg
|
||||
}](
|
||||
handler func(ctx context.Context, msg PT) (UT, error),
|
||||
) (*stf.MsgRouterBuilder, error) {
|
||||
// t.Helper()
|
||||
msgRouterBuilder := stf.NewMsgRouterBuilder()
|
||||
err := msgRouterBuilder.RegisterHandler(
|
||||
proto.MessageName(PT(new(T))),
|
||||
func(ctx context.Context, msg transaction.Msg) (msgResp transaction.Msg, err error) {
|
||||
typedReq := msg.(PT)
|
||||
typedResp, err := handler(ctx, typedReq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return typedResp, nil
|
||||
},
|
||||
)
|
||||
return msgRouterBuilder, err
|
||||
}
|
||||
|
||||
func setUpConsensus(
|
||||
logger log.Logger,
|
||||
gasLimit uint64,
|
||||
mempool mempool.Mempool[app.Tx],
|
||||
storageDir string,
|
||||
txConfig client.TxConfig,
|
||||
) (*cometbft.Consensus[app.Tx], error) {
|
||||
|
||||
msgRouterBuilder, err := getMsgRouterBuilder(func(ctx context.Context, msg *gogotypes.BoolValue) (*gogotypes.BoolValue, error) {
|
||||
return nil, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
queryRouterBuilder, err := getQueryRouterBuilder(func(ctx context.Context, q *consensustypes.QueryParamsRequest) (*consensustypes.QueryParamsResponse, error) {
|
||||
cParams := &v1.ConsensusParams{
|
||||
Block: &v1.BlockParams{
|
||||
MaxGas: 300000,
|
||||
},
|
||||
Feature: &v1.FeatureParams{
|
||||
VoteExtensionsEnableHeight: &gogotypes.Int64Value{Value: 2},
|
||||
},
|
||||
}
|
||||
return &consensustypes.QueryParamsResponse{
|
||||
Params: cParams,
|
||||
}, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s, err := stf.New(
|
||||
log.NewNopLogger().With("module", "stf"),
|
||||
msgRouterBuilder,
|
||||
queryRouterBuilder,
|
||||
func(ctx context.Context, txs []app.Tx) error { return nil },
|
||||
func(ctx context.Context) error { return nil },
|
||||
func(ctx context.Context) error { return nil },
|
||||
func(ctx context.Context, tx app.Tx) error { return nil },
|
||||
func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error) { return nil, nil },
|
||||
func(ctx context.Context, tx app.Tx, success bool) error { return nil },
|
||||
branch.DefaultNewWriterMap,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// todo pass tempdir
|
||||
ss := cometmock.NewMockStorage(log.NewNopLogger(), storageDir)
|
||||
sc := cometmock.NewMockCommiter(log.NewNopLogger(), string(actorName), "stf")
|
||||
mockStore := cometmock.NewMockStore(ss, sc)
|
||||
|
||||
am := appmanager.New(appmanager.Config{
|
||||
ValidateTxGasLimit: gasLimit,
|
||||
QueryGasLimit: gasLimit,
|
||||
SimulationGasLimit: gasLimit,
|
||||
},
|
||||
mockStore,
|
||||
s,
|
||||
func(ctx context.Context, src io.Reader, txHandler func(json.RawMessage) error) (store.WriterMap, error) {
|
||||
_, st, err := mockStore.StateLatest()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return branch.DefaultNewWriterMap(st), nil
|
||||
},
|
||||
nil,
|
||||
)
|
||||
|
||||
return cometbft.NewConsensus(
|
||||
logger,
|
||||
"laconicd",
|
||||
am,
|
||||
func() error { return nil },
|
||||
mempool,
|
||||
map[string]struct{}{},
|
||||
nil,
|
||||
mockStore,
|
||||
cometbft.Config{AppTomlConfig: cometbft.DefaultAppTomlConfig()},
|
||||
utils.GenericTxDecoder[app.Tx]{txConfig},
|
||||
"test",
|
||||
), nil
|
||||
}
|
@ -27,14 +27,15 @@ import (
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
|
||||
"git.vdb.to/cerc-io/laconicd/app/params"
|
||||
"git.vdb.to/cerc-io/laconicd/utils"
|
||||
auctionTypes "git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
auctiontypes "git.vdb.to/cerc-io/laconicd/x/auction"
|
||||
auctionkeeper "git.vdb.to/cerc-io/laconicd/x/auction/keeper"
|
||||
auctionmodule "git.vdb.to/cerc-io/laconicd/x/auction/module"
|
||||
bondTypes "git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
bondtypes "git.vdb.to/cerc-io/laconicd/x/bond"
|
||||
bondkeeper "git.vdb.to/cerc-io/laconicd/x/bond/keeper"
|
||||
bondmodule "git.vdb.to/cerc-io/laconicd/x/bond/module"
|
||||
registryTypes "git.vdb.to/cerc-io/laconicd/x/registry"
|
||||
registrytypes "git.vdb.to/cerc-io/laconicd/x/registry"
|
||||
registrykeeper "git.vdb.to/cerc-io/laconicd/x/registry/keeper"
|
||||
registrymodule "git.vdb.to/cerc-io/laconicd/x/registry/module"
|
||||
)
|
||||
@ -56,7 +57,7 @@ type TestFixture struct {
|
||||
|
||||
func (tf *TestFixture) Setup(t *testing.T) error {
|
||||
keys := storetypes.NewKVStoreKeys(
|
||||
authtypes.StoreKey, banktypes.StoreKey, auctionTypes.StoreKey, bondTypes.StoreKey, registryTypes.StoreKey,
|
||||
authtypes.StoreKey, banktypes.StoreKey, auctiontypes.StoreKey, bondtypes.StoreKey, registrytypes.StoreKey,
|
||||
)
|
||||
cdc := moduletestutil.MakeTestEncodingConfig(
|
||||
codectestutil.CodecOptions{},
|
||||
@ -85,12 +86,12 @@ func (tf *TestFixture) Setup(t *testing.T) error {
|
||||
|
||||
maccPerms := map[string][]string{
|
||||
minttypes.ModuleName: {authtypes.Minter},
|
||||
auctionTypes.ModuleName: {},
|
||||
auctionTypes.AuctionBurnModuleAccountName: {},
|
||||
bondTypes.ModuleName: {},
|
||||
registryTypes.ModuleName: {},
|
||||
registryTypes.RecordRentModuleAccountName: {},
|
||||
registryTypes.AuthorityRentModuleAccountName: {},
|
||||
auctiontypes.ModuleName: {},
|
||||
auctiontypes.AuctionBurnModuleAccountName: {},
|
||||
bondtypes.ModuleName: {},
|
||||
registrytypes.ModuleName: {},
|
||||
registrytypes.RecordRentModuleAccountName: {},
|
||||
registrytypes.AuthorityRentModuleAccountName: {},
|
||||
}
|
||||
|
||||
accountKeeper := authkeeper.NewAccountKeeper(
|
||||
@ -116,7 +117,7 @@ func (tf *TestFixture) Setup(t *testing.T) error {
|
||||
)
|
||||
|
||||
auctionKeeper := auctionkeeper.NewKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[auctionTypes.StoreKey]), logger),
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[auctiontypes.StoreKey]), logger),
|
||||
cdc,
|
||||
accountKeeper,
|
||||
bankKeeper,
|
||||
@ -125,15 +126,17 @@ func (tf *TestFixture) Setup(t *testing.T) error {
|
||||
)
|
||||
|
||||
bondKeeper := bondkeeper.NewKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[bondtypes.StoreKey]), logger),
|
||||
cdc,
|
||||
runtime.NewKVStoreService(keys[bondTypes.StoreKey]),
|
||||
runtime.NewKVStoreService(keys[bondtypes.StoreKey]),
|
||||
accountKeeper,
|
||||
bankKeeper,
|
||||
authority.String(),
|
||||
logger,
|
||||
)
|
||||
|
||||
registryKeeper := registrykeeper.NewKeeper(
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[registryTypes.StoreKey]), logger),
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[registrytypes.StoreKey]), logger),
|
||||
cdc,
|
||||
accountKeeper,
|
||||
bankKeeper,
|
||||
@ -159,32 +162,32 @@ func (tf *TestFixture) Setup(t *testing.T) error {
|
||||
map[string]appmodule.AppModule{
|
||||
authtypes.ModuleName: authModule,
|
||||
banktypes.ModuleName: bankModule,
|
||||
auctionTypes.ModuleName: auctionModule,
|
||||
bondTypes.ModuleName: bondModule,
|
||||
registryTypes.ModuleName: registryModule,
|
||||
auctiontypes.ModuleName: auctionModule,
|
||||
bondtypes.ModuleName: bondModule,
|
||||
registrytypes.ModuleName: registryModule,
|
||||
},
|
||||
router, queryRouter)
|
||||
|
||||
ctx := integrationApp.Context()
|
||||
|
||||
// Register MsgServer and QueryServer
|
||||
auctionTypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), auctionkeeper.NewMsgServerImpl(auctionKeeper))
|
||||
auctionTypes.RegisterQueryServer(integrationApp.QueryHelper(), auctionkeeper.NewQueryServerImpl(auctionKeeper))
|
||||
auctiontypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), auctionkeeper.NewMsgServerImpl(auctionKeeper))
|
||||
auctiontypes.RegisterQueryServer(integrationApp.QueryHelper(), auctionkeeper.NewQueryServerImpl(auctionKeeper))
|
||||
|
||||
bondTypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), bondkeeper.NewMsgServerImpl(bondKeeper))
|
||||
bondTypes.RegisterQueryServer(integrationApp.QueryHelper(), bondkeeper.NewQueryServerImpl(bondKeeper))
|
||||
bondtypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), bondkeeper.NewMsgServerImpl(bondKeeper))
|
||||
bondtypes.RegisterQueryServer(integrationApp.QueryHelper(), bondkeeper.NewQueryServerImpl(bondKeeper))
|
||||
|
||||
registryTypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), registrykeeper.NewMsgServerImpl(registryKeeper))
|
||||
registryTypes.RegisterQueryServer(integrationApp.QueryHelper(), registrykeeper.NewQueryServerImpl(registryKeeper))
|
||||
registrytypes.RegisterMsgServer(integrationApp.MsgServiceRouter(), registrykeeper.NewMsgServerImpl(registryKeeper))
|
||||
registrytypes.RegisterQueryServer(integrationApp.QueryHelper(), registrykeeper.NewQueryServerImpl(registryKeeper))
|
||||
|
||||
// set default params
|
||||
if err := auctionKeeper.Params.Set(ctx, auctionTypes.DefaultParams()); err != nil {
|
||||
if err := auctionKeeper.Params.Set(ctx, auctiontypes.DefaultParams()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := bondKeeper.Params.Set(ctx, bondTypes.DefaultParams()); err != nil {
|
||||
if err := bondKeeper.Params.Set(ctx, bondtypes.DefaultParams()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := registryKeeper.Params.Set(ctx, registryTypes.DefaultParams()); err != nil {
|
||||
if err := registryKeeper.Params.Set(ctx, registrytypes.DefaultParams()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user