Skip to content
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

feat(e2e): manage ica from gov module #1843

Merged
merged 35 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
983f060
ica gov proposal
Pantani Oct 24, 2022
0f90dfd
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Oct 24, 2022
4cba59e
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Oct 25, 2022
4e8526b
test clean up
Pantani Oct 25, 2022
fb95f50
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Oct 25, 2022
511e745
gov ica tests
Pantani Oct 26, 2022
11e4477
create proposal method to avoid global var
Pantani Oct 26, 2022
3290dc3
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Oct 26, 2022
cda0a4f
improve subtests scope
Pantani Oct 27, 2022
ba48f91
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Oct 27, 2022
30a2dd6
improve code readbility
Pantani Oct 31, 2022
34eb6ba
Merge remote-tracking branch 'origin/main' into feat/e2e-test-gov-ica
Pantani Oct 31, 2022
00743b9
fix test and remove hardcoded JSON file name
Pantani Oct 31, 2022
5e5f501
fix tests issues
Pantani Nov 1, 2022
4204ef4
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Nov 1, 2022
af9d60a
fix typo
Pantani Nov 1, 2022
79062c8
Update tests/e2e/e2e_gov_test.go
okwme Nov 2, 2022
befe071
Merge branch 'main' into feat/e2e-test-gov-ica
okwme Nov 2, 2022
e5c4d9e
Merge branch 'main' into feat/e2e-test-gov-ica
okwme Nov 2, 2022
ddd1ea2
update sdk in tests go.mod
okwme Nov 2, 2022
321c7c6
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Nov 4, 2022
ea8baee
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Nov 4, 2022
706b38d
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Nov 7, 2022
4120882
bump the ics23
Pantani Nov 7, 2022
32cf482
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Nov 9, 2022
0e989eb
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Nov 9, 2022
c8b8cec
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Nov 15, 2022
62c9661
Merge remote-tracking branch 'origin/main' into feat/e2e-test-gov-ica
Pantani Nov 16, 2022
3ce9d18
Merge branch 'main' into feat/e2e-test-gov-ica
Pantani Nov 17, 2022
0c59002
Merge remote-tracking branch 'origin/main' into feat/e2e-test-gov-ica
Pantani Nov 21, 2022
bf0de5e
update the cosmos sdk and remove some typos
Pantani Nov 22, 2022
ea6c5d6
rename icaChannelID to ibcTransferChannelID
Pantani Nov 23, 2022
f0d08e4
merge branch target-v0-46
Dec 14, 2022
1bda47d
fix: deadlink
Dec 14, 2022
1dd3f1f
fix: dead links
Dec 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
313 changes: 190 additions & 123 deletions tests/e2e/e2e_gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ func (s *IntegrationTestSuite) SendTokensFromNewGovAccount() {
s.Require().NoError(err)
sender := senderAddress.String()
// Gov tests may be run in arbitrary order, each test must increment proposalCounter to have the correct proposal id to submit and query
proposalCounter++
s.T().Logf("Proposal number: %d", proposalCounter)
s.proposalCounter++
s.T().Logf("Proposal number: %d", s.proposalCounter)

s.fundCommunityPool(chainAAPIEndpoint, sender)

s.T().Logf("Submitting Legacy Gov Proposal: Community Spend Funding Gov Module")
s.submitLegacyGovProposal(chainAAPIEndpoint, sender, standardFees.String(), "community-pool-spend", proposalCounter, configFile("proposal.json"))
s.submitLegacyGovProposal(chainAAPIEndpoint, sender, standardFees.String(), "community-pool-spend", s.proposalCounter, configFile(proposal1))
s.T().Logf("Depositing Legacy Gov Proposal: Community Spend Funding Gov Module")
s.depositGovProposal(chainAAPIEndpoint, sender, standardFees.String(), proposalCounter)
s.depositGovProposal(chainAAPIEndpoint, sender, standardFees.String(), s.proposalCounter)
s.T().Logf("Voting Legacy Gov Proposal: Community Spend Funding Gov Module")
s.voteGovProposal(chainAAPIEndpoint, sender, standardFees.String(), proposalCounter, "yes", false)
s.voteGovProposal(chainAAPIEndpoint, sender, standardFees.String(), s.proposalCounter, "yes", false)

initialGovBalance, err := getSpecificBalance(chainAAPIEndpoint, govModuleAddress, uatomDenom)
s.Require().NoError(err)
proposalCounter++
s.proposalCounter++

s.T().Logf("Submitting Gov Proposal: Sending Tokens from Gov Module to Recipient")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, configFile("proposal_2.json"))
s.submitNewGovProposal(chainAAPIEndpoint, sender, s.proposalCounter, configFile(proposal2))
s.T().Logf("Depositing Gov Proposal: Sending Tokens from Gov Module to Recipient")
s.depositGovProposal(chainAAPIEndpoint, sender, standardFees.String(), proposalCounter)
s.depositGovProposal(chainAAPIEndpoint, sender, standardFees.String(), s.proposalCounter)
s.T().Logf("Voting Gov Proposal: Sending Tokens from Gov Module to Recipient")
s.voteGovProposal(chainAAPIEndpoint, sender, standardFees.String(), proposalCounter, "yes", false)
s.voteGovProposal(chainAAPIEndpoint, sender, standardFees.String(), s.proposalCounter, "yes", false)
s.Require().Eventually(
func() bool {
newGovBalance, err := getSpecificBalance(chainAAPIEndpoint, govModuleAddress, uatomDenom)
Expand All @@ -71,45 +71,46 @@ Test Benchmarks:
TODO: Perform upgrade in place of chain restart
*/
func (s *IntegrationTestSuite) GovSoftwareUpgrade() {
chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp"))
senderAddress, err := s.chainA.validators[0].keyInfo.GetAddress()
s.Require().NoError(err)
sender := senderAddress.String()
height := s.getLatestBlockHeight(s.chainA, 0)
proposalHeight := height + govProposalBlockBuffer
// Gov tests may be run in arbitrary order, each test must increment proposalCounter to have the correct proposal id to submit and query
proposalCounter++

s.T().Logf("Writing proposal %d on chain %s", proposalCounter, s.chainA.id)
s.writeGovUpgradeSoftwareProposal(s.chainA, proposalHeight)

s.T().Logf("Submitting Gov Proposal: Software Upgrade")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, configFile("proposal_3.json"))
s.T().Logf("Depositing Gov Proposal: Software Upgrade")
s.depositGovProposal(chainAAPIEndpoint, sender, standardFees.String(), proposalCounter)
s.T().Logf("Weighted Voting Gov Proposal: Software Upgrade")
s.voteGovProposal(chainAAPIEndpoint, sender, standardFees.String(), proposalCounter, "yes=0.8,no=0.1,abstain=0.05,no_with_veto=0.05", true)

s.verifyChainHaltedAtUpgradeHeight(s.chainA, 0, proposalHeight)
s.T().Logf("Successfully halted chain at height %d", proposalHeight)
s.Run("Gov software upgrade", func() {
chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp"))
senderAddress, err := s.chainA.validators[0].keyInfo.GetAddress()
s.Require().NoError(err)
sender := senderAddress.String()
height := s.getLatestBlockHeight(s.chainA, 0)
proposalHeight := height + govProposalBlockBuffer
// Gov tests may be run in arbitrary order, each test must increment proposalCounter to have the correct proposal id to submit and query

s.proposalCounter++
s.T().Logf("Writing proposal %d on chain %s", s.proposalCounter, s.chainA.id)
s.writeGovUpgradeSoftwareProposal(s.chainA, proposalHeight)

s.T().Logf("Submitting Gov Proposal: Software Upgrade")
s.submitNewGovProposal(chainAAPIEndpoint, sender, s.proposalCounter, configFile(proposal3))
s.T().Logf("Depositing Gov Proposal: Software Upgrade")
s.depositGovProposal(chainAAPIEndpoint, sender, standardFees.String(), s.proposalCounter)
s.T().Logf("Weighted Voting Gov Proposal: Software Upgrade")
s.voteGovProposal(chainAAPIEndpoint, sender, standardFees.String(), s.proposalCounter, "yes=0.8,no=0.1,abstain=0.05,no_with_veto=0.05", true)

s.verifyChainHaltedAtUpgradeHeight(s.chainA, 0, proposalHeight)
s.T().Logf("Successfully halted chain at height %d", proposalHeight)

s.TearDownSuite()

s.T().Logf("Restarting containers")
s.SetupSuite()

s.TearDownSuite()

s.T().Logf("Restarting containers")
s.SetupSuite()

s.Require().Eventually(
func() bool {
h := s.getLatestBlockHeight(s.chainA, 0)
s.Require().NoError(err)

return h > 0
},
30*time.Second,
5*time.Second,
)
s.Require().Eventually(
func() bool {
h := s.getLatestBlockHeight(s.chainA, 0)
s.Require().NoError(err)

proposalCounter = 0
return h > 0
},
30*time.Second,
5*time.Second,
)
s.proposalCounter = 0
})
}

/*
Expand All @@ -120,36 +121,110 @@ Test Benchmarks:
3. Validation that the chain produced blocks past the intended upgrade height
*/
func (s *IntegrationTestSuite) GovCancelSoftwareUpgrade() {
s.Run("Gov software upgrade cancel", func() {
chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp"))
senderAddress, err := s.chainA.validators[0].keyInfo.GetAddress()
s.Require().NoError(err)
sender := senderAddress.String()
height := s.getLatestBlockHeight(s.chainA, 0)
proposalHeight := height + 50
// Gov tests may be run in arbitrary order, each test must increment proposalCounter to have the correct proposal id to submit and query
s.proposalCounter++

s.T().Logf("Writing proposal %d on chain %s", s.proposalCounter, s.chainA.id)
s.writeGovUpgradeSoftwareProposal(s.chainA, proposalHeight)

s.T().Logf("Submitting Gov Proposal: Software Upgrade")
s.submitNewGovProposal(chainAAPIEndpoint, sender, s.proposalCounter, configFile(proposal3))
s.depositGovProposal(chainAAPIEndpoint, sender, standardFees.String(), s.proposalCounter)
s.voteGovProposal(chainAAPIEndpoint, sender, standardFees.String(), s.proposalCounter, "yes", false)

s.proposalCounter++

s.T().Logf("Writing proposal %d on chain %s", s.proposalCounter, s.chainA.id)
s.writeGovCancelUpgradeSoftwareProposal(s.chainA)

s.T().Logf("Submitting Gov Proposal: Cancel Software Upgrade")
s.submitNewGovProposal(chainAAPIEndpoint, sender, s.proposalCounter, configFile(proposal4))
s.depositGovProposal(chainAAPIEndpoint, sender, standardFees.String(), s.proposalCounter)
s.voteGovProposal(chainAAPIEndpoint, sender, standardFees.String(), s.proposalCounter, "yes", false)

s.verifyChainPassesUpgradeHeight(s.chainA, 0, proposalHeight)
s.T().Logf("Successfully canceled upgrade at height %d", proposalHeight)
})
}

chainAAPIEndpoint := fmt.Sprintf("http://%s", s.valResources[s.chainA.id][0].GetHostPort("1317/tcp"))
senderAddress, err := s.chainA.validators[0].keyInfo.GetAddress()
s.Require().NoError(err)
sender := senderAddress.String()
height := s.getLatestBlockHeight(s.chainA, 0)
proposalHeight := height + 50
// Gov tests may be run in arbitrary order, each test must increment proposalCounter to have the correct proposal id to submit and query
proposalCounter++
/*
GovCreateICA tests the create a ICA account from a government proposal.
Test Benchmarks:
1. Create the ICA proposal
2. Approve proposal
3. Check if ICA account exist
*/
func (s *IntegrationTestSuite) GovCreateICA() {
s.Run("test create ica from gov module", func() {
var (
portID = "1317/tcp"
validatorChainA = s.chainA.validators[0]
validatorChainB = s.chainB.validators[0]
resourceChainA = s.valResources[s.chainA.id][0]
resourceChainB = s.valResources[s.chainA.id][0]
okwme marked this conversation as resolved.
Show resolved Hide resolved
chainAAPI = fmt.Sprintf("http://%s", resourceChainA.GetHostPort(portID))
chainBAPI = fmt.Sprintf("http://%s", resourceChainB.GetHostPort(portID))
)
// write and submit ICA gov proposal
s.writeGovICAProposal(s.chainA)

s.T().Logf("Writing proposal %d on chain %s", proposalCounter, s.chainA.id)
s.writeGovUpgradeSoftwareProposal(s.chainA, proposalHeight)
senderAddress, err := validatorChainA.keyInfo.GetAddress()
s.Require().NoError(err)
sender := senderAddress.String()

s.T().Logf("Submitting Gov Proposal: Software Upgrade")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, configFile("proposal_3.json"))
s.depositGovProposal(chainAAPIEndpoint, sender, standardFees.String(), proposalCounter)
s.voteGovProposal(chainAAPIEndpoint, sender, standardFees.String(), proposalCounter, "yes", false)
s.proposalCounter++
s.submitNewGovProposal(chainAAPI, sender, s.proposalCounter, configFile(proposalICACreate))
s.depositGovProposal(chainAAPI, sender, standardFees.String(), s.proposalCounter)
s.voteGovProposal(chainAAPI, sender, standardFees.String(), s.proposalCounter, "yes", false)

proposalCounter++
s.Require().Eventually(
func() bool {
icaAddr, err := queryICAAddress(chainAAPI, govModuleAddress, icaConnectionID)
s.T().Logf("%s's interchain account on chain %s: %s", sender, s.chainA.id, icaAddr)
s.Require().NoError(err)
return sender != "" && icaAddr != ""
},
2*time.Minute,
10*time.Second,
)

s.T().Logf("Writing proposal %d on chain %s", proposalCounter, s.chainA.id)
s.writeGovCancelUpgradeSoftwareProposal(s.chainA)
// get the chain B ICA account
var icaAddress string
s.Require().Eventually(
func() bool {
icaAddress, err = queryICAAddress(chainBAPI, govModuleAddress, icaConnectionID)
s.Require().NoError(err)

s.T().Logf("Submitting Gov Proposal: Cancel Software Upgrade")
s.submitNewGovProposal(chainAAPIEndpoint, sender, proposalCounter, configFile("proposal_4.json"))
s.depositGovProposal(chainAAPIEndpoint, sender, standardFees.String(), proposalCounter)
s.voteGovProposal(chainAAPIEndpoint, sender, standardFees.String(), proposalCounter, "yes", false)
return err == nil && icaAddress != ""
},
time.Minute,
5*time.Second,
)

// fund ica, send tokens from chain b val to ica on chain b
valChainBKey, err := validatorChainB.keyInfo.GetAddress()
s.Require().NoError(err)
valChainBAddr := valChainBKey.String()

s.execBankSend(s.chainB, 0, valChainBAddr, icaAddress, tokenAmount.String(), standardFees.String(), false)

s.verifyChainPassesUpgradeHeight(s.chainA, 0, proposalHeight)
s.T().Logf("Successfully canceled upgrade at height %d", proposalHeight)
s.Require().Eventually(
func() bool {
afterSenderICABalance, err := getSpecificBalance(chainBAPI, icaAddress, uatomDenom)
s.Require().NoError(err)
return afterSenderICABalance.IsEqual(tokenAmount)
},
time.Minute,
5*time.Second,
)
})
}

/*
Expand All @@ -160,7 +235,7 @@ Test Benchmarks:
3. Verification that correct funds have been deposited to distribution module account
*/
func (s *IntegrationTestSuite) fundCommunityPool(chainAAPIEndpoint, sender string) {
s.Run("fund_community_pool", func() {
s.Run("funding community pool", func() {
beforeDistUatomBalance, _ := getSpecificBalance(chainAAPIEndpoint, distModuleAddress, tokenAmount.Denom)
if beforeDistUatomBalance.IsNil() {
// Set balance to 0 if previous balance does not exist
Expand Down Expand Up @@ -227,73 +302,65 @@ func (s *IntegrationTestSuite) verifyChainPassesUpgradeHeight(c *chain, valIdx,
}

func (s *IntegrationTestSuite) submitLegacyGovProposal(chainAAPIEndpoint string, sender string, fees string, proposalTypeSubCmd string, proposalId int, proposalPath string) {
s.Run("submit_legacy_gov_proposal", func() {
s.execGovSubmitLegacyGovProposal(s.chainA, 0, sender, proposalPath, fees, proposalTypeSubCmd)
s.execGovSubmitLegacyGovProposal(s.chainA, 0, sender, proposalPath, fees, proposalTypeSubCmd)

s.Require().Eventually(
func() bool {
proposal, err := queryGovProposal(chainAAPIEndpoint, proposalId)
s.Require().NoError(err)
return proposal.GetProposal().Status == govv1beta1.StatusDepositPeriod
},
15*time.Second,
5*time.Second,
)
})
s.Require().Eventually(
func() bool {
proposal, err := queryGovProposal(chainAAPIEndpoint, proposalId)
s.Require().NoError(err)
return proposal.GetProposal().Status == govv1beta1.StatusDepositPeriod
},
15*time.Second,
5*time.Second,
)
}

func (s *IntegrationTestSuite) submitNewGovProposal(chainAAPIEndpoint, sender string, proposalId int, proposalPath string) {
s.Run("submit_new_gov_proposal", func() {
s.execGovSubmitProposal(s.chainA, 0, sender, proposalPath, standardFees.String())
s.execGovSubmitProposal(s.chainA, 0, sender, proposalPath, standardFees.String())

s.Require().Eventually(
func() bool {
proposal, err := queryGovProposal(chainAAPIEndpoint, proposalId)
s.T().Logf("Proposal: %s", proposal.String())
s.Require().NoError(err)
s.Require().Eventually(
func() bool {
proposal, err := queryGovProposal(chainAAPIEndpoint, proposalId)
s.T().Logf("Proposal: %s", proposal.String())
s.Require().NoError(err)

return proposal.GetProposal().Status == govv1beta1.StatusDepositPeriod
},
15*time.Second,
5*time.Second,
)
})
return proposal.GetProposal().Status == govv1beta1.StatusDepositPeriod
},
15*time.Second,
5*time.Second,
)
}

func (s *IntegrationTestSuite) depositGovProposal(chainAAPIEndpoint, sender string, fees string, proposalId int) {
s.Run("deposit_gov_proposal", func() {
s.execGovDepositProposal(s.chainA, 0, sender, proposalId, depositAmount.String(), fees)
s.execGovDepositProposal(s.chainA, 0, sender, proposalId, depositAmount.String(), fees)

s.Require().Eventually(
func() bool {
proposal, err := queryGovProposal(chainAAPIEndpoint, proposalId)
s.Require().NoError(err)
s.Require().Eventually(
func() bool {
proposal, err := queryGovProposal(chainAAPIEndpoint, proposalId)
s.Require().NoError(err)

return proposal.GetProposal().Status == govv1beta1.StatusVotingPeriod
},
15*time.Second,
5*time.Second,
)
})
return proposal.GetProposal().Status == govv1beta1.StatusVotingPeriod
},
15*time.Second,
5*time.Second,
)
}

func (s *IntegrationTestSuite) voteGovProposal(chainAAPIEndpoint, sender string, fees string, proposalId int, vote string, weighted bool) {
s.Run("vote_gov_proposal", func() {
if weighted {
s.execGovWeightedVoteProposal(s.chainA, 0, sender, proposalId, vote, fees)
} else {
s.execGovVoteProposal(s.chainA, 0, sender, proposalId, vote, fees)
}
if weighted {
s.execGovWeightedVoteProposal(s.chainA, 0, sender, proposalId, vote, fees)
} else {
s.execGovVoteProposal(s.chainA, 0, sender, proposalId, vote, fees)
}

s.Require().Eventually(
func() bool {
proposal, err := queryGovProposal(chainAAPIEndpoint, proposalId)
s.Require().NoError(err)
s.Require().Eventually(
func() bool {
proposal, err := queryGovProposal(chainAAPIEndpoint, proposalId)
s.Require().NoError(err)

return proposal.GetProposal().Status == govv1beta1.StatusPassed
},
15*time.Second,
5*time.Second,
)
})
return proposal.GetProposal().Status == govv1beta1.StatusPassed
},
15*time.Second,
5*time.Second,
)
}
Loading