Skip to content

Commit

Permalink
Merge pull request #11 from unchain-tech/feature/modify-test-script
Browse files Browse the repository at this point in the history
Feature/modify test script
  • Loading branch information
yk-saito authored Nov 13, 2023
2 parents b09044c + dbde1fe commit 5271bd8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 46 deletions.
44 changes: 22 additions & 22 deletions packages/client/lib/model/contract_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,47 @@ 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"]!,
name: "Uniswap",
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"];
Expand Down
51 changes: 27 additions & 24 deletions packages/contract/test/swap.test.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,75 @@
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
it('Get value between DAI and ETH', async 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);

Expand All @@ -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,
Expand All @@ -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);
});
});
});

0 comments on commit 5271bd8

Please sign in to comment.