Skip to content

Commit

Permalink
fix buy command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanchristo committed Jun 29, 2022
1 parent 1438220 commit 4120d28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
26 changes: 19 additions & 7 deletions x/ecocredit/client/testsuite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ func (s *IntegrationTestSuite) setupGenesis() {
}

func (s *IntegrationTestSuite) setupTestAccounts() {
// create validator account
// create secondary account
info, _, err := s.val.ClientCtx.Keyring.NewMnemonic(
"validator",
"addr2",
keyring.English,
sdk.FullFundraiserPath,
keyring.DefaultBIP39Passphrase,
Expand All @@ -255,9 +255,9 @@ func (s *IntegrationTestSuite) setupTestAccounts() {
// set secondary account
s.addr2 = sdk.AccAddress(info.GetPubKey().Address())

// fund the secondary account
s.fundAccount(s.val.ClientCtx, s.val.Address, s.addr2, sdk.Coins{
sdk.NewInt64Coin(s.cfg.BondDenom, 20000000000000000),
// fund secondary account
s.fundAccount(s.val.ClientCtx, s.addr1, s.addr2, sdk.Coins{
sdk.NewInt64Coin(s.cfg.BondDenom, 100000000),
})
}

Expand All @@ -270,14 +270,20 @@ func (s *IntegrationTestSuite) commonTxFlags() []string {
}

func (s *IntegrationTestSuite) fundAccount(clientCtx client.Context, from, to sdk.AccAddress, coins sdk.Coins) {
_, err := banktestutil.MsgSendExec(
require := s.Require()

out, err := banktestutil.MsgSendExec(
clientCtx,
from,
to,
coins,
s.commonTxFlags()...,
)
s.Require().NoError(err)
require.NoError(err)

var res sdk.TxResponse
require.NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &res))
require.Zero(res.Code, res.RawLog)
}

func (s *IntegrationTestSuite) createClass(clientCtx client.Context, msg *core.MsgCreateClass) (classId string) {
Expand All @@ -297,6 +303,8 @@ func (s *IntegrationTestSuite) createClass(clientCtx client.Context, msg *core.M

var res sdk.TxResponse
require.NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &res))
require.Zero(res.Code, res.RawLog)

for _, e := range res.Logs[0].Events {
if e.Type == proto.MessageName(&core.EventCreateClass{}) {
for _, attr := range e.Attributes {
Expand Down Expand Up @@ -329,6 +337,8 @@ func (s *IntegrationTestSuite) createProject(clientCtx client.Context, msg *core

var res sdk.TxResponse
require.NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &res))
require.Zero(res.Code, res.RawLog)

for _, e := range res.Logs[0].Events {
if e.Type == proto.MessageName(&core.EventCreateProject{}) {
for _, attr := range e.Attributes {
Expand Down Expand Up @@ -363,6 +373,8 @@ func (s *IntegrationTestSuite) createBatch(clientCtx client.Context, msg *core.M

var res sdk.TxResponse
require.NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), &res))
require.Zero(res.Code, res.RawLog)

for _, e := range res.Logs[0].Events {
if e.Type == proto.MessageName(&core.EventCreateBatch{}) {
for _, attr := range e.Attributes {
Expand Down
8 changes: 4 additions & 4 deletions x/ecocredit/client/testsuite/tx_marketplace.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (s *IntegrationTestSuite) TestTxUpdateSellOrders() {
func (s *IntegrationTestSuite) TestTxBuyDirectCmd() {
require := s.Require()

buyer := s.addr1.String()
buyer := s.addr2.String()

sellOrderId := fmt.Sprint(s.sellOrderId)
bidPrice := sdk.NewInt64Coin(s.allowedDenoms[0], 10).String()
Expand Down Expand Up @@ -326,7 +326,7 @@ func (s *IntegrationTestSuite) TestTxBuyDirectCmd() {
"10",
bidPrice,
"true",
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.val.Moniker),
fmt.Sprintf("--%s=%s", flags.FlagFrom, "addr2"),
},
},
{
Expand Down Expand Up @@ -364,7 +364,7 @@ func (s *IntegrationTestSuite) TestTxBuyDirectCmd() {
func (s *IntegrationTestSuite) TestTxBuyDirectBatchCmd() {
require := s.Require()

buyer := s.addr1.String()
buyer := s.addr2.String()

bidPrice := sdk.NewInt64Coin(s.allowedDenoms[0], 10)

Expand Down Expand Up @@ -451,7 +451,7 @@ func (s *IntegrationTestSuite) TestTxBuyDirectBatchCmd() {
name: "valid from key-name",
args: []string{
validJson,
fmt.Sprintf("--%s=%s", flags.FlagFrom, s.val.Moniker),
fmt.Sprintf("--%s=%s", flags.FlagFrom, "addr2"),
},
},
{
Expand Down

0 comments on commit 4120d28

Please sign in to comment.