Testing Your World Extension
Since the Primodium core contracts are not open source yet, the best way to test your world extension is to fork the Primodium live testnet using Foundry (opens in a new tab).
Building Upgrade Bounty Example
We will use
Foundry (opens in a new tab)'s
vm.createSelectFork() test function to test that the extension will deploy
correctly. Here are the suggested steps to complete building a test by forking
the live Primodium testnet:
- Copy
/examples/BuildingUpgradeBounty/packages/contracts/.env.exampleand paste it in the same directory, while renaming it to.env. - Change the
PRIMODIUM_RPC_URLto the appropriate URL. Our current testnet ishttps://primodium-sepolia.rpc.caldera.xyz/http - Change the
WORLD_ADDRESSto the appropriate contract address. Our current Primodium world address is available on the latest release page. - Change the
BLOCK_NUMBERto the your desired block. The current Primodium world was deployed at block number3007935, however you may want to use the most recent block given that we may be updating the chain and it will represent the most recent state of the world. - If you haven't already, make a new test file in the test folder, like
packages/contracts/test/[YOUR_TEST_FILE_NAME].t.sol - As seen in
/examples/BuildingUpgradeBounty/packages/contracts/test/UpgradeBountyExtension.t.sol, usevm.createSelectFork(vm.envString("PRIMODIUM_RPC_URL"), vm.envUint("BLOCK_NUMBER"));to fork the chain and run Foundry tests against it. - In your test file, make sure to at minimum import the following files. See
/examples/BuildingUpgradeBounty/packages/contracts/test/UpgradeBountyExtension.t.solfor more useful imports.
import "forge-std/Test.sol";
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";- In order to run the tests, make sure you have navigated your terminal to
examples/BuildingUpgradeBounty/packages/contractsand then runforge test.
Refer to the Foundry book (opens in a new tab) to learn more about building tests.