Skip to content

Commit 36b2d0c

Browse files
committed
fix foundry zip tests
1 parent d92a0fd commit 36b2d0c

File tree

4 files changed

+323
-55
lines changed

4 files changed

+323
-55
lines changed

packages/core/solidity/src/zip-foundry.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ async function runTest(c: Contract, t: ExecutionContext<Context>, opts: GenericO
156156
}
157157

158158
function assertLayout(zip: JSZip, c: Contract, t: ExecutionContext<Context>) {
159-
const sorted = Object.values(zip.files)
160-
.map(f => f.name)
161-
.sort();
159+
const sorted = Object.keys(zip.files).sort();
162160
t.deepEqual(sorted, [
163161
'README.md',
164162
'script/',

packages/core/solidity/src/zip-foundry.test.ts.md

Lines changed: 198 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ Generated by [AVA](https://avajs.dev).
322322
"MyToken.sol",␊
323323
abi.encodeCall(MyToken.initialize, (tokenBridge_, recipient, initialOwner))␊
324324
);␊
325-
MyToken instance = MyToken(payable(proxy));␊
325+
MyToken instance = MyToken(proxy);␊
326326
console.log("Proxy deployed to %s", address(instance));␊
327327
vm.stopBroadcast();␊
328328
*/␊
@@ -355,7 +355,8 @@ Generated by [AVA](https://avajs.dev).
355355
}␊
356356
357357
function initialize(address tokenBridge_, address recipient, address initialOwner)␊
358-
public initializer␊
358+
public␊
359+
initializer␊
359360
{␊
360361
__ERC20_init("My Token", "MTK");␊
361362
__ERC20Bridgeable_init();␊
@@ -433,7 +434,7 @@ Generated by [AVA](https://avajs.dev).
433434
"MyToken.sol",␊
434435
abi.encodeCall(MyToken.initialize, (tokenBridge_, recipient, initialOwner))␊
435436
);␊
436-
instance = MyToken(payable(proxy));␊
437+
instance = MyToken(proxy);␊
437438
}␊
438439
439440
function testName() public view {␊
@@ -563,7 +564,7 @@ Generated by [AVA](https://avajs.dev).
563564
"MyToken.sol",␊
564565
abi.encodeCall(MyToken.initialize, (defaultAdmin, upgrader))␊
565566
);␊
566-
MyToken instance = MyToken(payable(proxy));␊
567+
MyToken instance = MyToken(proxy);␊
567568
console.log("Proxy deployed to %s", address(instance));␊
568569
vm.stopBroadcast();␊
569570
*/␊
@@ -588,9 +589,7 @@ Generated by [AVA](https://avajs.dev).
588589
_disableInitializers();␊
589590
}␊
590591
591-
function initialize(address defaultAdmin, address upgrader)␊
592-
public initializer␊
593-
{␊
592+
function initialize(address defaultAdmin, address upgrader) public initializer {␊
594593
__ERC20_init("My Token", "MTK");␊
595594
__ERC20Permit_init("My Token");␊
596595
__AccessControl_init();␊
@@ -624,7 +623,7 @@ Generated by [AVA](https://avajs.dev).
624623
"MyToken.sol",␊
625624
abi.encodeCall(MyToken.initialize, (defaultAdmin, upgrader))␊
626625
);␊
627-
instance = MyToken(payable(proxy));␊
626+
instance = MyToken(proxy);␊
628627
}␊
629628
630629
function testName() public view {␊
@@ -753,7 +752,7 @@ Generated by [AVA](https://avajs.dev).
753752
"MyToken.sol",␊
754753
abi.encodeCall(MyToken.initialize, (initialOwner))␊
755754
);␊
756-
MyToken instance = MyToken(payable(proxy));␊
755+
MyToken instance = MyToken(proxy);␊
757756
console.log("Proxy deployed to %s", address(instance));␊
758757
vm.stopBroadcast();␊
759758
*/␊
@@ -804,7 +803,7 @@ Generated by [AVA](https://avajs.dev).
804803
"MyToken.sol",␊
805804
abi.encodeCall(MyToken.initialize, (initialOwner))␊
806805
);␊
807-
instance = MyToken(payable(proxy));␊
806+
instance = MyToken(proxy);␊
808807
}␊
809808
810809
function testName() public view {␊
@@ -1085,7 +1084,7 @@ Generated by [AVA](https://avajs.dev).
10851084
initialOwner,␊
10861085
abi.encodeCall(MyToken.initialize, (initialOwner))␊
10871086
);␊
1088-
MyToken instance = MyToken(payable(proxy));␊
1087+
MyToken instance = MyToken(proxy);␊
10891088
console.log("Proxy deployed to %s", address(instance));␊
10901089
vm.stopBroadcast();␊
10911090
*/␊
@@ -1133,7 +1132,7 @@ Generated by [AVA](https://avajs.dev).
11331132
initialOwner,␊
11341133
abi.encodeCall(MyToken.initialize, (initialOwner))␊
11351134
);␊
1136-
instance = MyToken(payable(proxy));␊
1135+
instance = MyToken(proxy);␊
11371136
}␊
11381137
11391138
function testUri() public view {␊
@@ -1291,6 +1290,191 @@ Generated by [AVA](https://avajs.dev).
12911290
`,
12921291
]
12931292

1293+
## account ecdsa uups
1294+
1295+
> Snapshot 1
1296+
1297+
[
1298+
`#!/usr/bin/env bash␊
1299+
1300+
# Check if git is installed␊
1301+
if ! which git &> /dev/null␊
1302+
then␊
1303+
echo "git command not found. Install git and try again."␊
1304+
exit 1␊
1305+
fi␊
1306+
1307+
# Check if Foundry is installed␊
1308+
if ! which forge &> /dev/null␊
1309+
then␊
1310+
echo "forge command not found. Install Foundry and try again. See https://book.getfoundry.sh/getting-started/installation"␊
1311+
exit 1␊
1312+
fi␊
1313+
1314+
# Setup Foundry project␊
1315+
if ! [ -f "foundry.toml" ]␊
1316+
then␊
1317+
echo "Initializing Foundry project..."␊
1318+
1319+
# Backup Wizard template readme to avoid it being overwritten␊
1320+
mv README.md README-oz.md␊
1321+
1322+
# Initialize sample Foundry project␊
1323+
forge init --force --quiet␊
1324+
1325+
# Install OpenZeppelin Contracts and Upgrades␊
1326+
forge install OpenZeppelin/[email protected] --quiet␊
1327+
forge install OpenZeppelin/openzeppelin-foundry-upgrades --quiet␊
1328+
1329+
# Remove unneeded Foundry template files␊
1330+
rm src/Counter.sol␊
1331+
rm script/Counter.s.sol␊
1332+
rm test/Counter.t.sol␊
1333+
rm README.md␊
1334+
1335+
# Restore Wizard template readme␊
1336+
mv README-oz.md README.md␊
1337+
1338+
# Add remappings␊
1339+
if [ -f "remappings.txt" ]␊
1340+
then␊
1341+
echo "" >> remappings.txt␊
1342+
fi␊
1343+
echo "@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/" >> remappings.txt␊
1344+
echo "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/" >> remappings.txt␊
1345+
1346+
# Add settings in foundry.toml␊
1347+
echo "" >> foundry.toml␊
1348+
echo "ffi = true" >> foundry.toml␊
1349+
echo "ast = true" >> foundry.toml␊
1350+
echo "build_info = true" >> foundry.toml␊
1351+
echo "extra_output = [\\"storageLayout\\"]" >> foundry.toml␊
1352+
1353+
# Perform initial git commit␊
1354+
git add .␊
1355+
git commit -m "openzeppelin: add wizard output" --quiet␊
1356+
1357+
echo "Done."␊
1358+
else␊
1359+
echo "Foundry project already initialized."␊
1360+
fi␊
1361+
`,
1362+
`# Sample Foundry Project␊
1363+
1364+
This project demonstrates a basic Foundry use case. It comes with a contract generated by [OpenZeppelin Wizard](https://wizard.openzeppelin.com/), a test for that contract, and a script that deploys that contract.␊
1365+
1366+
## Installing Foundry␊
1367+
1368+
See [Foundry installation guide](https://book.getfoundry.sh/getting-started/installation).␊
1369+
1370+
## Initializing the project␊
1371+
1372+
\`\`\`␊
1373+
bash setup.sh␊
1374+
\`\`\`␊
1375+
1376+
## Testing the contract␊
1377+
1378+
\`\`\`␊
1379+
forge test --force␊
1380+
\`\`\`␊
1381+
1382+
## Deploying the contract␊
1383+
1384+
You can simulate a deployment by running the script:␊
1385+
1386+
\`\`\`␊
1387+
forge script script/MyAccount.s.sol --force␊
1388+
\`\`\`␊
1389+
1390+
See [Solidity scripting guide](https://book.getfoundry.sh/guides/scripting-with-solidity) for more information.␊
1391+
`,
1392+
`// SPDX-License-Identifier: MIT␊
1393+
pragma solidity ^0.8.27;␊
1394+
1395+
import {Script} from "forge-std/Script.sol";␊
1396+
import {console} from "forge-std/console.sol";␊
1397+
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";␊
1398+
import {MyAccount} from "src/MyAccount.sol";␊
1399+
1400+
contract MyAccountScript is Script {␊
1401+
function setUp() public {}␊
1402+
1403+
function run() public {␊
1404+
// TODO: Set addresses for the variables below, then uncomment the following section:␊
1405+
/*␊
1406+
vm.startBroadcast();␊
1407+
address signer = <Set signer address here>;␊
1408+
MyAccount implementation = new MyAccount();␊
1409+
address proxy = address(new ERC1967Proxy(␊
1410+
address(implementation),␊
1411+
abi.encodeCall(MyAccount.initialize, (signer))␊
1412+
));␊
1413+
MyAccount instance = MyAccount(payable(proxy));␊
1414+
console.log("Proxy deployed to %s", address(instance));␊
1415+
vm.stopBroadcast();␊
1416+
*/␊
1417+
}␊
1418+
}␊
1419+
`,
1420+
`// SPDX-License-Identifier: MIT␊
1421+
// Compatible with OpenZeppelin Contracts ^5.4.0␊
1422+
pragma solidity ^0.8.27;␊
1423+
1424+
import {Account} from "@openzeppelin/contracts/account/Account.sol";␊
1425+
import {EIP712} from "@openzeppelin/contracts/utils/cryptography/EIP712.sol";␊
1426+
import {ERC1155Holder} from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";␊
1427+
import {ERC721Holder} from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";␊
1428+
import {ERC7739} from "@openzeppelin/contracts/utils/cryptography/signers/draft-ERC7739.sol";␊
1429+
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
1430+
import {SignerECDSAUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/cryptography/signers/SignerECDSAUpgradeable.sol";␊
1431+
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
1432+
1433+
contract MyAccount is Initializable, Account, EIP712, ERC7739, SignerECDSAUpgradeable, ERC721Holder, ERC1155Holder, UUPSUpgradeable {␊
1434+
/// @custom:oz-upgrades-unsafe-allow-reachable constructor␊
1435+
constructor() EIP712("My Account", "1") {␊
1436+
_disableInitializers();␊
1437+
}␊
1438+
1439+
function initialize(address signer) public initializer {␊
1440+
__SignerECDSA_init(signer);␊
1441+
__UUPSUpgradeable_init();␊
1442+
}␊
1443+
1444+
function _authorizeUpgrade(address newImplementation)␊
1445+
internal␊
1446+
override␊
1447+
onlyEntryPointOrSelf␊
1448+
{}␊
1449+
}␊
1450+
`,
1451+
`// SPDX-License-Identifier: MIT␊
1452+
pragma solidity ^0.8.27;␊
1453+
1454+
import {Test} from "forge-std/Test.sol";␊
1455+
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";␊
1456+
import {MyAccount} from "src/MyAccount.sol";␊
1457+
1458+
contract MyAccountTest is Test {␊
1459+
MyAccount public instance;␊
1460+
1461+
function setUp() public {␊
1462+
address signer = vm.addr(1);␊
1463+
MyAccount implementation = new MyAccount();␊
1464+
address proxy = address(new ERC1967Proxy(␊
1465+
address(implementation),␊
1466+
abi.encodeCall(MyAccount.initialize, (signer))␊
1467+
));␊
1468+
instance = MyAccount(payable(proxy));␊
1469+
}␊
1470+
1471+
function testSomething() public {␊
1472+
// Add your test here␊
1473+
}␊
1474+
}␊
1475+
`,
1476+
]
1477+
12941478
## custom basic
12951479

12961480
> Snapshot 1
@@ -1547,7 +1731,7 @@ Generated by [AVA](https://avajs.dev).
15471731
initialOwner,␊
15481732
abi.encodeCall(MyContract.initialize, (initialAuthority))␊
15491733
);␊
1550-
MyContract instance = MyContract(payable(proxy));␊
1734+
MyContract instance = MyContract(proxy);␊
15511735
console.log("Proxy deployed to %s", address(instance));␊
15521736
vm.stopBroadcast();␊
15531737
*/␊
@@ -1590,7 +1774,7 @@ Generated by [AVA](https://avajs.dev).
15901774
initialOwner,␊
15911775
abi.encodeCall(MyContract.initialize, (initialAuthority))␊
15921776
);␊
1593-
instance = MyContract(payable(proxy));␊
1777+
instance = MyContract(proxy);␊
15941778
}␊
15951779
15961780
function testSomething() public {␊
273 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)