Skip to content

Commit

Permalink
Merge pull request #357 from Concordium/allow-restake-below-threshold
Browse files Browse the repository at this point in the history
Allow changing restake when below threshold
  • Loading branch information
shjortConcordium authored Dec 13, 2023
2 parents 0f69389 + 017ee6b commit bf600e9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.7.2

### Fixed

- Allow validators to change restaking preference while below minimum threshold

## 1.7.1

### Changed
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "concordium-desktop-wallet",
"productName": "concordium-desktop-wallet",
"description": "concordium-desktop-wallet",
"version": "1.7.1",
"version": "1.7.2",
"main": "./main.prod.js",
"author": {
"name": "Concordium Software",
Expand Down
12 changes: 11 additions & 1 deletion app/utils/transactionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ReleaseSchedule,
TransactionSummaryType,
TransactionKindString,
isBakerAccount,
} from '@concordium/web-sdk';
import { Validate } from 'react-hook-form';
import {
Expand Down Expand Up @@ -682,7 +683,16 @@ export function validateBakerStake(
return 'Value is not a valid CCD amount';
}
const amount = ccdToMicroCcd(amountToValidate);
if (bakerStakeThreshold && bakerStakeThreshold > amount) {
const currentStake: bigint | undefined =
accountInfo && isBakerAccount(accountInfo)
? accountInfo.accountBaker.stakedAmount
: undefined;

if (
bakerStakeThreshold &&
bakerStakeThreshold > amount &&
(!currentStake || amount !== currentStake)
) {
return `Stake is below the threshold (${displayAsCcd(
bakerStakeThreshold
)}) for validation`;
Expand Down
48 changes: 47 additions & 1 deletion test/utils/transactionHelpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import '../mockWindow';
import { createRegularIntervalSchedule } from '../../app/utils/transactionHelpers';
import { AccountInfo } from '@concordium/web-sdk';
import {
createRegularIntervalSchedule,
validateBakerStake,
} from '../../app/utils/transactionHelpers';

test('createRegularIntervalSchedule release amounts should sum to input amount', () => {
const totalAmount = 100n;
Expand Down Expand Up @@ -44,3 +48,45 @@ test('createRegularIntervalSchedule should increase timestamps by interval', ()
)
).toEqual(true);
});

test('validateBakerStake allows amount below threshold (if equal to currentStake)', () => {
const stakedAmount = 1000000n; // microCCD (1 CCD)
const accountAmount = 1000000000n; // microCCD (1000 CCD)
const accountInfo = {
accountAmount,
accountBaker: { stakedAmount },
} as AccountInfo;
const threshold = 100000000n; // microCCD (100 CCD)
const amount = '1'; // CCD
expect(
validateBakerStake(threshold, amount, accountInfo, 1n)
).toBeUndefined();
});

test('validateBakerStake does not allow amount below threshold (if not equal to currentStake)', () => {
const stakedAmount = 1000000n; // microCCD (1 CCD)
const accountAmount = 1000000000n; // microCCD (1000 CCD)
const accountInfo = {
accountAmount,
accountBaker: { stakedAmount },
} as AccountInfo;
const threshold = 100000000n; // microCCD (100 CCD)
const amount = '5'; // CCD
expect(validateBakerStake(threshold, amount, accountInfo, 1n)).toContain(
'below the threshold'
);
});

test('validateBakerStake allows amount equal threshold', () => {
const stakedAmount = 1000000n; // microCCD (1 CCD)
const accountAmount = 1000000000n; // microCCD (1000 CCD)
const accountInfo = {
accountAmount,
accountBaker: { stakedAmount },
} as AccountInfo;
const threshold = 100000000n; // microCCD (100 CCD)
const amount = '100'; // CCD
expect(
validateBakerStake(threshold, amount, accountInfo, 1n)
).toBeUndefined();
});

0 comments on commit bf600e9

Please sign in to comment.