Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions modules/sdk-coin-vet/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,14 @@ export class Utils implements BaseUtils {
validateStakingContractAddress(address: string, coinConfig: Readonly<CoinConfig>): void {
const expectedAddress = this.getDefaultStakingAddress(coinConfig);
if (address.toLowerCase() !== expectedAddress.toLowerCase()) {
const validatorRegistrationAddress = this.getContractAddressForValidatorRegistration(coinConfig);
if (address.toLowerCase() === validatorRegistrationAddress.toLowerCase()) {
throw new Error(
'Delegation is not supported for wallets with an active validator registration. ' +
'A wallet can either delegate or register as a validator, but not both. ' +
'Please use a wallet without an existing validator registration to perform delegation.'
);
}
throw new Error(
`Invalid staking contract address. Expected ${expectedAddress} for ${coinConfig.network.type}, got ${address}`
);
Expand All @@ -476,6 +484,14 @@ export class Utils implements BaseUtils {
validateContractAddressForValidatorRegistration(address: string, coinConfig: Readonly<CoinConfig>): void {
const expectedAddress = this.getContractAddressForValidatorRegistration(coinConfig);
if (address.toLowerCase() !== expectedAddress.toLowerCase()) {
const stakingContractAddress = this.getDefaultStakingAddress(coinConfig);
if (address.toLowerCase() === stakingContractAddress.toLowerCase()) {
throw new Error(
'Validator registration is not supported for wallets with an active delegation. ' +
'A wallet can either register as a validator or delegate, but not both. ' +
'Please use a wallet without an existing delegation to perform validator registration.'
);
}
throw new Error(
`Invalid contract address for validator registration. Expected ${expectedAddress} for ${coinConfig.network.type}, got ${address}`
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { coins } from '@bitgo/statics';
import { TransactionBuilderFactory, Transaction, DelegateClauseTransaction } from '../../src/lib';
import should from 'should';
import { DELEGATE_CLAUSE_METHOD_ID, STARGATE_CONTRACT_ADDRESS_TESTNET } from '../../src/lib/constants';
import {
DELEGATE_CLAUSE_METHOD_ID,
STARGATE_CONTRACT_ADDRESS_TESTNET,
VALIDATOR_REGISTRATION_STAKER_CONTRACT_ADDRESS_TESTNET,
} from '../../src/lib/constants';
import EthereumAbi from 'ethereumjs-abi';
import * as testData from '../resources/vet';
import { BN } from 'ethereumjs-util';
Expand Down Expand Up @@ -107,6 +111,21 @@ describe('VET Delegation Transaction', function () {
}).throw(/Invalid address/);
});

it('should throw descriptive error when validator registration contract is used for delegation', async function () {
const txBuilder = createBasicTxBuilder();
txBuilder.stakingContractAddress(VALIDATOR_REGISTRATION_STAKER_CONTRACT_ADDRESS_TESTNET);
txBuilder.tokenId(tokenId);
txBuilder.validator(validatorAddress);

await txBuilder
.build()
.should.be.rejectedWith(
'Delegation is not supported for wallets with an active validator registration. ' +
'A wallet can either delegate or register as a validator, but not both. ' +
'Please use a wallet without an existing validator registration to perform delegation.'
);
});

it('should build transaction with undefined sender but include it in inputs', async function () {
const txBuilder = factory.getStakingDelegateBuilder();
txBuilder.stakingContractAddress(STARGATE_CONTRACT_ADDRESS_TESTNET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TransactionBuilderFactory, Transaction, ValidatorRegistrationTransactio
import should from 'should';
import {
ADD_VALIDATION_METHOD_ID,
STARGATE_CONTRACT_ADDRESS_TESTNET,
VALIDATOR_REGISTRATION_STAKER_CONTRACT_ADDRESS_TESTNET,
} from '../../src/lib/constants';
import EthereumAbi from 'ethereumjs-abi';
Expand Down Expand Up @@ -156,6 +157,22 @@ describe('VET Validator Registration Transaction', function () {
}).throw(/Invalid address/);
});

it('should throw descriptive error when delegation contract is used for validator registration', async function () {
const txBuilder = createBasicTxBuilder();
txBuilder.stakingContractAddress(STARGATE_CONTRACT_ADDRESS_TESTNET);
txBuilder.stakingPeriod(stakingPeriod);
txBuilder.validator(validatorAddress);
txBuilder.amountToStake(amountToStake);

await txBuilder
.build()
.should.be.rejectedWith(
'Validator registration is not supported for wallets with an active delegation. ' +
'A wallet can either register as a validator or delegate, but not both. ' +
'Please use a wallet without an existing delegation to perform validator registration.'
);
});

it('should build transaction with undefined sender but include it in inputs', async function () {
const txBuilder = factory.getValidatorRegistrationBuilder();
txBuilder.stakingContractAddress(VALIDATOR_REGISTRATION_STAKER_CONTRACT_ADDRESS_TESTNET);
Expand Down
Loading