|
| 1 | +const { expect } = require('chai'); |
| 2 | +const { ethers } = require('hardhat'); |
| 3 | +const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); |
| 4 | +const setup = require('./setup'); |
| 5 | + |
| 6 | +const poolId = 2n ** 95n; // overflows at uint96 |
| 7 | + |
| 8 | +describe('assignStakingPoolManager', function () { |
| 9 | + it('should revert if not called from internal address', async function () { |
| 10 | + const fixture = await loadFixture(setup); |
| 11 | + const { tokenController } = fixture.contracts; |
| 12 | + |
| 13 | + await expect(tokenController.assignStakingPoolManager(poolId, ethers.ZeroAddress)).to.be.revertedWithCustomError( |
| 14 | + tokenController, |
| 15 | + 'Unauthorized', |
| 16 | + ); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should transfer a staking pool when there is a previous manager', async function () { |
| 20 | + const fixture = await loadFixture(setup); |
| 21 | + const { tokenController } = fixture.contracts; |
| 22 | + const { |
| 23 | + members: [oldManager, newManager], |
| 24 | + stakingProducts: [stakingProducts], |
| 25 | + } = fixture.accounts; |
| 26 | + |
| 27 | + // Set old manager |
| 28 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId, oldManager.address); |
| 29 | + |
| 30 | + // Set new manager |
| 31 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId, newManager.address); |
| 32 | + |
| 33 | + const pools = await tokenController.getManagerStakingPools(newManager.address); |
| 34 | + expect(pools).to.be.deep.equal([poolId]); |
| 35 | + expect(pools.length).to.be.equal(1); |
| 36 | + |
| 37 | + expect(await tokenController.getStakingPoolManager(poolId)).to.equal(newManager.address); |
| 38 | + expect(await tokenController.isStakingPoolManager(newManager.address)).to.be.equal(true); |
| 39 | + |
| 40 | + expect(await tokenController.getManagerStakingPools(oldManager.address)).to.be.deep.equal([]); |
| 41 | + expect(await tokenController.isStakingPoolManager(oldManager.address)).to.be.equal(false); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should transfer a staking pool when there is no previous manager', async function () { |
| 45 | + const fixture = await loadFixture(setup); |
| 46 | + const { tokenController } = fixture.contracts; |
| 47 | + const { |
| 48 | + members: [newManager], |
| 49 | + stakingProducts: [stakingProducts], |
| 50 | + } = fixture.accounts; |
| 51 | + |
| 52 | + // Set new manager |
| 53 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId, newManager.address); |
| 54 | + |
| 55 | + expect(await tokenController.getStakingPoolManager(poolId)).to.equal(newManager.address); |
| 56 | + expect(await tokenController.isStakingPoolManager(newManager.address)).to.be.equal(true); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should transfer staking pools when the new owner is already a manager of another pool', async function () { |
| 60 | + const fixture = await loadFixture(setup); |
| 61 | + const { tokenController } = fixture.contracts; |
| 62 | + const { |
| 63 | + members: [oldManager, newManager], |
| 64 | + stakingProducts: [stakingProducts], |
| 65 | + } = fixture.accounts; |
| 66 | + |
| 67 | + // Set old manager |
| 68 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId, oldManager.address); |
| 69 | + |
| 70 | + // Set new manager |
| 71 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId + 1n, newManager.address); |
| 72 | + |
| 73 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId, newManager.address); |
| 74 | + |
| 75 | + const pools = await tokenController.getManagerStakingPools(newManager.address); |
| 76 | + expect(pools).to.be.deep.equal([poolId + 1n, poolId]); |
| 77 | + expect(pools.length).to.be.equal(2); |
| 78 | + |
| 79 | + expect(await tokenController.getStakingPoolManager(poolId + 1n)).to.equal(newManager.address); |
| 80 | + expect(await tokenController.getStakingPoolManager(poolId)).to.equal(newManager.address); |
| 81 | + expect(await tokenController.isStakingPoolManager(newManager.address)).to.be.equal(true); |
| 82 | + |
| 83 | + expect(await tokenController.getManagerStakingPools(oldManager.address)).to.be.deep.equal([]); |
| 84 | + expect(await tokenController.isStakingPoolManager(oldManager.address)).to.be.equal(false); |
| 85 | + }); |
| 86 | + |
| 87 | + it('should transfer several staking pools to a new manager', async function () { |
| 88 | + const fixture = await loadFixture(setup); |
| 89 | + const { tokenController } = fixture.contracts; |
| 90 | + const { |
| 91 | + members: [oldManager, newManager], |
| 92 | + stakingProducts: [stakingProducts], |
| 93 | + } = fixture.accounts; |
| 94 | + |
| 95 | + // Set old manager |
| 96 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId, oldManager.address); |
| 97 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId + 1n, oldManager.address); |
| 98 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId + 2n, oldManager.address); |
| 99 | + |
| 100 | + // Set new manager |
| 101 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId, newManager.address); |
| 102 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId + 1n, newManager.address); |
| 103 | + await tokenController.connect(stakingProducts).assignStakingPoolManager(poolId + 2n, newManager.address); |
| 104 | + |
| 105 | + const pools = await tokenController.getManagerStakingPools(newManager.address); |
| 106 | + expect(pools).to.be.deep.equal([poolId, poolId + 1n, poolId + 2n]); |
| 107 | + expect(pools.length).to.be.equal(3); |
| 108 | + |
| 109 | + // New manager is the owner of all the pools |
| 110 | + expect(await tokenController.getStakingPoolManager(poolId)).to.equal(newManager.address); |
| 111 | + expect(await tokenController.getStakingPoolManager(poolId + 1n)).to.equal(newManager.address); |
| 112 | + expect(await tokenController.getStakingPoolManager(poolId + 2n)).to.equal(newManager.address); |
| 113 | + expect(await tokenController.isStakingPoolManager(newManager.address)).to.be.equal(true); |
| 114 | + |
| 115 | + // Old manager is no longer staking pool manager |
| 116 | + expect(await tokenController.getManagerStakingPools(oldManager.address)).to.be.deep.equal([]); |
| 117 | + expect(await tokenController.isStakingPoolManager(oldManager.address)).to.be.equal(false); |
| 118 | + }); |
| 119 | +}); |
0 commit comments