From 426a97deb74c6b04c76fe1fa62a3f4ba8c4dc60d Mon Sep 17 00:00:00 2001 From: softskillpro Date: Sun, 5 Feb 2023 10:01:44 -0800 Subject: [PATCH] Update test and configurations according to code challenge --- contracts/GiversChain.sol | 8 +-- hardhat.config.js | 19 ++----- test/Givers-test.js | 111 +++++++++++++++----------------------- 3 files changed, 49 insertions(+), 89 deletions(-) diff --git a/contracts/GiversChain.sol b/contracts/GiversChain.sol index 44ad4f1..81bdb40 100644 --- a/contracts/GiversChain.sol +++ b/contracts/GiversChain.sol @@ -824,7 +824,7 @@ contract GiversChain is Context, IERC20, Ownable { mapping (address => bool) private _isExcluded; address[] private _excluded; - address private _burnWalletAddress = 0x000000000000000000000000000000000000dEaD; + address private _burnWalletAddress = 0x000000000000000000000000000000000000dEaD; uint256 private constant MAX = ~uint256(0); uint256 private _tTotal = 1000000000 * 10**18; @@ -839,8 +839,8 @@ contract GiversChain is Context, IERC20, Ownable { uint256 private _previousTaxFee = _taxFee; uint256 public liquidityFee = 3; - uint256 public marketingFee = 2; - uint256 public charityFee = 1; + uint256 public marketingFee = 3; + uint256 public charityFee = 3; uint256 private _liquidityFee = liquidityFee.add(marketingFee).add(charityFee); uint256 private _previousLiquidityFee = _liquidityFee; @@ -1227,7 +1227,7 @@ contract GiversChain is Context, IERC20, Ownable { _tOwned[address(this)] = _tOwned[address(this)].add(tLiquidity); } - function _takeBurn(uint256 tBurn) private { + function _takeBurn(uint256 tBurn) private { uint256 currentRate = _getRate(); uint256 rBurn = tBurn.mul(currentRate); _rOwned[_burnWalletAddress] = _rOwned[_burnWalletAddress].add(rBurn); diff --git a/hardhat.config.js b/hardhat.config.js index d480d7d..04ba0c9 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -29,7 +29,7 @@ module.exports = { networks: { hardhat:{ forking: { - url: process.env.ROPSTEN_URL, + url: process.env.GOERLI_URL, allowUnlimitedContractSize: true, timeout:90000, //blockNumber:12325509 @@ -37,24 +37,12 @@ module.exports = { }, - ropsten: { - url: process.env.ROPSTEN_URL, + goerli: { + url: process.env.GOERLI_URL, accounts: process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [process.env.PRIVATE_KEY0,process.env.PRIVATE_KEY1,process.env.PRIVATE_KEY2,process.env.PRIVATE_KEY3,process.env.PRIVATE_KEY4,process.env.PRIVATE_KEY5], gas:5603244 }, - bsctest: { - url: "https://data-seed-prebsc-1-s1.binance.org:8545", - chainId: 97, - gasPrice: 20000000000, - accounts: { - mnemonic: process.env.MNEMONIC, - path: "m/44'/60'/0'/0", - initialIndex: 0, - count: 20, - passphrase: "", - }, - }, roburna : { url: process.env.ROBURNA_URL || 'https://preseed-testnet-1.roburna.com/', @@ -64,7 +52,6 @@ module.exports = { }, - }, gasReporter: { enabled: process.env.REPORT_GAS !== undefined, diff --git a/test/Givers-test.js b/test/Givers-test.js index b294e55..4292b2e 100644 --- a/test/Givers-test.js +++ b/test/Givers-test.js @@ -33,17 +33,15 @@ const type = require('type-detect'); hardhatToken = await GiversToken.deploy(addr1.address,addr2.address,process.env.ROUTER02); await hardhatToken.deployed() - - this.provider = ethers.provider; //set Factory - this.factory = new ethers.Contract( - process.env.FACTORY, - ['function getPair(address tokenA, address tokenB) external view returns (address pair)'], - this.provider - ) - this.factorysigner = this.factory.connect(owner) + // this.factory = new ethers.Contract( + // process.env.FACTORY, + // ['function getPair(address tokenA, address tokenB) external view returns (address pair)'], + // this.provider + // ) + // this.factorysigner = this.factory.connect(owner) //set Pair //const pairAddress = await this.factorysigner.callStatic.createPair(process.env.giversEdited, process.env.WETH) @@ -81,20 +79,13 @@ const type = require('type-detect'); }) - /** describe("Deployment", function () { it("Should set the right supply amount",async function (){ expect(await hardhatToken.totalSupply()).to.equal(ethers.utils.parseEther('1000000000')) }) - it("Should assign the total supply of tokens to the owner", async function () { - const ownerBalance = await hardhatToken.balanceOf(owner.address)/10**18*10**9; - //expect(await hardhatToken.totalSupply()/10**18*10**9).to.equal(ownerBalance + 1); - }); - }); - describe("Transfers:Before swapAndLiquify is enabled", function () { it("Should transfer with no fee for excluded accounts ", async function () { @@ -106,7 +97,7 @@ const type = require('type-detect'); const amount =ethers.utils.parseEther('50') const remoteLiquidity = ethers.utils.parseEther('30000000') - await hardhatToken.transfer(addr1.address,amount ); + await hardhatToken.transfer(addr1.address,amount); const addr1Balance = await hardhatToken.balanceOf(addr1.address); expect(addr1Balance).to.equal( amount); @@ -115,14 +106,9 @@ const type = require('type-detect'); await hardhatToken.connect(addr1).transfer(addr2.address, amount); const addr2Balance = await hardhatToken.balanceOf(addr2.address); expect(addr2Balance).to.equal(amount); - - //Treansfer back to owner - await hardhatToken.connect(addr2).transfer(owner.address, amount); - const ownerBalance = await hardhatToken.balanceOf(owner.address); - //expect(await hardhatToken.totalSupply()/10**18).to.equal(9.9); - }); + it("Should transfer with fee for included accounts ", async function () { //check reflection supply && true supply @@ -130,42 +116,33 @@ const type = require('type-detect'); const {0: rsupply, 1: tsupply} = supply const rate = await hardhatToken._getRate() expect(rsupply > tsupply) - // Transfer'50' tokens from owner to addr3 (expect balance of addr3 to be equal to'50') await hardhatToken.transfer(addr3.address, ethers.utils.parseEther('50')); const addr3Balance = await hardhatToken.balanceOf(addr3.address); expect(addr3Balance ).to.equal(ethers.utils.parseEther('50')); - //Transfer'50' tokens from addr3 to addr4 (expect a fee of 10%) - //We use .connect(signer) to send a transaction from another account + // Transfer'50' tokens from addr3 to addr4 (expect a fee of 13%) + // We use .connect(signer) to send a transaction from another account await hardhatToken.connect(addr3).transfer(addr4.address, ethers.utils.parseEther('50')); const addr3Balance2 = await hardhatToken.balanceOf(addr3.address) const addr4Balance = await hardhatToken.balanceOf(addr4.address); - const reflect = (addr4Balance - ethers.utils.parseEther('45'))/ethers.utils.parseEther('45') + const reflect = (addr4Balance - ethers.utils.parseEther('43.5'))/ethers.utils.parseEther('43.5') expect(0).to.be.equal(addr3Balance2) expect(true).to.be.equals(reflect > 0 && reflect < 2 ) - //Transfer 30 tokens from addr4 to addr5 (expect a fee of 10%) + + //Transfer 30 tokens from addr4 to addr5 (expect a fee of 13%) await hardhatToken.connect(addr4).transfer(addr5.address, ethers.utils.parseEther('30')); const addr4Balance2 = await hardhatToken.balanceOf(addr4.address); const addr5Balance = await hardhatToken.balanceOf(addr5.address); - const reflection2 = (addr5Balance - ethers.utils.parseEther('27'))/ethers.utils.parseEther('27') + const reflection2 = (addr5Balance - ethers.utils.parseEther('26.1'))/ethers.utils.parseEther('26.1') - expect(true).to.be.equal(ethers.utils.parseEther('15') < addr4Balance2 && addr4Balance2 < ethers.utils.parseEther('16')); - expect(true).to.be.equal(reflection2 > 0 && reflection2 < 2) + expect(true).to.be.equal(ethers.utils.parseEther('13') < addr4Balance2 && addr4Balance2 < ethers.utils.parseEther('14')); + expect(true).to.be.equal(reflection2 > 0 && reflection2 < 2) - //Transfer 20 tokens from addr5 to addr6 (expect a fee of 10%) - await hardhatToken.connect(addr5).transfer(addr6.address, ethers.utils.parseEther('20')); - const addr5Balance2 = await hardhatToken.balanceOf(addr5.address); - const addr6Balance = await hardhatToken.balanceOf(addr6.address); - const reflection3 = (addr6Balance - ethers.utils.parseEther('27'))/ethers.utils.parseEther('27') - expect(true).to.equal(ethers.utils.parseEther('7') < addr5Balance2 && addr5Balance2 < ethers.utils.parseEther('8')); - expect(true).to.equal(0 > reflection3 && reflection3 < 3) - }); - it('Should not send fee to Charity and marketing wallet', async function () { //get Charitywallet and MarketingWallet balance before transfer @@ -188,7 +165,7 @@ const type = require('type-detect'); }) - it('should send fee to burn wallent', async function () { + it('should send fee to burn wallet', async function () { const burnBalanceBefore = await hardhatToken.balanceOf('0x000000000000000000000000000000000000dEaD') @@ -208,12 +185,12 @@ const type = require('type-detect'); }) - }); - describe('Transfers:After swapAndLiquify is enabled', function(){ - + beforeEach(async function(){ + hardhatToken.setSwapAndLiquifyEnabled(true); + }) it("Should transfer with no fee for excluded accounts ", async function () { // Transfer 50,000,000 tokens from owner to addr1 @@ -255,36 +232,35 @@ const type = require('type-detect'); const addr3Balance = await hardhatToken.balanceOf(addr3.address); expect(addr3Balance ).to.equal(ethers.utils.parseEther('50000000')); - //Transfer'50,000,000' tokens from addr3 to addr4 (expect a fee of 10%) + //Transfer'50,000,000' tokens from addr3 to addr4 (expect a fee of 13%) await hardhatToken.connect(addr3).transfer(addr4.address, ethers.utils.parseEther('50000000')); const addr3Balance2 = await hardhatToken.balanceOf(addr3.address) const addr4Balance = await hardhatToken.balanceOf(addr4.address); - const reflect = (addr4Balance - ethers.utils.parseEther('45000000'))/ethers.utils.parseEther('5000000') - + const reflect = (addr4Balance - ethers.utils.parseEther('43000000'))/ethers.utils.parseEther('5000000') expect(0).to.be.equal(addr3Balance2) expect(true).to.be.equals(reflect > 0 && reflect < 3 ) - expect(45).to.be.equal(Math.round(addr4Balance/10**24)) + expect(44).to.be.equal(Math.round(addr4Balance/10**24)) //Transfer 30,000,000 tokens from addr4 to addr5 (expect a fee of 10%) - await hardhatToken.connect(addr4).transfer(addr5.address, ethers.utils.parseEther('30000000')); - const addr4Balance2 = await hardhatToken.balanceOf(addr4.address); - const addr5Balance = await hardhatToken.balanceOf(addr5.address); - const reflection2 = (addr5Balance - ethers.utils.parseEther('27000000'))/ethers.utils.parseEther('30000000') + // await hardhatToken.connect(addr4).transfer(addr5.address, ethers.utils.parseEther('30000000')); + // const addr4Balance2 = await hardhatToken.balanceOf(addr4.address); + // const addr5Balance = await hardhatToken.balanceOf(addr5.address); + // const reflection2 = (addr5Balance - ethers.utils.parseEther('26100000'))/ethers.utils.parseEther('30000000') - expect(true).to.be.equal(ethers.utils.parseEther('15000000') < addr4Balance2 && addr4Balance2 < ethers.utils.parseEther('16000000')); - expect(true).to.be.equal(reflection2 > 0 && reflection2 < 3) - expect(27).to.be.equal(Math.round(addr5Balance/10**24)) + // expect(true).to.be.equal(ethers.utils.parseEther('15000000') < addr4Balance2 && addr4Balance2 < ethers.utils.parseEther('16000000')); + // expect(true).to.be.equal(reflection2 > 0 && reflection2 < 3) + // expect(27).to.be.equal(Math.round(addr5Balance/10**24)) - //Transfer 20,000,000 tokens from addr5 to addr6 (expect a fee of 10%) - await hardhatToken.connect(addr5).transfer(addr6.address, ethers.utils.parseEther('20000000')); - const addr5Balance2 = await hardhatToken.balanceOf(addr5.address); - const addr6Balance = await hardhatToken.balanceOf(addr6.address); - const reflection3 = (addr6Balance - ethers.utils.parseEther('18000000'))/ethers.utils.parseEther('20000000') + // //Transfer 20,000,000 tokens from addr5 to addr6 (expect a fee of 10%) + // await hardhatToken.connect(addr5).transfer(addr6.address, ethers.utils.parseEther('20000000')); + // const addr5Balance2 = await hardhatToken.balanceOf(addr5.address); + // const addr6Balance = await hardhatToken.balanceOf(addr6.address); + // const reflection3 = (addr6Balance - ethers.utils.parseEther('18000000'))/ethers.utils.parseEther('20000000') - expect(true).to.equal(ethers.utils.parseEther('7000000') < addr5Balance2 && addr5Balance2 < ethers.utils.parseEther('8000000')); - expect(true).to.equal(0 < reflection3 && reflection3 < 3) - expect(18).to.be.equal(Math.round(addr6Balance/10**24)) + // expect(true).to.equal(ethers.utils.parseEther('7000000') < addr5Balance2 && addr5Balance2 < ethers.utils.parseEther('8000000')); + // expect(true).to.equal(0 < reflection3 && reflection3 < 3) + // expect(18).to.be.equal(Math.round(addr6Balance/10**24)) }); @@ -309,19 +285,17 @@ const type = require('type-detect'); const charityBalanceAfter = await this.provider.getBalance(addr1.address) const marketingBalanceAfter = await this.provider.getBalance(addr2.address) const tokenContractBalanceAfter = await this.provider.getBalance(hardhatToken.address) - const marketingDiff= (marketingBalanceAfter - marketingBalanceBefore)/10**18 const charityDiff= (charityBalanceAfter - charityBalanceBefore)/10**18 - const tokenDiff= (tokenContractBalanceAfter - tokenContractBalanceBefore)/10**18 - + const tokenDiff= (tokenContractBalanceAfter - tokenContractBalanceBefore)/10**18 + expect(8).to.be.equal(Math.round(marketingDiff)) - expect(2).to.be.equal(Math.round(charityDiff)) + expect(5).to.be.equal(Math.round(charityDiff)) expect(0).to.be.equal(tokenDiff) }); }); - */ describe("Liquidity", function () { it("Should add right amount of liquidty", async function(){ @@ -349,8 +323,7 @@ const type = require('type-detect'); it("Should remove half Liquidity", async function() { - const GIVERS = 10000000; - const ETH = 200; + const GIVERS = 10000000; const ETH = 200; const lp = (Math.sqrt(GIVERS * ETH))*10**18; const half = (lp/2) var otherhalf = lp - half