Skip to content

Commit

Permalink
docs(examples): add PostDeploy, test examples (latticexyz#725)
Browse files Browse the repository at this point in the history
* fix(examples): add PostDeploy that tests expect

* docs(examples): add test command

* ci: test examples

* docs(examples): check in example .env

* ci: rename example workflow

* docs(examples): clarify .env comment a bit more

---------

Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
  • Loading branch information
dk1a and holic authored May 2, 2023
1 parent 1386c6b commit 8d86974
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
pull_request:

jobs:
build:
name: Build examples
main:
name: Build/test examples
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -33,3 +33,7 @@ jobs:

- name: Outdated files, run `pnpm gas-report` and commit them
uses: ./.github/actions/require-empty-diff

- name: Run tests
working-directory: ./examples/${{ matrix.example }}
run: pnpm test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ yarn.lock
.docs
lerna-debug.log
.retype
.env
yarn-error.log
.turbo

Expand Down
3 changes: 2 additions & 1 deletion examples/v2-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dev:client": "pnpm --filter 'client' run dev",
"dev:contracts": "pnpm --filter 'contracts' dev",
"dev:node": "pnpm --filter 'contracts' devnode",
"initialize": "pnpm recursive run initialize"
"initialize": "pnpm recursive run initialize",
"test": "pnpm recursive run test"
},
"devDependencies": {
"run-pty": "^4.0.3"
Expand Down
8 changes: 8 additions & 0 deletions examples/v2-minimal/packages/contracts/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This .env file is for demonstration purposes only.
#
# This should usually be excluded via .gitignore and the env vars attached to
# your deployment enviroment, but we're including this here for ease of local
# development. Please do not commit changes to this file!
#
# Anvil default private key:
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
1 change: 0 additions & 1 deletion examples/v2-minimal/packages/contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ bindings/
artifacts/
abi/
broadcast/
.env

# Ignore all deploy artifacts
deploys/**/*.json
Expand Down
24 changes: 24 additions & 0 deletions examples/v2-minimal/packages/contracts/script/PostDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;

import { Script } from "forge-std/Script.sol";
import { console } from "forge-std/console.sol";
import { IWorld } from "../src/codegen/world/IWorld.sol";

contract PostDeploy is Script {
function run(address worldAddress) external {
// Load the private key from the `PRIVATE_KEY` environment variable (in .env)
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");

// Start broadcasting transactions from the deployer account
vm.startBroadcast(deployerPrivateKey);

// ------------------ EXAMPLES ------------------

// Call increment on the world via the registered function selector
uint32 newValue = IWorld(worldAddress).increment();
console.log("Increment via IWorld:", newValue);

vm.stopBroadcast();
}
}

0 comments on commit 8d86974

Please sign in to comment.