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

Commit

Permalink
convert bignumbers properly for forked fallback balance lookup
Browse files Browse the repository at this point in the history
also update the test to make sure the balance isn't too large
(which it was in this case)
for #128
  • Loading branch information
mikeseese committed Jun 29, 2018
1 parent c5efa4f commit c55aeb5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/utils/forkedblockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var Web3 = require("web3");
var to = require("./to.js");
var async = require("async");
var txhelper = require("./txhelper.js")
var BN = require("bn.js");

var inherits = require("util").inherits;

Expand Down Expand Up @@ -467,7 +468,7 @@ ForkedBlockchain.prototype.fetchBalanceFromFallback = function(address, block_nu
self.web3.eth.getBalance(address, safe_block_number, function(err, balance) {
if (err) return callback(err);

balance = "0x" + balance.toString(16); // BigNumber
balance = "0x" + new BN(balance).toString(16);
callback(null, balance);
});
});
Expand Down
10 changes: 10 additions & 0 deletions test/forking.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,21 @@ describe("Forking", function() {
// are hard to assert in this case.
assert(balanceBeforeFork.gt(balanceAfterFork));

// Make sure it's not substantially larger. it should only be larger by a small
// amount (<2%). This assertion was added since forked balances were previously
// incorrectly being converted between decimal and hex
assert(balanceBeforeFork.muln(0.95).lt(balanceAfterFork));

// Since the forked provider had once extra transaction for this account,
// it should have a lower balance, and the main provider shouldn't acknowledge
// that transaction.
assert(balanceLatestMain.gt(balanceLatestFallback));

// Make sure it's not substantially larger. it should only be larger by a small
// amount (<2%). This assertion was added since forked balances were previously
// incorrectly being converted between decimal and hex
assert(balanceLatestMain.muln(0.95).lt(balanceLatestFallback));

done();
});
});
Expand Down

0 comments on commit c55aeb5

Please sign in to comment.