diff --git a/tests/integration/accounts/lockup/utils.go b/tests/integration/accounts/lockup/utils.go deleted file mode 100644 index d92586f1ac90..000000000000 --- a/tests/integration/accounts/lockup/utils.go +++ /dev/null @@ -1,97 +0,0 @@ -package lockup - -import ( - "testing" - "time" - - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - - "cosmossdk.io/core/transaction" - "cosmossdk.io/simapp" - types "cosmossdk.io/x/accounts/defaults/lockup/v1" - "cosmossdk.io/x/bank/testutil" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var ( - ownerAddr = secp256k1.GenPrivKey().PubKey().Address() - accOwner = sdk.AccAddress(ownerAddr) -) - -type IntegrationTestSuite struct { - suite.Suite - - app *simapp.SimApp -} - -func NewIntegrationTestSuite() *IntegrationTestSuite { - return &IntegrationTestSuite{} -} - -func (s *IntegrationTestSuite) SetupSuite() { - s.T().Log("setting up integration test suite") - s.app = setupApp(s.T()) -} - -func (s *IntegrationTestSuite) TearDownSuite() { - s.T().Log("tearing down integration test suite") -} - -func setupApp(t *testing.T) *simapp.SimApp { - t.Helper() - app := simapp.Setup(t, false) - return app -} - -func (s *IntegrationTestSuite) executeTx(ctx sdk.Context, msg sdk.Msg, app *simapp.SimApp, accAddr, sender []byte) error { - _, err := app.AccountsKeeper.Execute(ctx, accAddr, sender, msg, nil) - return err -} - -func (s *IntegrationTestSuite) queryAcc(ctx sdk.Context, req sdk.Msg, app *simapp.SimApp, accAddr []byte) (transaction.Msg, error) { - resp, err := app.AccountsKeeper.Query(ctx, accAddr, req) - return resp, err -} - -func (s *IntegrationTestSuite) fundAccount(app *simapp.SimApp, ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) { - require.NoError(s.T(), testutil.FundAccount(ctx, app.BankKeeper, addr, amt)) -} - -func (s *IntegrationTestSuite) queryLockupAccInfo(ctx sdk.Context, app *simapp.SimApp, accAddr []byte) *types.QueryLockupAccountInfoResponse { - req := &types.QueryLockupAccountInfoRequest{} - resp, err := s.queryAcc(ctx, req, app, accAddr) - require.NoError(s.T(), err) - require.NotNil(s.T(), resp) - - lockupAccountInfoResponse, ok := resp.(*types.QueryLockupAccountInfoResponse) - require.True(s.T(), ok) - - return lockupAccountInfoResponse -} - -func (s *IntegrationTestSuite) queryUnbondingEntries(ctx sdk.Context, app *simapp.SimApp, accAddr []byte, valAddr string) *types.QueryUnbondingEntriesResponse { - req := &types.QueryUnbondingEntriesRequest{ - ValidatorAddress: valAddr, - } - resp, err := s.queryAcc(ctx, req, app, accAddr) - require.NoError(s.T(), err) - require.NotNil(s.T(), resp) - - unbondingEntriesResponse, ok := resp.(*types.QueryUnbondingEntriesResponse) - require.True(s.T(), ok) - - return unbondingEntriesResponse -} - -func (s *IntegrationTestSuite) setupStakingParams(ctx sdk.Context, app *simapp.SimApp) { - params, err := app.StakingKeeper.Params.Get(ctx) - require.NoError(s.T(), err) - - // update unbonding time - params.UnbondingTime = time.Duration(time.Second * 10) - err = app.StakingKeeper.Params.Set(ctx, params) - require.NoError(s.T(), err) -} diff --git a/tests/integration/accounts/multisig/test_suite.go b/tests/integration/accounts/multisig/test_suite.go deleted file mode 100644 index 631ddb58ab4c..000000000000 --- a/tests/integration/accounts/multisig/test_suite.go +++ /dev/null @@ -1,115 +0,0 @@ -package multisig - -import ( - "context" - "testing" - - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - - "cosmossdk.io/core/transaction" - "cosmossdk.io/math" - "cosmossdk.io/simapp" - v1 "cosmossdk.io/x/accounts/defaults/multisig/v1" - "cosmossdk.io/x/bank/testutil" - - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type IntegrationTestSuite struct { - suite.Suite - - app *simapp.SimApp - members []sdk.AccAddress - membersAddr []string -} - -func NewIntegrationTestSuite() *IntegrationTestSuite { - return &IntegrationTestSuite{} -} - -func (s *IntegrationTestSuite) SetupSuite() { - s.app = setupApp(s.T()) - - s.members = []sdk.AccAddress{} - for i := 0; i < 10; i++ { - addr := secp256k1.GenPrivKey().PubKey().Address() - addrStr, err := s.app.AuthKeeper.AddressCodec().BytesToString(addr) - require.NoError(s.T(), err) - s.membersAddr = append(s.membersAddr, addrStr) - s.members = append(s.members, sdk.AccAddress(addr)) - } -} - -func (s *IntegrationTestSuite) TearDownSuite() {} - -func setupApp(t *testing.T) *simapp.SimApp { - t.Helper() - app := simapp.Setup(t, false) - return app -} - -func (s *IntegrationTestSuite) executeTx(ctx context.Context, msg sdk.Msg, accAddr, sender []byte) error { - _, err := s.app.AccountsKeeper.Execute(ctx, accAddr, sender, msg, nil) - return err -} - -func (s *IntegrationTestSuite) queryAcc(ctx context.Context, req sdk.Msg, accAddr []byte) (transaction.Msg, error) { - resp, err := s.app.AccountsKeeper.Query(ctx, accAddr, req) - return resp, err -} - -func (s *IntegrationTestSuite) fundAccount(ctx context.Context, addr sdk.AccAddress, amt sdk.Coins) { - require.NoError(s.T(), testutil.FundAccount(ctx, s.app.BankKeeper, addr, amt)) -} - -// initAccount initializes a multisig account with the given members and powers -// and returns the account address -func (s *IntegrationTestSuite) initAccount(ctx context.Context, sender []byte, membersPowers map[string]uint64) ([]byte, string) { - s.fundAccount(ctx, sender, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))}) - - members := []*v1.Member{} - for addrStr, power := range membersPowers { - members = append(members, &v1.Member{Address: addrStr, Weight: power}) - } - - _, accountAddr, err := s.app.AccountsKeeper.Init(ctx, "multisig", sender, - &v1.MsgInit{ - Members: members, - Config: &v1.Config{ - Threshold: 100, - Quorum: 100, - VotingPeriod: 120, - Revote: false, - EarlyExecution: true, - }, - }, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}, nil) - s.NoError(err) - - accountAddrStr, err := s.app.AuthKeeper.AddressCodec().BytesToString(accountAddr) - s.NoError(err) - - return accountAddr, accountAddrStr -} - -// createProposal -func (s *IntegrationTestSuite) createProposal(ctx context.Context, accAddr, sender []byte, msgs ...*codectypes.Any) { - propReq := &v1.MsgCreateProposal{ - Proposal: &v1.Proposal{ - Title: "test", - Summary: "test", - Messages: msgs, - }, - } - err := s.executeTx(ctx, propReq, accAddr, sender) - s.NoError(err) -} - -func (s *IntegrationTestSuite) executeProposal(ctx context.Context, accAddr, sender []byte, proposalID uint64) error { - execReq := &v1.MsgExecuteProposal{ - ProposalId: proposalID, - } - return s.executeTx(ctx, execReq, accAddr, sender) -} diff --git a/tests/integration/accounts/lockup/continous_lockup_test_suite.go b/tests/integration/v2/accounts/lockup/continous_lockup_test_suite.go similarity index 65% rename from tests/integration/accounts/lockup/continous_lockup_test_suite.go rename to tests/integration/v2/accounts/lockup/continous_lockup_test_suite.go index f3de1f753319..e94dc179f3f2 100644 --- a/tests/integration/accounts/lockup/continous_lockup_test_suite.go +++ b/tests/integration/v2/accounts/lockup/continous_lockup_test_suite.go @@ -13,23 +13,23 @@ import ( types "cosmossdk.io/x/accounts/defaults/lockup/v1" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/tests/integration/v2" sdk "github.com/cosmos/cosmos-sdk/types" ) func (s *IntegrationTestSuite) TestContinuousLockingAccount() { t := s.T() - app := setupApp(t) currentTime := time.Now() - ctx := sdk.NewContext(app.CommitMultiStore(), false, app.Logger()).WithHeaderInfo(header.Info{ - Time: currentTime, - }) - s.setupStakingParams(ctx, app) - ownerAddrStr, err := app.AuthKeeper.AddressCodec().BytesToString(accOwner) + ctx := s.ctx + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime}) + s.setupStakingParams(ctx, s.stakingKeeper) + + ownerAddrStr, err := s.authKeeper.AddressCodec().BytesToString(accOwner) require.NoError(t, err) - s.fundAccount(app, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))}) + s.fundAccount(s.bankKeeper, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))}) randAcc := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - _, accountAddr, err := app.AccountsKeeper.Init(ctx, lockupaccount.CONTINUOUS_LOCKING_ACCOUNT, accOwner, &types.MsgInitLockupAccount{ + _, accountAddr, err := s.accountsKeeper.Init(ctx, lockupaccount.CONTINUOUS_LOCKING_ACCOUNT, accOwner, &types.MsgInitLockupAccount{ Owner: ownerAddrStr, StartTime: currentTime, // end time in 1 minutes @@ -37,10 +37,10 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() { }, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}, nil) require.NoError(t, err) - addr, err := app.AuthKeeper.AddressCodec().BytesToString(randAcc) + addr, err := s.authKeeper.AddressCodec().BytesToString(randAcc) require.NoError(t, err) - vals, err := app.StakingKeeper.GetAllValidators(ctx) + vals, err := s.stakingKeeper.GetAllValidators(ctx) require.NoError(t, err) val := vals[0] @@ -50,7 +50,7 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NotNil(t, err) }) t.Run("error - execute send message, insufficient fund", func(t *testing.T) { @@ -59,15 +59,13 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NotNil(t, err) }) // Update context time // 12 sec = 1/5 of a minute so 200stake should be released - ctx = ctx.WithHeaderInfo(header.Info{ - Time: currentTime.Add(time.Second * 12), - }) + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime.Add(time.Second * 12)}) // Check if token is sendable t.Run("ok - execute send message", func(t *testing.T) { @@ -76,33 +74,32 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - balance := app.BankKeeper.GetBalance(ctx, randAcc, "stake") + balance := s.bankKeeper.GetBalance(ctx, randAcc, "stake") require.True(t, balance.Amount.Equal(math.NewInt(100))) }) - t.Run("ok - execute delegate message", func(t *testing.T) { msg := &types.MsgDelegate{ Sender: ownerAddrStr, ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(100)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - del, err := app.StakingKeeper.Delegations.Get( + del, err := s.stakingKeeper.Delegations.Get( ctx, collections.Join(sdk.AccAddress(accountAddr), sdk.ValAddress(valbz)), ) require.NoError(t, err) require.NotNil(t, del) // check if tracking is updated accordingly - lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr) + lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, s.accountsKeeper, accountAddr) delLocking := lockupAccountInfoResponse.DelegatedLocking require.True(t, delLocking.AmountOf("stake").Equal(math.NewInt(100))) }) @@ -111,11 +108,11 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() { Sender: ownerAddrStr, ValidatorAddress: val.OperatorAddress, } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) }) t.Run("ok - execute undelegate message", func(t *testing.T) { - vals, err := app.StakingKeeper.GetAllValidators(ctx) + vals, err := s.stakingKeeper.GetAllValidators(ctx) require.NoError(t, err) val := vals[0] msg := &types.MsgUndelegate{ @@ -123,31 +120,29 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() { ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(100)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - ubd, err := app.StakingKeeper.GetUnbondingDelegation( + ubd, err := s.stakingKeeper.GetUnbondingDelegation( ctx, sdk.AccAddress(accountAddr), sdk.ValAddress(valbz), ) require.NoError(t, err) require.Equal(t, len(ubd.Entries), 1) // check if an entry is added - unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress) + unbondingEntriesResponse := s.queryUnbondingEntries(ctx, s.accountsKeeper, accountAddr, val.OperatorAddress) entries := unbondingEntriesResponse.UnbondingEntries require.True(t, entries[0].Amount.Amount.Equal(math.NewInt(100))) require.True(t, entries[0].ValidatorAddress == val.OperatorAddress) }) // Update context time to end time - ctx = ctx.WithHeaderInfo(header.Info{ - Time: currentTime.Add(time.Minute), - }) + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime.Add(time.Minute)}) // trigger endblock for staking to handle matured unbonding delegation - _, err = app.StakingKeeper.EndBlocker(ctx) + _, err = s.stakingKeeper.EndBlocker(ctx) require.NoError(t, err) // test if tracking delegate work perfectly @@ -157,20 +152,20 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() { ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(100)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - del, err := app.StakingKeeper.Delegations.Get( + del, err := s.stakingKeeper.Delegations.Get( ctx, collections.Join(sdk.AccAddress(accountAddr), sdk.ValAddress(valbz)), ) require.NoError(t, err) require.NotNil(t, del) // check if tracking is updated accordingly - lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr) + lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, s.accountsKeeper, accountAddr) delLocking := lockupAccountInfoResponse.DelegatedLocking // should be update as ubd entry is matured require.True(t, delLocking.AmountOf("stake").Equal(math.ZeroInt())) @@ -178,7 +173,7 @@ func (s *IntegrationTestSuite) TestContinuousLockingAccount() { require.True(t, delFree.AmountOf("stake").Equal(math.NewInt(100))) // check if the entry is removed - unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress) + unbondingEntriesResponse := s.queryUnbondingEntries(ctx, s.accountsKeeper, accountAddr, val.OperatorAddress) entries := unbondingEntriesResponse.UnbondingEntries require.Len(t, entries, 0) }) diff --git a/tests/integration/accounts/lockup/delayed_lockup_test_suite.go b/tests/integration/v2/accounts/lockup/delayed_lockup_test_suite.go similarity index 64% rename from tests/integration/accounts/lockup/delayed_lockup_test_suite.go rename to tests/integration/v2/accounts/lockup/delayed_lockup_test_suite.go index 046240d9df3d..d78158663c62 100644 --- a/tests/integration/accounts/lockup/delayed_lockup_test_suite.go +++ b/tests/integration/v2/accounts/lockup/delayed_lockup_test_suite.go @@ -13,33 +13,34 @@ import ( types "cosmossdk.io/x/accounts/defaults/lockup/v1" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/tests/integration/v2" sdk "github.com/cosmos/cosmos-sdk/types" ) func (s *IntegrationTestSuite) TestDelayedLockingAccount() { t := s.T() - app := setupApp(t) currentTime := time.Now() - ctx := sdk.NewContext(app.CommitMultiStore(), false, app.Logger()).WithHeaderInfo(header.Info{ - Time: currentTime, - }) - s.setupStakingParams(ctx, app) - ownerAddrStr, err := app.AuthKeeper.AddressCodec().BytesToString(accOwner) + ctx := s.ctx + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime}) + + s.setupStakingParams(ctx, s.stakingKeeper) + + ownerAddrStr, err := s.authKeeper.AddressCodec().BytesToString(accOwner) require.NoError(t, err) - s.fundAccount(app, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))}) + s.fundAccount(s.bankKeeper, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))}) randAcc := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - _, accountAddr, err := app.AccountsKeeper.Init(ctx, lockupaccount.DELAYED_LOCKING_ACCOUNT, accOwner, &types.MsgInitLockupAccount{ + _, accountAddr, err := s.accountsKeeper.Init(ctx, lockupaccount.DELAYED_LOCKING_ACCOUNT, accOwner, &types.MsgInitLockupAccount{ Owner: ownerAddrStr, // end time in 1 minutes EndTime: currentTime.Add(time.Minute), }, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}, nil) require.NoError(t, err) - addr, err := app.AuthKeeper.AddressCodec().BytesToString(randAcc) + addr, err := s.authKeeper.AddressCodec().BytesToString(randAcc) require.NoError(t, err) - vals, err := app.StakingKeeper.GetAllValidators(ctx) + vals, err := s.stakingKeeper.GetAllValidators(ctx) require.NoError(t, err) val := vals[0] @@ -49,7 +50,7 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NotNil(t, err) }) t.Run("error - execute send message, insufficient fund", func(t *testing.T) { @@ -58,7 +59,7 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NotNil(t, err) }) t.Run("ok - execute delegate message", func(t *testing.T) { @@ -67,20 +68,20 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() { ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(100)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - del, err := app.StakingKeeper.Delegations.Get( + del, err := s.stakingKeeper.Delegations.Get( ctx, collections.Join(sdk.AccAddress(accountAddr), sdk.ValAddress(valbz)), ) require.NoError(t, err) require.NotNil(t, del) // check if tracking is updated accordingly - lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr) + lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, s.accountsKeeper, accountAddr) delLocking := lockupAccountInfoResponse.DelegatedLocking require.True(t, delLocking.AmountOf("stake").Equal(math.NewInt(100))) }) @@ -89,11 +90,11 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() { Sender: ownerAddrStr, ValidatorAddress: val.OperatorAddress, } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) }) t.Run("ok - execute undelegate message", func(t *testing.T) { - vals, err := app.StakingKeeper.GetAllValidators(ctx) + vals, err := s.stakingKeeper.GetAllValidators(ctx) require.NoError(t, err) val := vals[0] msg := &types.MsgUndelegate{ @@ -101,19 +102,19 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() { ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(100)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - ubd, err := app.StakingKeeper.GetUnbondingDelegation( + ubd, err := s.stakingKeeper.GetUnbondingDelegation( ctx, sdk.AccAddress(accountAddr), sdk.ValAddress(valbz), ) require.NoError(t, err) require.Equal(t, len(ubd.Entries), 1) // check if an entry is added - unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress) + unbondingEntriesResponse := s.queryUnbondingEntries(ctx, s.accountsKeeper, accountAddr, val.OperatorAddress) entries := unbondingEntriesResponse.UnbondingEntries require.True(t, entries[0].Amount.Amount.Equal(math.NewInt(100))) require.True(t, entries[0].ValidatorAddress == val.OperatorAddress) @@ -121,13 +122,10 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() { // Update context time // After endtime fund should be unlock - // And unbond time elapsed - ctx = ctx.WithHeaderInfo(header.Info{ - Time: currentTime.Add(time.Second * 61), - }) + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime.Add(time.Second * 61)}) // trigger endblock for staking to handle matured unbonding delegation - _, err = app.StakingKeeper.EndBlocker(ctx) + _, err = s.stakingKeeper.EndBlocker(ctx) require.NoError(t, err) // Check if token is sendable after unlock @@ -137,19 +135,19 @@ func (s *IntegrationTestSuite) TestDelayedLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - balance := app.BankKeeper.GetBalance(ctx, randAcc, "stake") + balance := s.bankKeeper.GetBalance(ctx, randAcc, "stake") require.True(t, balance.Amount.Equal(math.NewInt(100))) // check if tracking ubd entry is updated accordingly - lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr) + lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, s.accountsKeeper, accountAddr) delLocking := lockupAccountInfoResponse.DelegatedLocking require.True(t, delLocking.AmountOf("stake").Equal(math.ZeroInt())) // check if the entry is removed - unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress) + unbondingEntriesResponse := s.queryUnbondingEntries(ctx, s.accountsKeeper, accountAddr, val.OperatorAddress) entries := unbondingEntriesResponse.UnbondingEntries require.Len(t, entries, 0) }) diff --git a/tests/integration/accounts/lockup/lockup_account_test.go b/tests/integration/v2/accounts/lockup/lockup_account_test.go similarity index 100% rename from tests/integration/accounts/lockup/lockup_account_test.go rename to tests/integration/v2/accounts/lockup/lockup_account_test.go diff --git a/tests/integration/accounts/lockup/periodic_lockup_test_suite.go b/tests/integration/v2/accounts/lockup/periodic_lockup_test_suite.go similarity index 66% rename from tests/integration/accounts/lockup/periodic_lockup_test_suite.go rename to tests/integration/v2/accounts/lockup/periodic_lockup_test_suite.go index ef3a0dcd6d57..582833b2e8f2 100644 --- a/tests/integration/accounts/lockup/periodic_lockup_test_suite.go +++ b/tests/integration/v2/accounts/lockup/periodic_lockup_test_suite.go @@ -13,23 +13,24 @@ import ( types "cosmossdk.io/x/accounts/defaults/lockup/v1" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/tests/integration/v2" sdk "github.com/cosmos/cosmos-sdk/types" ) func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { t := s.T() - app := setupApp(t) currentTime := time.Now() - ctx := sdk.NewContext(app.CommitMultiStore(), false, app.Logger()).WithHeaderInfo(header.Info{ - Time: currentTime, - }) - s.setupStakingParams(ctx, app) - ownerAddrStr, err := app.AuthKeeper.AddressCodec().BytesToString(accOwner) + ctx := s.ctx + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime}) + + s.setupStakingParams(ctx, s.stakingKeeper) + + ownerAddrStr, err := s.authKeeper.AddressCodec().BytesToString(accOwner) require.NoError(t, err) - s.fundAccount(app, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))}) + s.fundAccount(s.bankKeeper, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))}) randAcc := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - _, accountAddr, err := app.AccountsKeeper.Init(ctx, lockupaccount.PERIODIC_LOCKING_ACCOUNT, accOwner, &types.MsgInitPeriodicLockingAccount{ + _, accountAddr, err := s.accountsKeeper.Init(ctx, lockupaccount.PERIODIC_LOCKING_ACCOUNT, accOwner, &types.MsgInitPeriodicLockingAccount{ Owner: ownerAddrStr, StartTime: currentTime, LockingPeriods: []types.Period{ @@ -49,10 +50,10 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { }, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1500))}, nil) require.NoError(t, err) - addr, err := app.AuthKeeper.AddressCodec().BytesToString(randAcc) + addr, err := s.authKeeper.AddressCodec().BytesToString(randAcc) require.NoError(t, err) - vals, err := app.StakingKeeper.GetAllValidators(ctx) + vals, err := s.stakingKeeper.GetAllValidators(ctx) require.NoError(t, err) val := vals[0] @@ -62,7 +63,7 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NotNil(t, err) }) // No token being unlocked yet @@ -72,15 +73,13 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NotNil(t, err) }) // Update context time // After first period 500stake should be unlock - ctx = ctx.WithHeaderInfo(header.Info{ - Time: currentTime.Add(time.Minute), - }) + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime.Add(time.Minute)}) // Check if 500 stake is sendable now t.Run("ok - execute send message", func(t *testing.T) { @@ -89,18 +88,16 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(500))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - balance := app.BankKeeper.GetBalance(ctx, randAcc, "stake") + balance := s.bankKeeper.GetBalance(ctx, randAcc, "stake") require.True(t, balance.Amount.Equal(math.NewInt(500))) }) // Update context time // After second period 1000stake should be unlock - ctx = ctx.WithHeaderInfo(header.Info{ - Time: currentTime.Add(time.Minute * 2), - }) + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime.Add(time.Minute * 2)}) t.Run("ok - execute delegate message", func(t *testing.T) { msg := &types.MsgDelegate{ @@ -108,20 +105,20 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(100)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - del, err := app.StakingKeeper.Delegations.Get( + del, err := s.stakingKeeper.Delegations.Get( ctx, collections.Join(sdk.AccAddress(accountAddr), sdk.ValAddress(valbz)), ) require.NoError(t, err) require.NotNil(t, del) // check if tracking is updated accordingly - lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr) + lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, s.accountsKeeper, accountAddr) delLocking := lockupAccountInfoResponse.DelegatedLocking require.True(t, delLocking.AmountOf("stake").Equal(math.NewInt(100))) }) @@ -130,11 +127,11 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { Sender: ownerAddrStr, ValidatorAddress: val.OperatorAddress, } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) }) t.Run("ok - execute undelegate message", func(t *testing.T) { - vals, err := app.StakingKeeper.GetAllValidators(ctx) + vals, err := s.stakingKeeper.GetAllValidators(ctx) require.NoError(t, err) val := vals[0] msg := &types.MsgUndelegate{ @@ -142,19 +139,19 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(100)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - ubd, err := app.StakingKeeper.GetUnbondingDelegation( + ubd, err := s.stakingKeeper.GetUnbondingDelegation( ctx, sdk.AccAddress(accountAddr), sdk.ValAddress(valbz), ) require.NoError(t, err) require.Equal(t, len(ubd.Entries), 1) // check if an entry is added - unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress) + unbondingEntriesResponse := s.queryUnbondingEntries(ctx, s.accountsKeeper, accountAddr, val.OperatorAddress) entries := unbondingEntriesResponse.UnbondingEntries require.True(t, entries[0].Amount.Amount.Equal(math.NewInt(100))) require.True(t, entries[0].ValidatorAddress == val.OperatorAddress) @@ -162,12 +159,10 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { // Update context time // After third period 1500stake should be unlock - ctx = ctx.WithHeaderInfo(header.Info{ - Time: currentTime.Add(time.Minute * 3), - }) + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime.Add(time.Minute * 3)}) // trigger endblock for staking to handle matured unbonding delegation - _, err = app.StakingKeeper.EndBlocker(ctx) + _, err = s.stakingKeeper.EndBlocker(ctx) require.NoError(t, err) t.Run("ok - execute delegate message", func(t *testing.T) { @@ -176,20 +171,20 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(100)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - del, err := app.StakingKeeper.Delegations.Get( + del, err := s.stakingKeeper.Delegations.Get( ctx, collections.Join(sdk.AccAddress(accountAddr), sdk.ValAddress(valbz)), ) require.NoError(t, err) require.NotNil(t, del) // check if tracking is updated accordingly - lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr) + lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, s.accountsKeeper, accountAddr) // check if matured ubd entry cleared delLocking := lockupAccountInfoResponse.DelegatedLocking require.True(t, delLocking.AmountOf("stake").Equal(math.ZeroInt())) @@ -197,7 +192,7 @@ func (s *IntegrationTestSuite) TestPeriodicLockingAccount() { require.True(t, delFree.AmountOf("stake").Equal(math.NewInt(100))) // check if the entry is removed - unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress) + unbondingEntriesResponse := s.queryUnbondingEntries(ctx, s.accountsKeeper, accountAddr, val.OperatorAddress) entries := unbondingEntriesResponse.UnbondingEntries require.Len(t, entries, 0) }) diff --git a/tests/integration/accounts/lockup/permanent_lockup_test_suite.go b/tests/integration/v2/accounts/lockup/permanent_lockup_test_suite.go similarity index 63% rename from tests/integration/accounts/lockup/permanent_lockup_test_suite.go rename to tests/integration/v2/accounts/lockup/permanent_lockup_test_suite.go index ca38f5629eb5..f3a3e6d71dce 100644 --- a/tests/integration/accounts/lockup/permanent_lockup_test_suite.go +++ b/tests/integration/v2/accounts/lockup/permanent_lockup_test_suite.go @@ -13,31 +13,32 @@ import ( types "cosmossdk.io/x/accounts/defaults/lockup/v1" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/tests/integration/v2" sdk "github.com/cosmos/cosmos-sdk/types" ) func (s *IntegrationTestSuite) TestPermanentLockingAccount() { t := s.T() - app := setupApp(t) currentTime := time.Now() - ctx := sdk.NewContext(app.CommitMultiStore(), false, app.Logger()).WithHeaderInfo(header.Info{ - Time: currentTime, - }) - s.setupStakingParams(ctx, app) - ownerAddrStr, err := app.AuthKeeper.AddressCodec().BytesToString(accOwner) + ctx := s.ctx + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime}) + + s.setupStakingParams(ctx, s.stakingKeeper) + + ownerAddrStr, err := s.authKeeper.AddressCodec().BytesToString(accOwner) require.NoError(t, err) - s.fundAccount(app, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))}) + s.fundAccount(s.bankKeeper, ctx, accOwner, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))}) randAcc := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - _, accountAddr, err := app.AccountsKeeper.Init(ctx, lockupaccount.PERMANENT_LOCKING_ACCOUNT, accOwner, &types.MsgInitLockupAccount{ + _, accountAddr, err := s.accountsKeeper.Init(ctx, lockupaccount.PERMANENT_LOCKING_ACCOUNT, accOwner, &types.MsgInitLockupAccount{ Owner: ownerAddrStr, }, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}, nil) require.NoError(t, err) - addr, err := app.AuthKeeper.AddressCodec().BytesToString(randAcc) + addr, err := s.authKeeper.AddressCodec().BytesToString(randAcc) require.NoError(t, err) - vals, err := app.StakingKeeper.GetAllValidators(ctx) + vals, err := s.stakingKeeper.GetAllValidators(ctx) require.NoError(t, err) val := vals[0] @@ -47,7 +48,7 @@ func (s *IntegrationTestSuite) TestPermanentLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NotNil(t, err) }) t.Run("error - execute send message, insufficient fund", func(t *testing.T) { @@ -56,7 +57,7 @@ func (s *IntegrationTestSuite) TestPermanentLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NotNil(t, err) }) t.Run("ok - execute delegate message", func(t *testing.T) { @@ -65,20 +66,20 @@ func (s *IntegrationTestSuite) TestPermanentLockingAccount() { ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(100)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - del, err := app.StakingKeeper.Delegations.Get( + del, err := s.stakingKeeper.Delegations.Get( ctx, collections.Join(sdk.AccAddress(accountAddr), sdk.ValAddress(valbz)), ) require.NoError(t, err) require.NotNil(t, del) // check if tracking is updated accordingly - lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr) + lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, s.accountsKeeper, accountAddr) delLocking := lockupAccountInfoResponse.DelegatedLocking require.True(t, delLocking.AmountOf("stake").Equal(math.NewInt(100))) }) @@ -87,11 +88,11 @@ func (s *IntegrationTestSuite) TestPermanentLockingAccount() { Sender: ownerAddrStr, ValidatorAddress: val.OperatorAddress, } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) }) t.Run("ok - execute undelegate message", func(t *testing.T) { - vals, err := app.StakingKeeper.GetAllValidators(ctx) + vals, err := s.stakingKeeper.GetAllValidators(ctx) require.NoError(t, err) val := vals[0] msg := &types.MsgUndelegate{ @@ -99,25 +100,25 @@ func (s *IntegrationTestSuite) TestPermanentLockingAccount() { ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(100)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - ubd, err := app.StakingKeeper.GetUnbondingDelegation( + ubd, err := s.stakingKeeper.GetUnbondingDelegation( ctx, sdk.AccAddress(accountAddr), sdk.ValAddress(valbz), ) require.NoError(t, err) require.Equal(t, len(ubd.Entries), 1) // check if an entry is added - unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress) + unbondingEntriesResponse := s.queryUnbondingEntries(ctx, s.accountsKeeper, accountAddr, val.OperatorAddress) entries := unbondingEntriesResponse.UnbondingEntries require.True(t, entries[0].Amount.Amount.Equal(math.NewInt(100))) require.True(t, entries[0].ValidatorAddress == val.OperatorAddress) }) - s.fundAccount(app, ctx, accountAddr, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}) + s.fundAccount(s.bankKeeper, ctx, accountAddr, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}) t.Run("ok - execute send message", func(t *testing.T) { msg := &types.MsgSend{ @@ -125,20 +126,18 @@ func (s *IntegrationTestSuite) TestPermanentLockingAccount() { ToAddress: addr, Amount: sdk.Coins{sdk.NewCoin("stake", math.NewInt(100))}, } - err := s.executeTx(ctx, msg, app, accountAddr, accOwner) + err := s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - balance := app.BankKeeper.GetBalance(ctx, randAcc, "stake") + balance := s.bankKeeper.GetBalance(ctx, randAcc, "stake") require.True(t, balance.Amount.Equal(math.NewInt(100))) }) // Update context time - ctx = ctx.WithHeaderInfo(header.Info{ - Time: currentTime.Add(time.Second * 11), - }) + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: currentTime.Add(time.Second * 11)}) // trigger endblock for staking to handle matured unbonding delegation - _, err = app.StakingKeeper.EndBlocker(ctx) + _, err = s.stakingKeeper.EndBlocker(ctx) require.NoError(t, err) t.Run("ok - execute delegate message", func(t *testing.T) { @@ -147,26 +146,26 @@ func (s *IntegrationTestSuite) TestPermanentLockingAccount() { ValidatorAddress: val.OperatorAddress, Amount: sdk.NewCoin("stake", math.NewInt(10)), } - err = s.executeTx(ctx, msg, app, accountAddr, accOwner) + err = s.executeTx(ctx, msg, s.accountsKeeper, accountAddr, accOwner) require.NoError(t, err) - valbz, err := app.StakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) + valbz, err := s.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.OperatorAddress) require.NoError(t, err) - del, err := app.StakingKeeper.Delegations.Get( + del, err := s.stakingKeeper.Delegations.Get( ctx, collections.Join(sdk.AccAddress(accountAddr), sdk.ValAddress(valbz)), ) require.NoError(t, err) require.NotNil(t, del) // check if tracking is updated accordingly - lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr) + lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, s.accountsKeeper, accountAddr) delLocking := lockupAccountInfoResponse.DelegatedLocking // matured ubd entry should be cleared so del locking should only be 10 require.True(t, delLocking.AmountOf("stake").Equal(math.NewInt(10))) // check if the entry is removed - unbondingEntriesResponse := s.queryUnbondingEntries(ctx, app, accountAddr, val.OperatorAddress) + unbondingEntriesResponse := s.queryUnbondingEntries(ctx, s.accountsKeeper, accountAddr, val.OperatorAddress) entries := unbondingEntriesResponse.UnbondingEntries require.Len(t, entries, 0) }) diff --git a/tests/integration/v2/accounts/lockup/utils.go b/tests/integration/v2/accounts/lockup/utils.go new file mode 100644 index 000000000000..efe329a8f092 --- /dev/null +++ b/tests/integration/v2/accounts/lockup/utils.go @@ -0,0 +1,253 @@ +package lockup + +import ( + "context" + "time" + + "github.com/stretchr/testify/require" + "github.com/stretchr/testify/suite" + + "cosmossdk.io/core/router" + "cosmossdk.io/core/transaction" + "cosmossdk.io/depinject" + "cosmossdk.io/log" + "cosmossdk.io/runtime/v2" + "cosmossdk.io/x/accounts" + basedepinject "cosmossdk.io/x/accounts/defaults/base/depinject" + lockupdepinject "cosmossdk.io/x/accounts/defaults/lockup/depinject" + types "cosmossdk.io/x/accounts/defaults/lockup/v1" + _ "cosmossdk.io/x/bank" // import as blank for app wiring + bankkeeper "cosmossdk.io/x/bank/keeper" + "cosmossdk.io/x/bank/testutil" + banktypes "cosmossdk.io/x/bank/types" + _ "cosmossdk.io/x/consensus" + _ "cosmossdk.io/x/distribution" // import as blank for app wiring + distrkeeper "cosmossdk.io/x/distribution/keeper" + distrtypes "cosmossdk.io/x/distribution/types" + _ "cosmossdk.io/x/staking" // import as blank for app wiring + stakingkeeper "cosmossdk.io/x/staking/keeper" + stakingtypes "cosmossdk.io/x/staking/types" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/tests/integration/v2" + "github.com/cosmos/cosmos-sdk/testutil/configurator" + sdk "github.com/cosmos/cosmos-sdk/types" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring`` + _ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring +) + +var ( + ownerAddr = secp256k1.GenPrivKey().PubKey().Address() + accOwner = sdk.AccAddress(ownerAddr) +) + +type IntegrationTestSuite struct { + suite.Suite + + app *integration.App + ctx context.Context + + authKeeper authkeeper.AccountKeeper + accountsKeeper accounts.Keeper + bankKeeper bankkeeper.BaseKeeper + stakingKeeper *stakingkeeper.Keeper + distrKeeper distrkeeper.Keeper +} + +func NewIntegrationTestSuite() *IntegrationTestSuite { + return &IntegrationTestSuite{} +} + +func (s *IntegrationTestSuite) SetupSuite() { + s.T().Log("setting up integration test suite") + moduleConfigs := []configurator.ModuleOption{ + configurator.AccountsModule(), + configurator.AuthModule(), + configurator.BankModule(), + configurator.VestingModule(), + configurator.StakingModule(), + configurator.TxModule(), + configurator.ValidateModule(), + configurator.ConsensusModule(), + configurator.GenutilModule(), + configurator.DistributionModule(), + } + + var err error + startupCfg := integration.DefaultStartUpConfig(s.T()) + + msgRouterService := integration.NewRouterService() + s.registerMsgRouterService(msgRouterService) + + var routerFactory runtime.RouterServiceFactory = func(_ []byte) router.Service { + return msgRouterService + } + + queryRouterService := integration.NewRouterService() + s.registerQueryRouterService(queryRouterService) + + serviceBuilder := runtime.NewRouterBuilder(routerFactory, queryRouterService) + + startupCfg.BranchService = &integration.BranchService{} + startupCfg.RouterServiceBuilder = serviceBuilder + startupCfg.HeaderService = &integration.HeaderService{} + startupCfg.GasService = &integration.GasService{} + + s.app, err = integration.NewApp( + depinject.Configs(configurator.NewAppV2Config(moduleConfigs...), depinject.Provide( + // inject desired account types: + basedepinject.ProvideAccount, + + // provide base account options + basedepinject.ProvideSecp256K1PubKey, + + // inject desired account types: + lockupdepinject.ProvideAllLockupAccounts, + ), depinject.Supply(log.NewNopLogger())), + startupCfg, + &s.bankKeeper, &s.accountsKeeper, &s.authKeeper, &s.stakingKeeper, &s.distrKeeper) + require.NoError(s.T(), err) + + s.ctx = s.app.StateLatestContext(s.T()) +} + +func (s *IntegrationTestSuite) registerMsgRouterService(router *integration.RouterService) { + // register custom router service + bankSendHandler := func(ctx context.Context, req transaction.Msg) (transaction.Msg, error) { + msg, ok := req.(*banktypes.MsgSend) + if !ok { + return nil, integration.ErrInvalidMsgType + } + msgServer := bankkeeper.NewMsgServerImpl(s.bankKeeper) + resp, err := msgServer.Send(ctx, msg) + return resp, err + } + + stakingDelegateHandler := func(ctx context.Context, req transaction.Msg) (transaction.Msg, error) { + msg, ok := req.(*stakingtypes.MsgDelegate) + if !ok { + return nil, integration.ErrInvalidMsgType + } + msgServer := stakingkeeper.NewMsgServerImpl(s.stakingKeeper) + resp, err := msgServer.Delegate(ctx, msg) + return resp, err + } + + stakingUndelegateHandler := func(ctx context.Context, req transaction.Msg) (transaction.Msg, error) { + msg, ok := req.(*stakingtypes.MsgUndelegate) + if !ok { + return nil, integration.ErrInvalidMsgType + } + msgServer := stakingkeeper.NewMsgServerImpl(s.stakingKeeper) + resp, err := msgServer.Undelegate(ctx, msg) + return resp, err + } + + distrWithdrawRewardHandler := func(ctx context.Context, req transaction.Msg) (transaction.Msg, error) { + msg, ok := req.(*distrtypes.MsgWithdrawDelegatorReward) + if !ok { + return nil, integration.ErrInvalidMsgType + } + msgServer := distrkeeper.NewMsgServerImpl(s.distrKeeper) + resp, err := msgServer.WithdrawDelegatorReward(ctx, msg) + return resp, err + } + + router.RegisterHandler(bankSendHandler, "cosmos.bank.v1beta1.MsgSend") + router.RegisterHandler(stakingDelegateHandler, "cosmos.staking.v1beta1.MsgDelegate") + router.RegisterHandler(stakingUndelegateHandler, "cosmos.staking.v1beta1.MsgUndelegate") + router.RegisterHandler(distrWithdrawRewardHandler, "cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward") +} + +func (s *IntegrationTestSuite) registerQueryRouterService(router *integration.RouterService) { + // register custom router service + stakingParamsQueryHandler := func(ctx context.Context, msg transaction.Msg) (transaction.Msg, error) { + req, ok := msg.(*stakingtypes.QueryParamsRequest) + if !ok { + return nil, integration.ErrInvalidMsgType + } + qs := stakingkeeper.NewQuerier(s.stakingKeeper) + resp, err := qs.Params(ctx, req) + return resp, err + } + + stakingUnbondingQueryHandler := func(ctx context.Context, msg transaction.Msg) (transaction.Msg, error) { + req, ok := msg.(*stakingtypes.QueryUnbondingDelegationRequest) + if !ok { + return nil, integration.ErrInvalidMsgType + } + qs := stakingkeeper.NewQuerier(s.stakingKeeper) + resp, err := qs.UnbondingDelegation(ctx, req) + return resp, err + } + + bankBalanceQueryHandler := func(ctx context.Context, msg transaction.Msg) (transaction.Msg, error) { + req, ok := msg.(*banktypes.QueryBalanceRequest) + if !ok { + return nil, integration.ErrInvalidMsgType + } + qs := bankkeeper.NewQuerier(&s.bankKeeper) + resp, err := qs.Balance(ctx, req) + return resp, err + } + + router.RegisterHandler(stakingParamsQueryHandler, "cosmos.staking.v1beta1.QueryParamsRequest") + router.RegisterHandler(stakingUnbondingQueryHandler, "cosmos.staking.v1beta1.QueryUnbondingDelegationRequest") + router.RegisterHandler(bankBalanceQueryHandler, "cosmos.bank.v1beta1.QueryBalanceRequest") +} + +func (s *IntegrationTestSuite) TearDownSuite() { + s.T().Log("tearing down integration test suite") +} + +func (s *IntegrationTestSuite) executeTx(ctx context.Context, msg sdk.Msg, ak accounts.Keeper, accAddr, sender []byte) error { + _, err := ak.Execute(ctx, accAddr, sender, msg, nil) + return err +} + +func (s *IntegrationTestSuite) queryAcc(ctx context.Context, req sdk.Msg, ak accounts.Keeper, accAddr []byte) (transaction.Msg, error) { + resp, err := ak.Query(ctx, accAddr, req) + return resp, err +} + +func (s *IntegrationTestSuite) fundAccount(bk bankkeeper.Keeper, ctx context.Context, addr sdk.AccAddress, amt sdk.Coins) { + require.NoError(s.T(), testutil.FundAccount(ctx, bk, addr, amt)) +} + +func (s *IntegrationTestSuite) queryLockupAccInfo(ctx context.Context, ak accounts.Keeper, accAddr []byte) *types.QueryLockupAccountInfoResponse { + req := &types.QueryLockupAccountInfoRequest{} + resp, err := s.queryAcc(ctx, req, ak, accAddr) + require.NoError(s.T(), err) + require.NotNil(s.T(), resp) + + lockupAccountInfoResponse, ok := resp.(*types.QueryLockupAccountInfoResponse) + require.True(s.T(), ok) + + return lockupAccountInfoResponse +} + +func (s *IntegrationTestSuite) queryUnbondingEntries(ctx context.Context, ak accounts.Keeper, accAddr []byte, valAddr string) *types.QueryUnbondingEntriesResponse { + req := &types.QueryUnbondingEntriesRequest{ + ValidatorAddress: valAddr, + } + resp, err := s.queryAcc(ctx, req, ak, accAddr) + require.NoError(s.T(), err) + require.NotNil(s.T(), resp) + + unbondingEntriesResponse, ok := resp.(*types.QueryUnbondingEntriesResponse) + require.True(s.T(), ok) + + return unbondingEntriesResponse +} + +func (s *IntegrationTestSuite) setupStakingParams(ctx context.Context, sk *stakingkeeper.Keeper) { + params, err := sk.Params.Get(ctx) + require.NoError(s.T(), err) + + // update unbonding time + params.UnbondingTime = time.Duration(time.Second * 10) + err = sk.Params.Set(ctx, params) + require.NoError(s.T(), err) +} diff --git a/tests/integration/accounts/multisig/account_test.go b/tests/integration/v2/accounts/multisig/account_test.go similarity index 80% rename from tests/integration/accounts/multisig/account_test.go rename to tests/integration/v2/accounts/multisig/account_test.go index 8e03674ec480..7cd17cb7a5c2 100644 --- a/tests/integration/accounts/multisig/account_test.go +++ b/tests/integration/v2/accounts/multisig/account_test.go @@ -15,6 +15,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/tests/integration/v2" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -24,12 +25,12 @@ func TestIntegrationTestSuite(t *testing.T) { // TestSimpleSendProposal creates a multisig account with 1 member, sends a tx, votes and executes it. func (s *IntegrationTestSuite) TestSimpleSendProposal() { - ctx := sdk.NewContext(s.app.CommitMultiStore(), false, s.app.Logger()).WithHeaderInfo(header.Info{ - Time: time.Now(), - }) + ctx := s.app.StateLatestContext(s.T()) + + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: time.Now()}) randAcc := sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address()) - addr, err := s.app.AuthKeeper.AddressCodec().BytesToString(randAcc) + addr, err := s.authKeeper.AddressCodec().BytesToString(randAcc) s.NoError(err) initialMembers := map[string]uint64{ @@ -37,7 +38,7 @@ func (s *IntegrationTestSuite) TestSimpleSendProposal() { } accountAddr, accAddrStr := s.initAccount(ctx, s.members[0], initialMembers) - balance := s.app.BankKeeper.GetBalance(ctx, randAcc, "stake") + balance := s.bankKeeper.GetBalance(ctx, randAcc, "stake") s.Equal(math.NewInt(0), balance.Amount) // do a simple bank send @@ -70,37 +71,39 @@ func (s *IntegrationTestSuite) TestSimpleSendProposal() { s.NoError(err) foundPropResult := false - for _, v := range ctx.EventManager().Events() { - if v.Type == "proposal_tally" { + events := integration.EventsFromContext(ctx) + for _, e := range events { + if e.Type == "proposal_tally" { foundPropResult = true - status, found := v.GetAttribute("status") + attr, found := integration.GetAttribute(e, "status") s.True(found) - s.Equal(v1.ProposalStatus_PROPOSAL_STATUS_PASSED.String(), status.Value) + s.Equal(v1.ProposalStatus_PROPOSAL_STATUS_PASSED.String(), attr.Value) - yesVotes, found := v.GetAttribute("yes_votes") + yesVotes, found := integration.GetAttribute(e, "yes_votes") s.True(found) s.Equal("100", yesVotes.Value) - noVotes, found := v.GetAttribute("no_votes") + noVotes, found := integration.GetAttribute(e, "no_votes") s.True(found) s.Equal("0", noVotes.Value) - propID, found := v.GetAttribute("proposal_id") + propID, found := integration.GetAttribute(e, "proposal_id") s.True(found) s.Equal("0", propID.Value) - execErr, found := v.GetAttribute("exec_err") + execErr, found := integration.GetAttribute(e, "exec_err") s.True(found) s.Equal("", execErr.Value) - rejectErr, found := v.GetAttribute("reject_err") + rejectErr, found := integration.GetAttribute(e, "reject_err") s.True(found) s.Equal("", rejectErr.Value) + } } s.True(foundPropResult) - balance = s.app.BankKeeper.GetBalance(ctx, randAcc, "stake") + balance = s.bankKeeper.GetBalance(ctx, randAcc, "stake") s.Equal(int64(100), balance.Amount.Int64()) // try to execute again, should fail @@ -111,9 +114,9 @@ func (s *IntegrationTestSuite) TestSimpleSendProposal() { // TestConfigUpdate creates a multisig with 1 member, adds 2 more members and // changes the config to require 2/3 majority (also through a proposal). func (s *IntegrationTestSuite) TestConfigUpdate() { - ctx := sdk.NewContext(s.app.CommitMultiStore(), false, s.app.Logger()).WithHeaderInfo(header.Info{ - Time: time.Now(), - }) + ctx := s.app.StateLatestContext(s.T()) + + ctx = integration.SetHeaderInfo(ctx, header.Info{Time: time.Now()}) initialMembers := map[string]uint64{ s.membersAddr[0]: 100, @@ -223,35 +226,37 @@ func (s *IntegrationTestSuite) TestConfigUpdate() { err = s.executeProposal(ctx, accountAddr, s.members[0], 1) s.ErrorContains(err, "voting period has not ended yet, and early execution is not enabled") - headerInfo := ctx.HeaderInfo() + headerInfo := integration.HeaderInfoFromContext(ctx) headerInfo.Time = headerInfo.Time.Add(time.Second * 121) - ctx = ctx.WithHeaderInfo(headerInfo) + ctx = integration.SetHeaderInfo(ctx, headerInfo) // now it should work, but the proposal will fail err = s.executeProposal(ctx, accountAddr, s.members[0], 1) s.NoError(err) foundPropResult := false - for _, v := range ctx.EventManager().Events() { - if v.Type == "proposal_tally" { - propID, found := v.GetAttribute("proposal_id") + events := integration.EventsFromContext(ctx) + for _, e := range events { + if e.Type == "proposal_tally" { + propID, found := integration.GetAttribute(e, "proposal_id") s.True(found) if propID.Value == "1" { foundPropResult = true - status, found := v.GetAttribute("status") + status, found := integration.GetAttribute(e, "status") s.True(found) s.Equal(v1.ProposalStatus_PROPOSAL_STATUS_REJECTED.String(), status.Value) // exec_err is nil because the proposal didn't execute - execErr, found := v.GetAttribute("exec_err") + execErr, found := integration.GetAttribute(e, "exec_err") s.True(found) s.Equal("", execErr.Value) - rejectErr, found := v.GetAttribute("reject_err") + rejectErr, found := integration.GetAttribute(e, "reject_err") s.True(found) s.Equal("threshold not reached", rejectErr.Value) } + } } s.True(foundPropResult) diff --git a/tests/integration/v2/accounts/multisig/test_suite.go b/tests/integration/v2/accounts/multisig/test_suite.go new file mode 100644 index 000000000000..e71c432f7495 --- /dev/null +++ b/tests/integration/v2/accounts/multisig/test_suite.go @@ -0,0 +1,223 @@ +package multisig + +import ( + "context" + + "github.com/stretchr/testify/suite" + + "cosmossdk.io/core/router" + "cosmossdk.io/core/transaction" + "cosmossdk.io/depinject" + "cosmossdk.io/log" + "cosmossdk.io/math" + "cosmossdk.io/runtime/v2" + "cosmossdk.io/x/accounts" + basedepinject "cosmossdk.io/x/accounts/defaults/base/depinject" + multisigdepinject "cosmossdk.io/x/accounts/defaults/multisig/depinject" + v1 "cosmossdk.io/x/accounts/defaults/multisig/v1" + accountsv1 "cosmossdk.io/x/accounts/v1" + _ "cosmossdk.io/x/bank" // import as blank for app wiring + bankkeeper "cosmossdk.io/x/bank/keeper" + "cosmossdk.io/x/bank/testutil" + banktypes "cosmossdk.io/x/bank/types" + _ "cosmossdk.io/x/consensus" + _ "cosmossdk.io/x/distribution" // import as blank for app wiring + distrkeeper "cosmossdk.io/x/distribution/keeper" + _ "cosmossdk.io/x/staking" // import as blank for app wiring + stakingkeeper "cosmossdk.io/x/staking/keeper" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + "github.com/cosmos/cosmos-sdk/tests/integration/v2" + "github.com/cosmos/cosmos-sdk/testutil/configurator" + sdk "github.com/cosmos/cosmos-sdk/types" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + _ "github.com/cosmos/cosmos-sdk/x/auth/tx/config" // import as blank for app wiring`` + _ "github.com/cosmos/cosmos-sdk/x/auth/vesting" // import as blank for app wiring + _ "github.com/cosmos/cosmos-sdk/x/genutil" // import as blank for app wiring +) + +type IntegrationTestSuite struct { + suite.Suite + + app *integration.App + + members []sdk.AccAddress + membersAddr []string + + authKeeper authkeeper.AccountKeeper + accountsKeeper accounts.Keeper + bankKeeper bankkeeper.BaseKeeper + stakingKeeper *stakingkeeper.Keeper + distrKeeper distrkeeper.Keeper +} + +func NewIntegrationTestSuite() *IntegrationTestSuite { + return &IntegrationTestSuite{} +} + +func (s *IntegrationTestSuite) SetupSuite() { + moduleConfigs := []configurator.ModuleOption{ + configurator.AccountsModule(), + configurator.AuthModule(), + configurator.BankModule(), + configurator.VestingModule(), + configurator.StakingModule(), + configurator.TxModule(), + configurator.ValidateModule(), + configurator.ConsensusModule(), + configurator.GenutilModule(), + configurator.DistributionModule(), + } + + var err error + startupCfg := integration.DefaultStartUpConfig(s.T()) + + msgRouterService := integration.NewRouterService() + s.registerMsgRouterService(msgRouterService) + + var routerFactory runtime.RouterServiceFactory = func(_ []byte) router.Service { + return msgRouterService + } + + queryRouterService := integration.NewRouterService() + s.registerQueryRouterService(queryRouterService) + + serviceBuilder := runtime.NewRouterBuilder(routerFactory, queryRouterService) + + startupCfg.BranchService = &integration.BranchService{} + startupCfg.RouterServiceBuilder = serviceBuilder + startupCfg.HeaderService = &integration.HeaderService{} + startupCfg.GasService = &integration.GasService{} + + s.app, err = integration.NewApp( + depinject.Configs(configurator.NewAppV2Config(moduleConfigs...), depinject.Provide( + // inject desired account types: + basedepinject.ProvideAccount, + + // provide base account options + basedepinject.ProvideSecp256K1PubKey, + + // inject desired account types: + multisigdepinject.ProvideAccount, + ), depinject.Supply(log.NewNopLogger())), + startupCfg, + &s.bankKeeper, &s.accountsKeeper, &s.authKeeper, &s.stakingKeeper, &s.distrKeeper) + s.NoError(err) + + s.members = []sdk.AccAddress{} + for i := 0; i < 10; i++ { + addr := secp256k1.GenPrivKey().PubKey().Address() + addrStr, err := s.authKeeper.AddressCodec().BytesToString(addr) + s.NoError(err) + s.membersAddr = append(s.membersAddr, addrStr) + s.members = append(s.members, sdk.AccAddress(addr)) + } +} + +func (s *IntegrationTestSuite) registerMsgRouterService(router *integration.RouterService) { + // register custom router service + bankSendHandler := func(ctx context.Context, req transaction.Msg) (transaction.Msg, error) { + msg, ok := req.(*banktypes.MsgSend) + if !ok { + return nil, integration.ErrInvalidMsgType + } + msgServer := bankkeeper.NewMsgServerImpl(s.bankKeeper) + resp, err := msgServer.Send(ctx, msg) + return resp, err + } + + // register custom router service + accountsExeccHandler := func(ctx context.Context, req transaction.Msg) (transaction.Msg, error) { + msg, ok := req.(*accountsv1.MsgExecute) + if !ok { + return nil, integration.ErrInvalidMsgType + } + msgServer := accounts.NewMsgServer(s.accountsKeeper) + resp, err := msgServer.Execute(ctx, msg) + return resp, err + } + + router.RegisterHandler(bankSendHandler, "cosmos.bank.v1beta1.MsgSend") + router.RegisterHandler(accountsExeccHandler, "cosmos.accounts.v1.MsgExecute") +} + +func (s *IntegrationTestSuite) registerQueryRouterService(router *integration.RouterService) { + // register custom router service + bankBalanceQueryHandler := func(ctx context.Context, msg transaction.Msg) (transaction.Msg, error) { + req, ok := msg.(*banktypes.QueryBalanceRequest) + if !ok { + return nil, integration.ErrInvalidMsgType + } + qs := bankkeeper.NewQuerier(&s.bankKeeper) + resp, err := qs.Balance(ctx, req) + return resp, err + } + + router.RegisterHandler(bankBalanceQueryHandler, "cosmos.bank.v1beta1.QueryBalanceRequest") +} + +func (s *IntegrationTestSuite) TearDownSuite() {} + +func (s *IntegrationTestSuite) executeTx(ctx context.Context, msg sdk.Msg, accAddr, sender []byte) error { + _, err := s.accountsKeeper.Execute(ctx, accAddr, sender, msg, nil) + return err +} + +func (s *IntegrationTestSuite) queryAcc(ctx context.Context, req sdk.Msg, accAddr []byte) (transaction.Msg, error) { + resp, err := s.accountsKeeper.Query(ctx, accAddr, req) + return resp, err +} + +func (s *IntegrationTestSuite) fundAccount(ctx context.Context, addr sdk.AccAddress, amt sdk.Coins) { + s.NoError(testutil.FundAccount(ctx, s.bankKeeper, addr, amt)) +} + +// initAccount initializes a multisig account with the given members and powers +// and returns the account address +func (s *IntegrationTestSuite) initAccount(ctx context.Context, sender []byte, membersPowers map[string]uint64) ([]byte, string) { + s.fundAccount(ctx, sender, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000000))}) + + members := []*v1.Member{} + for addrStr, power := range membersPowers { + members = append(members, &v1.Member{Address: addrStr, Weight: power}) + } + + _, accountAddr, err := s.accountsKeeper.Init(ctx, "multisig", sender, + &v1.MsgInit{ + Members: members, + Config: &v1.Config{ + Threshold: 100, + Quorum: 100, + VotingPeriod: 120, + Revote: false, + EarlyExecution: true, + }, + }, sdk.Coins{sdk.NewCoin("stake", math.NewInt(1000))}, nil) + s.NoError(err) + + accountAddrStr, err := s.authKeeper.AddressCodec().BytesToString(accountAddr) + s.NoError(err) + + return accountAddr, accountAddrStr +} + +// createProposal +func (s *IntegrationTestSuite) createProposal(ctx context.Context, accAddr, sender []byte, msgs ...*codectypes.Any) { + propReq := &v1.MsgCreateProposal{ + Proposal: &v1.Proposal{ + Title: "test", + Summary: "test", + Messages: msgs, + }, + } + err := s.executeTx(ctx, propReq, accAddr, sender) + s.NoError(err) +} + +func (s *IntegrationTestSuite) executeProposal(ctx context.Context, accAddr, sender []byte, proposalID uint64) error { + execReq := &v1.MsgExecuteProposal{ + ProposalId: proposalID, + } + return s.executeTx(ctx, execReq, accAddr, sender) +} diff --git a/tests/integration/v2/services.go b/tests/integration/v2/services.go index d77a72348866..96891da0b1ad 100644 --- a/tests/integration/v2/services.go +++ b/tests/integration/v2/services.go @@ -126,6 +126,20 @@ func GetAttributes(e []event.Event, key string) ([]event.Attribute, bool) { return attrs, len(attrs) > 0 } +func GetAttribute(e event.Event, key string) (event.Attribute, bool) { + attributes, err := e.Attributes() + if err != nil { + return event.Attribute{}, false + } + for _, attr := range attributes { + if attr.Key == key { + return attr, true + } + } + + return event.Attribute{}, false +} + func GasMeterFromContext(ctx context.Context) gas.Meter { iCtx, ok := ctx.Value(contextKey).(*integrationContext) if !ok {