From 2c93440986437c41d3f17964900c6ca0d5782754 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Wed, 14 Aug 2024 15:14:14 +0700 Subject: [PATCH] Create PiUSDTreasury.test.js --- .../pi-stablecoin/tests/PiUSDTreasury.test.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 blockchain_integration/pi_network/pi-stablecoin/tests/PiUSDTreasury.test.js diff --git a/blockchain_integration/pi_network/pi-stablecoin/tests/PiUSDTreasury.test.js b/blockchain_integration/pi_network/pi-stablecoin/tests/PiUSDTreasury.test.js new file mode 100644 index 000000000..e93789447 --- /dev/null +++ b/blockchain_integration/pi_network/pi-stablecoin/tests/PiUSDTreasury.test.js @@ -0,0 +1,40 @@ +const { expect } = require('chai'); +const { ethers } = require('hardhat'); + +describe('PiUSDTreasury', function () { + let piUSDTreasury; + let owner; + let user1; + let user2; + + beforeEach(async function () { + [owner, user1, user2] = await ethers.getSigners(); + piUSDTreasury = await ethers.getContractFactory('PiUSDTreasury'); + piUSDTreasury = await piUSDTreasury.deploy(); + }); + + it('should have a treasury manager', async function () { + expect(await piUSDTreasury.treasuryManager()).to.equal(owner.address); + }); + + it('should fund treasury correctly', async function () { + await piUSDTreasury.fundTreasury(ethers.utils.parseEther('100')); + expect(await piUSDTreasury.treasuryBalance()).to.equal(ethers.utils.parseEther('100')); + }); + + it('should withdraw from treasury correctly', async function () { + await piUSDTreasury.fundTreasury(ethers.utils.parseEther('100')); + await piUSDTreasury.withdrawFromTreasury(ethers.utils.parseEther('50')); + expect(await piUSDTreasury.treasuryBalance()).to.equal(ethers.utils.parseEther('50')); + }); + + it('should update interest rate correctly', async function () { + await piUSDTreasury.updateInterestRate(ethers.utils.parseEther('0.05')); + expect(await piUSDTreasury.interestRate()).to.equal(ethers.utils.parseEther('0.05')); + }); + + it('should update reserve ratio correctly', async function () { + await piUSDTreasury.updateReserveRatio(ethers.utils.parseEther('0.2')); + expect(await piUSDTreasury.reserveRatio()).to.equal(ethers.utils.parseEther('0.2')); + }); +});