-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathStablePiCore.test.js
50 lines (39 loc) · 1.91 KB
/
StablePiCore.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// tests/StablePiCore.test.js
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("StablePiCore Contract", function () {
let StablePiCore, stablePiCore, Proxy, proxy, NewImplementation, newImplementation;
beforeEach(async function () {
NewImplementation = await ethers.getContractFactory("NewImplementation");
newImplementation = await NewImplementation.deploy();
await newImplementation.deployed();
Proxy = await ethers.getContractFactory("Proxy");
proxy = await Proxy.deploy(newImplementation.address);
await proxy.deployed();
StablePiCore = await ethers.getContractFactory("StablePiCore");
stablePiCore = await StablePiCore.deploy(proxy.address);
await stablePiCore.deployed();
});
it("should initialize with correct values", async function () {
const initialValue = await stablePiCore.getValue();
expect(initialValue).to.equal(0);
});
it("should perform conversion correctly", async function () {
await stablePiCore.setConversionRate(2);
const convertedValue = await stablePiCore.convert(10);
expect(convertedValue).to.equal(20);
});
it("should upgrade the implementation and retain state", async function () {
const NewImplementation2 = await ethers.getContractFactory("NewImplementation");
const newImplementation2 = await NewImplementation2.deploy();
await newImplementation2.deployed();
const upgradeTx = await proxy.upgrade(newImplementation2.address);
await upgradeTx.wait();
await stablePiCore.setConversionRate(3);
const convertedValue = await stablePiCore.convert(10);
expect(convertedValue).to.equal(30);
});
it("should handle errors gracefully", async function () {
await expect(stablePiCore.convert(0)).to.be.revertedWith("Conversion amount must be greater than zero");
});
});