Skip to content

Commit

Permalink
tests cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdt committed Jul 30, 2024
1 parent aae9e1e commit c8e2622
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
7 changes: 0 additions & 7 deletions contracts/src/TokenPrice.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ contract TokenPrice {
helperAddr = _helperAddr;
}

function getTest(string calldata token) public {
tokenPrices[token] = TokenPriceStruct({
price: "10",
timestamp: block.timestamp
});
}

function fetchPrice(string calldata token) public {
HybridAccount ha = HybridAccount(payable(helperAddr));
string memory price;
Expand Down
1 change: 1 addition & 0 deletions contracts/test/TokenPrice.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ contract MockHybridAccount {
}
}

/** @dev Unit tests */
contract TokenPriceTest is Test {
TokenPrice public tokenPrice;
MockHybridAccount public mockHybridAccount;
Expand Down
46 changes: 25 additions & 21 deletions contracts/test/TokenPrice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,35 @@ import { ethers } from "hardhat";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { Contract } from "ethers";

describe("TokenPrice", function () {
let tokenPrice: Contract
/** Integration tests */
describe("Integration tests", () => {
describe("TokenPrice", () => {
let tokenPrice: Contract

before(async () => {
const [owner] = await ethers.getSigners();
before(async () => {
const [owner] = await ethers.getSigners();

// Deploy the HybridAccount contract
const HybridAccount = await ethers.getContractFactory("HybridAccount");
const hybridAccount = await HybridAccount.deploy();
await hybridAccount.deployed();
// Deploy the HybridAccount contract
const HybridAccount = await ethers.getContractFactory("HybridAccount");
const hybridAccount = await HybridAccount.deploy();
await hybridAccount.deployed();

// Deploy the TokenPrice contract
const TokenPrice = await ethers.getContractFactory("TokenPrice");
tokenPrice = await TokenPrice.deploy(hybridAccount.address);
await tokenPrice.deployed();
})
// Deploy the TokenPrice contract
const TokenPrice = await ethers.getContractFactory("TokenPrice");
tokenPrice = await TokenPrice.deploy(hybridAccount.address);
await tokenPrice.deployed();

it("should call fetchPrice function", async function () {
})

// Call the fetchPrice function
const tx = await tokenPrice.fetchPrice("ETH");
await tx.wait();
it("should call fetchPrice function", async function () {

// Verify the price was stored correctly
const storedPrice = await tokenPrice.tokenPrices("ETH");
expect(storedPrice.price).to.equal("1234");
// Call the fetchPrice function
const tx = await tokenPrice.fetchPrice("ETH");
await tx.wait();

// Verify the price was stored correctly
const storedPrice = await tokenPrice.tokenPrices("ETH");
expect(storedPrice.price).to.equal("1234");
});
});
});
})

0 comments on commit c8e2622

Please sign in to comment.