ci: clean up CI workflows and fix package dependencies
Some checks failed
Integration Tests / test-service-integration (push) Successful in 2m16s
Package Tests / Python package - aitbc-agent-sdk (push) Successful in 25s
Package Tests / Python package - aitbc-core (push) Successful in 22s
Package Tests / Python package - aitbc-crypto (push) Successful in 14s
Package Tests / Python package - aitbc-sdk (push) Successful in 18s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 6s
Package Tests / JavaScript package - aitbc-token (push) Successful in 21s
Production Tests / Production Integration Tests (push) Failing after 10s
Python Tests / test-python (push) Failing after 2m41s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 16s
Smart Contract Tests / lint-solidity (push) Successful in 12s
Some checks failed
Integration Tests / test-service-integration (push) Successful in 2m16s
Package Tests / Python package - aitbc-agent-sdk (push) Successful in 25s
Package Tests / Python package - aitbc-core (push) Successful in 22s
Package Tests / Python package - aitbc-crypto (push) Successful in 14s
Package Tests / Python package - aitbc-sdk (push) Successful in 18s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 6s
Package Tests / JavaScript package - aitbc-token (push) Successful in 21s
Production Tests / Production Integration Tests (push) Failing after 10s
Python Tests / test-python (push) Failing after 2m41s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 16s
Smart Contract Tests / lint-solidity (push) Successful in 12s
- Simplified npm install commands in CI workflows by removing fallback logic - Added aitbc-crypto local dependency installation for aitbc-sdk in package-tests.yml - Removed aitbc-token specific Hardhat dependency workarounds from package-tests.yml - Fixed bare except clause in agent_daemon.py to catch specific json.JSONDecodeError - Moved aitbc-crypto from poetry.dependencies to standard dependencies in aitbc-sdk - Fixed MyPy type errors in receip
This commit is contained in:
@@ -1,10 +1,69 @@
|
||||
import { expect } from "chai";
|
||||
import { ethers } from "hardhat";
|
||||
import { loadFixture } from "@nomicfoundation/hardhat-toolbox/network-helpers";
|
||||
import type { HardhatEthers } from "@nomicfoundation/hardhat-ethers/types";
|
||||
import type { NetworkHelpers } from "@nomicfoundation/hardhat-network-helpers/types";
|
||||
import type { BaseContract, ContractTransactionResponse } from "ethers";
|
||||
import { network } from "hardhat";
|
||||
import type { NetworkConnection } from "hardhat/types/network";
|
||||
import { AITokenRegistry__factory } from "../typechain-types";
|
||||
|
||||
type HardhatConnection = NetworkConnection & {
|
||||
ethers: HardhatEthers;
|
||||
networkHelpers: NetworkHelpers;
|
||||
};
|
||||
|
||||
const { ethers, networkHelpers } =
|
||||
(await network.connect()) as HardhatConnection;
|
||||
|
||||
async function expectRevert(
|
||||
operation: Promise<unknown>,
|
||||
expectedMessage?: string,
|
||||
) {
|
||||
let caughtError: unknown;
|
||||
|
||||
try {
|
||||
await operation;
|
||||
} catch (error) {
|
||||
caughtError = error;
|
||||
}
|
||||
|
||||
expect(caughtError).to.not.equal(undefined);
|
||||
|
||||
if (expectedMessage !== undefined) {
|
||||
const message =
|
||||
caughtError instanceof Error ? caughtError.message : String(caughtError);
|
||||
expect(message).to.contain(expectedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
async function expectEvent(
|
||||
contract: BaseContract,
|
||||
operation: Promise<ContractTransactionResponse>,
|
||||
eventName: string,
|
||||
expectedArgs: readonly unknown[],
|
||||
) {
|
||||
const tx = await operation;
|
||||
const receipt = await tx.wait();
|
||||
|
||||
expect(receipt).to.not.equal(null);
|
||||
|
||||
const parsedLog = receipt!.logs
|
||||
.map((log) => {
|
||||
try {
|
||||
return contract.interface.parseLog(log);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.find((entry) => entry?.name === eventName);
|
||||
|
||||
expect(parsedLog).to.not.equal(undefined);
|
||||
expect(parsedLog).to.not.equal(null);
|
||||
expect(Array.from(parsedLog!.args)).to.deep.equal([...expectedArgs]);
|
||||
}
|
||||
|
||||
async function deployRegistryFixture() {
|
||||
const [admin, coordinator, provider1, provider2, outsider] = await ethers.getSigners();
|
||||
const [admin, coordinator, provider1, provider2, outsider] =
|
||||
await ethers.getSigners();
|
||||
|
||||
const factory = new AITokenRegistry__factory(admin);
|
||||
const registry = await factory.deploy(admin.address);
|
||||
@@ -19,15 +78,19 @@ async function deployRegistryFixture() {
|
||||
describe("AITokenRegistry", function () {
|
||||
describe("Provider Registration", function () {
|
||||
it("allows coordinator to register a provider", async function () {
|
||||
const { registry, coordinator, provider1 } = await loadFixture(deployRegistryFixture);
|
||||
const { registry, coordinator, provider1 } =
|
||||
await networkHelpers.loadFixture(deployRegistryFixture);
|
||||
|
||||
const collateral = ethers.parseEther("100");
|
||||
|
||||
await expect(
|
||||
registry.connect(coordinator).registerProvider(provider1.address, collateral)
|
||||
)
|
||||
.to.emit(registry, "ProviderRegistered")
|
||||
.withArgs(provider1.address, collateral);
|
||||
await expectEvent(
|
||||
registry,
|
||||
registry
|
||||
.connect(coordinator)
|
||||
.registerProvider(provider1.address, collateral),
|
||||
"ProviderRegistered",
|
||||
[provider1.address, collateral],
|
||||
);
|
||||
|
||||
const info = await registry.providerInfo(provider1.address);
|
||||
expect(info.active).to.equal(true);
|
||||
@@ -35,43 +98,57 @@ describe("AITokenRegistry", function () {
|
||||
});
|
||||
|
||||
it("rejects registration of zero address", async function () {
|
||||
const { registry, coordinator } = await loadFixture(deployRegistryFixture);
|
||||
const { registry, coordinator } = await networkHelpers.loadFixture(
|
||||
deployRegistryFixture,
|
||||
);
|
||||
|
||||
await expect(
|
||||
registry.connect(coordinator).registerProvider(ethers.ZeroAddress, 0)
|
||||
).to.be.revertedWith("invalid provider");
|
||||
await expectRevert(
|
||||
registry.connect(coordinator).registerProvider(ethers.ZeroAddress, 0),
|
||||
"invalid provider",
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects duplicate registration", async function () {
|
||||
const { registry, coordinator, provider1 } = await loadFixture(deployRegistryFixture);
|
||||
const { registry, coordinator, provider1 } =
|
||||
await networkHelpers.loadFixture(deployRegistryFixture);
|
||||
|
||||
await registry.connect(coordinator).registerProvider(provider1.address, 100);
|
||||
await registry
|
||||
.connect(coordinator)
|
||||
.registerProvider(provider1.address, 100);
|
||||
|
||||
await expect(
|
||||
registry.connect(coordinator).registerProvider(provider1.address, 200)
|
||||
).to.be.revertedWith("already registered");
|
||||
await expectRevert(
|
||||
registry.connect(coordinator).registerProvider(provider1.address, 200),
|
||||
"already registered",
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects registration from non-coordinator", async function () {
|
||||
const { registry, provider1, outsider } = await loadFixture(deployRegistryFixture);
|
||||
const { registry, provider1, outsider } =
|
||||
await networkHelpers.loadFixture(deployRegistryFixture);
|
||||
|
||||
await expect(
|
||||
registry.connect(outsider).registerProvider(provider1.address, 100)
|
||||
).to.be.reverted;
|
||||
await expectRevert(
|
||||
registry.connect(outsider).registerProvider(provider1.address, 100),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Provider Updates", function () {
|
||||
it("allows coordinator to update provider status", async function () {
|
||||
const { registry, coordinator, provider1 } = await loadFixture(deployRegistryFixture);
|
||||
const { registry, coordinator, provider1 } =
|
||||
await networkHelpers.loadFixture(deployRegistryFixture);
|
||||
|
||||
await registry.connect(coordinator).registerProvider(provider1.address, 100);
|
||||
await registry
|
||||
.connect(coordinator)
|
||||
.registerProvider(provider1.address, 100);
|
||||
|
||||
await expect(
|
||||
registry.connect(coordinator).updateProvider(provider1.address, false, 50)
|
||||
)
|
||||
.to.emit(registry, "ProviderUpdated")
|
||||
.withArgs(provider1.address, false, 50);
|
||||
await expectEvent(
|
||||
registry,
|
||||
registry
|
||||
.connect(coordinator)
|
||||
.updateProvider(provider1.address, false, 50),
|
||||
"ProviderUpdated",
|
||||
[provider1.address, false, 50n],
|
||||
);
|
||||
|
||||
const info = await registry.providerInfo(provider1.address);
|
||||
expect(info.active).to.equal(false);
|
||||
@@ -79,11 +156,18 @@ describe("AITokenRegistry", function () {
|
||||
});
|
||||
|
||||
it("allows reactivating a deactivated provider", async function () {
|
||||
const { registry, coordinator, provider1 } = await loadFixture(deployRegistryFixture);
|
||||
const { registry, coordinator, provider1 } =
|
||||
await networkHelpers.loadFixture(deployRegistryFixture);
|
||||
|
||||
await registry.connect(coordinator).registerProvider(provider1.address, 100);
|
||||
await registry.connect(coordinator).updateProvider(provider1.address, false, 100);
|
||||
await registry.connect(coordinator).updateProvider(provider1.address, true, 200);
|
||||
await registry
|
||||
.connect(coordinator)
|
||||
.registerProvider(provider1.address, 100);
|
||||
await registry
|
||||
.connect(coordinator)
|
||||
.updateProvider(provider1.address, false, 100);
|
||||
await registry
|
||||
.connect(coordinator)
|
||||
.updateProvider(provider1.address, true, 200);
|
||||
|
||||
const info = await registry.providerInfo(provider1.address);
|
||||
expect(info.active).to.equal(true);
|
||||
@@ -91,32 +175,45 @@ describe("AITokenRegistry", function () {
|
||||
});
|
||||
|
||||
it("rejects update of unregistered provider", async function () {
|
||||
const { registry, coordinator, provider1 } = await loadFixture(deployRegistryFixture);
|
||||
const { registry, coordinator, provider1 } =
|
||||
await networkHelpers.loadFixture(deployRegistryFixture);
|
||||
|
||||
await expect(
|
||||
registry.connect(coordinator).updateProvider(provider1.address, false, 100)
|
||||
).to.be.revertedWith("provider not registered");
|
||||
await expectRevert(
|
||||
registry
|
||||
.connect(coordinator)
|
||||
.updateProvider(provider1.address, false, 100),
|
||||
"provider not registered",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Access Control", function () {
|
||||
it("admin can grant coordinator role", async function () {
|
||||
const { registry, admin, outsider } = await loadFixture(deployRegistryFixture);
|
||||
const { registry, admin, outsider } = await networkHelpers.loadFixture(
|
||||
deployRegistryFixture,
|
||||
);
|
||||
|
||||
const coordinatorRole = await registry.COORDINATOR_ROLE();
|
||||
await registry.connect(admin).grantRole(coordinatorRole, outsider.address);
|
||||
await registry
|
||||
.connect(admin)
|
||||
.grantRole(coordinatorRole, outsider.address);
|
||||
|
||||
expect(await registry.hasRole(coordinatorRole, outsider.address)).to.equal(true);
|
||||
expect(
|
||||
await registry.hasRole(coordinatorRole, outsider.address),
|
||||
).to.equal(true);
|
||||
});
|
||||
|
||||
it("non-admin cannot grant roles", async function () {
|
||||
const { registry, coordinator, outsider } = await loadFixture(deployRegistryFixture);
|
||||
const { registry, coordinator, outsider } =
|
||||
await networkHelpers.loadFixture(deployRegistryFixture);
|
||||
|
||||
const coordinatorRole = await registry.COORDINATOR_ROLE();
|
||||
|
||||
await expect(
|
||||
registry.connect(coordinator).grantRole(coordinatorRole, outsider.address)
|
||||
).to.be.reverted;
|
||||
await expectRevert(
|
||||
registry
|
||||
.connect(coordinator)
|
||||
.grantRole(coordinatorRole, outsider.address),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user