-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: CCIP-2465 ccip-enumerableMap for addressToBytesMap #13890
Conversation
@@ -2,17 +2,19 @@ | |||
pragma solidity ^0.8.0; | |||
|
|||
import {EnumerableMap} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/structs/EnumerableMap.sol"; | |||
import "./CCIPEnumerableMap.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use explicit imports
* | ||
* - `key` must be in the map. | ||
*/ | ||
// solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can turn off this rule for the entire file instead
// solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: whitespace
* array of CCIPEnumerableMap. | ||
* ==== | ||
*/ | ||
library CCIPEnumerableMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove the CCIP naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, something like EnumerableMapBytes32
to be consistent with EnumerableMapAddresses
// solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore | ||
function remove(Bytes32ToBytesMap storage map, bytes32 key) internal returns (bool) { | ||
delete map._values[key]; | ||
return map._keys.remove(key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: does this correctly remove all bytes values, since bytes
is a dynamic array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a test for this. will test on varying bytes size
contracts/src/v0.8/shared/test/enumerable/EnumerableMapAddresses.t.sol
Outdated
Show resolved
Hide resolved
assertTrue(s_addressToBytesMap.contains(address(this))); | ||
(bool success, bytes memory value) = s_addressToBytesMap.tryGet(address(this)); | ||
assertTrue(success); | ||
assertTrue(keccak256(value) == keccak256(MOCK_BYTES_VALUE)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertTrue(keccak256(value) == keccak256(MOCK_BYTES_VALUE)); | |
assertEq(value, MOCK_BYTES_VALUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
assertTrue(!s_addressToBytesMap.contains(address(this))); | ||
assertTrue(s_addressToBytesMap.set(address(this), MOCK_BYTES_VALUE)); | ||
assertTrue(s_addressToBytesMap.contains(address(this))); | ||
assertTrue(keccak256(s_addressToBytesMap.get(address(this))) == keccak256(MOCK_BYTES_VALUE)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertTrue(keccak256(s_addressToBytesMap.get(address(this))) == keccak256(MOCK_BYTES_VALUE)); | |
assertEq(s_addressToBytesMap.get(address(this)), MOCK_BYTES_VALUE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
assertTrue(!s_addressToBytesMap.contains(address(this))); | ||
assertTrue(s_addressToBytesMap.set(address(this), MOCK_BYTES_VALUE)); | ||
assertTrue(s_addressToBytesMap.contains(address(this))); | ||
assertTrue( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: same here - you can use assertEq
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
contracts/src/v0.8/shared/test/enumerable/EnumerableMapAddresses.t.sol
Outdated
Show resolved
Hide resolved
contracts/src/v0.8/shared/test/enumerable/EnumerableMapAddresses.t.sol
Outdated
Show resolved
Hide resolved
contracts/src/v0.8/shared/test/enumerable/EnumerableMapAddresses.t.sol
Outdated
Show resolved
Hide resolved
contracts/src/v0.8/shared/test/enumerable/EnumerableMapAddresses.t.sol
Outdated
Show resolved
Hide resolved
pragma solidity ^0.8.0; | ||
|
||
import {EnumerableMap} from "../../vendor/openzeppelin-solidity/v4.8.3/contracts/utils/structs/EnumerableMap.sol"; | ||
import {EnumerableMapBytes32} from "./EnumerableMapBytes32.sol"; | ||
|
||
// TODO: the lib can be replaced with OZ v5.1 post-upgrade, which has AddressToAddressMap and AddressToBytes32Map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this is no longer true as OZ v5 does not support AddressToBytesMap
LCOV of commit
|
|
EnumerableMap for mapping Bytes32 to Bytes
JIRA Ticket
https://smartcontract-it.atlassian.net/browse/CCIP-2465
Background
this needs to be changed to use
Change List
EnumerableMapBytes32.sol
which contains mapping from Bytes32 => BytesEnumerableMapAddresses.sol
for mapping arrangement functions for Address => Bytes