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

Commit

Permalink
Fix default net_version issue when forking (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmurdoch authored Dec 20, 2018
1 parent cff32e6 commit 7279345
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/statemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ StateManager.prototype.initialize = function(callback) {
// If the user didn't pass a specific version id in, then use the
// forked blockchain's version (if it exists) or create our own.
if (!self.net_version) {
self.net_version = self.blockchain.fork_version;
self.net_version = self.blockchain.forkVersion;
}

if (self.is_mining_on_interval) {
Expand Down
14 changes: 11 additions & 3 deletions test/forking.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ describe("Forking", function() {
var forkedWeb3 = new Web3();
var mainWeb3 = new Web3();

var forkedTargetUrl = "ws://localhost:21345";
var forkedWeb3NetworkId = Date.now();
var forkedWeb3Port = 21345;
var forkedTargetUrl = "ws://localhost:" + forkedWeb3Port;
var forkBlockNumber;

var initialDeployTransactionHash;
Expand Down Expand Up @@ -80,10 +82,11 @@ describe("Forking", function() {
// Do not change seed. Determinism matters for these tests.
seed: "let's make this deterministic",
ws: true,
logger: logger
logger: logger,
network_id: forkedWeb3NetworkId
});

forkedServer.listen(21345, function(err) {
forkedServer.listen(forkedWeb3Port, function(err) {
if (err) {
return done(err);
}
Expand Down Expand Up @@ -231,6 +234,11 @@ describe("Forking", function() {
});
});

it("should get the id of the forked chain", async() => {
const id = await mainWeb3.eth.net.getId();
assert.strictEqual(id, forkedWeb3NetworkId);
});

it("should fetch a contract from the forked provider via the main provider", function(done) {
mainWeb3.eth.getCode(contractAddress, function(err, mainCode) {
if (err) {
Expand Down

0 comments on commit 7279345

Please sign in to comment.