Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit 8c9ad51

Browse files
author
Denis Ermolin
committed
stuff
1 parent 2dd5fe5 commit 8c9ad51

File tree

3 files changed

+59
-22
lines changed

3 files changed

+59
-22
lines changed

contracts/staking/stakeManager/StakeManager.sol

+7-6
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,17 @@ contract StakeManager is
567567
address currentSigner = validators[validatorId].signer;
568568
// update signer event
569569
logger.logSignerChange(validatorId, currentSigner, signer, signerPubkey);
570+
571+
if (validators[validatorId].deactivationEpoch == 0) {
572+
// didn't unstake, safe to remove the signer from the list
573+
_removeSigner(currentSigner);
574+
}
575+
576+
_insertSigner(signer);
570577

571578
signerToValidator[currentSigner] = INCORRECT_VALIDATOR_ID;
572579
signerToValidator[signer] = validatorId;
573580
validators[validatorId].signer = signer;
574-
_updateSigner(currentSigner, signer);
575581

576582
// reset update time to current time
577583
latestSignerUpdateEpoch[validatorId] = _currentEpoch;
@@ -1202,11 +1208,6 @@ contract StakeManager is
12021208
}
12031209
}
12041210

1205-
function _updateSigner(address prevSigner, address newSigner) internal {
1206-
_removeSigner(prevSigner);
1207-
_insertSigner(newSigner);
1208-
}
1209-
12101211
function _removeSigner(address signerToDelete) internal {
12111212
uint256 totalSigners = signers.length;
12121213
address swapSigner = signers[totalSigners - 1];

package-lock.json

+9-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/units/staking/stakeManager/StakeManager.Staking.js

+43
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from '../../../helpers/utils.js'
77
import { expectEvent, expectRevert, BN } from '@openzeppelin/test-helpers'
88
import { wallets, walletAmounts, freshDeploy, approveAndStake } from '../deployment'
9+
import { assert } from 'chai'
910

1011
module.exports = function(accounts) {
1112
let owner = accounts[0]
@@ -317,6 +318,48 @@ module.exports = function(accounts) {
317318
})
318319

319320
describe('unstake', function() {
321+
describe('when Alice unstakes and update the signer', function() {
322+
const AliceWallet = wallets[1]
323+
const BobWallet = wallets[3]
324+
const AliceNewWallet = wallets[2]
325+
326+
before(freshDeploy)
327+
before(doStake(AliceWallet))
328+
before(doStake(BobWallet))
329+
before('Change signer', async function() {
330+
const signerUpdateLimit = await this.stakeManager.signerUpdateLimit()
331+
await this.stakeManager.advanceEpoch(signerUpdateLimit)
332+
333+
this.validatorId = await this.stakeManager.getValidatorId(AliceWallet.getAddressString())
334+
335+
})
336+
337+
it('Alice should unstake', async function() {
338+
this.receipt = await this.stakeManager.unstake(this.validatorId, {
339+
from: AliceWallet.getAddressString()
340+
})
341+
})
342+
343+
it('Signers list should have only Bob\'s signer', async function() {
344+
assert((await this.stakeManager.signers(0)) == BobWallet.getChecksumAddressString(), 'no Bob signer!')
345+
await expectRevert.unspecified(this.stakeManager.signers(1))
346+
})
347+
348+
it('Alice should update signer', async function() {
349+
await this.stakeManager.updateSigner(this.validatorId, AliceNewWallet.getPublicKeyString(), {
350+
from: AliceWallet.getAddressString()
351+
})
352+
})
353+
354+
it('Signers list should have new Alice\'s signer and Bob\'s signer', async function() {
355+
const signers = [await this.stakeManager.signers(0), await this.stakeManager.signers(1)]
356+
357+
358+
assert(signers.findIndex(x => x == AliceNewWallet.getChecksumAddressString()) !== -1, 'no Alice signer!')
359+
assert(signers.findIndex(x => x == BobWallet.getChecksumAddressString()) !== -1, 'no Bob signer!')
360+
})
361+
})
362+
320363
describe('when user unstakes right after stake', async function() {
321364
const user = wallets[2].getChecksumAddressString()
322365
const amounts = walletAmounts[wallets[2].getAddressString()]

0 commit comments

Comments
 (0)