Skip to content

Commit

Permalink
feat: addToExistingLock e2e tests (#2571)
Browse files Browse the repository at this point in the history
* add addToExistingLock tests

* second test pass

* clean up unused

* address Roman's suggestions
  • Loading branch information
czarcas7ic authored Sep 5, 2022
1 parent 6072607 commit fd59f43
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 63 deletions.
30 changes: 30 additions & 0 deletions tests/e2e/configurer/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
coretypes "github.com/tendermint/tendermint/rpc/core/types"

appparams "github.com/osmosis-labs/osmosis/v11/app/params"
"github.com/osmosis-labs/osmosis/v11/tests/e2e/configurer/config"

"github.com/osmosis-labs/osmosis/v11/tests/e2e/containers"
Expand Down Expand Up @@ -140,6 +141,35 @@ func (c *Config) SendIBC(dstChain *Config, recipient string, token sdk.Coin) {
c.t.Log("successfully sent IBC tokens")
}

func (c *Config) EnableSuperfluidAsset(denom string) {
chain, err := c.GetDefaultNode()
require.NoError(c.t, err)
chain.SubmitSuperfluidProposal(denom, sdk.NewCoin(appparams.BaseCoinUnit, sdk.NewInt(config.InitialMinDeposit)))
c.LatestProposalNumber += 1
chain.DepositProposal(c.LatestProposalNumber, false)
for _, node := range c.NodeConfigs {
node.VoteYesProposal(initialization.ValidatorWalletName, c.LatestProposalNumber)
}
}

func (c *Config) LockAndAddToExistingLock(amount sdk.Int, denom, lockupWalletAddr, lockupWalletSuperfluidAddr string) {
chain, err := c.GetDefaultNode()
require.NoError(c.t, err)

// lock tokens
chain.LockTokens(fmt.Sprintf("%v%s", amount, denom), "240s", lockupWalletAddr)
c.LatestLockNumber += 1
// add to existing lock
chain.AddToExistingLock(amount, denom, "240s", lockupWalletAddr)

// superfluid lock tokens
chain.LockTokens(fmt.Sprintf("%v%s", amount, denom), "240s", lockupWalletSuperfluidAddr)
c.LatestLockNumber += 1
chain.SuperfluidDelegate(c.LatestLockNumber, c.NodeConfigs[1].OperatorAddress, lockupWalletSuperfluidAddr)
// add to existing lock
chain.AddToExistingLock(amount, denom, "240s", lockupWalletSuperfluidAddr)
}

// GetDefaultNode returns the default node of the chain.
// The default node is the first one created. Returns error if no
// ndoes created.
Expand Down
70 changes: 68 additions & 2 deletions tests/e2e/configurer/chain/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,31 @@ import (

appparams "github.com/osmosis-labs/osmosis/v11/app/params"
"github.com/osmosis-labs/osmosis/v11/tests/e2e/configurer/config"
"github.com/osmosis-labs/osmosis/v11/tests/e2e/util"
gammtypes "github.com/osmosis-labs/osmosis/v11/x/gamm/types"
lockuptypes "github.com/osmosis-labs/osmosis/v11/x/lockup/types"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

func (n *NodeConfig) CreatePool(poolFile, from string) {
func (n *NodeConfig) CreatePool(poolFile, from string) uint64 {
n.LogActionF("creating pool from file %s", poolFile)
cmd := []string{"osmosisd", "tx", "gamm", "create-pool", fmt.Sprintf("--pool-file=/osmosis/%s", poolFile), fmt.Sprintf("--from=%s", from)}
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
require.NoError(n.t, err)
n.LogActionF("successfully created pool")

path := "osmosis/gamm/v1beta1/num_pools"

bz, err := n.QueryGRPCGateway(path)
require.NoError(n.t, err)

var numPools gammtypes.QueryNumPoolsResponse
err = util.Cdc.UnmarshalJSON(bz, &numPools)
require.NoError(n.t, err)
poolID := numPools.NumPools
n.LogActionF("successfully created pool %d", poolID)
return poolID
}

func (n *NodeConfig) SubmitUpgradeProposal(upgradeVersion string, upgradeHeight int64, initialDeposit sdk.Coin) {
Expand Down Expand Up @@ -85,6 +99,46 @@ func (n *NodeConfig) LockTokens(tokens string, duration string, from string) {
n.LogActionF("successfully created lock")
}

func (n *NodeConfig) AddToExistingLock(tokens sdk.Int, denom, duration, from string) {
n.LogActionF("retrieving existing lock ID")
durationPath := fmt.Sprintf("/osmosis/lockup/v1beta1/account_locked_longer_duration/%s?duration=%s", from, duration)
bz, err := n.QueryGRPCGateway(durationPath)
require.NoError(n.t, err)
var accountLockedDurationResp lockuptypes.AccountLockedDurationResponse
err = util.Cdc.UnmarshalJSON(bz, &accountLockedDurationResp)
require.NoError(n.t, err)
var lockID string
for _, periodLock := range accountLockedDurationResp.Locks {
if periodLock.Coins.AmountOf(denom).GT(sdk.ZeroInt()) {
lockID = fmt.Sprintf("%v", periodLock.ID)
break
}
}
n.LogActionF("noting previous lockup amount")
path := fmt.Sprintf("/osmosis/lockup/v1beta1/locked_by_id/%s", lockID)
bz, err = n.QueryGRPCGateway(path)
require.NoError(n.t, err)
var lockedResp lockuptypes.LockedResponse
err = util.Cdc.UnmarshalJSON(bz, &lockedResp)
require.NoError(n.t, err)
previousLockupAmount := lockedResp.Lock.Coins.AmountOf(denom)
n.LogActionF("previous lockup amount is %v", previousLockupAmount)
n.LogActionF("locking %s for %s", tokens, duration)
cmd := []string{"osmosisd", "tx", "lockup", "lock-tokens", fmt.Sprintf("%s%s", tokens, denom), fmt.Sprintf("--duration=%s", duration), fmt.Sprintf("--from=%s", from)}
_, _, err = n.containerManager.ExecTxCmd(n.t, n.chainId, n.Name, cmd)
require.NoError(n.t, err)
n.LogActionF("noting new lockup amount")
bz, err = n.QueryGRPCGateway(path)
require.NoError(n.t, err)
err = util.Cdc.UnmarshalJSON(bz, &lockedResp)
require.NoError(n.t, err)
newLockupAmount := lockedResp.Lock.Coins.AmountOf(denom)
n.LogActionF("new lockup amount is %v", newLockupAmount)
lockupDelta := newLockupAmount.Sub(previousLockupAmount)
require.True(n.t, lockupDelta.Equal(tokens))
n.LogActionF("successfully added to existing lock")
}

func (n *NodeConfig) SuperfluidDelegate(lockNumber int, valAddress string, from string) {
lockStr := strconv.Itoa(lockNumber)
n.LogActionF("superfluid delegating lock %s to %s", lockStr, valAddress)
Expand Down Expand Up @@ -114,6 +168,18 @@ func (n *NodeConfig) CreateWallet(walletName string) string {
return walletAddr
}

func (n *NodeConfig) GetWallet(walletName string) string {
n.LogActionF("retrieving wallet %s", walletName)
cmd := []string{"osmosisd", "keys", "show", walletName, "--keyring-backend=test"}
outBuf, _, err := n.containerManager.ExecCmd(n.t, n.Name, cmd, "")
require.NoError(n.t, err)
re := regexp.MustCompile("osmo1(.{38})")
walletAddr := fmt.Sprintf("%s\n", re.FindString(outBuf.String()))
walletAddr = strings.TrimSuffix(walletAddr, "\n")
n.LogActionF("wallet %s found, waller address - %s", walletName, walletAddr)
return walletAddr
}

func (n *NodeConfig) QueryPropStatusTimed(proposalNumber int, desiredStatus string, totalTime chan time.Duration) {
start := time.Now()
require.Eventually(
Expand Down
15 changes: 15 additions & 0 deletions tests/e2e/configurer/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func (uc *UpgradeConfigurer) ConfigureChain(chainConfig *chain.Config) error {
}

func (uc *UpgradeConfigurer) CreatePreUpgradeState() error {
const lockupWallet = "lockup-wallet"
const lockupWalletSuperfluid = "lockup-wallet-superfluid"

chainA := uc.chainConfigs[0]
chainANode, err := chainA.GetDefaultNode()
if err != nil {
Expand All @@ -124,6 +127,18 @@ func (uc *UpgradeConfigurer) CreatePreUpgradeState() error {

chainANode.CreatePool("pool1A.json", initialization.ValidatorWalletName)
chainBNode.CreatePool("pool1B.json", initialization.ValidatorWalletName)

// enable superfluid assets on chainA
chainA.EnableSuperfluidAsset("gamm/pool/1")

// setup wallets and send gamm tokens to these wallets (only chainA)
lockupWalletAddrA, lockupWalletSuperfluidAddrA := chainANode.CreateWallet(lockupWallet), chainANode.CreateWallet(lockupWalletSuperfluid)
chainANode.BankSend("10000000000000000000gamm/pool/1", chainA.NodeConfigs[0].PublicAddress, lockupWalletAddrA)
chainANode.BankSend("10000000000000000000gamm/pool/1", chainA.NodeConfigs[0].PublicAddress, lockupWalletSuperfluidAddrA)

// test lock and add to existing lock for both regular and superfluid lockups (only chainA)
chainA.LockAndAddToExistingLock(sdk.NewInt(1000000000000000000), "gamm/pool/1", lockupWalletAddrA, lockupWalletSuperfluidAddrA)

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *IntegrationTestSuite) SetupSuite() {
s.skipUpgrade, err = strconv.ParseBool(str)
s.Require().NoError(err)
if s.skipUpgrade {
s.T().Log(fmt.Sprintf("%s was true, skipping upgrade tests", skipIBCEnv))
s.T().Log(fmt.Sprintf("%s was true, skipping upgrade tests", skipUpgradeEnv))
}
}
upgradeSettings.IsEnabled = !s.skipUpgrade
Expand Down
Loading

0 comments on commit fd59f43

Please sign in to comment.