diff --git a/contracts/staking/tests/PoSValidatorManagerTests.t.sol b/contracts/staking/tests/PoSValidatorManagerTests.t.sol index 7d03d3096..213c45c5a 100644 --- a/contracts/staking/tests/PoSValidatorManagerTests.t.sol +++ b/contracts/staking/tests/PoSValidatorManagerTests.t.sol @@ -136,7 +136,12 @@ abstract contract PoSValidatorManagerTest is ValidatorManagerTest { blsPublicKey: DEFAULT_BLS_PUBLIC_KEY }); vm.expectRevert(_formatErrorMessage("invalid stake amount")); - _initializeValidatorRegistration(registrationInput, DEFAULT_MINIMUM_DELEGATION_FEE_BIPS, DEFAULT_MINIMUM_STAKE_DURATION, DEFAULT_MAXIMUM_STAKE + 1); + _initializeValidatorRegistration( + registrationInput, + DEFAULT_MINIMUM_DELEGATION_FEE_BIPS, + DEFAULT_MINIMUM_STAKE_DURATION, + DEFAULT_MAXIMUM_STAKE + 1 + ); } function testInvalidInitializeEndTime() public { diff --git a/go.sum b/go.sum index c85251bf5..e3aceb38b 100644 --- a/go.sum +++ b/go.sum @@ -56,10 +56,6 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.11.11-0.20240814200552-b3b720666238 h1:zxFjHBPwGo1WaNa7FLbIWgHeYk3y+ivm7RUdq4lZAW8= -github.com/ava-labs/avalanchego v1.11.11-0.20240814200552-b3b720666238/go.mod h1:8pnf2At/q0LRq5dvYJYn3CkhKzZNHRd5pjARC9psu+g= -github.com/ava-labs/avalanchego v1.11.11-0.20240916162929-49fbcf01b980 h1:cWdx1WV5lQylGjz7Q+7SiuDdgmSegmT93BPSvfdkxm0= -github.com/ava-labs/avalanchego v1.11.11-0.20240916162929-49fbcf01b980/go.mod h1:8pnf2At/q0LRq5dvYJYn3CkhKzZNHRd5pjARC9psu+g= github.com/ava-labs/avalanchego v1.11.11-0.20240916181957-b328a0503042 h1:Hk9sK9TPPXoVyIvl4rC+v1HF2M2BvjINCLtLmkbqWMo= github.com/ava-labs/avalanchego v1.11.11-0.20240916181957-b328a0503042/go.mod h1:8pnf2At/q0LRq5dvYJYn3CkhKzZNHRd5pjARC9psu+g= github.com/ava-labs/awm-relayer v1.4.0-rc.2.0.20240814200841-1c435873fd12 h1:vcCa4wZTDPObQFauhjtkAqbHWty3vXQaoPJMFgptnWM= diff --git a/tests/flows/staking/erc20_delegation.go b/tests/flows/staking/erc20_delegation.go index 87bd34e6e..471ab39af 100644 --- a/tests/flows/staking/erc20_delegation.go +++ b/tests/flows/staking/erc20_delegation.go @@ -36,15 +36,27 @@ func ERC20Delegation(network interfaces.LocalNetwork) { ids.Empty, // Primary network subnet ID }, ) + ctx := context.Background() // Deploy the staking manager contract stakingManagerAddress, stakingManager, _, erc20 := utils.DeployAndInitializeERC20TokenStakingManager( - context.Background(), + ctx, fundedKey, subnetAInfo, pChainInfo, ) + _ = utils.InitializeERC20TokenValidatorSet( + ctx, + fundedKey, + subnetAInfo, + pChainInfo, + stakingManager, + stakingManagerAddress, + network, + signatureAggregator, + ) + // // Register a validator // diff --git a/tests/flows/staking/erc20_token_staking.go b/tests/flows/staking/erc20_token_staking.go index 7c3fd4e07..a62fdfc0f 100644 --- a/tests/flows/staking/erc20_token_staking.go +++ b/tests/flows/staking/erc20_token_staking.go @@ -41,15 +41,27 @@ func ERC20TokenStakingManager(network interfaces.LocalNetwork) { ids.Empty, // Primary network subnet ID }, ) + ctx := context.Background() // Deploy the staking manager contract stakingManagerAddress, stakingManager, _, erc20 := utils.DeployAndInitializeERC20TokenStakingManager( - context.Background(), + ctx, fundedKey, subnetAInfo, pChainInfo, ) + _ = utils.InitializeERC20TokenValidatorSet( + ctx, + fundedKey, + subnetAInfo, + pChainInfo, + stakingManager, + stakingManagerAddress, + network, + signatureAggregator, + ) + // // Register a validator // diff --git a/tests/flows/staking/native_delegation.go b/tests/flows/staking/native_delegation.go index 3de9608f0..9e7d17498 100644 --- a/tests/flows/staking/native_delegation.go +++ b/tests/flows/staking/native_delegation.go @@ -36,15 +36,27 @@ func NativeDelegation(network interfaces.LocalNetwork) { ids.Empty, // Primary network subnet ID }, ) + ctx := context.Background() // Deploy the staking manager contract stakingManagerAddress, stakingManager := utils.DeployAndInitializeNativeTokenStakingManager( - context.Background(), + ctx, fundedKey, subnetAInfo, pChainInfo, ) + _ = utils.InitializeNativeTokenValidatorSet( + ctx, + fundedKey, + subnetAInfo, + pChainInfo, + stakingManager, + stakingManagerAddress, + network, + signatureAggregator, + ) + // // Register a validator // diff --git a/tests/flows/staking/native_token_staking.go b/tests/flows/staking/native_token_staking.go index 77ac8b6c3..c57fe136c 100644 --- a/tests/flows/staking/native_token_staking.go +++ b/tests/flows/staking/native_token_staking.go @@ -41,15 +41,27 @@ func NativeTokenStakingManager(network interfaces.LocalNetwork) { ids.Empty, // Primary network subnet ID }, ) + ctx := context.Background() // Deploy the staking manager contract stakingManagerContractAddress, stakingManager := utils.DeployAndInitializeNativeTokenStakingManager( - context.Background(), + ctx, fundedKey, subnetAInfo, pChainInfo, ) + _ = utils.InitializeNativeTokenValidatorSet( + ctx, + fundedKey, + subnetAInfo, + pChainInfo, + stakingManager, + stakingManagerContractAddress, + network, + signatureAggregator, + ) + // // Register a validator // diff --git a/tests/utils/staking.go b/tests/utils/staking.go index 8e8915083..fd471098e 100644 --- a/tests/utils/staking.go +++ b/tests/utils/staking.go @@ -218,20 +218,114 @@ func DeployAndInitializePoAValidatorManager( func InitializeNativeTokenValidatorSet( ctx context.Context, sendingKey *ecdsa.PrivateKey, - subnet interfaces.SubnetTestInfo, + subnetInfo interfaces.SubnetTestInfo, pChainInfo interfaces.SubnetTestInfo, + validatorManager *nativetokenstakingmanager.NativeTokenStakingManager, validatorManagerAddress common.Address, -) { + network interfaces.LocalNetwork, + signatureAggregator *aggregator.SignatureAggregator, +) ids.ID { + convertSubnetTxId := ids.GenerateTestID() + blsPublicKey := [bls.PublicKeyLen]byte{} + subnetConversionData := nativetokenstakingmanager.SubnetConversionData{ + ConvertSubnetTxID: convertSubnetTxId, + BlockchainID: subnetInfo.BlockchainID, + ValidatorManagerAddress: validatorManagerAddress, + InitialValidators: []nativetokenstakingmanager.InitialValidator{ + { + NodeID: ids.GenerateTestID(), + Weight: 1, + BlsPublicKey: blsPublicKey[:], + }, + }, + } + subnetConversionDataBytes, err := PackSubnetConversionData(subnetConversionData) + Expect(err).Should(BeNil()) + subnetConversionID := sha256.Sum256(subnetConversionDataBytes) + subnetConversionSignedMessage := ConstructSubnetConversionMessage( + subnetConversionID, + subnetInfo, + pChainInfo, + network, + signatureAggregator, + ) + // Deliver the Warp message to the subnet + receipt := DeliverNativeTokenSubnetConversion( + sendingKey, + subnetInfo, + validatorManagerAddress, + subnetConversionSignedMessage, + subnetConversionData, + ) + initialValidatorCreatedEvent, err := GetEventFromLogs( + receipt.Logs, + validatorManager.ParseInitialValidatorCreated, + ) + Expect(err).Should(BeNil()) + Expect(initialValidatorCreatedEvent.NodeID).Should(Equal(subnetConversionData.InitialValidators[0].NodeID)) + + expectedValidationID := CalculateSubnetConversionValidationId(convertSubnetTxId, 0) + emittedValidationID := ids.ID(initialValidatorCreatedEvent.ValidationID) + Expect(emittedValidationID).Should(Equal(expectedValidationID)) + + return emittedValidationID } func InitializeERC20TokenValidatorSet( ctx context.Context, sendingKey *ecdsa.PrivateKey, - subnet interfaces.SubnetTestInfo, + subnetInfo interfaces.SubnetTestInfo, pChainInfo interfaces.SubnetTestInfo, + validatorManager *erc20tokenstakingmanager.ERC20TokenStakingManager, validatorManagerAddress common.Address, -) { + network interfaces.LocalNetwork, + signatureAggregator *aggregator.SignatureAggregator, +) ids.ID { + convertSubnetTxId := ids.GenerateTestID() + blsPublicKey := [bls.PublicKeyLen]byte{} + subnetConversionData := erc20tokenstakingmanager.SubnetConversionData{ + ConvertSubnetTxID: convertSubnetTxId, + BlockchainID: subnetInfo.BlockchainID, + ValidatorManagerAddress: validatorManagerAddress, + InitialValidators: []erc20tokenstakingmanager.InitialValidator{ + { + NodeID: ids.GenerateTestID(), + Weight: 1, + BlsPublicKey: blsPublicKey[:], + }, + }, + } + subnetConversionDataBytes, err := PackSubnetConversionData(subnetConversionData) + Expect(err).Should(BeNil()) + subnetConversionID := sha256.Sum256(subnetConversionDataBytes) + subnetConversionSignedMessage := ConstructSubnetConversionMessage( + subnetConversionID, + subnetInfo, + pChainInfo, + network, + signatureAggregator, + ) + // Deliver the Warp message to the subnet + receipt := DeliverERC20TokenSubnetConversion( + sendingKey, + subnetInfo, + validatorManagerAddress, + subnetConversionSignedMessage, + subnetConversionData, + ) + initialValidatorCreatedEvent, err := GetEventFromLogs( + receipt.Logs, + validatorManager.ParseInitialValidatorCreated, + ) + Expect(err).Should(BeNil()) + Expect(initialValidatorCreatedEvent.NodeID).Should(Equal(subnetConversionData.InitialValidators[0].NodeID)) + + expectedValidationID := CalculateSubnetConversionValidationId(convertSubnetTxId, 0) + emittedValidationID := ids.ID(initialValidatorCreatedEvent.ValidationID) + Expect(emittedValidationID).Should(Equal(expectedValidationID)) + + return emittedValidationID }