-
Notifications
You must be signed in to change notification settings - Fork 523
Add new participation key e2e test. #3178
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
Merged
winder
merged 20 commits into
algorand:feature/partkey
from
winder:will/devmode-partkey-tests
Nov 3, 2021
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
184cd13
Use new endpoint for partkeyinfo and listpartkeys.
winder b6342fa
make fmt
winder cec7c56
Fix integration test.
winder 5805063
Add metrics.
winder 507a612
Update partkeyinfo and listpartkey format.
winder 5a1a286
Update listpartkey docs.
winder 0eedea4
Basic E2E test for 'listpartkeys' and 'partkeyinfo'.
winder 653074f
Run shellcheck.
winder b80c10a
Consolidate overlapping account key objects in REST model.
winder 34859d0
make fmt
winder f83369d
Fix test for arm64
winder 55915cc
Fix optional match.
winder 08ccf2a
Cleanup comments.
winder cf4ffc6
Mark PKI TODO.
winder ea0fc8f
Add new participation key e2e test.
winder 9400b64
Make fmt and make lint.
winder 43b2b5c
Cover more with test, add missing config file.
winder e9b4bad
make fmt
winder d0c7e45
Merge branch 'feature/partkey' into will/devmode-partkey-tests
winder fee748f
Make fmt - bad merge.
winder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,66 @@ | ||
| // Copyright (C) 2019-2021 Algorand, Inc. | ||
| // This file is part of go-algorand | ||
| // | ||
| // go-algorand is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // go-algorand is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with go-algorand. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| // Check that devmode is functioning as designed. | ||
| package devmode | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/algorand/go-algorand/crypto" | ||
| "github.com/algorand/go-algorand/data/basics" | ||
| "github.com/algorand/go-algorand/test/framework/fixtures" | ||
| "github.com/algorand/go-algorand/test/partitiontest" | ||
| ) | ||
|
|
||
| func TestDevMode(t *testing.T) { | ||
| partitiontest.PartitionTest(t) | ||
|
|
||
| if testing.Short() { | ||
| t.Skip() | ||
| } | ||
|
|
||
| t.Parallel() | ||
|
|
||
| // Start devmode network, and make sure everything is primed by sending a transaction. | ||
| var fixture fixtures.RestClientFixture | ||
| fixture.SetupNoStart(t, filepath.Join("nettemplates", "DevModeNetwork.json")) | ||
| fixture.Start() | ||
| sender, err := fixture.GetRichestAccount() | ||
| require.NoError(t, err) | ||
| key := crypto.GenerateSignatureSecrets(crypto.Seed{}) | ||
| receiver := basics.Address(key.SignatureVerifier) | ||
| txn := fixture.SendMoneyAndWait(0, 100000, 1000, sender.Address, receiver.String(), "") | ||
| firstRound := txn.ConfirmedRound + 1 | ||
| start := time.Now() | ||
|
|
||
| // 2 transactions should be sent within one normal confirmation time. | ||
| for i := uint64(0); i < 2; i++ { | ||
| txn = fixture.SendMoneyAndWait(firstRound+i, 100000, 1000, sender.Address, receiver.String(), "") | ||
| require.Equal(t, firstRound+i, txn.FirstRound) | ||
| } | ||
| require.True(t, time.Since(start) < 2*time.Second, "Transactions should be quickly confirmed.") | ||
|
|
||
| // Without transactions there should be no rounds even after a normal confirmation time. | ||
| time.Sleep(10 * time.Second) | ||
| status, err := fixture.LibGoalClient.Status() | ||
| require.NoError(t, err) | ||
| require.Equal(t, txn.ConfirmedRound, status.LastRound, "There should be no rounds without a transaction.") | ||
| } |
126 changes: 126 additions & 0 deletions
126
test/e2e-go/features/participation/accountParticipationTransitions_test.go
This file contains hidden or 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,126 @@ | ||
| // Copyright (C) 2019-2021 Algorand, Inc. | ||
| // This file is part of go-algorand | ||
| // | ||
| // go-algorand is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // go-algorand is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with go-algorand. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package participation | ||
|
|
||
| // Tests in this file are focused on testing how a specific account uses and | ||
| // manages its participation keys. DevMode is used to make things more | ||
| // deterministic. | ||
|
|
||
| import ( | ||
| "io/ioutil" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/algorand/go-algorand/daemon/algod/api/server/v2/generated" | ||
| "github.com/algorand/go-algorand/data/account" | ||
| "github.com/algorand/go-algorand/libgoal" | ||
| "github.com/algorand/go-algorand/test/framework/fixtures" | ||
| "github.com/algorand/go-algorand/test/partitiontest" | ||
| ) | ||
|
|
||
| // installParticipationKey generates a new key for a given account and installs it with the client. | ||
| func installParticipationKey(t *testing.T, client libgoal.Client, addr string, firstValid, lastValid uint64) (resp generated.PostParticipationResponse, part account.Participation, err error) { | ||
| dir, err := ioutil.TempDir("", "temporary_partkey_dir") | ||
| require.NoError(t, err) | ||
| defer os.RemoveAll(dir) | ||
|
|
||
| // Install overlapping participation keys... | ||
| part, filePath, err := client.GenParticipationKeysTo(addr, firstValid, lastValid, 100, dir) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, filePath) | ||
| require.Equal(t, addr, part.Parent.String()) | ||
|
|
||
| resp, err = client.AddParticipationKey(filePath) | ||
| return | ||
| } | ||
|
|
||
| func registerParticipationAndWait(t *testing.T, client libgoal.Client, part account.Participation) generated.NodeStatusResponse { | ||
| txParams, err := client.SuggestedParams() | ||
| require.NoError(t, err) | ||
| sAccount := part.Address().String() | ||
| sWH, err := client.GetUnencryptedWalletHandle() | ||
| require.NoError(t, err) | ||
| goOnlineTx, err := client.MakeUnsignedGoOnlineTx(sAccount, &part, txParams.LastRound+1, txParams.LastRound+1, txParams.Fee, [32]byte{}) | ||
| require.NoError(t, err) | ||
| require.Equal(t, sAccount, goOnlineTx.Src().String()) | ||
| onlineTxID, err := client.SignAndBroadcastTransaction(sWH, nil, goOnlineTx) | ||
| require.NoError(t, err) | ||
| require.NotEmpty(t, onlineTxID) | ||
| status, err := client.WaitForRound(txParams.LastRound) | ||
| require.NoError(t, err) | ||
| return status | ||
| } | ||
|
|
||
| func TestKeyRegistration(t *testing.T) { | ||
| partitiontest.PartitionTest(t) | ||
|
|
||
| if testing.Short() { | ||
| t.Skip() | ||
| } | ||
|
|
||
| t.Parallel() | ||
|
|
||
| // Start devmode network and initialize things for the test. | ||
| var fixture fixtures.RestClientFixture | ||
| fixture.SetupNoStart(t, filepath.Join("nettemplates", "DevModeOneWallet.json")) | ||
| fixture.Start() | ||
| sClient := fixture.GetLibGoalClientForNamedNode("Node") | ||
| minTxnFee, _, err := fixture.MinFeeAndBalance(0) | ||
| require.NoError(t, err) | ||
| accountResponse, err := fixture.GetRichestAccount() | ||
| require.NoError(t, err) | ||
| sAccount := accountResponse.Address | ||
|
|
||
| // Add an overlapping participation keys for the account on round 1 and 2 | ||
| last := uint64(6_000_000) | ||
| numNew := 2 | ||
| for i := 0; i < numNew; i++ { | ||
| response, part, err := installParticipationKey(t, sClient, sAccount, 0, last) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, response) | ||
| registerParticipationAndWait(t, sClient, part) | ||
| } | ||
|
|
||
| // Make sure the new keys are installed. | ||
| keys, err := fixture.LibGoalClient.GetParticipationKeys() | ||
| require.NoError(t, err) | ||
| require.Len(t, keys, numNew+1) | ||
|
|
||
| // Zip ahead MaxBalLookback. | ||
| params, err := fixture.CurrentConsensusParams() | ||
| require.NoError(t, err) | ||
| lookback := params.MaxBalLookback | ||
| for i := uint64(1); i < lookback; i++ { | ||
| fixture.SendMoneyAndWait(2+i, 0, minTxnFee, sAccount, sAccount, "") | ||
| } | ||
|
|
||
| keys, err = fixture.LibGoalClient.GetParticipationKeys() | ||
| require.Equal(t, *(keys[0].EffectiveFirstValid), uint64(1)) | ||
| require.Equal(t, *(keys[0].EffectiveLastValid), lookback) | ||
| require.Equal(t, *(keys[0].LastBlockProposal), lookback) | ||
|
|
||
| require.Equal(t, *(keys[1].EffectiveFirstValid), lookback+1) | ||
| require.Equal(t, *(keys[1].EffectiveLastValid), lookback+1) | ||
| require.Equal(t, *(keys[1].LastBlockProposal), lookback+1) | ||
|
|
||
| require.Equal(t, *(keys[2].EffectiveFirstValid), lookback+2) | ||
| require.Equal(t, *(keys[2].EffectiveLastValid), last) | ||
| require.Equal(t, *(keys[2].LastBlockProposal), lookback+2) | ||
| } |
This file contains hidden or 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,22 @@ | ||
| { | ||
| "Genesis": { | ||
| "NetworkName": "devmodenet", | ||
| "Wallets": [ | ||
| { | ||
| "Name": "Wallet1", | ||
| "Stake": 100, | ||
| "Online": true | ||
| } | ||
| ], | ||
| "DevMode": true | ||
| }, | ||
| "Nodes": [ | ||
| { | ||
| "Name": "Node", | ||
| "IsRelay": false, | ||
| "Wallets": [ | ||
| { "Name": "Wallet1", "ParticipationOnly": false } | ||
| ] | ||
| } | ||
| ] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Also found a bug, this was causing the wrong "EffectiveRound" variables to be set in the registry.