-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v8)!: validators can have different genesis and self-delegation …
…amounts (backport #1028) (#1039) * feat(v7)!: validators can have different genesis and self-delegation amounts (#1028) * feat validators can have different genesis and self-delegation amounts this is done by making ModifyGenesisAmounts take in an index parameter; the returned values will be used for the validator at that index. * Add a test for stake distribution in cosmos chains (cherry picked from commit 2908114) * fix v7 -> v8 namespace --------- Co-authored-by: violet <158512193+fastfadingviolets@users.noreply.github.com> Co-authored-by: Reece Williams <reecepbcups@gmail.com>
- Loading branch information
1 parent
8114cff
commit 5f41f4b
Showing
4 changed files
with
364 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package cosmos_test | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"strconv" | ||
"testing" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/strangelove-ventures/interchaintest/v8" | ||
"github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" | ||
"github.com/strangelove-ventures/interchaintest/v8/ibc" | ||
"github.com/strangelove-ventures/interchaintest/v8/testreporter" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap/zaptest" | ||
) | ||
|
||
func TestChainGenesisUnequalStake(t *testing.T) { | ||
if testing.Short() { | ||
t.Skip("skipping in short mode") | ||
} | ||
t.Parallel() | ||
const ( | ||
denom = "uatom" | ||
val1_stake = 1_000_000_000 | ||
val2_stake = 2_000_000_000 | ||
balance = 1_000_000_000_000 | ||
) | ||
validators := 2 | ||
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ | ||
{ | ||
Name: "gaia", | ||
ChainName: "gaia", | ||
Version: "v15.1.0", | ||
NumValidators: &validators, | ||
ChainConfig: ibc.ChainConfig{ | ||
Denom: denom, | ||
ModifyGenesisAmounts: func(i int) (sdk.Coin, sdk.Coin) { | ||
if i == 0 { | ||
return sdk.NewCoin(denom, sdkmath.NewInt(balance)), sdk.NewCoin(denom, sdkmath.NewInt(val1_stake)) | ||
} | ||
return sdk.NewCoin(denom, sdkmath.NewInt(balance)), sdk.NewCoin(denom, sdkmath.NewInt(val2_stake)) | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
chains, err := cf.Chains(t.Name()) | ||
require.NoError(t, err) | ||
|
||
client, network := interchaintest.DockerSetup(t) | ||
|
||
chain := chains[0].(*cosmos.CosmosChain) | ||
|
||
ic := interchaintest.NewInterchain(). | ||
AddChain(chain) | ||
rep := testreporter.NewNopReporter() | ||
|
||
err = ic.Build(context.Background(), rep.RelayerExecReporter(t), interchaintest.InterchainBuildOptions{ | ||
TestName: t.Name(), | ||
Client: client, | ||
NetworkID: network, | ||
BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(), | ||
SkipPathCreation: false, | ||
}) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { | ||
_ = ic.Close() | ||
}) | ||
|
||
stdout, _, err := chain.GetNode().ExecQuery(context.Background(), "staking", "validators") | ||
require.NoError(t, err) | ||
|
||
var validatorsResp map[string]interface{} | ||
require.NoError(t, json.Unmarshal(stdout, &validatorsResp)) | ||
require.Contains(t, validatorsResp, "validators") | ||
validatorsList := validatorsResp["validators"].([]interface{}) | ||
require.Len(t, validatorsList, 2) | ||
|
||
tokens1 := validatorsList[0].(map[string]interface{})["tokens"].(string) | ||
tokens2 := validatorsList[1].(map[string]interface{})["tokens"].(string) | ||
require.NotEmpty(t, tokens1) | ||
require.NotEmpty(t, tokens2) | ||
|
||
tokens1Int, err := strconv.Atoi(tokens1) | ||
require.NoError(t, err) | ||
tokens2Int, err := strconv.Atoi(tokens2) | ||
require.NoError(t, err) | ||
|
||
if tokens1Int > tokens2Int { | ||
require.Equal(t, val2_stake, tokens1Int) | ||
require.Equal(t, val1_stake, tokens2Int) | ||
} else { | ||
require.Equal(t, val1_stake, tokens1Int) | ||
require.Equal(t, val2_stake, tokens2Int) | ||
} | ||
|
||
} |
Oops, something went wrong.