Files
CurrenciCombo/contracts/test/ComboHandler.test.ts

152 lines
4.6 KiB
TypeScript

import { expect } from "chai";
import { ethers } from "hardhat";
import type { ComboHandler, AdapterRegistry, NotaryRegistry } from "../typechain-types";
describe("ComboHandler", function () {
let handler: ComboHandler;
let adapterRegistry: AdapterRegistry;
let notaryRegistry: NotaryRegistry;
beforeEach(async function () {
// Deploy AdapterRegistry
const AdapterRegistryFactory = await ethers.getContractFactory("AdapterRegistry");
adapterRegistry = await AdapterRegistryFactory.deploy();
await adapterRegistry.deployed();
// Deploy NotaryRegistry
const NotaryRegistryFactory = await ethers.getContractFactory("NotaryRegistry");
notaryRegistry = await NotaryRegistryFactory.deploy();
await notaryRegistry.deployed();
// Deploy ComboHandler
const HandlerFactory = await ethers.getContractFactory("ComboHandler");
handler = await HandlerFactory.deploy(adapterRegistry.address, notaryRegistry.address);
await handler.deployed();
});
it("Should register plan when executing", async function () {
const planId = ethers.utils.id("test-plan");
const steps: any[] = [];
const signature = "0x";
// This would require a whitelisted adapter
// For now, test that plan registration happens
await expect(
handler.executeCombo(planId, steps, signature)
).to.be.revertedWith("Adapter not whitelisted");
});
it("Should prepare and commit plan (2PC)", async function () {
const planId = ethers.utils.id("test-plan");
const steps: any[] = [];
// Prepare
await expect(handler.prepare(planId, steps))
.to.emit(handler, "PlanPrepared")
.withArgs(planId);
// Commit
await expect(handler.commit(planId))
.to.emit(handler, "PlanCommitted")
.withArgs(planId);
});
it("Should abort prepared plan", async function () {
const planId = ethers.utils.id("test-plan");
const steps: any[] = [];
// Prepare
await handler.prepare(planId, steps);
// Abort
await expect(handler.abort(planId))
.to.emit(handler, "PlanAborted")
.withArgs(planId);
});
it("Should return execution status", async function () {
const planId = ethers.utils.id("test-plan");
const status = await handler.getExecutionStatus(planId);
expect(status).to.equal(0); // PENDING
});
});
describe("AdapterRegistry", function () {
let registry: AdapterRegistry;
beforeEach(async function () {
const Factory = await ethers.getContractFactory("AdapterRegistry");
registry = await Factory.deploy();
await registry.deployed();
});
it("Should register adapter", async function () {
const [owner] = await ethers.getSigners();
const adapterAddress = ethers.Wallet.createRandom().address;
await expect(
registry.registerAdapter(adapterAddress, "Test Adapter", 0) // DEFI
)
.to.emit(registry, "AdapterRegistered")
.withArgs(adapterAddress, "Test Adapter", 0);
});
it("Should whitelist adapter", async function () {
const [owner] = await ethers.getSigners();
const adapterAddress = ethers.Wallet.createRandom().address;
await registry.registerAdapter(adapterAddress, "Test Adapter", 0);
await registry.setWhitelist(adapterAddress, true);
expect(await registry.isWhitelisted(adapterAddress)).to.be.true;
});
it("Should blacklist adapter", async function () {
const [owner] = await ethers.getSigners();
const adapterAddress = ethers.Wallet.createRandom().address;
await registry.registerAdapter(adapterAddress, "Test Adapter", 0);
await registry.setWhitelist(adapterAddress, true);
await registry.setBlacklist(adapterAddress, true);
expect(await registry.isWhitelisted(adapterAddress)).to.be.false;
});
});
describe("NotaryRegistry", function () {
let registry: NotaryRegistry;
beforeEach(async function () {
const Factory = await ethers.getContractFactory("NotaryRegistry");
registry = await Factory.deploy();
await registry.deployed();
});
it("Should register plan", async function () {
const planId = ethers.utils.id("test-plan");
const steps: any[] = [];
const [creator] = await ethers.getSigners();
await expect(
registry.registerPlan(planId, steps, creator.address)
)
.to.emit(registry, "PlanRegistered");
});
it("Should finalize plan", async function () {
const planId = ethers.utils.id("test-plan");
const steps: any[] = [];
const [creator] = await ethers.getSigners();
await registry.registerPlan(planId, steps, creator.address);
await expect(
registry.finalizePlan(planId, true)
)
.to.emit(registry, "PlanFinalized")
.withArgs(planId, true, ethers.utils.id(""));
});
});