-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:moonbeam-foundation/moonbeam-docs…
… into eshaben/2900-polkadot-sdk-v1.7.2
- Loading branch information
Showing
279 changed files
with
3,123 additions
and
2,270 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
.snippets/code/builders/build/eth-api/dev-env/foundry/ERC20.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
// Import OpenZeppelin Contract | ||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
// This ERC-20 contract mints the specified amount of tokens to the contract creator | ||
contract MyToken is ERC20 { | ||
constructor(uint256 initialSupply) ERC20("MyToken", "MYTOK") { | ||
_mint(msg.sender, initialSupply); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.snippets/code/builders/build/eth-api/dev-env/foundry/terminal/query-balance.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions
24
.snippets/code/builders/get-started/networks/moonbeam-dev/terminal/docker-pull.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
<div id="termynal" data-termynal> | ||
<span data-ty="input"><span class="file-path"></span>docker pull moonbeamfoundation/moonbeam:v0.36.0</span> | ||
<span data-ty="input"><span class="file-path"></span>docker pull moonbeamfoundation/moonbeam:v0.37.2</span> | ||
<br> | ||
<span data-ty>v0.36.0: Pulling from moonbeamfoundation/moonbeam | ||
<br> e1caac4eb9d2: Pull complete | ||
<br> 303f0b059437: Pull complete | ||
<br> 1987eeb667a4: Pull complete | ||
<br> c2b8e919bd5a: Pull complete | ||
<br> c6a7952896a0: Pull complete | ||
<br> 3ad97e77096a: Pull complete | ||
<br> a5e5655dbb4f: Pull complete | ||
<br> Digest: sha256:099e885c4601c8f7ba4408492f2df142920a794baf019cf71cf3a3a16810f504 | ||
<br> Status: Downloaded newer image for moonbeamfoundation/moonbeam:v0.36.0 | ||
<br> docker.io/moonbeamfoundation/moonbeam:v0.36.0 | ||
<span data-ty>v0.37.2: Pulling from moonbeamfoundation/moonbeam | ||
<br> b0a0cf830b12: Pull complete | ||
<br> fbff687640dd: Pull complete | ||
<br> 58ea427410e2: Pull complete | ||
<br> 811ba55e6e61: Pull complete | ||
<br> 4316d5f1b914: Pull complete | ||
<br> 128693ce218e: Pull complete | ||
<br> a3ac90b88463: Pull complete | ||
<br> Digest: sha256:1def3370159ee7d14fce3951a1198bda7c51af566e0b3d69ce4644338e29f046 | ||
<br> Status: Downloaded newer image for moonbeamfoundation/moonbeam:v0.37.2 | ||
<br> docker.io/moonbeamfoundation/moonbeam:v0.37.2 | ||
</span> | ||
</div> |
60 changes: 30 additions & 30 deletions
60
.snippets/code/builders/get-started/networks/moonbeam-dev/terminal/docker-run.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
<div id="termynal" data-termynal> | ||
<span data-ty="input"><span class="file-path"></span>docker run --rm --name moonbeam_development --network host \ | ||
<br> moonbeamfoundation/moonbeam:v0.36.0 \ | ||
<br> moonbeamfoundation/moonbeam:v0.37.2 \ | ||
<br> --dev --rpc-external | ||
</span> | ||
<br> | ||
<span data-ty>CLI parameter `--execution` has no effect anymore and will be removed in the future! | ||
<br> 2024-02-27 06:09:29 Moonbeam Parachain Collator | ||
<br> 2024-02-27 06:09:29 ✌️ 0.36.0-d1087f30917 | ||
<br> 2024-02-27 06:09:29 ❤️ by PureStake, 2019-2024 | ||
<br> 2024-02-27 06:09:29 📋 Chain specification: Moonbase Development Testnet | ||
<br> 2024-02-27 06:09:29 🏷 Node name: black-and-white-sticks-9174 | ||
<br> 2024-02-27 06:09:29 👤 Role: AUTHORITY | ||
<br> 2024-02-27 06:09:29 💾 Database: RocksDb at /tmp/substrateO3YeRz/chains/moonbase_dev/db/full | ||
<br> 2024-02-27 06:09:40 🔨 Initializing Genesis block/state (state: 0x7c34…99c5, header-hash: 0xa083…f354) | ||
<br> 2024-02-27 06:09:40 Using default protocol ID "sup" because none is configured in the chain specs | ||
<br> 2024-02-27 06:09:40 🏷 Local node identity is: 12D3KooWLcpczme2JeBEfLqmjqkzYVKTGKhhGmwSzHjRXGBVhDX7 | ||
<br> 2024-02-27 06:09:40 💻 Operating system: linux | ||
<br> 2024-02-27 06:09:40 💻 CPU architecture: x86_64 | ||
<br> 2024-02-27 06:09:40 💻 Target environment: gnu | ||
<br> 2024-02-27 06:09:40 💻 CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz | ||
<br> 2024-02-27 06:09:40 💻 CPU cores: 12 | ||
<br> 2024-02-27 06:09:40 💻 Memory: 7946MB | ||
<br> 2024-02-27 06:09:40 💻 Kernel: 6.4.16-linuxkit | ||
<br> 2024-02-27 06:09:40 💻 Linux distribution: Debian GNU/Linux 12 (bookworm) | ||
<br> 2024-02-27 06:09:40 💻 Virtual machine: yes | ||
<br> 2024-02-27 06:09:40 📦 Highest known block at #0 | ||
<br> 2024-02-27 06:09:40 Running JSON-RPC server: addr=0.0.0.0:9944, allowed origins=["*"] | ||
<br> 2024-02-27 06:09:40 🏁 CPU score: 1.14 GiBs | ||
<br> 2024-02-27 06:09:40 〽️ Prometheus exporter started at 127.0.0.1:9615 | ||
<br> 2024-02-27 06:09:40 🏁 Memory score: 10.41 GiBs | ||
<br> 2024-02-27 06:09:40 🏁 Disk score (seq. writes): 987.96 MiBs | ||
<br> 2024-02-27 06:09:40 🏁 Disk score (rand. writes): 363.65 MiBs | ||
<br> 2024-02-27 06:09:40 Development Service Ready | ||
<br> 2024-02-27 06:09:45 💤 Idle (0 peers), best: #0 (0xa083…f354), finalized #0 (0xa083…f354), ⬇ 0 ⬆ 0 | ||
<br> 2024-02-27 06:09:50 💤 Idle (0 peers), best: #0 (0xa083…f354), finalized #0 (0xa083…f354), ⬇ 0 ⬆ 0 | ||
<br> 2024-04-29 06:09:29 Moonbeam Parachain Collator | ||
<br> 2024-04-29 06:09:29 ✌️ 0.37.2-be5032c7749 | ||
<br> 2024-04-29 06:09:29 ❤️ by PureStake, 2019-2024 | ||
<br> 2024-04-29 06:09:29 📋 Chain specification: Moonbase Development Testnet | ||
<br> 2024-04-29 06:09:29 🏷 Node name: black-and-white-sticks-9174 | ||
<br> 2024-04-29 06:09:29 👤 Role: AUTHORITY | ||
<br> 2024-04-29 06:09:29 💾 Database: RocksDb at /tmp/substrateO3YeRz/chains/moonbase_dev/db/full | ||
<br> 2024-04-29 06:09:40 🔨 Initializing Genesis block/state (state: 0xf7c4…5c0f, header-hash: 0x42bd…3b5b) | ||
<br> 2024-04-29 06:09:40 Using default protocol ID "sup" because none is configured in the chain specs | ||
<br> 2024-04-29 06:09:40 🏷 Local node identity is: 12D3KooWLcpczme2JeBEfLqmjqkzYVKTGKhhGmwSzHjRXGBVhDX7 | ||
<br> 2024-04-29 06:09:40 💻 Operating system: linux | ||
<br> 2024-04-29 06:09:40 💻 CPU architecture: x86_64 | ||
<br> 2024-04-29 06:09:40 💻 Target environment: gnu | ||
<br> 2024-04-29 06:09:40 💻 CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz | ||
<br> 2024-04-29 06:09:40 💻 CPU cores: 12 | ||
<br> 2024-04-29 06:09:40 💻 Memory: 7946MB | ||
<br> 2024-04-29 06:09:40 💻 Kernel: 6.4.16-linuxkit | ||
<br> 2024-04-29 06:09:40 💻 Linux distribution: Debian GNU/Linux 12 (bookworm) | ||
<br> 2024-04-29 06:09:40 💻 Virtual machine: yes | ||
<br> 2024-04-29 06:09:40 📦 Highest known block at #0 | ||
<br> 2024-04-29 06:09:40 Running JSON-RPC server: addr=0.0.0.0:9944, allowed origins=["*"] | ||
<br> 2024-04-29 06:09:40 🏁 CPU score: 1.14 GiBs | ||
<br> 2024-04-29 06:09:40 〽️ Prometheus exporter started at 127.0.0.1:9615 | ||
<br> 2024-04-29 06:09:40 🏁 Memory score: 10.41 GiBs | ||
<br> 2024-04-29 06:09:40 🏁 Disk score (seq. writes): 987.96 MiBs | ||
<br> 2024-04-29 06:09:40 🏁 Disk score (rand. writes): 363.65 MiBs | ||
<br> 2024-04-29 06:09:40 Development Service Ready | ||
<br> 2024-04-29 06:09:45 💤 Idle (0 peers), best: #0 (0xa083…f354), finalized #0 (0xa083…f354), ⬇ 0 ⬆ 0 | ||
<br> 2024-04-29 06:09:50 💤 Idle (0 peers), best: #0 (0xa083…f354), finalized #0 (0xa083…f354), ⬇ 0 ⬆ 0 | ||
</span> | ||
</div> |
32 changes: 32 additions & 0 deletions
32
.snippets/code/builders/get-started/networks/moonbeam-dev/terminal/sidecar.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<div id="termynal" data-termynal> | ||
<span data-ty="input"><span class="file-path"></span>node_modules/.bin/substrate-api-sidecar</span> | ||
<br> | ||
<span data-ty>v0.37.2: Pulling from moonbeamfoundation/moonbeam | ||
<br>SAS: | ||
<br>📦 LOG: | ||
<br> ✅ LEVEL: "info" | ||
<br> ✅ JSON: false | ||
<br> ✅ FILTER_RPC: false | ||
<br> ✅ STRIP_ANSI: false | ||
<br> ✅ WRITE: false | ||
<br> ✅ WRITE_PATH: "/Users/wuzhongzhu/Documents/Work/Foundry/temp/node_modules/@substrate/api-sidecar/build/src/logs" | ||
<br> ✅ WRITE_MAX_FILE_SIZE: 5242880 | ||
<br> ✅ WRITE_MAX_FILES: 5 | ||
<br>📦 SUBSTRATE: | ||
<br> ✅ URL: "wss://wss.api.moonbeam.network" | ||
<br> ✅ TYPES_BUNDLE: undefined | ||
<br> ✅ TYPES_CHAIN: undefined | ||
<br> ✅ TYPES_SPEC: undefined | ||
<br> ✅ TYPES: undefined | ||
<br>📦 EXPRESS: | ||
<br> ✅ BIND_HOST: "127.0.0.1" | ||
<br> ✅ PORT: 8080 | ||
<br> ✅ KEEP_ALIVE_TIMEOUT: 5000 | ||
<br>2024-05-07 11:29:54 info: Version: 18.0.0 | ||
<br>2024-05-07 11:29:55 warn: API/INIT: RPC methods not decorated: eth_getBlockReceipts, moon_isBlockFinalized, moon_isTxFinalized | ||
<br>2024-05-07 11:29:55 warn: API/INIT: moonbeam/2902: Not decorating unknown runtime apis: 0xd0399cd053adda2b/1, 0xa33d43f58731ad84/2, 0xba8173bf23b2e6f8/1 | ||
<br>2024-05-07 11:29:55 info: Connected to chain Moonbeam on the moonbeam client at wss://wss.api.moonbeam.network | ||
<br>2024-05-07 11:29:55 info: Listening on http://127.0.0.1:8080/ | ||
<br>2024-05-07 11:29:55 info: Check the root endpoint (http://127.0.0.1:8080/) to see the available endpoints for the current node | ||
</span> | ||
</div> |
25 changes: 25 additions & 0 deletions
25
.snippets/code/builders/json-rpc/debug-trace/terminal/start-up-logs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div id="termynal" data-termynal> | ||
<span data-ty="input"><span class="file-path"></span>docker run --network host \ | ||
<br>-u $(id -u ${USER}):$(id -g ${USER}) \ | ||
moonbeamfoundation/moonbeam-tracing:v0.37.2-2902-latest \ | ||
<br>--name="Moonbean-Tracing-Tutorial" \ | ||
<br>--unsafe-rpc-external \ | ||
<br>--ethapi=debug,trace,txpool \ | ||
<br>--wasm-runtime-overrides=/moonbeam/moonbase-substitutes-tracing \ | ||
<br>--runtime-cache-size 64 \ | ||
<br>--dev | ||
</span> | ||
<br> | ||
<span data-ty>CLI parameter `--execution` has no effect anymore and will be removed in the future! | ||
<br> 2024-04-29 13:52:00 Moonbeam Parachain Collator | ||
<br> 2024-04-29 13:52:00 ✌️ version 0.37.2-be5032c7749 | ||
<br> 2024-04-29 13:52:00 ❤️ by PureStake, 2019-2024 | ||
<br> 2024-04-29 13:52:00 📋 Chain specification: Moonbase Development Testnet | ||
<br> 2024-04-29 13:52:00 🏷 Node name: Moonbean-Tracing-Tutorial | ||
<br> 2024-04-29 13:52:00 👤 Role: AUTHORITY | ||
<br> 2024-04-29 13:52:00 💾 Database: RocksDb at /tmp/substrateO3YeRz/chains/moonbase_dev/db/full | ||
<br> 2024-04-29 14:52:13 Found wasm override. version=moonbase-300 (moonbase-0.tx2.au3) file=/moonbeam/moonbase-substitutes-tracing/moonbase-runtime-300-substitute-tracing.wasm | ||
<br> ... | ||
<br> 2024-04-29 14:56:34 💤 Idle (0 peers), best: #0 (0x18e6…2eb1), finalized #0 (0x18e6…2eb1), ⬇ 0 ⬆ 0 | ||
</span> | ||
</div> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions
14
.snippets/code/node-operators/networks/tracing-node/terminal/logs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div id="termynal" data-termynal> | ||
<span data-ty>asm override. version=moonbase-400 (moonbase-0.tx2.au3) file=/var/lib/alphanet-data/wasm/moo nbase-runtime-400-substitute-tracing.wasm | ||
<br>Jun 03 12:45:55 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:45:55 [🌗] Found w asm override. version-moonbase-155 (moonbase-0.tx2.au3) file=/var/lib/alphanet-data/wasm/moo | ||
nbase-runtime-155-substitute-tracing. wasm | ||
<br>Jun 03 12:45:56 vmi719182. contaboserver.net moonbase [2115]: 2022-06-03 12:45:56 [🌗] Found w asm override. version-moonbase-501 (moonbase-0.tx2.au3) file=/var/lib/alphanet-data/wasm/moo nbase-runtime-501-substitute-tracing.wasm | ||
<br>Jun 03 12:45:57 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:45:57 [🌗] Found w asm override. version-moonbase-1200 (moonbase-0.tx2.au3) file=/var/lib/alphanet-data/wasm/mo onbase-runtime-1200-substitute-tracing.wasm | ||
<br>Jun 03 12:45:58 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:45:58 [🌗] Found w asm override. version-moonbase-47 (moonbase-1.tx2.au3) file=/var/lib/alphanet-data/wasm/moon base-runtime-47-substitute-tracing.wasm | ||
<br>Jun 03 12:46:00 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:46:00 [🌗] Found w asm override. version=moonbase-1501 (moonbase-0.tx2.au3) file=/var/lib/alphanet-data/wasm/mo onbase-runtime-1501-substitute-tracing.wasm | ||
<br>Jun 03 12:46:01 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:46:01 [🌗] Found w asm override. version-moonbase-900 (moonbase-0.tx2.au3) file=/var/lib/alphanet-data/wasm/moo nbase-runtime-900-substitute-tracing.wasm | ||
<br>Jun 03 12:46:04 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:46:04 [🌗] Found w asm override. version-moonbase-1504 (moonbase-0.tx2.au3) file=/var/lib/alphanet-data/wasm/mo onbase-runtime-1504-substitute-tracing.wasm | ||
<br>Jun 03 12:46:05 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:46:05 [🌗] Found w asm override. version-moonbase-1101 (moonbase-0.tx2.au3) file=/var/lib/alphanet-data/wasm/mo onbase-runtime-1101-substitute-tracing.wasm | ||
<br>Jun 03 12:46:07 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:46:07 [🌗] Found w asm override. version-moonbase-800 (moonbase-0.tx2.au3) file=/var/lib/alphanet-data/wasm/moo nbase-runtime-800-substitute-tracing.wasm | ||
</span> | ||
</div> |
24 changes: 24 additions & 0 deletions
24
.snippets/code/node-operators/networks/tracing-node/terminal/status.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<div id="termynal" data-termynal> | ||
<span data-ty="input"><span class="file-path"></span>systemctl status moonbeam.service</span> | ||
<span data-ty>● moonbeam.service - "Moonbase Alpha systemd service" | ||
<br>Loaded: loaded (/etc/systemd/system/moonbeam.service; enabled; vendor preset: enabled) | ||
<br>Active: active (running) since Fri 2022-06-03 12:45:08 EDT; 10min ago | ||
<br>Main PID: 2115 (moonbeam) | ||
<br>Tasks: 43 (limit: 19141) | ||
<br>Memory: 9.5G | ||
<br>CGroup:/system.slice/moonbeam.service | ||
<br>--2115 /var/lib/alphanet-data/moonbeam --port 30334 --rpc-port 9944 | ||
</span> | ||
<br> | ||
<span data-ty>Jun 03 12:55:07 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:55:07 [🌗] > | ||
<br>Jun 03 12:55:08 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:55:08 [Rela> | ||
<br>Jun 03 12:55:12 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:55:12 [🌗] > | ||
<br>Jun 03 12:55:13 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:55:13 [Rela> | ||
<br>Jun 03 12:55:17 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:55:17 [🌗] > | ||
<br>Jun 03 12:55:18 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:55:18 [Rela> | ||
<br>Jun 03 12:55:19 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:55:19 [Rela> | ||
<br>Jun 03 12:55:19 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:55:19 [Rela> | ||
<br>Jun 03 12:55:19 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:55:19 [Rela> | ||
<br>Jun 03 12:55:19 vmi719182.contaboserver.net moonbase [2115]: 2022-06-03 12:55:19 [Rela> | ||
</span> | ||
</div> |
34 changes: 34 additions & 0 deletions
34
.snippets/code/tutorials/eth-api/foundry-start-to-end/Container-initial-test.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Test.sol"; | ||
import {MyToken} from "../src/MyToken.sol"; | ||
import {Container, ContainerStatus} from "../src/Container.sol"; | ||
|
||
contract ContainerTest is Test { | ||
MyToken public token; | ||
Container public container; | ||
|
||
uint256 constant CAPACITY = 100; | ||
|
||
// Runs before each test | ||
function setUp() public { | ||
token = new MyToken(1000); | ||
container = new Container(token, CAPACITY); | ||
} | ||
|
||
// Tests if the container is unsatisfied right after constructing | ||
function testInitialUnsatisfied() public { | ||
assertEq(token.balanceOf(address(container)), 0); | ||
assertTrue(container.status() == ContainerStatus.Unsatisfied); | ||
} | ||
|
||
// Tests if the container will be "full" once it reaches its capacity | ||
function testContainerFull() public { | ||
token.transfer(address(container), CAPACITY); | ||
container.updateStatus(); | ||
|
||
assertEq(token.balanceOf(address(container)), CAPACITY); | ||
assertTrue(container.status() == ContainerStatus.Full); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
.snippets/code/tutorials/eth-api/foundry-start-to-end/Container.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
// Import OpenZeppelin Contract | ||
import {MyToken} from "./MyToken.sol"; | ||
|
||
enum ContainerStatus { | ||
Unsatisfied, | ||
Full, | ||
Overflowing | ||
} | ||
|
||
contract Container { | ||
MyToken token; | ||
uint256 capacity; | ||
ContainerStatus public status; | ||
|
||
constructor(MyToken _token, uint256 _capacity) { | ||
token = _token; | ||
capacity = _capacity; | ||
status = ContainerStatus.Unsatisfied; | ||
} | ||
|
||
// Updates the status value based on the number of tokens that this contract has | ||
function updateStatus() public { | ||
address container = address(this); | ||
uint256 balance = token.balanceOf(container); | ||
if (balance < capacity) { | ||
status = ContainerStatus.Unsatisfied; | ||
} else if (balance == capacity) { | ||
status = ContainerStatus.Full; | ||
} else if (_isOverflowing(balance)) { | ||
status = ContainerStatus.Overflowing; | ||
} | ||
} | ||
|
||
// Returns true if the contract should be in an overflowing state, false if otherwise | ||
function _isOverflowing(uint256 balance) internal view returns (bool) { | ||
return balance > capacity; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.snippets/code/tutorials/eth-api/foundry-start-to-end/ContainerDeployScript.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "forge-std/Script.sol"; | ||
import {MyToken} from "../src/MyToken.sol"; | ||
import {Container} from "../src/Container.sol"; | ||
|
||
contract ContainerDeployScript is Script { | ||
// Runs the script; deploys MyToken and Container | ||
function run() public { | ||
// Get the private key from the .env | ||
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
vm.startBroadcast(deployerPrivateKey); | ||
|
||
// Make a new token | ||
MyToken token = new MyToken(1000); | ||
|
||
// Make a new container | ||
new Container(token, 500); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.snippets/code/tutorials/eth-api/foundry-start-to-end/ContainerHarness.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
contract ContainerHarness is Container { | ||
constructor(MyToken _token, uint256 _capacity) Container(_token, _capacity) {} | ||
|
||
function exposed_isOverflowing(uint256 balance) external view returns(bool) { | ||
return _isOverflowing(balance); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.snippets/code/tutorials/eth-api/foundry-start-to-end/ERC20.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
// Import OpenZeppelin Contract | ||
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
// This ERC-20 contract mints the specified amount of tokens to the contract creator | ||
contract MyToken is ERC20 { | ||
constructor(uint256 initialSupply) ERC20("MyToken", "MYTOK") { | ||
_mint(msg.sender, initialSupply); | ||
} | ||
|
||
// An external minting function allows anyone to mint as many tokens as they want | ||
function mint(uint256 toMint, address to) external { | ||
require(toMint <= 1 ether); | ||
_mint(to, toMint); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.snippets/code/tutorials/eth-api/foundry-start-to-end/Fuzz-test.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Fuzz tests for success upon minting tokens one ether or below | ||
function testMintOneEtherOrBelow(uint256 amountToMint) public { | ||
vm.assume(amountToMint <= 1 ether); | ||
|
||
token.mint(amountToMint, msg.sender); | ||
assertEq(token.balanceOf(msg.sender), amountToMint); | ||
} |
6 changes: 6 additions & 0 deletions
6
.snippets/code/tutorials/eth-api/foundry-start-to-end/Fuzz-test2.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Fuzz tests for failure upon minting tokens above one ether | ||
function testFailMintAboveOneEther(uint256 amountToMint) public { | ||
vm.assume(amountToMint > 1 ether); | ||
|
||
token.mint(amountToMint, msg.sender); | ||
} |
7 changes: 7 additions & 0 deletions
7
.snippets/code/tutorials/eth-api/foundry-start-to-end/IsOverflowing.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Tests for negative cases of the internal _isOverflowing function | ||
function testIsOverflowingFalse() public { | ||
ContainerHarness harness = new ContainerHarness(token , CAPACITY); | ||
assertFalse(harness.exposed_isOverflowing(CAPACITY - 1)); | ||
assertFalse(harness.exposed_isOverflowing(CAPACITY)); | ||
assertFalse(harness.exposed_isOverflowing(0)); | ||
} |
Oops, something went wrong.