Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
fix: ensure txs in forked mode can access uncommitted code state (#488)
Browse files Browse the repository at this point in the history
Fixes #454
  • Loading branch information
nicholasjpaterno authored and davidmurdoch committed Sep 26, 2019
1 parent ca16291 commit 34cdd8a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/utils/forkedblockchain.js
Expand Up @@ -69,7 +69,6 @@ ForkedBlockchain.prototype.patchVM = function(vm) {
// Unfortunately forking requires a bit of monkey patching, but it gets the job done.
vm.stateManager._cache._lookupAccount = lookupAccount;
vm.stateManager._lookupStorageTrie = this.getLookupStorageTrie(trie, lookupAccount);
vm.stateManager.getContractCode = this.getCode.bind(this);
};

/**
Expand Down
19 changes: 19 additions & 0 deletions test/contracts/forking/IntraBlockCache.sol
@@ -0,0 +1,19 @@
pragma solidity >=0.4.21 <0.6.0;

contract Test2 {
// Just make sure there really is some code here
uint256 foo;
function test() external {
foo = 1337;
}
}

contract IntraBlockCache {
function deploy() external {
Test2 x = new Test2();
address addr = address(x);
uint32 size;
assembly { size := extcodesize(addr) }
require(size > 0, 'extcodesize is broken');
}
}
21 changes: 21 additions & 0 deletions test/forking.js
Expand Up @@ -552,6 +552,27 @@ describe("Forking", function() {
});
});

describe("Intra block state", function() {
it("should be aware of the vm cache", async() => {
const { result } = compile("./test/contracts/forking/", "IntraBlockCache");
const contract = new mainWeb3.eth.Contract(result.contracts["IntraBlockCache.sol"].IntraBlockCache.abi);
const accounts = await mainWeb3.eth.getAccounts();
const ibc = await contract
.deploy({
data: result.contracts["IntraBlockCache.sol"].IntraBlockCache.evm.bytecode.object
})
.send({
from: accounts[0],
gas: 190941
});
return assert.doesNotReject(
ibc.methods.deploy().send({ from: accounts[0] }),
undefined,
"Should reference state in the VM's cache"
);
});
});

after("Shutdown server", (done) => {
forkedWeb3._provider.connection.close();
forkedServer.close(function(serverCloseErr) {
Expand Down

0 comments on commit 34cdd8a

Please sign in to comment.