Test & Deploy a Smart Contract

Testing smart contracts is crucial to ensure they function correctly and securely. Follow these steps to test your smart contracts on the Cyan BasedAI Testnet.

Interacting with the Contract

  • Add the Contract to MetaMask: After deploying the contract, add its address to MetaMask to interact with it.

  • Verify Token Balance: Check the balance of your token in MetaMask.

  • Perform Transactions: Use MetaMask to perform transactions, such as transferring tokens or calling contract functions.

Testing with Remix

  • Deploy the Contract: Use Remix to deploy your contract to the BasedAI Testnet.

  • Execute Functions: Test the core functionalities (e.g., issueToken, deployAgent, addLiquidity, accessService) directly in Remix.

  • Check State Changes: Verify the contract's state changes and event emissions to ensure expected behavior.

Automated Testing

Automated testing provides a robust approach for verifying your contracts. Set up your environment with Truffle or Hardhat for automated testing.

Example Test Script with Hardhat:

const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("AchievementToken", function () {
    it("Should deploy and issue tokens correctly", async function () {
        const [owner, addr1] = await ethers.getSigners();
        const AchievementToken = await ethers.getContractFactory("AchievementToken");
        const token = await AchievementToken.deploy();
        await token.deployed();

        await token.issueToken(addr1.address, 100, "Test Achievement");
        expect(await token.balanceOf(addr1.address)).to.equal(100);
    });
});

By following these guidelines, you can ensure that your smart contracts are robust and ready for deployment on the BasedAI Testnet.

Last updated