Skip to content

Commit

Permalink
Update other tests and go mod tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
iansuvak committed Sep 17, 2024
1 parent 695aaff commit dac8d50
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 13 deletions.
7 changes: 6 additions & 1 deletion contracts/staking/tests/PoSValidatorManagerTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 13 additions & 1 deletion tests/flows/staking/erc20_delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
14 changes: 13 additions & 1 deletion tests/flows/staking/erc20_token_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
14 changes: 13 additions & 1 deletion tests/flows/staking/native_delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
14 changes: 13 additions & 1 deletion tests/flows/staking/native_token_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
102 changes: 98 additions & 4 deletions tests/utils/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

Expand Down

0 comments on commit dac8d50

Please sign in to comment.