ci: Add Foundry tooling integration test (#511)

## Description

Adds a CI workflow that builds and tests a small Foundry project with
`foundry-polkadot`'s `forge`, exercising the standard JSON interface
between `resolc` and `foundry-polkadot` end-to-end.

## Resolved Issues

Closes #513
This commit is contained in:
LJ authored and GitHub committed 2026-06-24 10:38:07 +02:00
1 parent fb0e9e6a30
commit 3d70def08c
10 files changed
+239 -12

No files matched your search

@@ -0,0 +1,25 @@
[profile.default]
src = "src"
test = "test"
libs = ["lib"]
solc = "0.8.35"
remappings = [
"forge-std/=lib/forge-std/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
]
extra_output = [
"abi",
"metadata",
"devdoc",
"userdoc",
"storageLayout",
"ir",
"irOptimized",
"evm.bytecode",
"evm.deployedBytecode",
"evm.assembly",
"evm.methodIdentifiers",
]
[profile.default.polkadot]
resolc_compile = true
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.22;
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
contract MyToken is ERC20, Ownable {
constructor(address initialOwner)
ERC20("MyToken", "MTK")
Ownable(initialOwner)
{}
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
}
@@ -0,0 +1,61 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;
import { Test } from "forge-std/Test.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { MyToken } from "../src/MyToken.sol";
contract MyTokenTest is Test {
MyToken internal token;
address internal owner = address(this);
address internal alice = address(0xA11CE);
address internal bob = address(0xB0B);
function setUp() public {
token = new MyToken(owner);
}
function test_NameAndSymbol() public view {
assertEq(token.name(), "MyToken");
assertEq(token.symbol(), "MTK");
}
function test_Owner() public view {
assertEq(token.owner(), owner);
}
function test_OwnerCanMint() public {
token.mint(alice, 1000);
assertEq(token.balanceOf(alice), 1000);
}
function test_NonOwnerCannotMint() public {
vm.prank(alice);
vm.expectRevert(
abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, alice)
);
token.mint(alice, 1000);
}
function test_TotalSupplyIncreases() public {
uint256 before = token.totalSupply();
token.mint(alice, 500);
assertEq(token.totalSupply() - before, 500);
}
function test_Transfer() public {
token.mint(owner, 1000);
assertTrue(token.transfer(alice, 100));
assertEq(token.balanceOf(alice), 100);
assertEq(token.balanceOf(owner), 900);
}
function test_TransferFrom() public {
token.mint(owner, 1000);
token.approve(alice, 50);
vm.prank(alice);
assertTrue(token.transferFrom(owner, bob, 50));
assertEq(token.balanceOf(bob), 50);
assertEq(token.allowance(owner, alice), 0);
}
}
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Asserts that the compiled project contains the expected compiler output.
# Requires `forge` in PATH. Run from the project's root.
#
# Usage: verify-compiler-output.sh <resolc-path>
set -euxo pipefail
if [[ $# -ne 1 ]]; then
echo "usage: $(basename "$0") <resolc-path>" >&2
exit 2
fi
resolc=$1
inspect() {
forge inspect --use-resolc "$resolc" MyToken "$@"
}
inspect bytecode | grep '^0x50564d' > /dev/null
inspect deployedBytecode | grep '^0x50564d' > /dev/null
inspect irOptimized | grep . > /dev/null
inspect ir | grep . > /dev/null
inspect assembly | grep . > /dev/null
inspect abi --json | jq -e 'length > 0' > /dev/null
inspect methodIdentifiers --json | jq -e 'length > 0' > /dev/null
inspect storageLayout --json | jq -e '.storage | length > 0' > /dev/null
inspect metadata --json | jq -e 'length > 0' > /dev/null
inspect devdoc --json | jq -e 'length > 0' > /dev/null
inspect userdoc --json | jq -e 'length > 0' > /dev/null
echo "all checks passed"