Skip to content

Commit af82ecb

Browse files
committed
course finished
1 parent 3378d5a commit af82ecb

File tree

14 files changed

+88
-9
lines changed

14 files changed

+88
-9
lines changed

04 Advanced Foundry/AA/lib/forge-std/src/LibVariable.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum TypeKind {
4848
/// // string memory notANumber = config.get("important_number").toString();
4949
///
5050
/// // Retrieve a address array from the config.
51-
/// string[] memory admins = config.get("whitelisted_admins").toAddressArray();
51+
/// address[] memory admins = config.get("whitelisted_admins").toAddressArray();
5252
/// }
5353
/// }
5454
/// ```

04 Advanced Foundry/AA/lib/forge-std/src/StdCheats.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ abstract contract StdCheatsSafe {
392392
function rawToConvertedEIPTx1559(RawTx1559 memory rawTx) internal pure virtual returns (Tx1559 memory) {
393393
Tx1559 memory transaction;
394394
transaction.arguments = rawTx.arguments;
395+
transaction.contractAddress = rawTx.contractAddress;
395396
transaction.contractName = rawTx.contractName;
396397
transaction.functionSig = rawTx.functionSig;
397398
transaction.hash = rawTx.hash;

04 Advanced Foundry/AA/lib/forge-std/src/StdConfig.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,25 @@ contract StdConfig {
321321
return get(vm.getChainId(), key);
322322
}
323323

324+
/// @dev Checks the existence of a variable for a given chain ID and key, and returns a boolean.
325+
/// Example: `bool hasKey = config.exists(1, "my_key");`
326+
///
327+
/// @param chain_id The chain ID to check.
328+
/// @param key The variable key name.
329+
/// @return `bool` indicating whether a variable with the given key exists.
330+
function exists(uint256 chain_id, string memory key) public view returns (bool) {
331+
return _dataOf[chain_id][key].length > 0;
332+
}
333+
334+
/// @dev Checks the existence of a variable for the current chain id and a given key, and returns a boolean.
335+
/// Example: `bool hasKey = config.exists("my_key");`
336+
///
337+
/// @param key The variable key name.
338+
/// @return `bool` indicating whether a variable with the given key exists.
339+
function exists(string memory key) public view returns (bool) {
340+
return exists(vm.getChainId(), key);
341+
}
342+
324343
/// @notice Returns the numerical chain ids for all configured chains.
325344
function getChainIds() public view returns (uint256[] memory) {
326345
string[] memory keys = _chainKeys;

04 Advanced Foundry/AA/lib/forge-std/src/StdStorage.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,11 @@ library stdStorageSafe {
282282
function bytesToBytes32(bytes memory b, uint256 offset) private pure returns (bytes32) {
283283
bytes32 out;
284284

285-
uint256 max = b.length > 32 ? 32 : b.length;
285+
// Cap read length by remaining bytes from `offset`, and at most 32 bytes to avoid out-of-bounds
286+
uint256 max = b.length > offset ? b.length - offset : 0;
287+
if (max > 32) {
288+
max = 32;
289+
}
286290
for (uint256 i = 0; i < max; i++) {
287291
out |= bytes32(b[offset + i] & 0xFF) >> (i * 8);
288292
}

04 Advanced Foundry/AA/lib/forge-std/src/StdUtils.sol

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ pragma solidity >=0.6.2 <0.9.0;
44
pragma experimental ABIEncoderV2;
55

66
import {IMulticall3} from "./interfaces/IMulticall3.sol";
7+
import {StdConstants} from "./StdConstants.sol";
78
import {VmSafe} from "./Vm.sol";
89

910
abstract contract StdUtils {
1011
/*//////////////////////////////////////////////////////////////////////////
1112
CONSTANTS
1213
//////////////////////////////////////////////////////////////////////////*/
1314

14-
IMulticall3 private constant multicall = IMulticall3(0xcA11bde05977b3631167028862bE2a173976CA11);
1515
VmSafe private constant vm = VmSafe(address(uint160(uint256(keccak256("hevm cheat code")))));
1616
address private constant CONSOLE2_ADDRESS = 0x000000000000000000636F6e736F6c652e6c6f67;
1717
uint256 private constant INT256_MIN_ABS =
@@ -21,9 +21,6 @@ abstract contract StdUtils {
2121
uint256 private constant UINT256_MAX =
2222
115792089237316195423570985008687907853269984665640564039457584007913129639935;
2323

24-
// Used by default when deploying with create2, https://github.com/Arachnid/deterministic-deployment-proxy.
25-
address private constant CREATE2_FACTORY = 0x4e59b44847b379578588920cA78FbF26c0B4956C;
26-
2724
/*//////////////////////////////////////////////////////////////////////////
2825
INTERNAL FUNCTIONS
2926
//////////////////////////////////////////////////////////////////////////*/
@@ -148,7 +145,7 @@ abstract contract StdUtils {
148145
}
149146

150147
// Make the aggregate call.
151-
(, bytes[] memory returnData) = multicall.aggregate(calls);
148+
(, bytes[] memory returnData) = StdConstants.MULTICALL3_ADDRESS.aggregate(calls);
152149

153150
// ABI decode the return data and return the balances.
154151
balances = new uint256[](length);

04 Advanced Foundry/AA/lib/forge-std/test/Config.t.sol

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,35 @@ contract ConfigTest is Test, Config {
125125
assertEq(vm.getChainId(), 10);
126126
}
127127

128+
function test_configExists() public {
129+
_loadConfig("./test/fixtures/config.toml", false);
130+
131+
string[] memory keys = new string[](7);
132+
keys[0] = "is_live";
133+
keys[1] = "weth";
134+
keys[2] = "word";
135+
keys[3] = "number";
136+
keys[4] = "signed_number";
137+
keys[5] = "b";
138+
keys[6] = "str";
139+
140+
// Read and assert RPC URL for Mainnet (chain ID 1)
141+
assertEq(config.getRpcUrl(1), "https://reth-ethereum.ithaca.xyz/rpc");
142+
143+
for (uint256 i = 0; i < keys.length; ++i) {
144+
assertTrue(config.exists(1, keys[i]));
145+
assertFalse(config.exists(1, string.concat(keys[i], "_")));
146+
}
147+
148+
// Assert RPC URL for Optimism (chain ID 10)
149+
assertEq(config.getRpcUrl(10), "https://mainnet.optimism.io");
150+
151+
for (uint256 i = 0; i < keys.length; ++i) {
152+
assertTrue(config.exists(10, keys[i]));
153+
assertFalse(config.exists(10, string.concat(keys[i], "_")));
154+
}
155+
}
156+
128157
function test_writeConfig() public {
129158
// Create a temporary copy of the config file to avoid modifying the original.
130159
string memory originalConfig = "./test/fixtures/config.toml";

04 Advanced Foundry/AA/lib/openzeppelin-contracts/contracts/token/ERC6909/extensions/ERC6909ContentURI.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity ^0.8.20;
55

66
import {ERC6909} from "../ERC6909.sol";
77
import {IERC6909ContentURI} from "../../../interfaces/IERC6909.sol";
8+
import {IERC165} from "../../../utils/introspection/IERC165.sol";
89

910
/**
1011
* @dev Implementation of the Content URI extension defined in ERC6909.
@@ -19,6 +20,11 @@ contract ERC6909ContentURI is ERC6909, IERC6909ContentURI {
1920
/// @dev See {IERC1155-URI}
2021
event URI(string value, uint256 indexed id);
2122

23+
/// @inheritdoc IERC165
24+
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC6909, IERC165) returns (bool) {
25+
return interfaceId == type(IERC6909ContentURI).interfaceId || super.supportsInterface(interfaceId);
26+
}
27+
2228
/// @inheritdoc IERC6909ContentURI
2329
function contractURI() public view virtual override returns (string memory) {
2430
return _contractURI;

04 Advanced Foundry/AA/lib/openzeppelin-contracts/contracts/token/ERC6909/extensions/ERC6909Metadata.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity ^0.8.20;
55

66
import {ERC6909} from "../ERC6909.sol";
77
import {IERC6909Metadata} from "../../../interfaces/IERC6909.sol";
8+
import {IERC165} from "../../../utils/introspection/IERC165.sol";
89

910
/**
1011
* @dev Implementation of the Metadata extension defined in ERC6909. Exposes the name, symbol, and decimals of each token id.
@@ -42,6 +43,11 @@ contract ERC6909Metadata is ERC6909, IERC6909Metadata {
4243
return _tokenMetadata[id].decimals;
4344
}
4445

46+
/// @inheritdoc IERC165
47+
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC6909, IERC165) returns (bool) {
48+
return interfaceId == type(IERC6909Metadata).interfaceId || super.supportsInterface(interfaceId);
49+
}
50+
4551
/**
4652
* @dev Sets the `name` for a given token of type `id`.
4753
*

04 Advanced Foundry/AA/lib/openzeppelin-contracts/contracts/token/ERC6909/extensions/ERC6909TokenSupply.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pragma solidity ^0.8.20;
55

66
import {ERC6909} from "../ERC6909.sol";
77
import {IERC6909TokenSupply} from "../../../interfaces/IERC6909.sol";
8+
import {IERC165} from "../../../utils/introspection/IERC165.sol";
89

910
/**
1011
* @dev Implementation of the Token Supply extension defined in ERC6909.
@@ -18,6 +19,11 @@ contract ERC6909TokenSupply is ERC6909, IERC6909TokenSupply {
1819
return _totalSupplies[id];
1920
}
2021

22+
/// @inheritdoc IERC165
23+
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC6909, IERC165) returns (bool) {
24+
return interfaceId == type(IERC6909TokenSupply).interfaceId || super.supportsInterface(interfaceId);
25+
}
26+
2127
/// @dev Override the `_update` function to update the total supply of each token id as necessary.
2228
function _update(address from, address to, uint256 id, uint256 amount) internal virtual override {
2329
super._update(from, to, id, amount);

04 Advanced Foundry/AA/lib/openzeppelin-contracts/test/token/ERC6909/extensions/ERC6909ContentURI.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { ethers } = require('hardhat');
22
const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
4+
const { shouldSupportInterfaces } = require('../../../utils/introspection/SupportsInterface.behavior');
45

56
async function fixture() {
67
const token = await ethers.deployContract('$ERC6909ContentURI');
@@ -46,4 +47,6 @@ describe('ERC6909ContentURI', function () {
4647
.withArgs('https://example.com/1', 1n);
4748
});
4849
});
50+
51+
shouldSupportInterfaces(['ERC6909', 'ERC6909ContentURI']);
4952
});

0 commit comments

Comments
 (0)