-
Notifications
You must be signed in to change notification settings - Fork 637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing: adding multiple sender accounts for testing purposes #935
Changes from 4 commits
028a344
8ba3325
d6dd06f
fd60d98
0d81595
e39e6d0
ac2e438
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,22 +91,23 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs | |
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec())) | ||
} | ||
|
||
// set validators and delegations | ||
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations) | ||
genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenesis) | ||
|
||
totalSupply := sdk.NewCoins() | ||
for _, b := range balances { | ||
// add genesis acc tokens and delegated tokens to total supply | ||
totalSupply = totalSupply.Add(b.Coins.Add(sdk.NewCoin(sdk.DefaultBondDenom, bondAmt))...) | ||
} | ||
|
||
// add bonded amount to bonded pool module account | ||
balances = append(balances, banktypes.Balance{ | ||
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(), | ||
Coins: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, bondAmt)}, | ||
Coins: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, bondAmt.Mul(sdk.NewInt(int64(len(valSet.Validators)))))}, | ||
}) | ||
|
||
for _, b := range balances { | ||
// add genesis acc tokens and delegated tokens to total supply | ||
totalSupply = totalSupply.Add(b.Coins...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually think it is possible for totalSupply to be empty in genesis (sdk will calculate it). Maybe we should try that to avoid future issues There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. It works There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue for reference: cosmos/cosmos-sdk#9372 (comment) |
||
} | ||
|
||
// set validators and delegations | ||
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations) | ||
genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenesis) | ||
|
||
// update total supply | ||
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}) | ||
genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,15 @@ import ( | |
"github.com/cosmos/ibc-go/v3/testing/simapp" | ||
) | ||
|
||
const ( | ||
MAX_ACCOUNTS = 9 | ||
seantking marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
type SenderAccount struct { | ||
SenderPrivKey cryptotypes.PrivKey | ||
SenderAccount authtypes.AccountI | ||
} | ||
|
||
// TestChain is a testing struct that wraps a simapp with the last TM Header, the current ABCI | ||
// header and the validators of the TestChain. It also contains a field called ChainID. This | ||
// is the clientID that *other* chains use to refer to this TestChain. The SenderAccount | ||
|
@@ -59,6 +68,8 @@ type TestChain struct { | |
// autogenerated sender private key | ||
SenderPrivKey cryptotypes.PrivKey | ||
SenderAccount authtypes.AccountI | ||
|
||
SenderAccounts []SenderAccount | ||
} | ||
|
||
// NewTestChain initializes a new TestChain instance with a single validator set using a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment needs to be updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch |
||
|
@@ -84,18 +95,34 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain { | |
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator}) | ||
signers := []tmtypes.PrivValidator{privVal} | ||
|
||
// generate genesis account | ||
senderPrivKey := secp256k1.GenPrivKey() | ||
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0) | ||
amount, ok := sdk.NewIntFromString("10000000000000000000") | ||
require.True(t, ok) | ||
genAccs := []authtypes.GenesisAccount{} | ||
genBals := []banktypes.Balance{} | ||
senderAccs := []SenderAccount{} | ||
|
||
// generate genesis accounts | ||
for i := 0; i < MAX_ACCOUNTS; i++ { | ||
senderPrivKey := secp256k1.GenPrivKey() | ||
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), uint64(i), 0) | ||
amount, ok := sdk.NewIntFromString("10000000000000000000") | ||
require.True(t, ok) | ||
|
||
balance := banktypes.Balance{ | ||
Address: acc.GetAddress().String(), | ||
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)), | ||
} | ||
|
||
genAccs = append(genAccs, acc) | ||
genBals = append(genBals, balance) | ||
|
||
senderAcc := SenderAccount{ | ||
SenderAccount: acc, | ||
SenderPrivKey: senderPrivKey, | ||
} | ||
|
||
balance := banktypes.Balance{ | ||
Address: acc.GetAddress().String(), | ||
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)), | ||
senderAccs = append(senderAccs, senderAcc) | ||
} | ||
|
||
app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, chainID, balance) | ||
app := SetupWithGenesisValSet(t, valSet, genAccs, chainID, genBals...) | ||
|
||
// create current header and call begin block | ||
header := tmproto.Header{ | ||
|
@@ -108,18 +135,19 @@ func NewTestChain(t *testing.T, coord *Coordinator, chainID string) *TestChain { | |
|
||
// create an account to send transactions from | ||
chain := &TestChain{ | ||
t: t, | ||
Coordinator: coord, | ||
ChainID: chainID, | ||
App: app, | ||
CurrentHeader: header, | ||
QueryServer: app.GetIBCKeeper(), | ||
TxConfig: txConfig, | ||
Codec: app.AppCodec(), | ||
Vals: valSet, | ||
Signers: signers, | ||
SenderPrivKey: senderPrivKey, | ||
SenderAccount: acc, | ||
t: t, | ||
Coordinator: coord, | ||
ChainID: chainID, | ||
App: app, | ||
CurrentHeader: header, | ||
QueryServer: app.GetIBCKeeper(), | ||
TxConfig: txConfig, | ||
Codec: app.AppCodec(), | ||
Vals: valSet, | ||
Signers: signers, | ||
SenderPrivKey: senderAccs[0].SenderPrivKey, | ||
SenderAccount: senderAccs[0].SenderAccount, | ||
SenderAccounts: senderAccs, | ||
} | ||
|
||
coord.CommitBlock(chain) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea that each validator in valSet receives the bondAmt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's that the bonded pool gets the bondAmt for each validator. And the bonded pool account balance is part of the total supply.
This is a little bit looking ahead to a future pr ill put up that allows multiple validators per testchain. The current code assumes only 1 validator