Skip to content

Commit 4403dc4

Browse files
authored
fix: preserve all removed function selectors (#54)
1 parent f222501 commit 4403dc4

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/shared/diamond.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export const resolveUpgrade = async (params: {
168168
trace(`[Will not remove] method [${f}] pointing to facet ${liveFunctions[f]} (PROTECTED)`)
169169
} else {
170170
trace(`[Remove] method [${f}] pointing to facet ${liveFunctions[f]}`)
171-
todo.remove[ZeroAddress] = todo.remove[liveFunctions[f]] || []
171+
todo.remove[ZeroAddress] ??= []
172172
todo.remove[ZeroAddress].push(f)
173173
}
174174
}

test/common-deploy-steps.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,32 @@ export const addDeployTestSteps = ({
175175
expect(contract.getInt1()).to.be.rejectedWith('execution reverted')
176176
})
177177

178+
it('and can handle multiple removals from the same facet', async () => {
179+
writeFile(join(cwd, `${contractSrcBasePath}/facets/ExampleFacet.sol`), `
180+
pragma solidity >=0.8.21;
181+
import "../libs/LibAppStorage.sol";
182+
contract ExampleFacet {
183+
function setInt2(uint i) external {
184+
AppStorage storage s = LibAppStorage.diamondStorage();
185+
s.data.i1 = i + 1;
186+
}
187+
}
188+
`)
189+
190+
expect(cli('build', { cwd }).success).to.be.true
191+
expect(cli_deploy([]).success).to.be.true
192+
193+
const { contract } = await loadDiamondContract(cwd, [
194+
'function setInt2(uint i) external',
195+
'function setInt1(uint i) external',
196+
'function getInt1() external view returns (uint)',
197+
])
198+
199+
await sendTx(contract.setInt2(2))
200+
await expect(contract.setInt1(2)).to.be.rejected
201+
await expect(contract.getInt1()).to.be.rejected
202+
})
203+
178204
it('and can prevent removals of protected methods', async () => {
179205
writeFile(join(cwd, `${contractSrcBasePath}/facets/ExampleFacet.sol`), `
180206
pragma solidity >=0.8.21;
@@ -972,4 +998,3 @@ export const addDeployTestSteps = ({
972998

973999
})
9741000
}
975-

0 commit comments

Comments
 (0)