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.example
and paste it in the same directory, while renaming it to.env
. - Change the
PRIMODIUM_RPC_URL
to the appropriate URL. Our current testnet ishttps://primodium-sepolia.rpc.caldera.xyz/http
- Change the
WORLD_ADDRESS
to the appropriate contract address. Our current Primodium world address is available on the latest release page. - Change the
BLOCK_NUMBER
to 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.sol
for 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/contracts
and then runforge test
.
Refer to the Foundry book (opens in a new tab) to learn more about building tests.