Testing Your World Extension

Since the Primodium core contracts are not open source yet (coming soon!), 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:

  1. Copy /examples/building-upgrade-bounty/packages/contracts/.env.example and paste it in the same directory, while renaming it to .env.
  2. Change the PRIMODIUM_RPC_URL to the appropriate URL. Our current testnet is https://primodium-sepolia.rpc.caldera.xyz/http
  3. Change the WORLD_ADDRESS to the appropriate contract address. Our current Primodium world address is available on the latest release page.
  4. Change the BLOCK_NUMBER to the your desired block. The current Primodium world was deployed at block number 3007935, 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.
  5. If you haven't already, make a new test file in the test folder, like packages/contracts/test/[YOUR_TEST_FILE_NAME].t.sol
  6. As seen in /examples/building-upgrade-bounty/packages/contracts/test/UpgradeBountyExtension.t.sol, use vm.createSelectFork(vm.envString("PRIMODIUM_RPC_URL"), vm.envUint("BLOCK_NUMBER")); to fork the chain and run Foundry tests against it.
  7. In your test file, make sure to at minimum import the following files. See /examples/building-upgrade-bounty/packages/contracts/test/UpgradeBountyExtension.t.sol for more useful imports.
import "forge-std/Test.sol";
import { MudTest } from "@latticexyz/world/test/MudTest.t.sol";
  1. In order to run the tests, make sure you have navigated your terminal to examples/building-upgrade-bounty/packages/contracts and then run forge test.

Refer to the Foundry book (opens in a new tab) to learn more about building tests.