diff --git a/packages/client/lib/model/contract_model.dart b/packages/client/lib/model/contract_model.dart index 03e77cc..ae9d2f8 100644 --- a/packages/client/lib/model/contract_model.dart +++ b/packages/client/lib/model/contract_model.dart @@ -21,29 +21,35 @@ class ContractModel extends ChangeNotifier { imagePath: "assets/aurora-aoa-logo.png", ), Token( - address: dotenv.env["SHIB_CONTRACT_ADDRESS"]!, - contractName: dotenv.env["SHIB_CONTRACT_NAME"]!, - name: "Shibainu", - symbol: "SHIB", - imagePath: "assets/shib-logo.png"), + address: dotenv.env["DAI_CONTRACT_ADDRESS"]!, + contractName: dotenv.env["DAI_CONTRACT_NAME"]!, + name: "Dai", + symbol: "DAI", + imagePath: "assets/dai-dai-logo.png"), Token( address: dotenv.env["ETH_CONTRACT_ADDRESS"]!, contractName: dotenv.env["ETH_CONTRACT_NAME"]!, name: "Ethereum", symbol: "ETH", imagePath: "assets/ethereum-eth-logo.png"), + Token( + address: dotenv.env["MATIC_CONTRACT_ADDRESS"]!, + contractName: dotenv.env["MATIC_CONTRACT_NAME"]!, + name: "Polygon", + symbol: "MATIC", + imagePath: "assets/polygon-matic-logo.png"), + Token( + address: dotenv.env["SHIB_CONTRACT_ADDRESS"]!, + contractName: dotenv.env["SHIB_CONTRACT_NAME"]!, + name: "Shibainu", + symbol: "SHIB", + imagePath: "assets/shib-logo.png"), Token( address: dotenv.env["SOL_CONTRACT_ADDRESS"]!, contractName: dotenv.env["SOL_CONTRACT_NAME"]!, name: "Solana", symbol: "SOL", imagePath: "assets/solana-sol-logo.png"), - Token( - address: dotenv.env["USDT_CONTRACT_ADDRESS"]!, - contractName: dotenv.env["USDT_CONTRACT_NAME"]!, - name: "Tether", - symbol: "USDT", - imagePath: "assets/tether-usdt-logo.png"), Token( address: dotenv.env["UNI_CONTRACT_ADDRESS"]!, contractName: dotenv.env["UNI_CONTRACT_NAME"]!, @@ -51,17 +57,11 @@ class ContractModel extends ChangeNotifier { symbol: "UNI", imagePath: "assets/uniswap-uni-logo.png"), Token( - address: dotenv.env["MATIC_CONTRACT_ADDRESS"]!, - contractName: dotenv.env["MATIC_CONTRACT_NAME"]!, - name: "Polygon", - symbol: "MATIC", - imagePath: "assets/polygon-matic-logo.png"), - Token( - address: dotenv.env["DAI_CONTRACT_ADDRESS"]!, - contractName: dotenv.env["DAI_CONTRACT_NAME"]!, - name: "Dai", - symbol: "DAI", - imagePath: "assets/dai-dai-logo.png"), + address: dotenv.env["USDT_CONTRACT_ADDRESS"]!, + contractName: dotenv.env["USDT_CONTRACT_NAME"]!, + name: "Tether", + symbol: "USDT", + imagePath: "assets/tether-usdt-logo.png"), ]; final SWAP_CONTRACT_ADDRESS = dotenv.env["SWAP_CONTRACT_ADDRESS"]; diff --git a/packages/contract/test/swap.test.ts b/packages/contract/test/swap.test.ts index 83b882e..6cc4db7 100644 --- a/packages/contract/test/swap.test.ts +++ b/packages/contract/test/swap.test.ts @@ -1,50 +1,55 @@ import { loadFixture } from '@nomicfoundation/hardhat-network-helpers'; +import { expect } from 'chai'; import { ethers } from 'hardhat'; describe('Swap Contract', function () { async function deployTokenFixture() { const [owner, addr1] = await ethers.getSigners(); + const swapFactory = await ethers.getContractFactory('SwapContract'); + const auroraToken = await ethers.getContractFactory('AuroraToken'); const daiToken = await ethers.getContractFactory('DaiToken'); const ethToken = await ethers.getContractFactory('EthToken'); - const auroraToken = await ethers.getContractFactory('AuroraToken'); + const polygonToken = await ethers.getContractFactory('PolygonToken'); const shibainuToken = await ethers.getContractFactory('ShibainuToken'); const solanaToken = await ethers.getContractFactory('SolanaToken'); const tetherToken = await ethers.getContractFactory('TetherToken'); const uniswapToken = await ethers.getContractFactory('UniswapToken'); - const polygonToken = await ethers.getContractFactory('PolygonToken'); - const swapFactory = await ethers.getContractFactory('SwapContract'); const SwapContract = await swapFactory.deploy(); + const AoaToken = await auroraToken.deploy(SwapContract.address); const DaiToken = await daiToken.deploy(SwapContract.address); const EthToken = await ethToken.deploy(SwapContract.address); - const AoaToken = await auroraToken.deploy(SwapContract.address); + const MaticToken = await polygonToken.deploy(SwapContract.address); const ShibToken = await shibainuToken.deploy(SwapContract.address); const SolToken = await solanaToken.deploy(SwapContract.address); - const UsdtToken = await tetherToken.deploy(SwapContract.address); const UniToken = await uniswapToken.deploy(SwapContract.address); - const MaticToken = await polygonToken.deploy(SwapContract.address); + const UsdtToken = await tetherToken.deploy(SwapContract.address); return { owner, addr1, + SwapContract, + AoaToken, DaiToken, EthToken, - AoaToken, + MaticToken, ShibToken, SolToken, - UsdtToken, UniToken, - MaticToken, - SwapContract, + UsdtToken, }; } describe('Deployment', function () { // check if the owner of DAI token is smart contract it('ERC20 token is minted from smart contract', async function () { const { DaiToken, SwapContract } = await loadFixture(deployTokenFixture); + const balanceOfDai = await DaiToken.balanceOf(SwapContract.address); - console.log(balanceOfDai.toString()); + // convert expected value `1000000 Ether` to Wei units + const expectedValue = ethers.utils.parseUnits('1000000', 18); + + expect(balanceOfDai).to.equal(expectedValue); }); // get the value between DAI and ETH @@ -52,19 +57,19 @@ describe('Swap Contract', function () { const { DaiToken, EthToken, SwapContract } = await loadFixture( deployTokenFixture, ); + const value = await SwapContract.calculateValue( EthToken.address, DaiToken.address, ); - console.log( - `value of ETH/DAI is ${ - value / parseInt(ethers.utils.parseEther('1').toString()) - }`, - ); + // convert expected value `0.1 Ether` to Wei units + const expectedValue = ethers.utils.parseUnits('0.1', 18); + + expect(value).to.equal(expectedValue); }); // check swap function works - it('swap function', async function () { + it('Swap function', async function () { const { owner, addr1, DaiToken, EthToken, UniToken, SwapContract } = await loadFixture(deployTokenFixture); @@ -77,10 +82,9 @@ describe('Swap Contract', function () { ethers.utils.parseEther('100'), owner.address, ); + const ethAmountBefore = await DaiToken.balanceOf(addr1.address); - console.log( - `Before transfer, address_1 has ${ethAmountBefore.toString()} ETH`, - ); + expect(ethAmountBefore).to.equal(0); await SwapContract.swap( DaiToken.address, @@ -90,10 +94,9 @@ describe('Swap Contract', function () { addr1.address, ); - const ethAmountAfter = ethers.utils.formatEther( - await EthToken.balanceOf(addr1.address), - ); - console.log(`After transfer, address_1 has ${ethAmountAfter} ETH`); + const ethAmountAfter = await EthToken.balanceOf(addr1.address); + const expectedValue = ethers.utils.parseUnits('0.1', 18); + expect(ethAmountAfter).to.equal(expectedValue); }); }); });