Skip to content

Commit cca0980

Browse files
Krishang NadgaudaKrishang Nadgauda
authored andcommitted
Add asset role tests to Multiwrap tests
1 parent 11f8160 commit cca0980

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

src/test/Multiwrap.t.sol

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,44 @@ contract MultiwrapTest is BaseTest {
171171
assertEq(uriForWrappedToken, multiwrap.tokenURI(expectedIdForWrappedToken));
172172
}
173173

174+
/**
175+
* note: Testing state changes; token owner calls `wrap` to wrap owned tokens.
176+
* Only assets with ASSET_ROLE can be wrapped.
177+
*/
178+
function test_state_wrap_withAssetRoleRestriction() public {
179+
180+
// ===== setup =====
181+
182+
vm.startPrank(deployer);
183+
multiwrap.revokeRole(keccak256("ASSET_ROLE"), address(0));
184+
185+
for(uint i = 0; i < wrappedContent.length; i += 1) {
186+
multiwrap.grantRole(keccak256("ASSET_ROLE"), wrappedContent[i].assetContract);
187+
}
188+
189+
vm.stopPrank();
190+
191+
// ===== target test content =====
192+
uint256 expectedIdForWrappedToken = multiwrap.nextTokenIdToMint();
193+
address recipient = address(0x123);
194+
195+
vm.prank(address(tokenOwner));
196+
multiwrap.wrap(wrappedContent, uriForWrappedToken, recipient);
197+
198+
assertEq(expectedIdForWrappedToken + 1, multiwrap.nextTokenIdToMint());
199+
200+
ITokenBundle.Token[] memory contentsOfWrappedToken = multiwrap.getWrappedContents(expectedIdForWrappedToken);
201+
assertEq(contentsOfWrappedToken.length, wrappedContent.length);
202+
for (uint256 i = 0; i < contentsOfWrappedToken.length; i += 1) {
203+
assertEq(contentsOfWrappedToken[i].assetContract, wrappedContent[i].assetContract);
204+
assertEq(uint256(contentsOfWrappedToken[i].tokenType), uint256(wrappedContent[i].tokenType));
205+
assertEq(contentsOfWrappedToken[i].tokenId, wrappedContent[i].tokenId);
206+
assertEq(contentsOfWrappedToken[i].totalAmount, wrappedContent[i].totalAmount);
207+
}
208+
209+
assertEq(uriForWrappedToken, multiwrap.tokenURI(expectedIdForWrappedToken));
210+
}
211+
174212
/**
175213
* note: Testing event emission; token owner calls `wrap` to wrap owned tokens.
176214
*/
@@ -246,6 +284,30 @@ contract MultiwrapTest is BaseTest {
246284
multiwrap.wrap(reentrantContentToWrap, uriForWrappedToken, recipient);
247285
}
248286

287+
/**
288+
* note: Testing revert condition; token owner calls `wrap` to wrap owned tokens.
289+
* Only assets with ASSET_ROLE can be wrapped, but assets being wrapped don't have that role.
290+
*/
291+
function test_revert_wrap_access_ASSET_ROLE() public {
292+
vm.prank(deployer);
293+
multiwrap.revokeRole(keccak256("ASSET_ROLE"), address(0));
294+
295+
address recipient = address(0x123);
296+
297+
string memory errorMsg = string(
298+
abi.encodePacked(
299+
"Permissions: account ",
300+
Strings.toHexString(uint160(wrappedContent[0].assetContract), 20),
301+
" is missing role ",
302+
Strings.toHexString(uint256(keccak256("ASSET_ROLE")), 32)
303+
)
304+
);
305+
306+
vm.prank(address(tokenOwner));
307+
vm.expectRevert(bytes(errorMsg));
308+
multiwrap.wrap(wrappedContent, uriForWrappedToken, recipient);
309+
}
310+
249311
/**
250312
* note: Testing revert condition; token owner calls `wrap` to wrap owned tokens, without MINTER_ROLE.
251313
*/
@@ -257,7 +319,7 @@ contract MultiwrapTest is BaseTest {
257319

258320
string memory errorMsg = string(
259321
abi.encodePacked(
260-
"AccessControl: account ",
322+
"Permissions: account ",
261323
Strings.toHexString(uint160(address(tokenOwner)), 20),
262324
" is missing role ",
263325
Strings.toHexString(uint256(keccak256("MINTER_ROLE")), 32)
@@ -581,7 +643,7 @@ contract MultiwrapTest is BaseTest {
581643

582644
string memory errorMsg = string(
583645
abi.encodePacked(
584-
"AccessControl: account ",
646+
"Permissions: account ",
585647
Strings.toHexString(uint160(recipient), 20),
586648
" is missing role ",
587649
Strings.toHexString(uint256(keccak256("UNWRAP_ROLE")), 32)

0 commit comments

Comments
 (0)