This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 680
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(forking): invalidate
_deleted
in ForkedStorageTrie
if a subse…
…quent `put` happens (#612)
- Loading branch information
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
pragma solidity ^0.6.0; | ||
|
||
contract StorageDelete { | ||
bool entered; | ||
|
||
constructor() public { | ||
entered = true; | ||
} | ||
|
||
function test() public nonReentrant {} | ||
|
||
modifier nonReentrant() { | ||
require(entered, "re-entered"); | ||
entered = false; | ||
_; | ||
entered = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const assert = require("assert"); | ||
const bootstrap = require("../helpers/contract/bootstrap"); | ||
const intializeTestProvider = require("../helpers/web3/initializeTestProvider"); | ||
|
||
/** | ||
* NOTE: Naming in these tests is a bit confusing. Here, the "main chain" | ||
* is the main chain the tests interact with; and the "forked chain" is the | ||
* chain that _was forked_. This is in contrast to general naming, where the | ||
* main chain represents the main chain to be forked (like the Ethereum live | ||
* network) and the fork chaing being "the fork". | ||
*/ | ||
|
||
describe("Forking Deletion", () => { | ||
let forkedContext; | ||
let mainContext; | ||
const logger = { | ||
log: function(msg) {} | ||
}; | ||
|
||
before("Set up forked provider with web3 instance and deploy a contract", async function() { | ||
this.timeout(5000); | ||
|
||
const contractRef = { | ||
contractFiles: ["StorageDelete"], | ||
contractSubdirectory: "forking" | ||
}; | ||
|
||
const ganacheProviderOptions = { | ||
logger, | ||
seed: "main provider" | ||
}; | ||
|
||
forkedContext = await bootstrap(contractRef, ganacheProviderOptions); | ||
}); | ||
|
||
before("Set up main provider and web3 instance", async function() { | ||
const { provider: forkedProvider } = forkedContext; | ||
mainContext = await intializeTestProvider({ | ||
fork: forkedProvider, | ||
logger, | ||
seed: "forked provider" | ||
}); | ||
}); | ||
|
||
it("successfully manages storage slot deletion", async() => { | ||
const { instance: forkedInstance, abi } = forkedContext; | ||
const { web3: mainWeb3 } = mainContext; | ||
|
||
const instance = new mainWeb3.eth.Contract(abi, forkedInstance._address); | ||
|
||
assert.ok(await instance.methods.test().call()); | ||
assert.ok(await instance.methods.test().call()); | ||
}); | ||
}); |