-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #497 from ava-labs/poa-e2e-test
PoA e2e test
- Loading branch information
Showing
26 changed files
with
1,780 additions
and
76 deletions.
There are no files selected for viewing
1,358 changes: 1,358 additions & 0 deletions
1,358
abi-bindings/go/staking/PoAValidatorManager/PoAValidatorManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package flows | ||
|
||
const ( | ||
errTxReverted = "execution reverted" | ||
ErrTxReverted = "execution reverted" | ||
) |
2 changes: 1 addition & 1 deletion
2
tests/flows/validator_set_sig.go → tests/flows/governance/validator_set_sig.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package governance | ||
|
||
import ( | ||
"context" | ||
|
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
2 changes: 1 addition & 1 deletion
2
tests/flows/native_token_staking.go → tests/flows/staking/native_token_staking.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package staking | ||
|
||
import ( | ||
"context" | ||
|
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,206 @@ | ||
package staking | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"time" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/utils/crypto/bls" | ||
"github.com/ava-labs/subnet-evm/accounts/abi/bind" | ||
"github.com/ava-labs/subnet-evm/core/types" | ||
"github.com/ava-labs/teleporter/tests/interfaces" | ||
"github.com/ava-labs/teleporter/tests/utils" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
/* | ||
* Register a PoA validator manager on a L1. The steps are as follows: | ||
* - Generate random address to be the owner address | ||
* - Fund native assets to the owner address | ||
* - Deploy the PoAValidatorManager contract | ||
* - Attempt to initiate with non owner and check that it fails | ||
* - Initiate validator registration | ||
* - Deliver the Warp message to the P-Chain (not implemented) | ||
* - Aggregate P-Chain signatures on the response Warp message | ||
* - Deliver the Warp message to the L1 | ||
* - Verify that the validator is registered in the validator manager contract | ||
* | ||
* Delists the validator from the L1. The steps are as follows: | ||
* - Attempt to initiate with non owner and check that it fails | ||
* - Initiate validator delisting | ||
* - Deliver the Warp message to the P-Chain (not implemented) | ||
* - Aggregate P-Chain signatures on the response Warp message | ||
* - Deliver the Warp message to the L1 | ||
* - Verify that the validator is delisted from the validator manager contract | ||
*/ | ||
func PoAValidatorManager(network interfaces.LocalNetwork) { | ||
cChainInfo := network.GetPrimaryNetworkInfo() | ||
subnetAInfo, _ := utils.GetTwoSubnets(network) | ||
_, fundedKey := network.GetFundedAccountInfo() | ||
pChainInfo := utils.GetPChainInfo(cChainInfo) | ||
|
||
signatureAggregator := utils.NewSignatureAggregator( | ||
cChainInfo.NodeURIs[0], | ||
[]ids.ID{ | ||
subnetAInfo.SubnetID, | ||
ids.Empty, // Primary network subnet ID | ||
}, | ||
) | ||
|
||
// Generate random address to be the owner address | ||
ownerKey, err := crypto.GenerateKey() | ||
Expect(err).Should(BeNil()) | ||
ownerAddress := crypto.PubkeyToAddress(ownerKey.PublicKey) | ||
|
||
// Transfer native assets to the owner account | ||
ctx := context.Background() | ||
fundAmount := big.NewInt(1e18) // 1avax | ||
utils.SendNativeTransfer( | ||
ctx, | ||
subnetAInfo, | ||
fundedKey, | ||
ownerAddress, | ||
fundAmount, | ||
) | ||
|
||
validatorManagerAddress, validatorManager := utils.DeployAndInitializePoAValidatorManager( | ||
ctx, | ||
fundedKey, | ||
subnetAInfo, | ||
pChainInfo, | ||
ownerAddress, | ||
) | ||
|
||
var validationID ids.ID // To be used in the delisting step | ||
nodeID := ids.GenerateTestID() | ||
blsPublicKey := [bls.PublicKeyLen]byte{} | ||
weight := uint64(1) | ||
|
||
{ | ||
// Try to call with invalid owner | ||
opts, err := bind.NewKeyedTransactorWithChainID(fundedKey, subnetAInfo.EVMChainID) | ||
Expect(err).Should(BeNil()) | ||
|
||
_, err = validatorManager.InitializeValidatorRegistration( | ||
opts, | ||
weight, | ||
nodeID, | ||
uint64(time.Now().Add(24*time.Hour).Unix()), | ||
blsPublicKey[:], | ||
) | ||
Expect(err).ShouldNot(BeNil()) | ||
|
||
// Initiate validator registration | ||
var receipt *types.Receipt | ||
receipt, validationID = utils.InitializePoAValidatorRegistration( | ||
ownerKey, | ||
subnetAInfo, | ||
weight, | ||
nodeID, | ||
blsPublicKey, | ||
validatorManager, | ||
) | ||
|
||
// Gather subnet-evm Warp signatures for the RegisterSubnetValidatorMessage & relay to the P-Chain | ||
// (Sending to the P-Chain will be skipped for now) | ||
signedWarpMessage := network.ConstructSignedWarpMessage(context.Background(), receipt, subnetAInfo, pChainInfo) | ||
|
||
// Validate the Warp message, (this will be done on the P-Chain in the future) | ||
utils.ValidateRegisterSubnetValidatorMessage( | ||
signedWarpMessage, | ||
nodeID, | ||
weight, | ||
subnetAInfo.SubnetID, | ||
blsPublicKey, | ||
) | ||
|
||
// Construct a SubnetValidatorRegistrationMessage Warp message from the P-Chain | ||
registrationSignedMessage := utils.ConstructSubnetValidatorRegistrationMessage( | ||
validationID, | ||
true, | ||
subnetAInfo, | ||
pChainInfo, | ||
network, | ||
signatureAggregator, | ||
) | ||
|
||
// Deliver the Warp message to the subnet | ||
receipt = utils.CompletePoAValidatorRegistration( | ||
fundedKey, | ||
subnetAInfo, | ||
validatorManagerAddress, | ||
registrationSignedMessage, | ||
) | ||
// Check that the validator is registered in the staking contract | ||
registrationEvent, err := utils.GetEventFromLogs( | ||
receipt.Logs, | ||
validatorManager.ParseValidationPeriodRegistered, | ||
) | ||
Expect(err).Should(BeNil()) | ||
Expect(registrationEvent.ValidationID[:]).Should(Equal(validationID[:])) | ||
} | ||
|
||
// | ||
// Delist the validator | ||
// | ||
{ | ||
// Try with invalid validator owner | ||
opts, err := bind.NewKeyedTransactorWithChainID(fundedKey, subnetAInfo.EVMChainID) | ||
Expect(err).Should(BeNil()) | ||
_, err = validatorManager.InitializeEndValidation( | ||
opts, | ||
validationID, | ||
) | ||
Expect(err).ShouldNot(BeNil()) | ||
|
||
receipt := utils.InitializeEndPoAValidation( | ||
ownerKey, | ||
subnetAInfo, | ||
validatorManager, | ||
validationID, | ||
) | ||
validatorRemovalEvent, err := utils.GetEventFromLogs( | ||
receipt.Logs, | ||
validatorManager.ParseValidatorRemovalInitialized, | ||
) | ||
Expect(err).Should(BeNil()) | ||
Expect(validatorRemovalEvent.ValidationID[:]).Should(Equal(validationID[:])) | ||
Expect(validatorRemovalEvent.Weight.Uint64()).Should(Equal(weight)) | ||
|
||
// Gather subnet-evm Warp signatures for the SetSubnetValidatorWeightMessage & relay to the P-Chain | ||
// (Sending to the P-Chain will be skipped for now) | ||
signedWarpMessage := network.ConstructSignedWarpMessage(context.Background(), receipt, subnetAInfo, pChainInfo) | ||
Expect(err).Should(BeNil()) | ||
|
||
// Validate the Warp message, (this will be done on the P-Chain in the future) | ||
utils.ValidateSetSubnetValidatorWeightMessage(signedWarpMessage, validationID, 0, 0) | ||
|
||
// Construct a SubnetValidatorRegistrationMessage Warp message from the P-Chain | ||
registrationSignedMessage := utils.ConstructSubnetValidatorRegistrationMessage( | ||
validationID, | ||
false, | ||
subnetAInfo, | ||
pChainInfo, | ||
network, | ||
signatureAggregator, | ||
) | ||
|
||
// Deliver the Warp message to the subnet | ||
receipt = utils.CompleteEndPoAValidation( | ||
ownerKey, | ||
subnetAInfo, | ||
validatorManagerAddress, | ||
registrationSignedMessage, | ||
) | ||
|
||
// Check that the validator is has been delisted from the staking contract | ||
registrationEvent, err := utils.GetEventFromLogs( | ||
receipt.Logs, | ||
validatorManager.ParseValidationPeriodEnded, | ||
) | ||
Expect(err).Should(BeNil()) | ||
Expect(registrationEvent.ValidationID[:]).Should(Equal(validationID[:])) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
tests/flows/add_fee_amount.go → tests/flows/teleporter/add_fee_amount.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/basic_send_receive.go → tests/flows/teleporter/basic_send_receive.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
.../flows/deliver_to_nonexistent_contract.go → ...porter/deliver_to_nonexistent_contract.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/deliver_to_wrong_chain.go → ...lows/teleporter/deliver_to_wrong_chain.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/insufficient_gas.go → tests/flows/teleporter/insufficient_gas.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
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
2 changes: 1 addition & 1 deletion
2
tests/flows/pause_teleporter.go → ...s/teleporter/registry/pause_teleporter.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package registry | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/teleporter_registry.go → ...eleporter/registry/teleporter_registry.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package registry | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/relay_message_twice.go → ...s/flows/teleporter/relay_message_twice.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/relayer_modifies_message.go → ...ws/teleporter/relayer_modifies_message.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/resubmit_altered_message.go → ...ws/teleporter/resubmit_altered_message.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/retry_successful_execution.go → .../teleporter/retry_successful_execution.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/send_specific_receipts.go → ...lows/teleporter/send_specific_receipts.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"bytes" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/teleporter_message_ids.go → ...lows/teleporter/teleporter_message_ids.go
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
2 changes: 1 addition & 1 deletion
2
tests/flows/unallowed_relayer.go → tests/flows/teleporter/unallowed_relayer.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
tests/flows/validator_churn.go → tests/flows/teleporter/validator_churn.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package flows | ||
package teleporter | ||
|
||
import ( | ||
"context" | ||
|
Oops, something went wrong.