From 944da5888d31cd4cba496a6a38aa95510f9bf5b8 Mon Sep 17 00:00:00 2001 From: SevenSwen Date: Thu, 14 Sep 2023 17:18:36 +0700 Subject: [PATCH 1/8] merge tests in to files --- test/DelegationSt1inch.js | 129 -------------------------------------- test/PowerPod.js | 94 +++++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 135 deletions(-) delete mode 100644 test/DelegationSt1inch.js diff --git a/test/DelegationSt1inch.js b/test/DelegationSt1inch.js deleted file mode 100644 index 1741079b..00000000 --- a/test/DelegationSt1inch.js +++ /dev/null @@ -1,129 +0,0 @@ -const { expect, time, ether, constants } = require('@1inch/solidity-utils'); -const { ethers } = require('hardhat'); -const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { expBase } = require('./helpers/utils'); - -describe('Delegation st1inch', function () { - let addr, addr1; - let accounts; - const MAX_WHITELISTED = 3; - const commonLockDuration = time.duration.days('40'); - const BALANCE_THRESHOLD = 1000; // 10% - - const stakeAndRegisterInDelegation = async (st1inch, delegation, user, amount, userIndex) => { - await st1inch.connect(user).deposit(0, commonLockDuration); - await st1inch.depositFor(user.address, amount); - await st1inch.connect(user).addPod(delegation.address); - await delegation - .connect(user) - .functions['register(string,string)']( - `${userIndex}DelegatingToken`, - `A${userIndex}DT`, - ); - await delegation.connect(user).delegate(user.address); - }; - - async function initContracts() { - const TokenPermitMock = await ethers.getContractFactory('ERC20PermitMock'); - const oneInch = await TokenPermitMock.deploy('1inch', '1inch', addr.address, ether('200')); - await oneInch.deployed(); - await oneInch.transfer(addr1.address, ether('100')); - - const St1inch = await ethers.getContractFactory('St1inch'); - const st1inch = await St1inch.deploy(oneInch.address, expBase, addr.address); - await st1inch.deployed(); - await oneInch.approve(st1inch.address, ether('100')); - await oneInch.connect(addr1).approve(st1inch.address, ether('100')); - - const PowerPod = await ethers.getContractFactory('PowerPod'); - const delegation = await PowerPod.deploy('PowerPod', 'PP', st1inch.address); - await delegation.deployed(); - const WhitelistRegistry = await ethers.getContractFactory('WhitelistRegistry'); - const whitelistRegistry = await WhitelistRegistry.deploy(delegation.address, BALANCE_THRESHOLD); - await whitelistRegistry.deployed(); - // fill all whitelist into WhitelistRegistry - for (let i = 0; i < MAX_WHITELISTED; ++i) { - const userIndex = i + 2; - const user = accounts[userIndex]; - await stakeAndRegisterInDelegation(st1inch, delegation, user, ether('2') * BigInt(i + 1), userIndex); - await whitelistRegistry.connect(user).register(); - } - await stakeAndRegisterInDelegation(st1inch, delegation, addr, ether('1'), 0); - - return { st1inch, delegation, whitelistRegistry }; - } - - before(async function () { - accounts = await ethers.getSigners(); - addr = accounts[0]; - addr1 = accounts[1]; - }); - - describe('For add to whitelist', function () { - const depositAndDelegateTo = async (st1inch, delegation, from, to, amount, duration = commonLockDuration) => { - await st1inch.connect(from).deposit(amount, duration); - await st1inch.connect(from).addPod(delegation.address); - await delegation.connect(from).delegate(to); - }; - - it('should add account, when sum stacked st1inch and deposit st1inch is sufficient', async function () { - const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); - // addr shouldn't register becouse his st1inch balance less that all of the whitelisted accounts - await expect(whitelistRegistry.register()).to.be.revertedWithCustomError( - whitelistRegistry, - 'BalanceLessThanThreshold', - ); - // create other stake and delegate to addr - await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('2')); - // register addr into whitelistRegistry and chack that - await whitelistRegistry.register(); - expect(await whitelistRegistry.getWhitelist()).to.contain(addr.address); - }); - - it('should add account, when sum stacked st1inch and deposit st1inch is sufficient (delegate before deposit)', async function () { - const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); - // delegate to addr and deposit 1inch - await st1inch.connect(addr1).addPod(delegation.address); - await delegation.connect(addr1).delegate(addr.address); - await st1inch.connect(addr1).deposit(ether('2'), commonLockDuration); - - await whitelistRegistry.register(); - }); - - it('should accrue DelegatedShare token after delegate', async function () { - const { st1inch, delegation } = await loadFixture(initContracts); - const DelegatedShare = await ethers.getContractFactory('DelegatedShare'); - const delegatedShare = await DelegatedShare.attach(await delegation.registration(addr.address)); - const balanceDelegated = await delegatedShare.balanceOf(addr.address); - expect(await delegatedShare.totalSupply()).to.equal(balanceDelegated); - expect(await st1inch.balanceOf(addr.address)).to.equal(balanceDelegated); - - await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('2')); - - const balanceDelegator = await delegatedShare.balanceOf(addr1.address); - expect(balanceDelegated.mul(await st1inch.balanceOf(addr1.address))).to.equal( - balanceDelegator.mul(await st1inch.balanceOf(addr.address)), - ); - }); - - it('should decrease delegatee balance, if delegator undelegate stake', async function () { - const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); - await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('8')); - await whitelistRegistry.register(); - - await delegation.connect(addr1).delegate(constants.ZERO_ADDRESS); - await whitelistRegistry.connect(accounts[2]).register(); - expect(await whitelistRegistry.getWhitelist()).to.not.contain(addr.address); - }); - - it('should decrease delegatee balance, if delegator delegate to other account', async function () { - const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); - await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('8')); - await whitelistRegistry.register(); - - await delegation.connect(addr1).delegate(accounts[2].address); - await whitelistRegistry.connect(accounts[2]).register(); - expect(await whitelistRegistry.getWhitelist()).to.not.contain(addr.address); - }); - }); -}); diff --git a/test/PowerPod.js b/test/PowerPod.js index 86b57099..2cb1206f 100644 --- a/test/PowerPod.js +++ b/test/PowerPod.js @@ -1,13 +1,14 @@ -const { expect, time, ether } = require('@1inch/solidity-utils'); +const { expect, time, ether, constants } = require('@1inch/solidity-utils'); const { ethers } = require('hardhat'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { expBase } = require('./helpers/utils'); describe('PowerPod', function () { - let addr, addr1; + let addr, addr1, addr2; let accounts; const commonLockDuration = time.duration.days('40'); - const amountToStake = ether('1'); + const MAX_WHITELISTED = 3; + const BALANCE_THRESHOLD = 1000; // 10% const stakeAndRegisterInDelegation = async (st1inch, delegation, user, amount, userIndex) => { await st1inch.connect(user).deposit(0, commonLockDuration); @@ -26,18 +27,31 @@ describe('PowerPod', function () { const TokenPermitMock = await ethers.getContractFactory('ERC20PermitMock'); const oneInch = await TokenPermitMock.deploy('1inch', '1inch', addr.address, ether('200')); await oneInch.deployed(); + await oneInch.transfer(addr1.address, ether('100')); const St1inch = await ethers.getContractFactory('St1inch'); const st1inch = await St1inch.deploy(oneInch.address, expBase, addr.address); await st1inch.deployed(); await oneInch.approve(st1inch.address, ether('100')); + await oneInch.connect(addr1).approve(st1inch.address, ether('100')); const PowerPod = await ethers.getContractFactory('PowerPod'); const delegation = await PowerPod.deploy('PowerPod', 'PP', st1inch.address); await delegation.deployed(); - await stakeAndRegisterInDelegation(st1inch, delegation, addr1, amountToStake, 0); - return { st1inch, delegation }; + const WhitelistRegistry = await ethers.getContractFactory('WhitelistRegistry'); + const whitelistRegistry = await WhitelistRegistry.deploy(delegation.address, BALANCE_THRESHOLD); + await whitelistRegistry.deployed(); + // fill all whitelist into WhitelistRegistry + for (let i = 0; i < MAX_WHITELISTED; ++i) { + const userIndex = i + 2; + const user = accounts[userIndex]; + await stakeAndRegisterInDelegation(st1inch, delegation, user, ether('2') * BigInt(i + 1), userIndex); + await whitelistRegistry.connect(user).register(); + } + await stakeAndRegisterInDelegation(st1inch, delegation, addr, ether('1'), 0); + + return { st1inch, delegation, whitelistRegistry }; } before(async function () { @@ -49,7 +63,7 @@ describe('PowerPod', function () { describe('Should calculate voting power', function () { it('for account with 0 balance', async function () { const { delegation } = await loadFixture(initContracts); - expect(await delegation.votingPowerOf(addr.address)).to.equal(0); + expect(await delegation.votingPowerOf(accounts[9].address)).to.equal(0); }); it('for account with st1inch balance', async function () { @@ -57,4 +71,72 @@ describe('PowerPod', function () { expect(await delegation.votingPowerOf(addr1.address)).to.equal(await st1inch.votingPowerOf(addr1.address)); }); }); + + describe('For add to whitelist', function () { + const depositAndDelegateTo = async (st1inch, delegation, from, to, amount, duration = commonLockDuration) => { + await st1inch.connect(from).deposit(amount, duration); + await st1inch.connect(from).addPod(delegation.address); + await delegation.connect(from).delegate(to); + }; + + it('should add account, when sum stacked st1inch and deposit st1inch is sufficient', async function () { + const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); + // addr shouldn't register becouse his st1inch balance less that all of the whitelisted accounts + await expect(whitelistRegistry.register()).to.be.revertedWithCustomError( + whitelistRegistry, + 'BalanceLessThanThreshold', + ); + // create other stake and delegate to addr + await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('2')); + // register addr into whitelistRegistry and chack that + await whitelistRegistry.register(); + expect(await whitelistRegistry.getWhitelist()).to.contain(addr.address); + }); + + it('should add account, when sum stacked st1inch and deposit st1inch is sufficient (delegate before deposit)', async function () { + const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); + // delegate to addr and deposit 1inch + await st1inch.connect(addr1).addPod(delegation.address); + await delegation.connect(addr1).delegate(addr.address); + await st1inch.connect(addr1).deposit(ether('2'), commonLockDuration); + + await whitelistRegistry.register(); + }); + + it('should accrue DelegatedShare token after delegate', async function () { + const { st1inch, delegation } = await loadFixture(initContracts); + const DelegatedShare = await ethers.getContractFactory('DelegatedShare'); + const delegatedShare = await DelegatedShare.attach(await delegation.registration(addr.address)); + const balanceDelegated = await delegatedShare.balanceOf(addr.address); + expect(await delegatedShare.totalSupply()).to.equal(balanceDelegated); + expect(await st1inch.balanceOf(addr.address)).to.equal(balanceDelegated); + + await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('2')); + + const balanceDelegator = await delegatedShare.balanceOf(addr1.address); + expect(balanceDelegated.mul(await st1inch.balanceOf(addr1.address))).to.equal( + balanceDelegator.mul(await st1inch.balanceOf(addr.address)), + ); + }); + + it('should decrease delegatee balance, if delegator undelegate stake', async function () { + const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); + await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('8')); + await whitelistRegistry.register(); + + await delegation.connect(addr1).delegate(constants.ZERO_ADDRESS); + await whitelistRegistry.connect(accounts[2]).register(); + expect(await whitelistRegistry.getWhitelist()).to.not.contain(addr.address); + }); + + it('should decrease delegatee balance, if delegator delegate to other account', async function () { + const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); + await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('8')); + await whitelistRegistry.register(); + + await delegation.connect(addr1).delegate(accounts[2].address); + await whitelistRegistry.connect(accounts[2]).register(); + expect(await whitelistRegistry.getWhitelist()).to.not.contain(addr.address); + }); + }); }); From 96d17880553bcd2dde3993e71f05e46b2c686a11 Mon Sep 17 00:00:00 2001 From: SevenSwen Date: Thu, 14 Sep 2023 17:29:38 +0700 Subject: [PATCH 2/8] refactor PowerPods tests --- test/PowerPod.js | 154 ++++++++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 67 deletions(-) diff --git a/test/PowerPod.js b/test/PowerPod.js index 2cb1206f..8a15ce9e 100644 --- a/test/PowerPod.js +++ b/test/PowerPod.js @@ -4,36 +4,37 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { expBase } = require('./helpers/utils'); describe('PowerPod', function () { - let addr, addr1, addr2; - let accounts; - const commonLockDuration = time.duration.days('40'); - const MAX_WHITELISTED = 3; - const BALANCE_THRESHOLD = 1000; // 10% - - const stakeAndRegisterInDelegation = async (st1inch, delegation, user, amount, userIndex) => { - await st1inch.connect(user).deposit(0, commonLockDuration); - await st1inch.depositFor(user.address, amount); - await st1inch.connect(user).addPod(delegation.address); - await delegation - .connect(user) - .functions['register(string,string)']( - `${userIndex}DelegatingToken`, - `A${userIndex}DT`, - ); - await delegation.connect(user).delegate(user.address); - }; - async function initContracts() { + const commonLockDuration = time.duration.days('40'); + const MAX_WHITELISTED = 3; + const BALANCE_THRESHOLD = 1000; // 10% + + const stakeAndRegisterInDelegation = async (st1inch, delegation, user, amount, userIndex) => { + await st1inch.connect(user).deposit(0, commonLockDuration); + await st1inch.depositFor(user.address, amount); + await st1inch.connect(user).addPod(delegation.address); + await delegation + .connect(user) + .functions['register(string,string)']( + `${userIndex}DelegatingToken`, + `A${userIndex}DT`, + ); + await delegation.connect(user).delegate(user.address); + }; + + const accounts = await ethers.getSigners(); + const [owner, alice] = accounts; + const TokenPermitMock = await ethers.getContractFactory('ERC20PermitMock'); - const oneInch = await TokenPermitMock.deploy('1inch', '1inch', addr.address, ether('200')); + const oneInch = await TokenPermitMock.deploy('1inch', '1inch', owner.address, ether('200')); await oneInch.deployed(); - await oneInch.transfer(addr1.address, ether('100')); + await oneInch.transfer(alice.address, ether('100')); const St1inch = await ethers.getContractFactory('St1inch'); - const st1inch = await St1inch.deploy(oneInch.address, expBase, addr.address); + const st1inch = await St1inch.deploy(oneInch.address, expBase, owner.address); await st1inch.deployed(); await oneInch.approve(st1inch.address, ether('100')); - await oneInch.connect(addr1).approve(st1inch.address, ether('100')); + await oneInch.connect(alice).approve(st1inch.address, ether('100')); const PowerPod = await ethers.getContractFactory('PowerPod'); const delegation = await PowerPod.deploy('PowerPod', 'PP', st1inch.address); @@ -49,94 +50,113 @@ describe('PowerPod', function () { await stakeAndRegisterInDelegation(st1inch, delegation, user, ether('2') * BigInt(i + 1), userIndex); await whitelistRegistry.connect(user).register(); } - await stakeAndRegisterInDelegation(st1inch, delegation, addr, ether('1'), 0); + await stakeAndRegisterInDelegation(st1inch, delegation, owner, ether('1'), 0); - return { st1inch, delegation, whitelistRegistry }; - } + const depositAndDelegateTo = async (st1inch, delegation, from, to, amount, duration = commonLockDuration) => { + await st1inch.connect(from).deposit(amount, duration); + await st1inch.connect(from).addPod(delegation.address); + await delegation.connect(from).delegate(to); + }; - before(async function () { - accounts = await ethers.getSigners(); - addr = accounts[0]; - addr1 = accounts[1]; - }); + return { + contracts: { st1inch, delegation, whitelistRegistry }, + accounts: { owner, alice, accounts }, + functions: { depositAndDelegateTo }, + other: { commonLockDuration }, + }; + } describe('Should calculate voting power', function () { it('for account with 0 balance', async function () { - const { delegation } = await loadFixture(initContracts); + const { contracts: { delegation }, accounts: { accounts } } = await loadFixture(initContracts); expect(await delegation.votingPowerOf(accounts[9].address)).to.equal(0); }); it('for account with st1inch balance', async function () { - const { st1inch, delegation } = await loadFixture(initContracts); - expect(await delegation.votingPowerOf(addr1.address)).to.equal(await st1inch.votingPowerOf(addr1.address)); + const { contracts: { st1inch, delegation }, accounts: { alice } } = await loadFixture(initContracts); + expect(await delegation.votingPowerOf(alice.address)).to.equal(await st1inch.votingPowerOf(alice.address)); }); }); describe('For add to whitelist', function () { - const depositAndDelegateTo = async (st1inch, delegation, from, to, amount, duration = commonLockDuration) => { - await st1inch.connect(from).deposit(amount, duration); - await st1inch.connect(from).addPod(delegation.address); - await delegation.connect(from).delegate(to); - }; - it('should add account, when sum stacked st1inch and deposit st1inch is sufficient', async function () { - const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); - // addr shouldn't register becouse his st1inch balance less that all of the whitelisted accounts + const { + contracts: { st1inch, delegation, whitelistRegistry }, + accounts: { owner, alice }, + functions: { depositAndDelegateTo }, + } = await loadFixture(initContracts); + // owner shouldn't register becouse his st1inch balance less that all of the whitelisted accounts await expect(whitelistRegistry.register()).to.be.revertedWithCustomError( whitelistRegistry, 'BalanceLessThanThreshold', ); - // create other stake and delegate to addr - await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('2')); - // register addr into whitelistRegistry and chack that + // create other stake and delegate to owner + await depositAndDelegateTo(st1inch, delegation, alice, owner.address, ether('2')); + // register owner into whitelistRegistry and chack that await whitelistRegistry.register(); - expect(await whitelistRegistry.getWhitelist()).to.contain(addr.address); + expect(await whitelistRegistry.getWhitelist()).to.contain(owner.address); }); it('should add account, when sum stacked st1inch and deposit st1inch is sufficient (delegate before deposit)', async function () { - const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); - // delegate to addr and deposit 1inch - await st1inch.connect(addr1).addPod(delegation.address); - await delegation.connect(addr1).delegate(addr.address); - await st1inch.connect(addr1).deposit(ether('2'), commonLockDuration); + const { + contracts: { st1inch, delegation, whitelistRegistry }, + accounts: { owner, alice }, + other: { commonLockDuration }, + } = await loadFixture(initContracts); + // delegate to owner and deposit 1inch + await st1inch.connect(alice).addPod(delegation.address); + await delegation.connect(alice).delegate(owner.address); + await st1inch.connect(alice).deposit(ether('2'), commonLockDuration); await whitelistRegistry.register(); }); it('should accrue DelegatedShare token after delegate', async function () { - const { st1inch, delegation } = await loadFixture(initContracts); + const { + contracts: { st1inch, delegation }, + accounts: { owner, alice }, + functions: { depositAndDelegateTo }, + } = await loadFixture(initContracts); const DelegatedShare = await ethers.getContractFactory('DelegatedShare'); - const delegatedShare = await DelegatedShare.attach(await delegation.registration(addr.address)); - const balanceDelegated = await delegatedShare.balanceOf(addr.address); + const delegatedShare = DelegatedShare.attach(await delegation.registration(owner.address)); + const balanceDelegated = await delegatedShare.balanceOf(owner.address); expect(await delegatedShare.totalSupply()).to.equal(balanceDelegated); - expect(await st1inch.balanceOf(addr.address)).to.equal(balanceDelegated); + expect(await st1inch.balanceOf(owner.address)).to.equal(balanceDelegated); - await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('2')); + await depositAndDelegateTo(st1inch, delegation, alice, owner.address, ether('2')); - const balanceDelegator = await delegatedShare.balanceOf(addr1.address); - expect(balanceDelegated.mul(await st1inch.balanceOf(addr1.address))).to.equal( - balanceDelegator.mul(await st1inch.balanceOf(addr.address)), + const balanceDelegator = await delegatedShare.balanceOf(alice.address); + expect(balanceDelegated.mul(await st1inch.balanceOf(alice.address))).to.equal( + balanceDelegator.mul(await st1inch.balanceOf(owner.address)), ); }); it('should decrease delegatee balance, if delegator undelegate stake', async function () { - const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); - await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('8')); + const { + contracts: { st1inch, delegation, whitelistRegistry }, + accounts: { owner, alice, accounts }, + functions: { depositAndDelegateTo }, + } = await loadFixture(initContracts); + await depositAndDelegateTo(st1inch, delegation, alice, owner.address, ether('8')); await whitelistRegistry.register(); - await delegation.connect(addr1).delegate(constants.ZERO_ADDRESS); + await delegation.connect(alice).delegate(constants.ZERO_ADDRESS); await whitelistRegistry.connect(accounts[2]).register(); - expect(await whitelistRegistry.getWhitelist()).to.not.contain(addr.address); + expect(await whitelistRegistry.getWhitelist()).to.not.contain(owner.address); }); it('should decrease delegatee balance, if delegator delegate to other account', async function () { - const { st1inch, delegation, whitelistRegistry } = await loadFixture(initContracts); - await depositAndDelegateTo(st1inch, delegation, addr1, addr.address, ether('8')); + const { + contracts: { st1inch, delegation, whitelistRegistry }, + accounts: { owner, alice, accounts }, + functions: { depositAndDelegateTo }, + } = await loadFixture(initContracts); + await depositAndDelegateTo(st1inch, delegation, alice, owner.address, ether('8')); await whitelistRegistry.register(); - await delegation.connect(addr1).delegate(accounts[2].address); + await delegation.connect(alice).delegate(accounts[2].address); await whitelistRegistry.connect(accounts[2]).register(); - expect(await whitelistRegistry.getWhitelist()).to.not.contain(addr.address); + expect(await whitelistRegistry.getWhitelist()).to.not.contain(owner.address); }); }); }); From ef4220aebe21ad5e47ab150a83e0ce83435a1440 Mon Sep 17 00:00:00 2001 From: SevenSwen Date: Thu, 14 Sep 2023 17:34:28 +0700 Subject: [PATCH 3/8] use deployContract --- test/PowerPod.js | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/test/PowerPod.js b/test/PowerPod.js index 8a15ce9e..dc3ca699 100644 --- a/test/PowerPod.js +++ b/test/PowerPod.js @@ -1,4 +1,4 @@ -const { expect, time, ether, constants } = require('@1inch/solidity-utils'); +const { expect, time, ether, deployContract, constants } = require('@1inch/solidity-utils'); const { ethers } = require('hardhat'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { expBase } = require('./helpers/utils'); @@ -22,27 +22,25 @@ describe('PowerPod', function () { await delegation.connect(user).delegate(user.address); }; + const depositAndDelegateTo = async (st1inch, delegation, from, to, amount, duration = commonLockDuration) => { + await st1inch.connect(from).deposit(amount, duration); + await st1inch.connect(from).addPod(delegation.address); + await delegation.connect(from).delegate(to); + }; + const accounts = await ethers.getSigners(); const [owner, alice] = accounts; - const TokenPermitMock = await ethers.getContractFactory('ERC20PermitMock'); - const oneInch = await TokenPermitMock.deploy('1inch', '1inch', owner.address, ether('200')); - await oneInch.deployed(); + const oneInch = await deployContract('ERC20PermitMock', ['1inch', '1inch', owner.address, ether('200')]); await oneInch.transfer(alice.address, ether('100')); - const St1inch = await ethers.getContractFactory('St1inch'); - const st1inch = await St1inch.deploy(oneInch.address, expBase, owner.address); - await st1inch.deployed(); + const st1inch = await deployContract('St1inch', [oneInch.address, expBase, owner.address]); await oneInch.approve(st1inch.address, ether('100')); await oneInch.connect(alice).approve(st1inch.address, ether('100')); - const PowerPod = await ethers.getContractFactory('PowerPod'); - const delegation = await PowerPod.deploy('PowerPod', 'PP', st1inch.address); - await delegation.deployed(); + const delegation = await deployContract('PowerPod', ['PowerPod', 'PP', st1inch.address]); - const WhitelistRegistry = await ethers.getContractFactory('WhitelistRegistry'); - const whitelistRegistry = await WhitelistRegistry.deploy(delegation.address, BALANCE_THRESHOLD); - await whitelistRegistry.deployed(); + const whitelistRegistry = await deployContract('WhitelistRegistry', [delegation.address, BALANCE_THRESHOLD]); // fill all whitelist into WhitelistRegistry for (let i = 0; i < MAX_WHITELISTED; ++i) { const userIndex = i + 2; @@ -52,12 +50,6 @@ describe('PowerPod', function () { } await stakeAndRegisterInDelegation(st1inch, delegation, owner, ether('1'), 0); - const depositAndDelegateTo = async (st1inch, delegation, from, to, amount, duration = commonLockDuration) => { - await st1inch.connect(from).deposit(amount, duration); - await st1inch.connect(from).addPod(delegation.address); - await delegation.connect(from).delegate(to); - }; - return { contracts: { st1inch, delegation, whitelistRegistry }, accounts: { owner, alice, accounts }, From 23b39884e1def57211e977f1fc5837abb8c9b408 Mon Sep 17 00:00:00 2001 From: SevenSwen Date: Thu, 14 Sep 2023 17:37:59 +0700 Subject: [PATCH 4/8] fix typo --- test/FeeBank.js | 2 +- test/Settlement.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/FeeBank.js b/test/FeeBank.js index 2650aee4..bc01bef7 100644 --- a/test/FeeBank.js +++ b/test/FeeBank.js @@ -24,7 +24,7 @@ describe('FeeBank', function () { await matcher.deployed(); const FeeBank = await ethers.getContractFactory('FeeBank'); - const feeBank = await FeeBank.attach(await matcher.feeBank()); + const feeBank = FeeBank.attach(await matcher.feeBank()); await inch.transfer(addr1.address, ether('100')); await inch.approve(feeBank.address, ether('1000')); diff --git a/test/Settlement.js b/test/Settlement.js index f9486ddd..d343282e 100644 --- a/test/Settlement.js +++ b/test/Settlement.js @@ -26,7 +26,7 @@ describe('Settlement', function () { await settlement.deployed(); const FeeBank = await ethers.getContractFactory('FeeBank'); - const feeBank = await FeeBank.attach(await settlement.feeBank()); + const feeBank = FeeBank.attach(await settlement.feeBank()); const ResolverMock = await ethers.getContractFactory('ResolverMock'); const resolver = await ResolverMock.deploy(settlement.address, swap.address); From 9f507948eb7b963101b226aedf404e3a898af203 Mon Sep 17 00:00:00 2001 From: SevenSwen Date: Thu, 14 Sep 2023 17:47:43 +0700 Subject: [PATCH 5/8] use deployContract in all files --- test/FeeBank.js | 10 +++------- test/FeeBankCharger.js | 11 ++++------- test/FusionDetailsMock.js | 6 ++---- test/Settlement.js | 6 ++---- test/WhitelistChecker.js | 10 ++++------ test/WhitelistRegistry.js | 27 +++++++++------------------ test/helpers/fixtures.js | 17 +---------------- 7 files changed, 25 insertions(+), 62 deletions(-) diff --git a/test/FeeBank.js b/test/FeeBank.js index bc01bef7..b101f692 100644 --- a/test/FeeBank.js +++ b/test/FeeBank.js @@ -1,4 +1,4 @@ -const { expect, ether, getPermit } = require('@1inch/solidity-utils'); +const { expect, ether, getPermit, deployContract } = require('@1inch/solidity-utils'); const { ethers } = require('hardhat'); const { BigNumber: BN } = require('ethers'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); @@ -15,13 +15,9 @@ describe('FeeBank', function () { }); async function initContracts() { - const TokenPermitMock = await ethers.getContractFactory('ERC20PermitMock'); - const inch = await TokenPermitMock.deploy('1INCH', '1INCH', addr.address, ether('1000')); - await inch.deployed(); + const inch = await deployContract('ERC20PermitMock', ['1INCH', '1INCH', addr.address, ether('1000')]); const { swap } = await deploySwapTokens(); - const SettlementMock = await ethers.getContractFactory('SettlementMock'); - const matcher = await SettlementMock.deploy(swap.address, inch.address); - await matcher.deployed(); + const matcher = await deployContract('SettlementMock', [swap.address, inch.address]); const FeeBank = await ethers.getContractFactory('FeeBank'); const feeBank = FeeBank.attach(await matcher.feeBank()); diff --git a/test/FeeBankCharger.js b/test/FeeBankCharger.js index 41131ca1..564178dd 100644 --- a/test/FeeBankCharger.js +++ b/test/FeeBankCharger.js @@ -1,4 +1,4 @@ -const { expect, ether } = require('@1inch/solidity-utils'); +const { expect, ether, deployContract } = require('@1inch/solidity-utils'); const { ethers } = require('hardhat'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); @@ -10,12 +10,9 @@ describe('FeeBankCharger', function () { }); async function initContracts() { - const TokenPermitMock = await ethers.getContractFactory('ERC20PermitMock'); - const inch = await TokenPermitMock.deploy('1INCH', '1INCH', addr.address, ether('1000')); - await inch.deployed(); - const FeeBankCharger = await ethers.getContractFactory('FeeBankCharger'); - const charger = await FeeBankCharger.deploy(inch.address); - await charger.deployed(); + const inch = await deployContract('ERC20PermitMock', ['1INCH', '1INCH', addr.address, ether('1000')]); + + const charger = await deployContract('FeeBankCharger', [inch.address]); const FeeBank = await ethers.getContractFactory('FeeBank'); const feeBank = FeeBank.attach(await charger.feeBank()); diff --git a/test/FusionDetailsMock.js b/test/FusionDetailsMock.js index a38bca46..4a2e7a63 100644 --- a/test/FusionDetailsMock.js +++ b/test/FusionDetailsMock.js @@ -1,14 +1,12 @@ const { ethers } = require('hardhat'); const { BigNumber } = require('ethers'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); -const { expect, constants, time } = require('@1inch/solidity-utils'); +const { expect, constants, time, deployContract } = require('@1inch/solidity-utils'); const { buildFusions } = require('./helpers/fusionUtils'); describe('FusionDetailsMock', function () { async function initContracts() { - const FusionDetailsMock = await ethers.getContractFactory('FusionDetailsMock'); - const fusionDetailsMock = await FusionDetailsMock.deploy(); - await fusionDetailsMock.deployed(); + const fusionDetailsMock = await deployContract('FusionDetailsMock', []); return { fusionDetailsMock }; } diff --git a/test/Settlement.js b/test/Settlement.js index d343282e..0642d2cf 100644 --- a/test/Settlement.js +++ b/test/Settlement.js @@ -1,4 +1,4 @@ -const { time, expect, ether, trim0x, timeIncreaseTo, getPermit, getPermit2, compressPermit, permit2Contract } = require('@1inch/solidity-utils'); +const { time, expect, ether, trim0x, timeIncreaseTo, getPermit, getPermit2, compressPermit, permit2Contract, deployContract } = require('@1inch/solidity-utils'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { ethers } = require('hardhat'); const { deploySwapTokens, getChainId } = require('./helpers/fixtures'); @@ -21,9 +21,7 @@ describe('Settlement', function () { await weth.deposit({ value: ether('1') }); await weth.connect(addr1).deposit({ value: ether('1') }); - const SettlementMock = await ethers.getContractFactory('SettlementMock'); - const settlement = await SettlementMock.deploy(swap.address, inch.address); - await settlement.deployed(); + const settlement = await deployContract('SettlementMock', [swap.address, inch.address]); const FeeBank = await ethers.getContractFactory('FeeBank'); const feeBank = FeeBank.attach(await settlement.feeBank()); diff --git a/test/WhitelistChecker.js b/test/WhitelistChecker.js index b8361f07..948faf63 100644 --- a/test/WhitelistChecker.js +++ b/test/WhitelistChecker.js @@ -1,8 +1,8 @@ const { ethers } = require('hardhat'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { signOrder, buildOrder, compactSignature, fillWithMakingAmount } = require('@1inch/limit-order-protocol-contract/test/helpers/orderUtils'); -const { expect, ether, trim0x } = require('@1inch/solidity-utils'); -const { deploySwapTokens, getChainId, deploySimpleRegistry } = require('./helpers/fixtures'); +const { expect, ether, trim0x, deployContract } = require('@1inch/solidity-utils'); +const { deploySwapTokens, getChainId } = require('./helpers/fixtures'); const { buildFusions } = require('./helpers/fusionUtils'); describe('WhitelistChecker', function () { @@ -27,10 +27,8 @@ describe('WhitelistChecker', function () { await weth.approve(swap.address, ether('1')); await weth.connect(addr1).approve(swap.address, ether('1')); - const whitelistRegistrySimple = await deploySimpleRegistry(); - const Settlement = await ethers.getContractFactory('Settlement'); - const settlement = await Settlement.deploy(swap.address, weth.address); - await settlement.deployed(); + const whitelistRegistrySimple = await deployContract('WhitelistRegistrySimple', []); + const settlement = await deployContract('Settlement', [swap.address, weth.address]); const ResolverMock = await ethers.getContractFactory('ResolverMock'); const resolver = await ResolverMock.deploy(settlement.address, swap.address); diff --git a/test/WhitelistRegistry.js b/test/WhitelistRegistry.js index b5c021a7..938bae33 100644 --- a/test/WhitelistRegistry.js +++ b/test/WhitelistRegistry.js @@ -1,4 +1,4 @@ -const { expect, constants, ether, trackReceivedTokenAndTx } = require('@1inch/solidity-utils'); +const { expect, constants, ether, trackReceivedTokenAndTx, deployContract } = require('@1inch/solidity-utils'); const { ethers } = require('hardhat'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { expBase } = require('./helpers/utils'); @@ -26,21 +26,12 @@ describe('WhitelistRegistry', function () { before(async function () { addrs = await ethers.getSigners(); - const St1inch = await ethers.getContractFactory('St1inch'); - st1inch = await St1inch.deploy(constants.ZERO_ADDRESS, expBase, addrs[0].address); - await st1inch.deployed(); + st1inch = await deployContract('St1inch', [constants.ZERO_ADDRESS, expBase, addrs[0].address]); }); async function initContracts() { - const PowerPodMock = await ethers.getContractFactory('PowerPodMock'); - const rewardableDelegationPod = await PowerPodMock.deploy('reward1INCH', 'reward1INCH', st1inch.address); - await rewardableDelegationPod.deployed(); - const WhitelistRegistry = await ethers.getContractFactory('WhitelistRegistry'); - const whitelistRegistry = await WhitelistRegistry.deploy( - rewardableDelegationPod.address, - PERCENTAGE_THRESHOLD, - ); - await whitelistRegistry.deployed(); + const rewardableDelegationPod = await deployContract('PowerPodMock', ['reward1INCH', 'reward1INCH', st1inch.address]); + const whitelistRegistry = await deployContract('WhitelistRegistry', [rewardableDelegationPod.address, PERCENTAGE_THRESHOLD]); return { rewardableDelegationPod, whitelistRegistry }; } @@ -127,16 +118,16 @@ describe('WhitelistRegistry', function () { whitelistRegistry.connect(addrs[WHITELIST_LIMIT + 1]).register(), ).to.be.revertedWithCustomError(whitelistRegistry, 'BalanceLessThanThreshold'); expect(await whitelistRegistry.getWhitelist()).to.not.contain(addrs[WHITELIST_LIMIT + 1].address); - + await rewardableDelegationPod.burn(addrs[1].address, RESOLVER_BALANCE); await rewardableDelegationPod.mint(addrs[WHITELIST_LIMIT + 1].address, RESOLVER_BALANCE); - + await whitelistRegistry.connect(addrs[WHITELIST_LIMIT + 1]).register(); const whitelist = await whitelistRegistry.getWhitelist(); expect(whitelist).to.contain(addrs[WHITELIST_LIMIT + 1].address); await expectAddrsInWhitelist(whitelistRegistry, 1, WHITELIST_LIMIT + 1, [1]); }); - + it('5/10 addresses, then lower balance, then whitelist +1 successfully', async function () { const { rewardableDelegationPod, whitelistRegistry } = await loadFixture(initContracts); const resolversNumber = WHITELIST_LIMIT / 2; @@ -157,7 +148,7 @@ describe('WhitelistRegistry', function () { expect(whitelist).to.contain(addrs[3].address); expect(whitelist).to.contain(addrs[resolversNumber + 1].address); }); - + it('5/10 addresses, then lower balance, then whitelist instead successfully', async function () { const { rewardableDelegationPod, whitelistRegistry } = await loadFixture(initContracts); const resolversNumber = WHITELIST_LIMIT / 2; @@ -203,7 +194,7 @@ describe('WhitelistRegistry', function () { 'BalanceLessThanThreshold', ); }); - + it('the same address twice', async function () { const { rewardableDelegationPod, whitelistRegistry } = await loadFixture(initContracts); await rewardableDelegationPod.mint(addrs[1].address, RESOLVER_BALANCE); diff --git a/test/helpers/fixtures.js b/test/helpers/fixtures.js index c4ea5a60..0854a215 100644 --- a/test/helpers/fixtures.js +++ b/test/helpers/fixtures.js @@ -1,17 +1,10 @@ const { ethers } = require('hardhat'); -const { ether } = require('@1inch/solidity-utils'); +const { ether, deployContract } = require('@1inch/solidity-utils'); async function getChainId() { return (await ethers.provider.getNetwork()).chainId; } -async function deployContract(contractFactoryName, params = []) { - const Contract = await ethers.getContractFactory(contractFactoryName); - const contract = await Contract.deploy(...params); - await contract.deployed(); - return contract; -} - async function deploySwapTokens() { const [account] = await ethers.getSigners(); const dai = await deployContract('ERC20PermitMock', ['DAI', 'DAI', account.address, ether('1000')]); @@ -21,16 +14,8 @@ async function deploySwapTokens() { return { dai, weth, inch, swap }; } -async function deploySimpleRegistry() { - const WhitelistRegistrySimple = await ethers.getContractFactory('WhitelistRegistrySimple'); - const whitelistRegistrySimple = await WhitelistRegistrySimple.deploy(); - await whitelistRegistrySimple.deployed(); - return whitelistRegistrySimple; -} - module.exports = { deployContract, - deploySimpleRegistry, deploySwapTokens, getChainId, }; From f4068529de476515b9951435ca98e9423c7cf7ec Mon Sep 17 00:00:00 2001 From: SevenSwen Date: Thu, 14 Sep 2023 17:49:16 +0700 Subject: [PATCH 6/8] fix lint --- test/FusionDetailsMock.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/FusionDetailsMock.js b/test/FusionDetailsMock.js index 4a2e7a63..400a4d76 100644 --- a/test/FusionDetailsMock.js +++ b/test/FusionDetailsMock.js @@ -1,4 +1,3 @@ -const { ethers } = require('hardhat'); const { BigNumber } = require('ethers'); const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { expect, constants, time, deployContract } = require('@1inch/solidity-utils'); From c5bac00f5068450ce0fed8ac313939b7b6cec562 Mon Sep 17 00:00:00 2001 From: SevenSwen Date: Mon, 18 Sep 2023 17:39:13 +0700 Subject: [PATCH 7/8] fix after review --- test/PowerPod.js | 66 +++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/test/PowerPod.js b/test/PowerPod.js index dc3ca699..0caa217d 100644 --- a/test/PowerPod.js +++ b/test/PowerPod.js @@ -4,32 +4,32 @@ const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); const { expBase } = require('./helpers/utils'); describe('PowerPod', function () { - async function initContracts() { - const commonLockDuration = time.duration.days('40'); - const MAX_WHITELISTED = 3; - const BALANCE_THRESHOLD = 1000; // 10% - - const stakeAndRegisterInDelegation = async (st1inch, delegation, user, amount, userIndex) => { - await st1inch.connect(user).deposit(0, commonLockDuration); - await st1inch.depositFor(user.address, amount); - await st1inch.connect(user).addPod(delegation.address); - await delegation - .connect(user) - .functions['register(string,string)']( - `${userIndex}DelegatingToken`, - `A${userIndex}DT`, - ); - await delegation.connect(user).delegate(user.address); - }; + const COMMON_LOCK_DURATION = time.duration.days('40'); + const MAX_WHITELISTED = 3; + const BALANCE_THRESHOLD = 1000; // 10% + + const stakeAndRegisterInDelegation = async (st1inch, delegation, user, amount, userIndex) => { + await st1inch.connect(user).deposit(0, COMMON_LOCK_DURATION); + await st1inch.depositFor(user.address, amount); + await st1inch.connect(user).addPod(delegation.address); + await delegation + .connect(user) + .functions['register(string,string)']( + `${userIndex}DelegatingToken`, + `A${userIndex}DT`, + ); + await delegation.connect(user).delegate(user.address); + }; - const depositAndDelegateTo = async (st1inch, delegation, from, to, amount, duration = commonLockDuration) => { - await st1inch.connect(from).deposit(amount, duration); - await st1inch.connect(from).addPod(delegation.address); - await delegation.connect(from).delegate(to); - }; + const depositAndDelegateTo = async (st1inch, delegation, from, to, amount, duration = COMMON_LOCK_DURATION) => { + await st1inch.connect(from).deposit(amount, duration); + await st1inch.connect(from).addPod(delegation.address); + await delegation.connect(from).delegate(to); + }; + async function initContracts() { const accounts = await ethers.getSigners(); - const [owner, alice] = accounts; + const [owner, alice, whitelistedUser1, /* whitelistedUser2 */, /* whitelistedUser3 */, clearAddress] = accounts; const oneInch = await deployContract('ERC20PermitMock', ['1inch', '1inch', owner.address, ether('200')]); await oneInch.transfer(alice.address, ether('100')); @@ -52,16 +52,15 @@ describe('PowerPod', function () { return { contracts: { st1inch, delegation, whitelistRegistry }, - accounts: { owner, alice, accounts }, + accounts: { owner, alice, whitelistedUser1, clearAddress }, functions: { depositAndDelegateTo }, - other: { commonLockDuration }, }; } describe('Should calculate voting power', function () { it('for account with 0 balance', async function () { - const { contracts: { delegation }, accounts: { accounts } } = await loadFixture(initContracts); - expect(await delegation.votingPowerOf(accounts[9].address)).to.equal(0); + const { contracts: { delegation }, accounts: { clearAddress } } = await loadFixture(initContracts); + expect(await delegation.votingPowerOf(clearAddress.address)).to.equal(0); }); it('for account with st1inch balance', async function () { @@ -93,12 +92,11 @@ describe('PowerPod', function () { const { contracts: { st1inch, delegation, whitelistRegistry }, accounts: { owner, alice }, - other: { commonLockDuration }, } = await loadFixture(initContracts); // delegate to owner and deposit 1inch await st1inch.connect(alice).addPod(delegation.address); await delegation.connect(alice).delegate(owner.address); - await st1inch.connect(alice).deposit(ether('2'), commonLockDuration); + await st1inch.connect(alice).deposit(ether('2'), COMMON_LOCK_DURATION); await whitelistRegistry.register(); }); @@ -126,28 +124,28 @@ describe('PowerPod', function () { it('should decrease delegatee balance, if delegator undelegate stake', async function () { const { contracts: { st1inch, delegation, whitelistRegistry }, - accounts: { owner, alice, accounts }, + accounts: { owner, alice, whitelistedUser1 }, functions: { depositAndDelegateTo }, } = await loadFixture(initContracts); await depositAndDelegateTo(st1inch, delegation, alice, owner.address, ether('8')); await whitelistRegistry.register(); await delegation.connect(alice).delegate(constants.ZERO_ADDRESS); - await whitelistRegistry.connect(accounts[2]).register(); + await whitelistRegistry.connect(whitelistedUser1).register(); expect(await whitelistRegistry.getWhitelist()).to.not.contain(owner.address); }); it('should decrease delegatee balance, if delegator delegate to other account', async function () { const { contracts: { st1inch, delegation, whitelistRegistry }, - accounts: { owner, alice, accounts }, + accounts: { owner, alice, whitelistedUser1 }, functions: { depositAndDelegateTo }, } = await loadFixture(initContracts); await depositAndDelegateTo(st1inch, delegation, alice, owner.address, ether('8')); await whitelistRegistry.register(); - await delegation.connect(alice).delegate(accounts[2].address); - await whitelistRegistry.connect(accounts[2]).register(); + await delegation.connect(alice).delegate(whitelistedUser1.address); + await whitelistRegistry.connect(whitelistedUser1).register(); expect(await whitelistRegistry.getWhitelist()).to.not.contain(owner.address); }); }); From 3e871745e18018762ec09af07a65a1fc2f22e0fb Mon Sep 17 00:00:00 2001 From: SevenSwen Date: Tue, 19 Sep 2023 14:25:46 +0700 Subject: [PATCH 8/8] remove unused --- test/PowerPod.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/PowerPod.js b/test/PowerPod.js index 0caa217d..1dde35c0 100644 --- a/test/PowerPod.js +++ b/test/PowerPod.js @@ -53,7 +53,6 @@ describe('PowerPod', function () { return { contracts: { st1inch, delegation, whitelistRegistry }, accounts: { owner, alice, whitelistedUser1, clearAddress }, - functions: { depositAndDelegateTo }, }; } @@ -74,7 +73,6 @@ describe('PowerPod', function () { const { contracts: { st1inch, delegation, whitelistRegistry }, accounts: { owner, alice }, - functions: { depositAndDelegateTo }, } = await loadFixture(initContracts); // owner shouldn't register becouse his st1inch balance less that all of the whitelisted accounts await expect(whitelistRegistry.register()).to.be.revertedWithCustomError( @@ -105,7 +103,6 @@ describe('PowerPod', function () { const { contracts: { st1inch, delegation }, accounts: { owner, alice }, - functions: { depositAndDelegateTo }, } = await loadFixture(initContracts); const DelegatedShare = await ethers.getContractFactory('DelegatedShare'); const delegatedShare = DelegatedShare.attach(await delegation.registration(owner.address)); @@ -125,7 +122,6 @@ describe('PowerPod', function () { const { contracts: { st1inch, delegation, whitelistRegistry }, accounts: { owner, alice, whitelistedUser1 }, - functions: { depositAndDelegateTo }, } = await loadFixture(initContracts); await depositAndDelegateTo(st1inch, delegation, alice, owner.address, ether('8')); await whitelistRegistry.register(); @@ -139,7 +135,6 @@ describe('PowerPod', function () { const { contracts: { st1inch, delegation, whitelistRegistry }, accounts: { owner, alice, whitelistedUser1 }, - functions: { depositAndDelegateTo }, } = await loadFixture(initContracts); await depositAndDelegateTo(st1inch, delegation, alice, owner.address, ether('8')); await whitelistRegistry.register();