Test Environmnet

You have two testing environments: testnet and an instance of the blockchain running locally (a solo node).

Testing your app on testnet is more straightforward since all contracts are already deployed by us and you can use our testnet dApp to add apps, interact with smart contracts, and manage reward distribution.

Testing on solo will be a bit more complicated because you will need to deploy some mocked VeBetterDAO contracts by yourself, but we tried to make that easy as well.

Testnet

Use our testnet environment, running on vechain testnet network, to create apps, interact with smart contracts, and manage reward distribution.

  • Add an app

  • Now you will need to get some B3TR tokens: claim them from the Faucet

  • Deposit the B3TR tokens to your app balance so you can distribute them: go to your managed app page, and click "Deposit" in the app balance section

  • To allow your contract to distribute the rewards you need to click the cogs icon to enter the Settings section of your app and add the address of your contract (that will call the distributeReward function) as a "Reward Distributor".

That's it, you are all set and can distribute rewards through your backend or smart contract.

If you need to simulate allocation rounds, go to the Admin section and press the "Start round" button. In testnet rounds last 10 minutes, but apart from this everything else is the same as mainnet.

Testnet contracts addresses:

"B3TR": "0xbf64cf86894Ee0877C4e7d03936e35Ee8D8b864F",
"B3TRGovernor": "0xDF5E114D391CAC840529802fe8D01f6bdeBE41eC",
"Emissions": "0x148d21032F4a7b4aeF236E2E9C0c5bF62d10f8EB",
"GalaxyMember": "0xCf73039913e05aa1838d5869E72290d2b454C1E8",
"TimeLock": "0x30ee94F303643902a68aD8A7A6456cA69d763192",
"Treasury": "0x039893EBe092A2D22B08E2b029735D211bfF7F50",
"VOT3": "0xa704c45971995467696EE9544Da77DD42Bc9706E",
"VoterRewards": "0x2E47fc4aabB3403037fB5E1f38995E7a91Ce8Ed2",
"X2EarnApps": "0xcB23Eb1bBD5c07553795b9538b1061D0f4ABA153",
"X2EarnRewardsPool": "0x5F8f86B8D0Fa93cdaE20936d150175dF0205fB38",
"XAllocationPool": "0x9B9CA9D0C41Add1d204f90BA0E9a6844f1843A84",
"XAllocationVoting": "0x5859ff910d8b0c127364c98E24233b0af7443c1c",
"B3TRFaucet": "0x5e9c1F0f52aC6b5004122059053b00017EAfB561"

Solo node

Testing on the solo node is a bit more complicated than testing on testnet, since you will need to deploy the VeBetterDAO contracts locally and interact with them to create your app, obtain the APP_ID, start an allocation round, vote, start round again, and add the reward distributor.

We recommend following the testnet path, but if you need to do it on the solo network you will need to mock a few VeBetterDAO contracts:

  • B3TR token mock: you need a fake token to distribute

  • X2EarnApps mock: you need a contract where to add your app, generate an APP_ID and add a reward distributor

  • X2EarnRewardsPool mock: you need a contract to distribute the rewards

While the X2EarnRewardsPoolMock contract can be the exact same contract deployed on mainnet and testnet, the other two can be customized in order to have only the essential logic needed for running tests.

You can take a look at the mocked contracts in the X-App-Template repository, under the contracts/mocks folder.

After you added the mock contracts to your repository you should adjust the deploy script in a way that you will deploy and configure the mocked contracts only if you are deploying to the vechain_solo network.

Your script should look something like this:

import { ethers, network } from "hardhat";
import { Challenges, Cleanify, RolesManager } from "../../typechain-types";
import { networkConfig } from "@repo/config";
import { deployProxy } from "../helpers/upgrades";
import { faker } from "@faker-js/faker";

let REWARD_TOKEN_ADDRESS = "0xE5FEfcB230364ef7f9B5B0df6DA81B227726612b"; // mainnet address

export async function deploy(): Promise<{
    mySustainableContractAddress: string;
}> {
    console.log(
        `Deploying on ${network.name} (${networkConfig.network.defaultNodeUrl})...`
    );

    console.log(`Deploying my app contract...`);
    const MySustainableContract = await ethers.getContractFactory("MySustainableContract");
    const mySustainableContract = await MySustainableContract.deploy();
    await mySustainableContract.waitForDeployment();
    console.log(`Sustainable Contract deployed to ${await mySustainableContract.getAddress()}`);

    if (network.name === "vechain_solo") {
        console.log(`Deploying mock RewardToken...`);
        const RewardToken = await ethers.getContractFactory("B3TR_Mock");
        const rewardToken = await RewardToken.deploy();
        await rewardToken.waitForDeployment();
        REWARD_TOKEN_ADDRESS = await rewardToken.getAddress();
        console.log(`RewardToken deployed to ${REWARD_TOKEN_ADDRESS}`);

        console.log("Deploying X2EarnApps mock contract...");
        const X2EarnApps = await ethers.getContractFactory("X2EarnAppsMock");
        const x2EarnApps = await X2EarnApps.deploy();
        await x2EarnApps.waitForDeployment();
        console.log(`X2EarnApps deployed to ${await x2EarnApps.getAddress()}`);

        console.log("Deploying X2EarnRewardsPool mock contract...");
        const X2EarnRewardsPool = await ethers.getContractFactory(
            "X2EarnRewardsPoolMock"
        );
        const x2EarnRewardsPool = await X2EarnRewardsPool.deploy(
            deployer.address,
            REWARD_TOKEN_ADDRESS,
            await x2EarnApps.getAddress()
        );
        await x2EarnRewardsPool.waitForDeployment();
        console.log(
            `X2EarnRewardsPool deployed to ${await x2EarnRewardsPool.getAddress()}`
        );

        console.log("Adding app in X2EarnApps...");
        await x2EarnApps.addApp(deployer.address, deployer.address, "MySustainableApp");
        const appID = await x2EarnApps.hashAppName("MySustainableApp");

        console.log(`Funding contract...`);
        await rewardToken.approve(
            await x2EarnRewardsPool.getAddress(),
            ethers.parseEther("10000")
        );
        await x2EarnRewardsPool.deposit(ethers.parseEther("2000"), appID);
        console.log("Funded");

        console.log("Add MySustainableContract as distributor...");
        await x2EarnApps.addRewardDistributor(
            appID,
            await mySustainableContract.getAddress()
        );
        console.log("Added");

        console.log(
            "Set APP_ID and X2EarnRewardsPool address in Challenges contract..."
        );
        await mySustainableContract.setVBDAppId(appID);
        await mySustainableContract.setX2EarnRewardsPool(
            await x2EarnRewardsPool.getAddress()
        );
        console.log("Set");
    }
    
    return {
        mySustainableContract: await mySustainableContract.getAddress()
    };
}

That's it, you can now deploy your contracts locally/run tests where you simulate the VeBetterDAO contracts, your app added to the ecosystem, and tokens distribution.

Last updated